fix(copies): close the eleventh verification round of owner review 6
- A merge's Verify stage journals a second version, with the hash it is filed as, before it files it. A run that stops between filing it and leaving it out of Main (a drive dropping out, project.json held, the app closing) now leaves it out on resume, instead of reading it as the kept sequence's own photo and keeping both versions in Main for good. - Upload all local ignores a Kept apart pair whose server sequence is confirmed deleted only when the answer came before the first 404. A Keep here, answered after the deletion was shown, skips the sequence again instead of uploading it and erasing the answer. - An upload's checkpoint records whether the job joined a server sequence this PC already knew. A resumed or retried upload no longer takes such a sequence for one it made and overwrites its details. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e002c583d6
commit
6db4c2e80c
10 files changed
+168
-10
No files matched your search
@@ -52,6 +52,9 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
|
||||
/// <summary>Called before each stage runs (tests: a crash, a change made between stages).</summary>
|
||||
internal Func<MergeStage, Task>? BeforeStage { get; set; }
|
||||
|
||||
/// <summary>Called before a second version is left out of Main (tests: a failure between filing it and saving the journal).</summary>
|
||||
internal Func<string, Task>? BeforeLeaveOutOfMain { get; set; }
|
||||
|
||||
public async Task RunAsync(JobContext context)
|
||||
{
|
||||
var job = context.Job;
|
||||
@@ -395,6 +398,7 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
|
||||
private async Task LeaveOutOfMainAsync(string sha)
|
||||
{
|
||||
var ct = CancellationToken.None;
|
||||
if (owner.BeforeLeaveOutOfMain is { } hook) await hook(sha).ConfigureAwait(false);
|
||||
for (var attempt = 1; ; attempt++)
|
||||
{
|
||||
var keep = await _db.Sequences.GetAsync(journal.KeepId, ct).ConfigureAwait(false) ?? throw new StaleCopyPlanException();
|
||||
@@ -655,9 +659,17 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
|
||||
?? throw new InvalidOperationException(Loc.L("Errors.Copies.ChangedFile", frame.FileName));
|
||||
if (frame.Sha256 is { Length: > 0 } recorded && !string.Equals(recorded, sha, StringComparison.OrdinalIgnoreCase))
|
||||
throw new InvalidOperationException(Loc.L("Errors.Copies.ChangedFile", frame.FileName));
|
||||
var version = journal.SecondVersions.Contains(frame.Id);
|
||||
if (version && !string.Equals(journal.VersionShas.GetValueOrDefault(frame.Id), sha, StringComparison.OrdinalIgnoreCase))
|
||||
// A run that stopped while filing it as a second version read other bytes: changed since.
|
||||
throw new InvalidOperationException(Loc.L("Errors.Copies.ChangedFile", frame.FileName));
|
||||
if (held.TryGetValue(sha, out var keepFrame))
|
||||
{
|
||||
// Filed as a second version by a run that stopped before the journal said so: left out of Main again
|
||||
// (nothing changes when it already is), and still left out at the Details stage.
|
||||
if (version) await LeaveOutOfMainAsync(sha).ConfigureAwait(false);
|
||||
journal.Verified[frame.Id] = new MergeVerified(sha, keepFrame);
|
||||
if (version) Save();
|
||||
continue;
|
||||
}
|
||||
if (journal.Absent.Contains(sha))
|
||||
@@ -669,9 +681,13 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
|
||||
if (frame.Sha256 is not { Length: > 0 } && !keepRemoved.Contains(sha))
|
||||
{
|
||||
// Compared by size and time only, and another photo after all: filed in the kept sequence as a second version.
|
||||
// The journal says so before it is filed: a run that stops before it is left out of Main (the exclusion
|
||||
// fails, the app ends) finds it in the kept sequence on resume and leaves it out then.
|
||||
if (!version) journal.SecondVersions.Add(frame.Id);
|
||||
journal.VersionShas[frame.Id] = sha.ToLowerInvariant();
|
||||
Save();
|
||||
var filed = await FileAsync(frame, sha, planned: false).ConfigureAwait(false);
|
||||
await LeaveOutOfMainAsync(sha).ConfigureAwait(false);
|
||||
journal.SecondVersions.Add(frame.Id);
|
||||
journal.Verified[frame.Id] = new MergeVerified(sha, filed.FrameId);
|
||||
held.TryAdd(sha, filed.FrameId);
|
||||
Save();
|
||||
|
||||
Reference in new issue
Block a user