Open savuor opened 8 years ago
TODO: write a test for the following situation:
If everything is broken the way it described above then in description B metadata records will be loaded in the order [2, 1] which will produce an exception at saving.
UPD. This may work because of the following: In modules/vmdatasource/src/xmpmetadatasource.cpp:226:
stream.sortById();
The problem appears when disabling return codes in
MetadataStream::save()
andsaveTo()
methods (see PR #36). Test case TestSaveLoadReference.OneToOneReference fails because of incorrect procedure of metadata saving.In modules/vmdatasource/src/xmpmetadatasource.cpp:118:
That string deletes a branch from the syntax tree that XMP keeps internally.
After that the saving procedure writes metadata records, generating paths for them. In modules/vmdatasource/src/xmpmetadatasource.cpp:137:
Shortly, if there is an existing metadata record then save it using old path in the tree, if there's a new metadata record then append it to the tree.
This code works only if saving old records exactly in the order they were stored in the original file and only after that adding new items. Metadata removal should be performed separately from that procedure. If it's performed before then all paths are becoming outdated, that is why open/close or SerializeToBuffer/ParseFromBuffer routines should be performed after removal procedure.
Due to some concourse of circumstances in most cases the metadata records are saved in the described order. But in the test case TestSaveLoadReference.OneToOneReference we have a single metadata record that belongs to the description we didn't ask to load (but this record should be loaded because there's a reference pointing on it). Here we cannot guarantee the order of records and get an exception.
Moreover, here we drop the branch containing the metadata records for the same description that were not loaded. That's why opening and saving such a file will erase them.