#732955 exiv2: creates new file in wrong place when old file is a relative symlink

Package:
exiv2
Source:
exiv2
Description:
EXIF/IPTC/XMP metadata manipulation tool
Submitter:
"Adam M. Costello"
Date:
2013-12-23 02:57:09 UTC
Severity:
normal
#732955#5
Date:
2013-12-23 02:28:14 UTC
From:
To:
Dear Maintainer,

exiv2 version 0.18.2 fixed a bug related to symlinks, but the fix
introduced two more bugs.

exiv2 is designed to give the illusion of modifying a file in place, but
actually it creates the new file, removes the old file, and renames the
new file to the old name.

The old bug (already fixed): If the file was a symlink, it would become
a plain file, and the file it used to point to would be truncated.

First new bug: If the file is a relative symlink, exiv2 interprets it
relative to the current working directory, rather than relative to the
symlink, when deciding where to create the new file.

Second new bug: If the file is a symlink to another symlink, exiv2
follows only the first.  If the first symlink is relative, the other bug
happens too, otherwise the second symlink gets replaced by a plain file.

The relative-symlink bug is very dangerous, because it can cause an
unrelated file to be removed.  For example, given these files:

foo.jpg
dir/foo.jpg
dir/bar.jpg --> foo.jpg

The command 'exiv2 <options> dir/foo.jpg' will unlink and replace
./foo.jpg, not dir/foo.jpg.

My workaround may provide a hint about how to fix this:

# Assume $@ contains all desired exiv2 options except the filename,
# which is in $file.
file=`readlink -e "$file"`
exiv2 "$@" "$file"