Skip to content
Merged
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,35 @@ project uses [semantic versioning][semver].
`D1` and pass. Given a folder, an entry resolving outside it now fails as
`OUTSIDE` and is not read; a manifest named directly is unconfined. An ASC
MHL path must always stay inside its history's root.
- **The source could become its own "verified" copy.** A destination that
named the source in another case on a case-insensitive volume
(`/Volumes/a001` for `/Volumes/A001`), or a destination folder that was a
junction or symlink into the source, put each staging file beside its clip
and then replaced the clip with its own copy, and the job read Verified.
Destinations are now compared with the source and with each other by
identity as well as by resolved path, and every folder a copy is staged in
is checked before anything is written there; a file refused this way fails.
The ancestors are taken from the effective path, so a sibling destination
spelled `card/../backup` is still accepted while the source spelled with
`..` is still refused.
- **A leftover staging file could be certified and then destroyed.** A
source file named `*.offloader-partial` (a leftover on a re-offloaded
shuttle drive) was copied under that name, where a later file's staging
copy could truncate or delete it after it was reported Verified. Such files
are no longer copied; each one found by a scan is named in a job warning.
A timeline selection entry whose source or requested name carries the
suffix fails at every destination with a reason instead of being skipped,
so the job cannot read Verified with a chosen file missing.
- **A job name could put reports outside the destination.** `--name`, the
app's job name and the volume label were joined onto each destination as
`<name>_Reports` unsanitized, so `..\..\X` or `a/b` wrote reports elsewhere
and `a:b` failed on Windows. Every job name is now sanitized by the engine,
with a warning when a typed name had to change.
- **New reports could land in a copied reports folder on macOS.** The check
that keeps a job's reports out of a `<name>_Reports` folder being copied
compared names with `normcase`, which folds case on Windows only, so a
copied `a001_Reports/` and a job named `A001` shared one folder on APFS. It
now uses the flatten collision check's casefolded, NFC-normalized key.
- **A timeline offload could call a partial cut complete.** With nothing to
copy it printed "every reference is already here" and exited 0 while
references were missing or ambiguous, and with gaps to copy it reported
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,9 @@ The short version:
by the engine, so the CLI, GUI and library callers cannot disagree about it.
- Files are written under a `.offloader-partial` name and only moved into place
once complete and verified. A failed or interrupted copy never damages what
was already there and never leaves a plausible-looking filename.
was already there and never leaves a plausible-looking filename. A source
file already named like that is a leftover, and is reported rather than
copied.
- `--verify full` evicts each file from the page cache before reading it back,
because a read straight after a write is otherwise served from memory and
proves nothing about the device.
Expand Down
58 changes: 57 additions & 1 deletion docs/data-safety.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@ own source. The check lives in the engine, not the interface, so the CLI, the
GUI and library callers all get it — previously only the GUI checked, and the
CLI had nothing.

Comparing resolved paths is not enough on its own. POSIX `realpath` keeps the
case a path was typed in, so on APFS or exFAT `--source /Volumes/A001 --dest
/Volumes/a001` passed both checks; each staging file was written beside its
clip, and promotion replaced the clip with its own copy. Everything read
Verified and nothing existed off the card. A bind mount or a substituted drive
hides an alias from `realpath` on any platform. So destinations are also
compared with the source, and with each other, by identity (device and file
id): a destination that is the source, a destination with the source among its
existing ancestors, and two destinations that are one folder are all refused.
A destination that does not exist yet is judged by its nearest existing
ancestors. Those ancestors are taken from the effective path, with links and
`..` parts resolved, not from the spelling: `card/../backup` is the sibling
folder `backup` and is copied to, while `card/../card` and
`backup/../card/inner` still resolve into the source and are refused.

A safe destination root can still hold a folder that leads back into the
source: `dst/Clips` as a junction or symlink to `src/Clips`. Before anything is
staged or created in a folder, the copy checks that folder, by resolved path
and by identity along its existing ancestors, and refuses one that is or is
inside the source. A refused file fails at every destination with the reason,
so the job reads Failed, and nothing is created for it. `_copy_fanout`'s own
check now compares the staging path *and* the final name it will be promoted
to, by resolved path and by identity. Filesystems that report a file id of 0
are judged by resolved path alone.

### 2. A failed copy destroyed the good copy it was replacing

Re-running an offload over an existing archive, with the card failing partway:
Expand All @@ -63,6 +88,33 @@ the *right name* and the wrong length. That is the most dangerous artefact an
offload tool can produce — it survives a visual check, and it survives a
size-only comparison on the next run.

Cleanup deletes staging files and promotion replaces them, which is only safe
while no real final file carries the suffix. So a source file whose name ends
in `.offloader-partial` (compared case-insensitively) is never copied. It is a
leftover from an interrupted offload, typically on a shuttle drive being
offloaded again. It used to be copied like any other file, under a final name
that a later file's staging name could equal; that file was then truncated or
deleted after being reported Verified. Each one found by the scan is named in
a job warning saying it was not copied. It does not fail the job and has no
manifest entry: it is not card content, and an unhashed entry could never be
answered by a rerun. The scan applies the rule, so the copy, `report` and the
app's duplicate-card check all see the same file list.

A timeline selection is different, because every entry in it was chosen. One
whose source name or requested final name carries the suffix is never copied
and never skipped silently: it stays in the job as a file that failed at every
destination, with the reason, so the job reads Failed, the CLI exits 1, and
the manifest lists it. The rest of the selection is still copied and verified.

A file already sitting at a staging name at a destination is treated as this
tool's own leftover from a run that was killed mid-copy, and the next copy of
that file stages over it, as it always has. That is what keeps a crash from
stranding dead bytes on the destination. **Limit:** a version before this rule
could copy a leftover from a source and promote it under its staging name. If
such a file is still at a destination, a later copy of the file it shadows
(`x.mov` for `x.mov.offloader-partial`, in the same folder) overwrites it, and
the earlier manifest that listed it then fails `verify` as missing.

## What "verified" actually means

Three modes, and it is worth being precise about what each proves.
Expand Down Expand Up @@ -403,7 +455,10 @@ Re-offloading a previous destination (a shuttle drive holding
`A001/A001_Reports/`) used to write the new reports over the copied folder,
replacing files the job had just certified, the shuttle's own manifest among
them. The folder choice above covers that case too, with a warning naming the
folder used.
folder used. Copied folder names are compared casefolded and NFC-normalized on
every platform, as the flatten collision check compares paths, because the
destination may be case- or normalization-insensitive: a copied `a001_Reports/`
and a job named `A001` are one folder on APFS.

## Other things that are guarded

Expand All @@ -421,6 +476,7 @@ folder used.
| A source folder that cannot be listed | The job fails, naming the folder, and the CLI exits `1`. Its manifests carry an unhashed entry for the folder, so `verify` fails too. It used to be dropped silently and the job read Verified. |
| A file deleted after the scan | That file fails with "source vanished after scan"; the rest of the job carries on and its paperwork is written. |
| A different card with the same folder layout | A finished copy never replaces an existing destination file whose content differs. The existing file is hashed and compared; identical content is replaced (that changes nothing), different content fails that file with the reason and keeps the existing copy. `--replace-existing` (in the app, *Replace existing files whose content differs*, off by default) overrides this. |
| A job name that is not one plain folder name | `--name`, the app's job name, the source folder's name and the volume label (removable-media metadata) all become `<name>_Reports` inside each destination. Every one goes through `naming.sanitize`, so `..\..\X` or `a/b` cannot put reports outside the destination and `a:b` or a trailing dot cannot fail on Windows. A typed name that had to change is named in a warning with the name used. |
| A source that already holds `<name>_Reports` | Reports go to `<name>_Reports-2` (or the next free number) with a warning; the copied folder is left as copied. |
| Same-named clips in different folders | Thumbnail files are named by a hash of each clip's relative path, so one clip's frames never replace another's in the report. |
| Corrupt config file | Treated as empty. Config must never stand between someone and their card. |
Expand Down
Loading
Loading