fix(copies): close the owner review 6 verification findings

A merge could still trash photos it never verified, resume against a
pair the user had answered meanwhile, and take different unhashed
photos for copies; the dialog and the lists worded several facts
wrongly or lost them on refresh.

- Merge: a retry resumes only while the pair is still the job's;
  Verify requires the other archive online and its folder in place,
  stops on an unreadable photo, files a differing unhashed photo as a
  second version and must cover every frame before Trash; the plan
  hashes unmatched unhashed photos first, lists "Deleted in the other"
  and names the relinked servers; second versions stay discoverable
  (CopySides.VersionsAsync).
- Integrate: a retry after a failure before the journal runs again.
- Sync: a sequence back after a 404 stays Linked while its link holds;
  a local cull no longer asks for attention.
- Block lines of both planners name the right sequence, archive,
  server and space through one formatter.
- Compare dialog: one Details row per setting with worded values,
  Projects headings, Choose focuses the kept-sequence radios, the
  photo selection reaches rows outside the viewport, the Replace
  confirmation lists the losers per side, plan lines read as queued.
- Matches and Library: counts first and grouped, integrating shown as
  a share, local matches name the other archive, the Library keeps its
  match and "deleted on server" statuses across a refresh.

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 15:02:39 +01:00
1 parent d10577b175
commit b34b6b6fe0
41 files changed
+1046 -193

No files matched your search

+69 -8
View File
@@ -32,8 +32,14 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
private readonly CopySides _sides = sides ?? throw new ArgumentNullException(nameof(sides));
private readonly DbAccess _access = new(db.Database);
/// <summary>The name a server key is shown by (default: the key): the links a merge moves and the server both are linked to.</summary>
public Func<string, string?>? ServerNames { get; init; }
internal ChronosDatabase Db => _db;
/// <summary>The name <paramref name="key"/> is shown by.</summary>
internal string ServerName(string key) => ServerNames?.Invoke(key) is { Length: > 0 } name ? name : key;
internal ArchiveService Archives => _archives;
/// <summary>The handler of <see cref="JobKind.MergeSequences"/> jobs; register it on the <see cref="JobEngine"/>.</summary>
@@ -99,6 +105,13 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
var here = await _sides.LocalAsync(keep, ct).ConfigureAwait(false);
var there = await _sides.LocalAsync(drop, ct).ConfigureAwait(false);
var comparison = CopyComparer.Compare(here, there);
if (online && await HashOnlyThereAsync(comparison, there, dropPaths, ct).ConfigureAwait(false) is { } hashed)
{
// Compared by content now: a photo the kept sequence deleted reads Deleted here (a last copy when nothing else
// holds it), never a copy the kept sequence's tombstone refuses.
there = hashed;
comparison = CopyComparer.Compare(here, there);
}
var steps = new List<PhotoStep>();
var excluded = new List<string>();
foreach (var photo in comparison.Photos)
@@ -201,7 +214,8 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
var links = await _access.ListAsync("SELECT server, local_id FROM sync_links WHERE local_id = $1 OR local_id = $2", [keep, drop],
r => (Server: r.GetString(0), Local: r.GetGuid(1)), ct).ConfigureAwait(false);
var moved = links.Where(l => l.Local == drop).Select(l => l.Server).Distinct(StringComparer.Ordinal).Order(StringComparer.Ordinal).ToList();
if (links.GroupBy(l => l.Server, StringComparer.Ordinal).Any(g => g.Select(l => l.Local).Distinct().Count() > 1)) blocks.Add(CopyBlock.BothLinked);
var bothLinked = links.GroupBy(l => l.Server, StringComparer.Ordinal).FirstOrDefault(g => g.Select(l => l.Local).Distinct().Count() > 1)?.Key;
if (bothLinked is not null) blocks.Add(CopyBlock.BothLinked);
// The other goes to the trash.
var trash = await _archives.Trash.PlanAsync([drop], null, ct, exceptJob).ConfigureAwait(false);
@@ -220,7 +234,46 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
projects, sessionKeys, skippedKeys));
return new MergePlan(copyId, keep, drop, choices, steps, lastCopies, renders, payload, changes, projects, sessionKeys, skippedKeys, moved, trash,
copyBytes, free ?? -1, [.. blocks.Distinct()], keepRow.FramesVersion, keepRow.SettingsVersion, dropRow.FramesVersion, dropRow.SettingsVersion,
fingerprint);
fingerprint)
{
LinkNames = [.. moved.Select(ServerName)],
BothLinkedServer = bothLinked is null ? null : ServerName(bothLinked),
DeletedInOther = comparison.Photos.Count(p => p.Class == PhotoClass.DeletedThere),
};
}
/// <summary>
/// The other's unhashed photos only it holds, hashed now (in memory: a dry run writes nothing); null when there are none.
/// Matched by size and time only they would be copied blindly, even a photo whose content the kept sequence deleted.
/// </summary>
private async Task<CopySideInput?> HashOnlyThereAsync(CopyComparisonResult comparison, CopySideInput there, ArchivePaths dropPaths, CancellationToken ct)
{
var keys = comparison.Photos.Where(p => p.Class == PhotoClass.OnlyThere && p.Key.StartsWith(CopyComparer.UnhashedPrefix, StringComparison.Ordinal))
.Select(p => p.Key).ToHashSet(StringComparer.Ordinal);
if (keys.Count == 0) return null;
var photos = new List<CopyPhotoInput>(there.Photos.Count);
var changed = false;
foreach (var photo in there.Photos)
{
if (photo.Unusable || photo.Sha256 is { Length: > 0 } || !keys.Contains(CopyComparer.UnhashedKey(photo.Size, photo.CapturedAt, photo.FrameId))
|| await _db.Frames.GetAsync(photo.FrameId, ct).ConfigureAwait(false) is not { } frame)
{
photos.Add(photo);
continue;
}
try
{
var sha = await ContentHash.Sha256Async(dropPaths.FromRelative(frame.RelativePath), null, ct).ConfigureAwait(false);
photos.Add(photo with { Sha256 = sha.ToLowerInvariant() });
changed = true;
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
// Unreadable now: left as it is (the job's copy fails on it and says which file).
photos.Add(photo);
}
}
return changed ? there with { Photos = photos } : null;
}
/// <summary>
@@ -260,18 +313,26 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
{
var keep = await _db.Sequences.GetAsync(plan.KeepId, ct).ConfigureAwait(false);
var drop = await _db.Sequences.GetAsync(plan.DropId, ct).ConfigureAwait(false);
var (keepTitle, dropTitle) = (keep?.DisplayTitle ?? string.Empty, drop?.DisplayTitle ?? string.Empty);
return plan.Blocks[0] switch
return BlockText(plan, plan.Blocks[0], keep?.DisplayTitle ?? string.Empty, drop?.DisplayTitle ?? string.Empty);
}
/// <summary>
/// The sentence of <paramref name="block"/> of a merge plan, the one the dialog shows and the job fails with: the kept
/// sequence for space, the other for where it lies and its trash, the server both are linked to by its name.
/// </summary>
public static string BlockText(MergePlan plan, CopyBlock block, string keepTitle, string dropTitle, int unchosen = 1)
{
ArgumentNullException.ThrowIfNull(plan);
return block switch
{
CopyBlock.Busy => Loc.L("Errors.Copies.Busy"),
CopyBlock.ArchiveOffline => Loc.L("Errors.Copies.ArchiveOffline", dropTitle),
CopyBlock.FolderMoved => Loc.L("Errors.Copies.FolderMoved", dropTitle),
CopyBlock.ArchiveOffline or CopyBlock.FolderMoved or CopyBlock.ChangedFile => Loc.L("Errors.Copies." + block, dropTitle),
CopyBlock.NoSpace => Loc.L("Errors.Copies.NoSpace", keepTitle, Size(plan.CopyBytes + SpaceReserve)),
CopyBlock.BothLinked => Loc.L("Errors.Copies.BothLinked", string.Empty),
CopyBlock.BothLinked => Loc.L("Errors.Copies.BothLinked", plan.BothLinkedServer ?? string.Empty),
CopyBlock.UnsentWorkspace => Loc.L("Errors.Copies.Unsent", dropTitle),
CopyBlock.TrashBlocked => Loc.L("Errors.Copies.TrashBlocked", dropTitle,
plan.Trash.Blocked.Select(b => Loc.L("Archive.Delete.Reason." + b.Reason)).FirstOrDefault() ?? string.Empty),
CopyBlock.DetailsUnchosen => Loc.Plural("Errors.Copies.DetailsUnchosen", 1),
CopyBlock.DetailsUnchosen => Loc.Plural("Errors.Copies.DetailsUnchosen", Math.Max(1, unchosen)),
CopyBlock.KeptUnchosen => Loc.L("Errors.Copies.KeptUnchosen"),
_ => Loc.L("Errors.Copies.StalePlan"),
};