I'm trying to figure out what's the most efficient way to save a file package using NSFileWrapper
.
When I'm saving the file wrapper, I don't use atomic writing and hand in the URL of the previous contents.
However, the second write always fails with error: "Code=516 "The file “test.package” couldn’t be saved in the folder “tempfolder” because a file with the same name already exists."
NSError *error;
[wrapper writeToURL:fileURL options:0 originalContentsURL:fileURL error:&error];
STAssertNil(error, @""); // First time works (new file)
// Write a second time without changes
[wrapper writeToURL:fileURL options:0 originalContentsURL:fileURL error:&error];
STAssertNil(error, @""); // Fails with error 516, file already exists
Of course the file exists the second time, because I'm saving it a second time. What I would expect is that the saving succeeds without actually having to write out anything, because the contents have not changed.
The code above works when I use the flag NSFileWrapperWritingAtomic
, but this will write the entire contents to a temp file first, which is what I would like to avoid. Even if writing uses hard links for files, directories inside the file package will change, which leads to other side effects (iCloud reporting changes, although effectively no files have changed, only directory inodes).
Isn't there some sort of flag to have the file wrapper simply overwrite the existing file non-atomically?