Support for preserving file identity (inode/fileIndex).

#41 Merged at a06b2d5
Repository
h_schreiber
Branch
Preserve_CreationDate
Repository
ijabz
Branch
master
Author
  1. Hendrik Schreiber
Reviewers
Description

The general AudioFileWriter behavior is, that a temp file is created with the new contents, the original file is moved out of the way and then the temp file is moved in its place. This has the advantage that a copy operation may be avoided, if both the temp file and the original file live in the same filesystem.

Unfortunately, this behavior creates a completely new file. Some applications actually have the capability of remembering the file identity (i.e. the inode on Unix and fileIndex on Windows). These applications are confused, when the file identity suddenly changes.

The proposed fix allows the user to simply write over the existing original file instead of moving it out of the way and replacing it with the temp file. This preserves the file's identity.

The new behavior can be turned on/off via a switch in TagOptionSingleton, as it's probably not desirable for everyone. By default it is turned off.

The pull request also contains a small addition for the default behavior: If possible, the creation date is adjusted to mirror the original file. This does not work on all file systems, but fails silently (with a log message), if it does not.

Comments (8)

  1. IJabz repo owner

    Great I never thought of doing it this way. Im aware of the problem which is one reason why I have moved most formats to now use AudioFileWriter2 which does not do it this way, it just makes changes to the original file so doesnt change the creation date either. But your method is a good (possibly interim) solution for those formats we have not converted and I think it should be the default, Ill review it properly as soon as I can.

  2. Hendrik Schreiber author

    Ah! That's what AudioFileWriter2 is for! :-) Didn't realize that that was its purpose.

    I guess first writing to a temp file makes it a little bit more "transactional", if that's desired.

    Thanks for taking a look at it!

  3. IJabz repo owner

    The transactional thing was the original idea but it doesn't work well, too often we end up with tmp files remaining and user permissions sometimes allow editing files but not creating new ones that causes issues so I abandoned the transactional idea when I moved over to AudioFileWriter2, Will merge in.

  4. IJabz repo owner

    Hendrik, this test is failing on drone automated build, do you know why ?

    Failed tests: org.jaudiotagger.audio.generic.AudioFileWriterTest#testCreationTimeWithFileIdentityPreserved AssertionFailedError

  5. IJabz repo owner

    No it wasn't that, and it worked on my Windows machine only failed on drone.io but then i realized testFileIdentity() doesn't run on WIndows. I have found the problem the new creationtime was a couple of seconds out from the oldcreationtime that was causing the failure, Ive changed the test to have an allowance of 3 seconds