On Sun, Jun 16, 2019 at 10:31:50AM -0500, Ryan Coleman wrote:
> I have a platform I’m working on, Ubuntu 18.04.2 LTS, where I am trying to update files referenced through symlinks.
> 
> The one program I am using (exiv2) requires that the metadata file be the same name as the file it’s being applied to with the exception of the extension. No problem. 
> Except that to maintain the integrity of all my files and directories I have symlinks for everything in the directory structure. This works well for almost all needs except…
> 
> > root at server:/# /usr/bin/exiv2 -i X /storage/events-photos/outdoor/2019/folder1/folder2/filename-24996-ALA.JPG
> > /storage/events-photos/outdoor/2019/folder1/folder2/filename-24996-ALA.JPG: Could not write metadata to file: /storage/events-photos/outdoor/2019/folder1/folder2/filename-24996-ALA.JPG19518: Failed to rename file to /temp1/03942919-2C8E-F675-5BE8-7F82E060481E/CB2C28D6-5196-AB51-59C2-33F0ECD497D7: Invalid cross-device link (errno = 18)
> > 
> 
> Running the command in “debug” mode just adds one thing to give a hint...
> 
> > root at server:/# /usr/bin/exiv2 -Q d -i X /storage/events-photos/outdoor/2019/folder1/folder2/filename-24996-ALA.JPG
> > Info: Write strategy: Non-intrusive
> > /storage/events-photos/outdoor/2019/folder1/folder2/filename-24996-ALA.JPG: Could not write metadata to file: /storage/events-photos/outdoor/2019/folder1/folder2/filename-24996-ALA.JPG19522: Failed to rename file to /temp1/03942919-2C8E-F675-5BE8-7F82E060481E/CB2C28D6-5196-AB51-59C2-33F0ECD497D7: Invalid cross-device link (errno = 18)
> > root at d3photo_images:/# 

Hi Ryan

My guess is, the symlinks crosses filesystem boundaries. So the file
is in one filesystem and the symlink is in another filesystem.

The application is creating a new temporary file, next to the
symlink. It puts the new contents into this temporary file. It then
ask the kernel to rename the temporary file to the source jpg
file. This is guaranteed to be an atomic operation. If bad things
happen, you either get the old file, or the new file, but never no
file, 1/2 a file, etc. But you can only do a rename when the files are
on the same filesystem. The kernel however follows the symlink, sees
the destination is on a different filesystem and says no, sorry,
cannot do that atomically, and errors out. This is all well
documented, expected behaviour.

See

man 2 rename

    Andrew