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

Upload again now deletes the gone pair row once the new sequence is linked, so
the pair stops reading "deleted on server" or "kept here". A linked upload the
server refuses into its sequence (403 for an account without Edit that does not
own it) falls back to ordinary uploads instead of failing; an Integrate that
would add photos to such a sequence is blocked in its plan (NoAddRight).
Automatic photo transfers pause on a metered connection whatever the option
says. Integrate trashes server photos only against the manifest version that
checked the winner, and a merge is blocked while the other sequence holds a
damaged photo nothing else holds (DamagedPhotos), so nothing unverified reaches
the trash.

The plan and the confirmations now say what really happens: replaced versions
are no longer counted as kept, a merge lists the kept sequence's replaced
photos, plan lines use the text colour, an integrated pair that left photos out
says new photos move by hand, and a merging pair reads "merging" with its
progress. The Compare dialog gets per-side tooltips, class sizes for both
sides, policy-aware class tooltips, column headings and readable file names;
the sync table shows "deleted there" with Review and warns on skipped rows; the
Edit picker names the server, the Library card shows the match status second,
a deleted server sequence is named instead of "0 photos", and the match
tooltips stop calling a sequence a copy. The capture scenes use the server
name, the link names and consistent sample sizes.

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 16:08:49 +01:00
1 parent b34b6b6fe0
commit 9657c1711d
44 files changed
+802 -128

No files matched your search

+34 -1
View File
@@ -144,6 +144,10 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
var losers = steps.Where(s => s.Action == PhotoAction.TrashHere).Select(s => s.FrameId!.Value).ToHashSet();
var keepHolds = here.Photos.Where(p => !p.Unusable && p.Sha256 is { Length: > 0 } && !losers.Contains(p.FrameId))
.Select(p => p.Sha256!.ToLowerInvariant()).ToHashSet(StringComparer.Ordinal);
// Photos of the other a verify flagged Corrupt (changed since import, or damaged) whose file is still there: the
// comparison leaves them out, so nothing would copy or hash-verify them before their folder goes to the trash. One
// whose content now nothing else holds (an edited photo's only copy) blocks the merge until it is resolved.
if (online && await DamagedAsync(drop, dropPaths, keepHolds, ct).ConfigureAwait(false)) blocks.Add(CopyBlock.DamagedPhotos);
var absent = new List<CopyPhotoInput>();
foreach (var frame in there.Photos.Where(p => !p.Unusable && p.Sha256 is { Length: > 0 }))
{
@@ -276,6 +280,35 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
return changed ? there with { Photos = photos } : null;
}
/// <summary>
/// Whether the other sequence holds a frame flagged Corrupt (not Missing) whose file is still there and whose content,
/// hashed now (in memory), neither the kept sequence (<paramref name="keepHolds"/>) nor any other sequence of this
/// index holds; an unreadable such file counts too.
/// </summary>
private async Task<bool> DamagedAsync(Guid drop, ArchivePaths dropPaths, IReadOnlySet<string> keepHolds, CancellationToken ct)
{
var flagged = (await _db.Frames.ListBySequenceAsync(drop, cancellationToken: ct).ConfigureAwait(false))
.Where(f => (f.Flags & FrameFlags.Corrupt) != 0 && (f.Flags & FrameFlags.Missing) == 0).ToList();
var hashes = new List<string>();
foreach (var frame in flagged)
{
var path = dropPaths.FromRelative(frame.RelativePath);
if (!File.Exists(path)) continue;
try
{
var sha = (await ContentHash.Sha256Async(path, null, ct).ConfigureAwait(false)).ToLowerInvariant();
if (!keepHolds.Contains(sha)) hashes.Add(sha);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
return true;
}
}
if (hashes.Count == 0) return false;
var held = await _sides.HeldElsewhereAsync(hashes, [drop], ct).ConfigureAwait(false);
return hashes.Any(h => !held.Contains(h));
}
/// <summary>
/// Queues the job that applies <paramref name="plan"/>: the pair goes to <see cref="CopyState.Integrating"/> (its state
/// before kept as the previous one), the job targets the kept sequence, then the other (both held from other jobs).
@@ -326,7 +359,7 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
return block switch
{
CopyBlock.Busy => Loc.L("Errors.Copies.Busy"),
CopyBlock.ArchiveOffline or CopyBlock.FolderMoved or CopyBlock.ChangedFile => Loc.L("Errors.Copies." + block, dropTitle),
CopyBlock.ArchiveOffline or CopyBlock.FolderMoved or CopyBlock.ChangedFile or CopyBlock.DamagedPhotos => 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", plan.BothLinkedServer ?? string.Empty),
CopyBlock.UnsentWorkspace => Loc.L("Errors.Copies.Unsent", dropTitle),
+1 -1
View File
@@ -503,7 +503,7 @@ public sealed class CopyEngine(SyncService sync, ArchiveService archives, Integr
if (here is null && there is null) continue;
var local = await Db.Sequences.GetAsync(pair.LocalId, ct).ConfigureAwait(false);
twins.Add(new CopyTwin(pair.Id, pair.LocalId, local is null ? string.Empty : archives.GetValueOrDefault(local.ArchiveId) ?? string.Empty, here, pair.Server!,
pair.RemoteId!.Value, there));
pair.RemoteId!.Value, there, ServerName(pair.Server!)));
}
return twins;
}
+11 -1
View File
@@ -46,6 +46,12 @@ public enum CopyBlock
TrashBlocked,
KeptUnchosen,
ChangedFile,
/// <summary>Photos sent into a server sequence the account neither owns nor may edit (the server refuses that, 403).</summary>
NoAddRight,
/// <summary>The other sequence of a merge holds photos a verify flagged changed or damaged: they would go to the trash unchecked.</summary>
DamagedPhotos,
}
/// <summary>The choices of an Integrate: photo policy, per-photo choices (by photo key), per-detail sides (by path), projects.</summary>
@@ -114,7 +120,11 @@ public sealed record MergePlan(Guid CopyId, Guid KeepId, Guid DropId, MergeChoic
/// </summary>
public sealed record CopyPlanContext(string PcName, string? ServerName, bool CanUpload, bool CanFetch, bool CanEdit, bool CanDelete,
bool OwnsOrAdmin, bool KeepsProjects, long? QuotaLeft, IReadOnlySet<Guid> UnsentWorkspaceSequences,
IReadOnlySet<Guid> ServerOriginalsArchives);
IReadOnlySet<Guid> ServerOriginalsArchives)
{
/// <summary>The signed-in account's id: it owns a server sequence whose owner it is (null: unknown, signed out).</summary>
public Guid? UserId { get; init; }
}
/// <summary>The server-side dry run of moving photos of a pair's server sequence to the server's trash (design §6.2).</summary>
public sealed record TrashTherePlan(Guid CopyId, string Server, Guid RemoteId, IReadOnlyList<Guid> FrameIds, IReadOnlyList<string> Keys, int Photos,
+3 -1
View File
@@ -38,5 +38,7 @@ public sealed record FoundCopyView(FoundCopy Copy, CopyFacts Here, CopyFacts The
/// <summary>
/// The same time-lapse with workspace projects at two homes (a linked or integrated pair): the Edit picker marks each as the
/// other's twin. LocalHome names the local copy's archive; a project name is null when that home has no workspace project.
/// ServerName is the name shown for Server (the key itself when no name is known).
/// </summary>
public sealed record CopyTwin(Guid CopyId, Guid LocalId, string LocalHome, string? LocalProject, string Server, Guid RemoteId, string? ServerProject);
public sealed record CopyTwin(Guid CopyId, Guid LocalId, string LocalHome, string? LocalProject, string Server, Guid RemoteId, string? ServerProject,
string ServerName);
+8 -1
View File
@@ -163,7 +163,8 @@ public sealed class FoundCopyStore(ChronosDatabase db, TimeProvider? time = null
/// <summary>
/// The row of a link (evidence Link, state Linked) when it has none; the link's row otherwise kept (moved to Linked when it
/// was a Candidate). Any other Linked or Integrated row of the same server sequence, or of the same local sequence and
/// server, is demoted to Candidate (a link re-pointed to another copy: sync_links holds one link per side and server).
/// server, is demoted to Candidate (a link re-pointed to another copy: sync_links holds one link per side and server); the
/// local copy's rows with another server sequence that answered 404 are deleted (Upload again).
/// </summary>
public Task<FoundCopy> EnsureLinkedAsync(string server, Guid remoteId, Guid localId, CancellationToken ct)
{
@@ -186,6 +187,12 @@ public sealed class FoundCopyStore(ChronosDatabase db, TimeProvider? time = null
[row.Id, false, now], ct).ConfigureAwait(false);
}
await DemoteAsync(inner, server, remoteId, localId, now, ct).ConfigureAwait(false);
// The rows of the local copy with a server sequence that server answered 404 for (design §6.3, "Upload again
// deletes the gone row"), Candidate and Kept apart included: the local copy is linked to another sequence now, and a
// gone sequence listed again is found anew.
await inner.ExecuteAsync(
$"DELETE FROM found_copies WHERE kind = 0 AND server = $1 AND local_id = $3 AND remote_id <> $2 AND remote_gone_hits >= 1 AND {Effective} <> 3",
[server, remoteId, localId], ct).ConfigureAwait(false);
return (await inner.SingleAsync($"{Select} WHERE id = $1", [row.Id], Map, ct).ConfigureAwait(false))!;
}
@@ -349,8 +349,10 @@ internal sealed class IntegrateJobHandler(SyncService sync, IntegratePlanner pla
}
try
{
var dryRun = await remote.DeleteFramesAsync(journal.RemoteId, new FrameDeleteRequest([step.FrameId], null, DryRun: true), _ct).ConfigureAwait(false);
await remote.DeleteFramesAsync(journal.RemoteId, new FrameDeleteRequest([step.FrameId], dryRun.FramesVersion, DryRun: false), _ct).ConfigureAwait(false);
// At the frames version of the manifest that showed the winner in place: a server sequence changed since (the
// winner trashed or replaced by another client) refuses the delete, and the loser stays.
await remote.DeleteFramesAsync(journal.RemoteId, new FrameDeleteRequest([step.FrameId], manifest.FramesVersion, DryRun: true), _ct).ConfigureAwait(false);
await remote.DeleteFramesAsync(journal.RemoteId, new FrameDeleteRequest([step.FrameId], manifest.FramesVersion, DryRun: false), _ct).ConfigureAwait(false);
journal.TrashedThere.Add(step.Key);
Save();
}
@@ -199,6 +199,10 @@ public sealed class IntegratePlanner(SyncService sync, CopySides sides, ProjectS
// Rights.
if (steps.Any(s => s.Action is PhotoAction.Send or PhotoAction.SendVersion) && !context.CanUpload) blocks.Add(CopyBlock.NoUploadRight);
// Sent into the server sequence: the server allows that to its owner, an admin or an account with Edit only.
var owns = context.OwnsOrAdmin || (context.UserId is { } me && dto.OwnerUserId == me);
if (steps.Any(s => s.Action is PhotoAction.Send or PhotoAction.SendVersion) && context.CanUpload && !owns && !context.CanEdit)
blocks.Add(CopyBlock.NoAddRight);
if (steps.Any(s => s.Action is PhotoAction.Fetch or PhotoAction.FetchVersion) && !context.CanFetch) blocks.Add(CopyBlock.NoFetchRight);
// Nothing left but versions whose loser stays for want of the Delete right: there is nothing to integrate.
if (dropped.Count > 0 && steps.All(s => dropped.Contains(s.Key)) && payload is null && projectSteps.Count == 0) blocks.Add(CopyBlock.NoDeleteRight);
@@ -232,6 +236,7 @@ public sealed class IntegratePlanner(SyncService sync, CopySides sides, ProjectS
CopyBlock.NoUploadRight => Loc.L("Errors.Copies.NoUploadRight"),
CopyBlock.NoFetchRight => Loc.L("Errors.Copies.NoFetchRight"),
CopyBlock.NoEditRight => Loc.L("Errors.Copies.NoEditRight"),
CopyBlock.NoAddRight => Loc.L("Errors.Copies.NoAddRight"),
CopyBlock.NoDeleteRight => Loc.L("Errors.Copies.NoDeleteRight"),
CopyBlock.LinkTaken => Loc.L("Errors.Copies.LinkTaken", title, server),
CopyBlock.NoSpace => Loc.L("Errors.Copies.NoSpace", title, Size(plan.FetchBytes + SpaceReserve)),
+11
View File
@@ -405,6 +405,17 @@ public sealed class SyncService
EnqueueAsync(engine, JobKind.Download, remoteId, title, new SyncJobParameters(server, SyncDownloadMode.Originals, archiveId, Automatic: true),
JobPriority.Background, cancellationToken);
/// <summary>
/// Whether <paramref name="job"/> is an automatic transfer of an integrated pair's new photos
/// (<see cref="EnqueueAutomaticUploadAsync"/>, <see cref="EnqueueAutomaticDownloadAsync"/>): a metered connection pauses
/// those whatever the option says (owner review 6, Q6).
/// </summary>
public static bool IsAutomaticTransfer(Job job)
{
ArgumentNullException.ThrowIfNull(job);
return SyncJobParameters.Read(job)?.IsAutomatic == true;
}
/// <summary>Queues sending the renders of a local copy the server lacks (BRIEF §14.5), unless that is already waiting or running.</summary>
public Task<Job> EnqueueSendExportsAsync(JobEngine engine, string server, Sequence local, CancellationToken cancellationToken = default) =>
EnqueueAsync(engine, JobKind.UploadCommit, local.Id, local.DisplayTitle, new SyncJobParameters(server, Upload: SyncUploadMode.Exports), JobPriority.User,
+42 -5
View File
@@ -98,12 +98,15 @@ internal sealed class SyncTransfers(SyncService sync)
// A server that files a photo it holds in another sequence into this one (owner review 6): the map's "missing on the
// server" reaches 0 once every original is in the target, not merely somewhere on the server.
var into = (await remote.CapabilitiesAsync(ct).ConfigureAwait(false)).Contains(ServerCapabilities.UploadInto);
if (into)
// An account that may upload but neither owns the target nor may edit it is refused that (403): the originals then go
// as before, each to the target unless the server holds it elsewhere (IntoRefusal).
var into = (await remote.CapabilitiesAsync(ct).ConfigureAwait(false)).Contains(ServerCapabilities.UploadInto) ? new IntoRefusal() : null;
if (into is not null)
{
// Counted already (they reached the server before the target existed): filed into it now, nothing stepped again.
foreach (var frame in heldElsewhere)
{
if (into.Refused) break;
if (await UploadFrameAsync(context, remote, target, null, paths.FromRelative(frame.RelativePath), frame, tombstones, hashes, ct, into)
.ConfigureAwait(false) is null)
skipped++;
@@ -978,8 +981,18 @@ internal sealed class SyncTransfers(SyncService sync)
/// original the index has none for goes into <paramref name="hashes"/>; known by content only now, such an original
/// the server deleted (<paramref name="tombstones"/>) is not sent back.
/// </summary>
private static Task<CompleteUploadResponse?> UploadFrameAsync(JobContext context, ISyncRemote remote, Guid? sequenceId, string? sessionKey, string path,
Frame frame, SyncTombstones tombstones, ConcurrentDictionary<Guid, string> hashes, CancellationToken cancellationToken, IntoRefusal? into) =>
UploadFrameAsync(context, remote, sequenceId, sessionKey, path, frame, tombstones, hashes, cancellationToken, into is not null, into);
/// <summary>
/// <paramref name="into"/>: through <see cref="ISyncRemote.UploadFileIntoAsync"/>; with <paramref name="fallback"/>, a
/// 403 for that (an account that neither owns the target nor may edit it) sends this original and every later one of
/// the job the plain way instead (<see cref="IntoRefusal"/>).
/// </summary>
private static async Task<CompleteUploadResponse?> UploadFrameAsync(JobContext context, ISyncRemote remote, Guid? sequenceId, string? sessionKey, string path,
Frame frame, SyncTombstones tombstones, ConcurrentDictionary<Guid, string> hashes, CancellationToken cancellationToken, bool into = false)
Frame frame, SyncTombstones tombstones, ConcurrentDictionary<Guid, string> hashes, CancellationToken cancellationToken, bool into = false,
IntoRefusal? fallback = null)
{
if (!File.Exists(path))
{
@@ -1002,11 +1015,35 @@ internal sealed class SyncTransfers(SyncService sync)
context.Log(Loc.L("Archive.Log.SyncChanged", frame.FileName));
return null;
}
if (into && sequenceId is { } target)
return await remote.UploadFileIntoAsync(path, target, sha, frame.CapturedAt, cancellationToken).ConfigureAwait(false) ?? notSent;
if (into && sequenceId is { } target && fallback is not { Refused: true })
{
try
{
return await remote.UploadFileIntoAsync(path, target, sha, frame.CapturedAt, cancellationToken).ConfigureAwait(false) ?? notSent;
}
catch (ChronosApiException ex) when (fallback is not null && ex.Status == HttpStatusCode.Forbidden
&& string.Equals(ex.Error.Code, "forbidden", StringComparison.Ordinal))
{
if (fallback.Refuse()) context.Log(Loc.L("Archive.Log.SyncIntoRefused"));
}
}
return await remote.UploadFileAsync(path, sequenceId, sessionKey, sha, frame.CapturedAt, cancellationToken).ConfigureAwait(false) ?? notSent;
}
/// <summary>
/// Whether the server refused an upload into the target to this account (owner review 6, #73): set once, by the first
/// refusal; the job's later originals go the plain way, as before the server could file into a target.
/// </summary>
private sealed class IntoRefusal
{
private int _refused;
public bool Refused => Volatile.Read(ref _refused) == 1;
/// <summary>Records the refusal; true for the first one.</summary>
public bool Refuse() => Interlocked.Exchange(ref _refused, 1) == 0;
}
/// <summary>Commits one original from staging into the local sequence (created from the server id when null).</summary>
private async Task<IngestResult> CommitAsync(Guid remoteId, Guid archiveId, Guid? sequenceId, ManifestFrame frame, string staged, string sha,
IReadOnlyDictionary<Guid, DateTime?> captured, CancellationToken cancellationToken)