Skip to content
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,34 @@ project uses [semantic versioning][semver].

### Fixed

- **A different card's manifest could clear a failed card's entry.** When
card A001 failed a clip and card A002 was offloaded into the same root,
A002's clip at the same relative path superseded A001's unhashed entry and
`verify` passed with A001's clip never copied. An unhashed entry is now
superseded only when both entries record the same source size and
modification date. A folder marker, or a file a cancelled job never
reached, records neither and is superseded only by a manifest naming the
same job; ASC MHL records no job name, so its markers and never-reached
entries are never superseded. Only an entry with no size or date counts as
a folder marker. Which entry is later is judged by the manifest that
recorded it, not by the newest generation of the history it was read from.
A classic manifest now records the job's own name, without the `-2` the
app's queue adds to a second entry for the same card, and names are
compared whole.
- **An ASC MHL history hid what its earlier generations recorded.** `verify`
checked only the newest generation, so a clip an earlier card's run had
recorded as failed passed once a second card wrote a generation of its own,
and files a `--skip-existing` rerun skipped were never re-hashed. A history
is now verified as one view: each path is judged by the latest generation
that lists it, each file is hashed once, and an earlier generation that
cannot be read is an error. An earlier failure is dropped only for a later
hashed record of the same source file, so a different card's clip at the
same path does not hide it.
- **`verify` on a folder could pass on files outside it.** A manifest under
`D2` listing `D1`'s files by absolute path or `..` made `verify D2` hash
`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.
- **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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,11 @@ destination, including any that failed (recorded with no checksum when none
could be taken), so a destination missing a clip fails here; every manifest
under the folder is checked, earlier runs' included. An entry a failed run could
not hash is reported as superseded, and stops failing, once a newer manifest for
the same destination lists that file with a hash that still matches; a hashed
entry is never superseded. See
the same destination lists that file with a hash that still matches and the
same source size and modification date; a hashed entry is never superseded. See
[`docs/data-safety.md`](docs/data-safety.md#a-manifest-lists-what-did-not-arrive).
Given a folder, an entry pointing outside it fails as `OUTSIDE` and is not read;
name the manifest file to verify it wherever its paths point.
`--allow-cache` skips the page-cache eviction: faster, and may verify memory
rather than the device.

Expand Down
13 changes: 10 additions & 3 deletions docs/ascmhl.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,16 @@ file checksum in its own right — `--hash c4`.
offloader verify D:\video\A001
```

Only the newest generation of a history is checked. Every generation covers the
same files, so verifying all of them would hash the media once per generation
for no additional evidence.
A history is checked as one view. A generation lists only what its own run
handled (a second card into the same root, a `--skip-existing` rerun), so the
newest one alone can omit a failure or a file an earlier one recorded. Every
path any generation lists is judged by the latest generation that lists it: a
`failed` or unhashed latest record fails, a hashed one is checked, and each
file is hashed once however many generations list it. An earlier failure is
dropped only for a later hashed record of the same source file (same size and
modification date); otherwise it is still reported. Directory hashes are the
newest generation's, over the files it lists. The rules and limits are in
[data-safety.md](data-safety.md#an-asc-mhl-history-is-verified-as-one).

Digests, file and directory alike, are compared per algorithm rather than as
plain strings. Hex formats compare case-insensitively, because a manifest is an
Expand Down
141 changes: 127 additions & 14 deletions docs/data-safety.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,30 @@ even when it sat inside destination 2, which then skipped its own: `verify` on
destination 2 re-hashed destination 1's copy and passed while its own copy was
corrupt.

### A folder is verified only by what is inside it

`verify D2` checks every manifest found under `D2`, and a manifest's paths
were never confined: one listing `D1`'s files, by absolute path or a run of
`..`, made `verify D2` hash `D1` and say VERIFIED about a folder it never read.
When `verify` is given a folder, an entry that resolves outside that folder now
fails as `OUTSIDE` and is not read, with the advice to verify the folder the
manifest describes or to name the manifest file itself. The check is on the
path as it would be opened (`..` resolved the way the long-path helpers
resolve it), not through links, so a destination reached through a junction
or a mapped drive still counts as itself.

Naming a classic manifest file directly is unconfined: its entries go wherever
its paths say, which is what an old manifest written to a separate report
folder, or one carrying absolute paths, needs. An ASC MHL path is always
confined to its history's root, the folder holding `ascmhl/`, file or folder,
because the format defines its paths as relative to it.

Nothing this tool writes is affected: a classic manifest always sits inside its
own destination and lists `../` paths that stay there, and a `--report-dir`
outside every destination receives no manifest. Pointing `verify` at a
`<name>_Reports` folder itself, rather than the destination holding it, now
fails as `OUTSIDE` instead of checking the media one level up.

### A manifest lists what did not arrive

A manifest used to list only the files that copied. A clip that failed was
Expand All @@ -211,39 +235,128 @@ Every file the job scanned is now listed for each destination:
An unhashed entry has nothing to pass against, so on its own it keeps failing.
After a failed run has been resumed, its manifest still lists the files it could
not read. When `verify` checks a folder, such an entry is **superseded** if a
newer manifest for the same destination root lists the same path with a hash
and that file matches it now. The entry is printed as `superseded by
<manifest>`, not dropped, and the older manifest passes only if nothing else in
it failed.
newer manifest for the same destination root lists the same path with a hash,
that file matches it now, and the two entries can be tied to the same source
(the same recorded size and last-modification date, or, for an entry that
records neither, the same job name). The entry is printed as `superseded by <manifest>`, not
dropped, and the older manifest passes only if nothing else in it failed.

Supersession runs one way only:

- Only an entry with no hash can be superseded. A hashed entry is never
answered by a later manifest, so a copy corrupted since an earlier run still
fails on that run's manifest, whatever a later run recorded.
- The size and date must agree because a path alone does not say which card a
file came from. Both are the *source* file's, so a rerun of the same card
records the same pair. Card A002 offloaded into the same root after card
A001 failed has its own `Clips/C0001.MXF`; without the check its manifest
answered A001's unhashed entry, and the tree read VERIFIED with A001's clip
never copied. Dates are compared as instants, so the same moment written
with a different UTC offset (MHL 1.1 writes local time, ASC MHL writes UTC)
matches, and a date with an offset never matches one without. An entry that
records one of the two and not the other is not superseded.
- A file a cancelled job never reached is recorded with neither a size nor a
date: the job knew its path and nothing else. Cancel and rerun is the
ordinary way to recover, so such an entry is superseded when the newer
manifest lists the same path with a hash that matches and both manifests
name the same job, the rule a folder marker gets below, with the same
limit. ASC MHL records no job name, so in an ASC MHL history such an entry
keeps failing `verify` after the rerun; the classic manifest of the same
jobs is answered.
- A folder marker (a source folder that could not be listed, or a skipped
link, recorded as one unhashed entry at the folder's path) is superseded by a
newer manifest for the same destination root when that manifest lists at
least one hashed file under the folder and every entry it lists under the
folder matched. Any unhashed, missing, mismatched or unreadable entry under
the folder keeps the marker failing: a rerun lists the files inside a folder,
never the folder itself, so exact-path matching could never clear it.
least one hashed file under the folder, every entry it lists under the
folder matched, and both manifests name the same job. Any unhashed, missing,
mismatched or unreadable entry under the folder keeps the marker failing: a
rerun lists the files inside a folder, never the folder itself, so
exact-path matching could never clear it. A marker records no size or date,
so the job name (MHL 1.1 `creatorinfo/name`) is what ties the rerun to the
card. Only an entry that records neither is treated as a marker: a failed
file records both, and files a later run lists under its path never answer
it. Names are compared whole, ignoring case. A manifest records the job's
own name: when the app's queue renames a second entry for a card `A001-2`

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.

Nonblocking suggestion to document the upgrade limit for older queue names

Older GUI releases recorded the queue's display name. I verified that a classic manifest stored as A001-2 in that situation keeps its folder marker unresolved after a successful A001 retry on this version. A literal card named A001-2 produces the same old metadata. A sentence here would explain the conservative result for existing archives.

to keep report folders apart, its manifest still says `A001`, so a queued
retry names the same job as the run it repeats. The suffix is never worked
back out of a name, since a card can really be called `A001-2` and
`Shoot-100` and `Shoot-101` are two jobs. ASC MHL records no job
name, so a marker in an ASC MHL history is never superseded and keeps
failing `verify` even after a rerun copied the folder. **Limit:** two
different cards given the same job name (a naming template without
`{card}`, or `--name` reused) still clear each other's folder markers and
never-reached entries; entries that record a size and date are protected
by them.
- Manifests written by an earlier version of the app recorded the queue's
name, suffix included. Such a manifest stored as `A001-2` is a different
job from `A001` here, so its folder markers and never-reached entries stay
unresolved after a retry on this version. That is the conservative
result: nothing in the old manifest says whether the `-2` was the queue's.
- Only a hashed entry that matched can supersede. A later run that could not
read the file lists it unhashed, and that entry fails on its own.
- "Newer" is the manifest's own recorded time (MHL 1.1 `finishdate`, ASC MHL
`creationdate`). When those are equal (two runs inside one second) or
missing, the numbering decides (`<name>_Reports-2`, `JobReport-2.mhl`), and
only between manifests in the same numbered series. File modification times
are never used. When neither says which is newer, nothing is superseded.
- "Newer" is judged entry by entry, by the manifest that recorded each one.
An ASC MHL history is read as one view (below), so its entries come from
several generations with different dates. A checksum generation 1 recorded
never answers a failure written after generation 1, however many
generations followed; and a repair written between two generations still
answers generation 1's failure. `superseded by` names the manifest that
recorded the answer.
- Same destination root means the root `verify` already derives for each
manifest: the folder above `<name>_Reports*`, or the folder above `ascmhl/`.
A manifest for a subfolder (another job whose destination was
`dst/Clips`) does not answer one for `dst`, even about the same file.
- Directory hash failures are not touched, so the ASC MHL false alarm after a
`--skip-existing` rerun (below) still fails.
- Directory hash failures are not touched: a manifest that has them still
fails.

Verifying a single `.mhl` file checks that file alone, so its unhashed entries
fail as before.
fail as before. An ASC MHL generation is the exception, since it is never the
whole record on its own: see "An ASC MHL history is verified as one" below.

### An ASC MHL history is verified as one

A generation lists only what its own run handled. Card A002 offloaded into the
root card A001 used writes a generation that lists A002's files alone, and a
`--skip-existing` rerun writes one that lists only what it copied. `verify`
used to check only the newest generation, so a clip A001's run had recorded
as failed or unhashed was never looked at and the tree read VERIFIED, and a
copy the rerun skipped was never re-hashed, however corrupt.

`verify` now reads every generation of a history as one view. Each path that
any generation lists is judged by the latest generation that lists it:

- A path whose latest record is labelled `failed`, or has no hash, fails as
`no hash`.
- An earlier failed or unhashed record is dropped only when the later record
of that path has a hash and the same source size and modification date,
the rule supersession uses between manifests. A different card's clip at
the same relative path is a later record of the path and no evidence the
first clip was copied, so the earlier failure is still reported, beside the
check of the later file. An earlier record with no size or date (a file a
cancelled job never reached) has nothing to compare and stays failing; see
the limit on job names above.
- A path whose latest record has a hash is checked against it, missing,
mismatched and unreadable all failing, even when the newest generation does
not list it. The verdict names the generation the record came from.
- Each file is hashed once per history, however many generations list it.
- An earlier generation that cannot be read stops `verify` with an error
(exit `2`) rather than being skipped, since it may hold the only record of
a failure.

This also happens when the newest generation is passed as a file: it stands
for the history up to itself. Directory and root hashes are still the newest
generation's own, recomputed over the files it lists, because that is all
they ever covered; a file recorded only in an earlier generation is checked
by its file hash and does not move a directory hash.

Still not covered: the directory hashes an *earlier* generation recorded are
not rechecked, so a rename of a file only an earlier generation lists is
caught as a missing file, not as a structure change. A path is matched by its
text, so a generation that renamed a file is not linked to the old name.
Generations are ordered by their sequence number, not by date.

### A manifest is never overwritten

Expand Down Expand Up @@ -326,9 +439,9 @@ known.
safety one, and should not be used on a tree whose integrity is in question.
Skipped files are left out of the rerun's manifest and the job reads
`Incomplete` (CLI exit `4`). An earlier classic manifest that covered them is
kept and still checked; an ASC MHL history checks only its newest
generation, which omits them, so its directory hashes fail `verify` after such
a rerun (a false alarm, in the safe direction).
kept and still checked, and so is an earlier ASC MHL generation that covered
them: a history is verified as one view (see above), so the skipped files
are re-hashed against the generation that last recorded them.
- **Concurrent instances.** One app instance serialises its queue. Two instances
pointed at the same destination are not coordinated.
- **Duplicate detection is a heuristic.** The fingerprint is the source's
Expand Down
7 changes: 6 additions & 1 deletion src/offloader/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,10 @@ def cmd_verify(args: argparse.Namespace) -> int:
from . import verify as verify_mod

target = Path(args.path)
# A folder is a claim about that folder, so every entry must stay inside
# it: a manifest found there that lists files elsewhere cannot pass it.
# A manifest named directly is taken at its word.
confine_to = None if target.is_file() else target
if target.is_file():
manifests = [target]
else:
Expand All @@ -637,7 +641,8 @@ def progress(index: int, total: int, path: Path) -> None:
for manifest in manifests:
try:
reports.append(verify_mod.verify_manifest(
manifest, progress=progress, bypass_cache=not args.allow_cache))
manifest, progress=progress, bypass_cache=not args.allow_cache,
confine_to=confine_to))
except Exception as exc:
print(f"error: could not read {manifest}: {exc}", file=sys.stderr)
worst = max(worst, 2)
Expand Down
7 changes: 7 additions & 0 deletions src/offloader/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,11 @@ class OffloadOptions:
#: order. See `order_for_transfer`.
proxies_first: bool = True
job_name: str | None = None
#: The job's own name when `job_name` was made unique by the queue; see
#: `Job.identity`. Leave unset when `job_name` is the name as given.
#: Keyword-only, so the fields after it keep the positions they had: a
#: caller passing `thumbnail_dir` tenth must not find it has named a job.
job_identity: str | None = field(default=None, kw_only=True)
thumbnail_dir: Path | None = None
extra_probe: bool = True
#: The workflow this offload is. `Profile.DATA` is a generic large-data
Expand Down Expand Up @@ -1196,6 +1201,7 @@ def run(source_root: Path, options: OffloadOptions,
verification=options.verification,
profile=options.profile,
hash_label=algorithm.label,
identity=options.job_identity,
started=_dt.datetime.now(),
os_version=host.os_version,
processors=host.processors,
Expand Down Expand Up @@ -1780,6 +1786,7 @@ def rescan(source_root: Path, destination_roots: Sequence[Path],
verification=options.verification,
profile=options.profile,
hash_label=algorithm.label,
identity=options.job_identity,
started=_dt.datetime.now(),
os_version=host.os_version,
processors=host.processors,
Expand Down
Loading
Loading