fix(archive): weigh replaced originals against the archive, not this index

Owner review 2, phase 4b, fix round 2 (trash and sync).

- Emptying a Replaced entry decided "conversion deleted" from this host's index
  alone, so a conversion another host made, or one this index had not read yet,
  could be taken for deleted and its originals erased without re-hashing it. The
  survey now reads the archive: the sequence's sidecar where the index or the
  entry says it is, in the trash, or found by walking the archive's folders. Its
  Replaced tombstones are followed and every conversion it holds is re-hashed. A
  conversion counts as deleted only when the sidecar shows it (a Deleted
  tombstone, or the frame gone while every frame is hashed and no photo of the
  folder is unlisted), when the sequence is in the trash, or when no sidecar of it
  exists and this index has no row either. Whatever the archive cannot tell, or a
  converted frame whose file changed since, keeps the entry, and the job log says
  why (changed after the plan, sequence busy, conversion no longer matches,
  conversion not located).
- The erase weighs a Replaced entry under the entry's and the sequence's leases
  and settles the sequence first (an undo waiting for that entry's lease
  completes), so the entry it reads again and fingerprints is the one it erases.
  Read before the settle, a consumed entry's folder vanished under the erase.
- Each sidecar is indexed once per survey: one conversion's entry (every frame it
  swapped) is weighed in one pass, not one pass over the sidecar per photo.
- The desktop Empty confirmation names every entry whose conversion was deleted
  first, with why, wherever the trash lists it; the detail scrolls when long. The
  panel lists them first as well.
- Download originals queues the passes a frame swapped to another encoding
  cleared (light analysis, the deep analysis it had, thumbnails, proxies), as any
  replacement does.
- The job log lines of uploads and downloads are resources (en, it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 27d9a512183e64da9a3d7fa69a267470ca3ce744)
This commit is contained in:
Alby96 committed 2026-11-02 10:33:34 +01:00
1 parent c669d0504d
commit 48a0ce3e02
15 files changed
+834 -164

No files matched your search

@@ -627,12 +627,13 @@ public sealed partial class FrameTrash
/// <paramref name="sha256"/> and has no file, <paramref name="staged"/> takes its place (<see cref="ReplaceAsync"/>,
/// <see cref="FrameSwap.Missing"/>): the same id and index, the user's flags, a record read from the file as filing reads
/// one (named as the frame with the file's extension), the old content as its source and a tombstone naming the new one,
/// so the photo is neither filed twice nor missing. Nothing goes to the trash. False, nothing touched, when the frame
/// changed or its file is back.
/// so the photo is neither filed twice nor missing. Nothing goes to the trash. Returns the sequence as it is now and its
/// statuses before, whose passes (<see cref="FollowUps"/>) the swap cleared as any replacement does; null, nothing
/// touched, when the frame changed or its file is back.
/// </summary>
/// <param name="staged">The verified copy, inside the archive (its staging); moved in.</param>
/// <param name="fileName">The copy's name on the other side, whose extension the frame's file takes.</param>
internal async Task<bool> ReplaceMissingAsync(Archive archive, Guid sequenceId, Guid frameId, string sha256, string staged, string stagedSha256,
internal async Task<ReplaceResult?> ReplaceMissingAsync(Archive archive, Guid sequenceId, Guid frameId, string sha256, string staged, string stagedSha256,
string fileName, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(archive);
@@ -641,10 +642,9 @@ public sealed partial class FrameTrash
var metadata = Core.Metadata.MetadataReader.Read(staged, cancellationToken);
var extension = Path.GetExtension(fileName);
var swap = new FrameSwap(frameId, paths.ToRelative(staged), [], Named, Read) { Missing = true };
var replaced = await ReplaceAsync(archive, sequenceId, null, [swap], null, null, null,
return await ReplaceAsync(archive, sequenceId, null, [swap], null, null, null,
(manifest, _, _) => Task.FromResult(manifest.Frames.Any(f => f.Id == frameId && string.Equals(f.Sha256, sha256, StringComparison.OrdinalIgnoreCase))),
cancellationToken).ConfigureAwait(false);
return replaced is not null;
string Named(SidecarFrame current, SequenceManifest _) => extension.Length > 1 ? Path.ChangeExtension(current.File, extension) : current.File;