Skip to content

Keep copies out of the source, staging names out of the manifest, and job names inside the destination - #41

Merged
owenpkent merged 9 commits into
mainfrom
destination-identity
Nov 29, 2026
Merged

owenpkent merged 9 commits into
mainfrom
destination-identity

Conversation

@owenpkent

Copy link
Copy Markdown
Owner

What

Four engine fixes, one commit each, plus one follow-up commit from review.

  1. The source could become its own "verified" copy. Destination checks compared resolved paths only. On a case-insensitive volume under POSIX, or when a folder inside the destination was a junction or symlink into the source, each staging file was written beside its clip and then replaced it. Destinations are now also compared with the source, and with each other, by identity (device and file id), and every folder a copy is staged in is checked before anything is written there. A refused file fails at every destination, so the job reads Failed, and nothing is created for it.
  2. A leftover staging file could be copied as real content. A source file named *.offloader-partial is never copied now. Each one is named in a job warning. It does not fail the job and gets no manifest entry. The rule lives in scan, so the copy, report and the duplicate-card check see the same file list, and it applies to timeline selections too.
  3. A job name could put reports outside the destination. --name, the app's job name, the source folder name and the volume label all go through naming.sanitize in the engine, with a warning when a typed name had to change.
  4. Report-folder choice was case-sensitive on POSIX. choose_report_folder now uses the collision check's casefolded, NFC-normalized key.

Behaviour to know about

  • A file already at a staging name at a destination is still overwritten by the next copy of that file, as before. That keeps a crash from stranding leftovers. The one documented limit: a file that a version before this change promoted under a staging name is overwritten by a later copy of the file it shadows.
  • Identity comparison refuses two volumes that report the same device and file id (cloned volumes). That is the safe direction. Filesystems that report a file id of 0 are judged by resolved path alone.
  • Timeline selections do not get the per-folder guard, only the last-line check in the copy function: a selection's search roots may legitimately hold the destination.
  • Job warnings are printed by the CLI and shown in the app's completion dialog, but the PDF, HTML and CSV reports do not print them. That gap is older than this change and is tracked separately.

Tests

New tests in tests/test_data_safety.py, each run against the unfixed engine.py and failing there, with two exceptions that are platform guards on Windows: the native case-variant test and the linked-destination test already pass here because Windows resolves case. They become real regression tests on the macOS runner. test_a_rerun_clears_the_staging_file_a_killed_run_left is a guard for existing behaviour, not a failure proof.

No existing test was modified.

Checked

  • ruff check src tests: clean
  • Full suite on Windows, Python 3.12: 953 passed, 5 skipped
  • Property checks (--fuzz): 95 passed, 1 skipped

Destinations were compared with the source by resolved path only. POSIX realpath keeps the typed case, so on a case-insensitive volume a destination naming the source in another case passed, and a destination folder that was a junction or symlink into the source passed too. Each staging file was then written beside its clip and promoted over it, and the job read Verified with nothing off the card.

assert_safe_destinations now also compares by identity along each destination's existing ancestors, a per-directory guard refuses staging into any folder that is or is inside the source (the file fails, nothing is created), and the copy's last check covers the final name as well as the staging path, by resolved path and identity.
A source file named *.offloader-partial was copied like any other, under a final name that a later file's staging name could equal, so it could be truncated or deleted after being reported Verified. The scan now leaves such files out (casefolded) and reports each one as a job warning, without failing the job or adding a manifest entry; selections apply the same rule to source and final names.

A file already at a staging name is never opened with wb or deleted: the copy is staged under the next free staging name and a warning names the file left alone.
The job name, from --name, the app's job name, the source folder's name or the volume label, was joined onto each destination as <name>_Reports unsanitized. A traversal or separator in it wrote reports outside the destination, and a colon or trailing dot failed on Windows. Both places a Job is built now pass the final name through naming.sanitize, and a typed name that changed gets a warning naming the one used.
choose_report_folder compared copied folder names with os.path.normcase, a no-op on POSIX and blind to Unicode composition everywhere, so a copied a001_Reports/ and a job named A001 shared one folder on APFS. It now uses _collision_key, which casefolds and NFC-normalizes on every platform.
The previous commit staged a copy under the next free staging name whenever
a file was already at <name>.offloader-partial, and left that file alone.
After a crash that strands a clip-sized leftover on the destination on every
rerun, with nothing to clear it. No source file with the staging suffix is
copied any more, so a file at a staging name is this tool's own leftover and
the next copy of that file stages over it, as it always has. The one case
that differs, a file an earlier version promoted under a staging name, is
documented as a limit.
A fully verified job on a platform that cannot evict the page cache carries
that warning, so the plain-job-name test checks for the absence of a job
name warning instead of an empty list.

@owenpkent owenpkent left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A valid sibling destination can be rejected before copying starts. I confirmed the difference between the merge base and 2b4852b with the Windows CLI. Four focused tests passed for staging files, explicit selection, job names, and report-folder collisions. All nine GitHub checks passed.

Comment thread src/offloader/engine.py Outdated
Lexical ancestors of the absolute path, `..` and all, so a link part-way
up is examined as itself and as whatever it points at, via `stat`.
"""
absolute = Path(path).absolute()

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Check the ancestors of the effective destination

For a source named card and a destination spelled card/../backup, Path.absolute().parents includes card even though the destination resolves to its sibling. The identity comparison then rejects a valid transfer. The Windows CLI copied the fixture and exited 0 on the merge base. This head exited 3 before creating the backup.

Build the ancestor chain from the effective path after resolving links and parent components, including any suffix that has yet to be created. Add a regression for the sibling spelling alongside the existing alias and nested-destination cases.

@owenpkent owenpkent left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No new actionable findings at f38f7a3. The sibling-path regression is fixed. An explicitly selected file with a reserved source or delivery name now fails at every destination and stays in the manifest. Ordinary scans still exclude the reserved staging suffix as documented.

Eleven focused Windows tests passed for sibling paths, source aliases, destination identity, and explicit selections. All nine GitHub checks passed. The PR description still describes the previous warning-only behavior for explicit selections.

@owenpkent
owenpkent merged commit e05945e into main Nov 29, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant