fix/photorenamer-moveback #12

Merged
ludovic.terrier merged 6 commits from fix/photorenamer-moveback into master 2026-11-12 14:05:57 +01:00
Owner
No description provided.
exiftool -filename replaces a dangling symlink at the destination and
exits 0, so move_back destroyed a link that appeared at the picture's
old name and logged "picture moved back". The on-disk check passed
because the name then held a regular file. An earlier commit said
exiftool refuses any existing name; that holds for files, directories
and live links, not for a dangling link.

move_back now fails before it calls exiftool when the old name is a
link. The picture stays renamed and the existing "renamed to ... but
the sidecar was not moved" path reports it. No log message changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
exiftool -testname treats a dangling symlink as a free name, so its
counter does not move past it, and -filename then replaces the link and
exits 0. A link left at the computed name was destroyed by the rename.
This also applies to a Live Photo video, whose target has no counter.

The target is now refused when it is a link, in dry run and write mode,
like a sidecar target. A live link never reaches this check, because
-testname counts it as taken.

New log message, at error level, counted as a failure:
  <file> | rename skipped, target exists: <target>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mv -n moves the sidecar into a directory that appears at its target
name between the clash check and the move, exits 0, and leaves no
source behind, so the run reported the picture and its sidecar as
renamed while the sidecar sat inside that directory.

The sidecar now moves with exiftool -filename, like move_back. exiftool
refuses a file, a directory or a link to a directory at the target,
renames a .xmp whose content is not XMP, and renames a link sidecar as
the link. The target name comes from testname_base, so it has no "%".
The clash pre-checks stay. A dangling link put at the target after them
is replaced, as mv -n on macOS also does.

After the move, the target must be a file or a link and the source must
be gone, so an exiftool that exits 0 without the rename counts as a
failure. Shims test each clause: the source stays, the target is
missing, the source is left as a dangling link, and a link sidecar
whose referent goes away after a real move still counts as moved.

The test shims that failed mv for the sidecar now fail the exiftool
sidecar call, and the race shims match only the picture rename, so they
keep testing the same paths. A new test puts a directory at the sidecar
target before the move.

No info or error message changes. mv printed its own error on stderr;
exiftool's error now goes to the temp error file, and one new line at
debug level, shown only with -d, gives its first line:
  <file> | sidecar move: <first exiftool error line, or "no output from exiftool">

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Removing the on-disk check from move_back left the suite green: no test
had an exiftool that exits 0 on the move back. Each clause of the check
also needs its own case, since a move back that does nothing fails both.

Shims now lie on the move-back call after a failed sidecar move: they
do nothing, copy the picture to the old name and keep the renamed file
(only "the renamed file is gone" catches it), or remove the renamed
file and leave a directory or nothing at the old name (only "the old
name is a file" catches it). Each time the log says "renamed to ... but
the sidecar was not moved" and never "moved back". Removing the whole
check, or either clause alone, now fails a test.

Test-only change; no log message changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without exiftool on PATH, the guard test linked its shims to a fallback
path that may not exist. The suite then skipped the dangling shim, fell
back to its own exiftool dir and put that dir first on PATH, where a
real rm and mktemp would bypass the guard's shims. The guard cases could
then pass or fail for reasons unrelated to the guards they check.

The guard test now needs exiftool on PATH: it takes the path from
type -P, requires it to be absolute and executable, and otherwise exits
1 with "exiftool not found" before it creates or removes anything. Its
fallback path is dropped: with it, a machine that has that path would
never reach the check. A new case runs the guard test with no exiftool
on PATH, and with rm and mktemp shims that log each call. It expects
status 1, the message, and no rm or mktemp call.

The suite keeps its fallback path, so it still runs from a PATH without
exiftool, but stops the same way when neither exists, before it changes
PATH or makes its work dir.

New stderr line in both test scripts, not in photorenamer.sh:
  exiftool not found

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With a work dir path that holds a space, the unquoted R= and O= in the
move-back lie shim ran part of the path as a command, so the copy case
no longer reached its check: dropping [ ! -e "$1" ] from move_back
passed the suite. The suite's exiftool check now matches the guard
test's: an absolute, executable path from type -P.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ludovic.terrier/scripts!12
No description provided.