This fixes the issue reported at #619.
FilePrivate() :
tag(0),
atoms(0),
- properties(0),
- hasMP4Tag(false) {}
+ properties(0) {}
~FilePrivate()
{
MP4::Tag *tag;
MP4::Atoms *atoms;
MP4::Properties *properties;
-
- bool hasMP4Tag;
};
MP4::File::File(FileName file, bool readProperties, AudioProperties::ReadStyle) :
return;
}
- if(d->atoms->find("moov", "udta", "meta", "ilst")) {
- d->hasMP4Tag = true;
- }
-
d->tag = new Tag(this, d->atoms);
if(readProperties) {
d->properties = new Properties(this, d->atoms);
return false;
}
- const bool success = d->tag->save();
- if(success) {
- d->hasMP4Tag = true;
- }
-
- return success;
+ return d->tag->save();
}
bool
MP4::File::hasMP4Tag() const
{
- return d->hasMP4Tag;
+ return (d->atoms->find("moov", "udta", "meta", "ilst") != 0);
}
* Save the file.
*
* This returns true if the save was successful.
- *
- * \warning In the current implementation, it's dangerous to call save()
- * repeatedly. At worst it will corrupt the file.
*/
bool save();
updateParents(path, data.size());
updateOffsets(data.size(), offset);
+
+ // Insert the newly created atoms into the tree to keep it up-to-date.
+
+ d->file->seek(offset);
+ path.back()->children.prepend(new Atom(d->file));
}
void
CPPUNIT_TEST(testCovrRead2);
CPPUNIT_TEST(testProperties);
CPPUNIT_TEST(testFuzzedFile);
+ CPPUNIT_TEST(testRepeatedSave);
CPPUNIT_TEST_SUITE_END();
public:
CPPUNIT_ASSERT(f.isValid());
}
+ void testRepeatedSave()
+ {
+ ScopedFileCopy copy("no-tags", ".m4a");
+
+ MP4::File f(copy.fileName().c_str());
+ f.tag()->setTitle("0123456789");
+ f.save();
+ f.save();
+ CPPUNIT_ASSERT_EQUAL(2862L, f.find("0123456789"));
+ CPPUNIT_ASSERT_EQUAL(-1L, f.find("0123456789", 2863));
+ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestMP4);