fix(copies): close the fifth verification round of owner review 6

The metered hold now records the jobs it paused in the index and forgets
any job the user pauses, resumes, retries or cancels, so it never resumes
a pause of the user's and still resumes its own after a restart.

Drop... reports why its dry run is blocked instead of asking first, and
dropping the version Main uses lets Main use the version that stays,
with its hero and keyframes. That version reads "In Main".

Merges:
- A re-plan no longer hashes the other's photos again.
- A resumed merge verifies photos flagged damaged while it waited.
- A merge is blocked while the other's folder holds photos the index
  has not read; this is checked again under the lease before the trash.
- Choose each offers Keep both, Kept and Other, and blocks until every
  differing photo is chosen.
- Classes are named by role.

The Compare dialog:
- Its headings stay over their columns.
- The Projects part scrolls.
- Every confirmation line carries its own prefix, and a merge's facts
  carry none.
- A server card in a match offers Compare... alone.

The Italian strings follow the glossary.

Finding 9 (a local drop counting 0 photos) is not reproduced; a test now
keeps the count at 2.

Refs #73

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-17 20:51:23 +01:00
1 parent 2c06e7ac2b
commit bf7701d279
159 files changed
+1759 -126

No files matched your search

@@ -518,10 +518,12 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
var drop = await _db.Sequences.GetAsync(journal.DropId, _ct).ConfigureAwait(false) ?? throw Changed(_dropTitle);
if (drop.FramesVersion != journal.DropFramesVersion) throw Changed(_dropTitle);
EnsureDropReadable(drop);
await EnsureFolderReadAsync(drop).ConfigureAwait(false);
var keepFrames = await ProcessingFrames.ListAsync(_db, journal.KeepId, _ct).ConfigureAwait(false);
var dropFrames = (await ProcessingFrames.ListAsync(_db, journal.DropId, _ct).ConfigureAwait(false))
.Where(f => (f.Flags & CopySides.UnusableFlags) == 0).ToList();
var total = keepFrames.Count + dropFrames.Count;
var allDrop = await ProcessingFrames.ListAsync(_db, journal.DropId, _ct).ConfigureAwait(false);
var dropFrames = allDrop.Where(f => (f.Flags & CopySides.UnusableFlags) == 0).ToList();
var flagged = allDrop.Where(f => (f.Flags & CopySides.UnusableFlags) != 0).ToList();
var total = keepFrames.Count + dropFrames.Count + flagged.Count;
var done = 0;
// What the kept sequence holds now, hashed again.
@@ -583,10 +585,96 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
foreach (var sha in failed.Select(f => f.Sha256).Distinct(StringComparer.Ordinal))
if (!journal.SettledElsewhere.Contains(sha)) journal.SettledElsewhere.Add(sha);
}
await VerifyFlaggedAsync(flagged, held, done, total).ConfigureAwait(false);
journal.VerifiedDropFramesVersion = drop.FramesVersion;
Save();
}
/// <summary>
/// The plan's damaged-photo rule again (design §5d; owner Q2): a frame of the other a verify flagged Corrupt, or Missing
/// although its file is back, changes no frames version, so one flagged since the plan was never listed. Each such
/// frame whose file is there is hashed now (its recorded hash says nothing of it) and must be held by the kept
/// sequence (hashed again above), be a last copy the plan listed, or be held by another sequence of this index.
/// Otherwise, or when the file cannot be read, the merge stops and is planned again, where the plan shows the block.
/// </summary>
private async Task VerifyFlaggedAsync(IReadOnlyList<Frame> flagged, Dictionary<string, Guid> held, int done, int total)
{
var elsewhere = new List<(Guid FrameId, string Sha256)>();
foreach (var frame in flagged)
{
_ct.ThrowIfCancellationRequested();
await context.ReportAsync(Done(), Total, new JobDetail(JobStep.Verify, frame.FileName, ++done, total)).ConfigureAwait(false);
var path = _dropPaths.FromRelative(frame.RelativePath);
if (!File.Exists(path)) continue;
string? sha;
try
{
sha = await HashAsync(path).ConfigureAwait(false);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
ForgetJournal();
throw new InvalidOperationException(Loc.L("Errors.Copies.DamagedPhotos", _dropTitle), ex);
}
if (sha is null) continue;
if (!journal.FlaggedVerified.Contains(frame.Id)) journal.FlaggedVerified.Add(frame.Id);
if (held.TryGetValue(sha, out var keepFrame))
{
journal.Verified[frame.Id] = new MergeVerified(sha, keepFrame);
continue;
}
if (journal.Absent.Contains(sha))
{
if (!journal.Settled.Contains(frame.Id)) journal.Settled.Add(frame.Id);
continue;
}
elsewhere.Add((frame.Id, sha));
}
if (elsewhere.Count == 0) return;
var others = await new CopySides(_db).HeldElsewhereAsync([.. elsewhere.Select(f => f.Sha256)], [journal.DropId, journal.KeepId], _ct)
.ConfigureAwait(false);
if (elsewhere.Any(f => !others.Contains(f.Sha256)))
{
ForgetJournal();
throw new InvalidOperationException(Loc.L("Errors.Copies.DamagedPhotos", _dropTitle));
}
foreach (var (frameId, sha) in elsewhere)
{
if (!journal.Settled.Contains(frameId)) journal.Settled.Add(frameId);
if (!journal.SettledElsewhere.Contains(sha)) journal.SettledElsewhere.Add(sha);
}
}
/// <summary>
/// The other's folder is as this index last read it (<see cref="SequenceMerger.FolderChangedAsync"/>): photos copied in
/// by hand or filed by another index sharing the archive would otherwise go to the trash unread. Asked at the verify
/// and before the links stage, which rewrites the other's sidecar without recording the folder's stamps.
/// </summary>
private async Task EnsureFolderReadAsync(Sequence drop)
{
if (!await owner.Merger.FolderChangedAsync(_dropArchive, _dropPaths, drop, _ct).ConfigureAwait(false)) return;
ForgetJournal();
throw new InvalidOperationException(Loc.L("Errors.Copies.FolderChanged", _dropTitle));
}
/// <summary>
/// At the trash, under the other's lease (after the links stage rewrote its sidecar): no photo was copied in or removed
/// since this index last read its folder, and its sidecar's frames are still those the verify read.
/// </summary>
private async Task<bool> FolderStillReadAsync(SequencePaths folder, CancellationToken ct)
{
if (await owner.Archives.Indexer.PhotosChangedAsync(_dropArchive, folder, ct).ConfigureAwait(false)) return false;
if (!File.Exists(folder.ManifestPath)) return true;
try
{
return ManifestStore.ReadSequence(folder.ManifestPath).Versions.Frames == journal.VerifiedDropFramesVersion;
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or System.Text.Json.JsonException)
{
return false;
}
}
private async Task<string?> HashAsync(string path)
{
try
@@ -759,7 +847,7 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
if (journal.LinksUndo is null)
{
// Nothing of the other is touched while a check before the trash can still abandon the merge.
await CheckTrashAsync(drop).ConfigureAwait(false);
await CheckTrashAsync(drop, beforeLinks: true).ConfigureAwait(false);
await using (await owner.Archives.Writer.LockAsync(keepPaths, journal.KeepId, _ct).ConfigureAwait(false))
await PlanTrashAsync().ConfigureAwait(false);
journal.LinksUndo = new MergeLinksUndo(KeysOf(keepPaths, keep), KeysOf(_dropPaths, drop), _dropArchive.Id,
@@ -822,7 +910,7 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
/// unsent workspace work, no work saved into the other since the plan, the other at the frames version the verify read
/// and readable. Returns that frames version.
/// </summary>
private async Task<int> CheckTrashAsync(Sequence drop)
private async Task<int> CheckTrashAsync(Sequence drop, bool beforeLinks = false)
{
if (await owner.Workspace.HasUnsentAsync(journal.DropId, _ct).ConfigureAwait(false))
throw new InvalidOperationException(Loc.L("Errors.Copies.Unsent", _dropTitle));
@@ -835,6 +923,7 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
var expected = journal.VerifiedDropFramesVersion ?? throw Changed(_dropTitle);
if (drop.FramesVersion != expected) throw Changed(_dropTitle);
EnsureDropReadable(drop);
if (beforeLinks) await EnsureFolderReadAsync(drop).ConfigureAwait(false);
return expected;
}
@@ -859,12 +948,14 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
var plan = await PlanTrashAsync().ConfigureAwait(false);
try
{
await owner.Archives.Trash.DeleteAsync(plan, null, null, _ct, journal.JobId, new Dictionary<Guid, int> { [journal.DropId] = expected })
.ConfigureAwait(false);
await owner.Archives.Trash.DeleteAsync(plan, null, null, _ct, journal.JobId, new Dictionary<Guid, int> { [journal.DropId] = expected },
FolderStillReadAsync).ConfigureAwait(false);
}
catch (StaleDeletePlanException ex)
{
throw new InvalidOperationException(Loc.L("Errors.Copies.Changed", _dropTitle), ex);
// Photos copied into the other since the verify (a scan reads them), or its frames moved: planned again.
ForgetJournal();
throw new InvalidOperationException(Loc.L("Errors.Copies.FolderChanged", _dropTitle), ex);
}
}
context.Log(Loc.L("Archive.Log.MergeTrashed", _dropTitle));
@@ -908,6 +999,13 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
var dropFrames = await ProcessingFrames.ListAsync(_db, journal.DropId, _ct).ConfigureAwait(false);
if (dropFrames.Any(f => (f.Flags & CopySides.UnusableFlags) == 0 && !journal.Verified.ContainsKey(f.Id) && !journal.Settled.Contains(f.Id)))
throw Changed(_dropTitle);
// A frame flagged Missing or Corrupt since the verify, its file there: never hashed as such, so planned again.
if (dropFrames.Any(f => (f.Flags & CopySides.UnusableFlags) != 0 && !journal.FlaggedVerified.Contains(f.Id)
&& File.Exists(_dropPaths.FromRelative(f.RelativePath))))
{
ForgetJournal();
throw new InvalidOperationException(Loc.L("Errors.Copies.DamagedPhotos", _dropTitle));
}
// The photos a third sequence held at the verify: one it no longer holds would leave only with the other, never
// listed as a last copy. Planned again, the plan lists it.