fix(convert): close the last edges round 3's checkers found in the trash and the copy check
- A frame flagged corrupt, like one whose file is missing, is one no verify can hash (a verify does not hash a file whose size differs from its record): a replaced entry of its sequence is kept with "restore it", never with an advice to verify that would never settle it. - Erasing a deleted sequence leaves no record that its conversions went with it while the sequence also lives (this index has it, or a folder's sidecar names it: a folder copied back, a second deletion of the same id), so a later emptying whose walk misses that folder keeps the originals. - A copy another conversion made since this one was confirmed supersedes it only once that conversion is done; while it is not (it failed while filing the copy), a retry is left as it was with a reason (new string Archive.Convert.CopyUnfinished, en and it), neither making a second copy nor calling the sequence done with. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5012c3bbd2
commit
74ccde7210
7 files changed
+75
-11
No files matched your search
@@ -561,8 +561,15 @@ public sealed class MassConverter
|
||||
: null;
|
||||
}
|
||||
if (by.Confirmed is not { } confirmed
|
||||
|| await LaterCopyAsync(archive, paths, step.Id, jobId, options, confirmed, cancellationToken).ConfigureAwait(false) is not { } other)
|
||||
|| await LaterCopyAsync(archive, paths, step.Id, jobId, options, confirmed, cancellationToken).ConfigureAwait(false) is not { } later)
|
||||
return null;
|
||||
var (other, done) = later;
|
||||
if (!done)
|
||||
{
|
||||
// Its job has not finished the copy (it failed while filing it, or still runs): neither a second copy nor done with.
|
||||
Core.Diagnostics.Log.Info("archive", $"{row.DisplayTitle}: another conversion made its copy {other} in this format since this one was confirmed and has not finished it");
|
||||
return new StepDone(Result(row, ConvertOutcome.Blocked, error: Loc.L("Archive.Convert.CopyUnfinished")));
|
||||
}
|
||||
Core.Diagnostics.Log.Info("archive", $"{row.DisplayTitle}: another conversion made its copy {other} in this format since this one was confirmed; no second copy is made");
|
||||
progress.Count(row.Id, 0, 0);
|
||||
return new StepDone(Result(row, ConvertOutcome.Superseded));
|
||||
@@ -606,16 +613,18 @@ public sealed class MassConverter
|
||||
/// <summary>
|
||||
/// A copy of <paramref name="source"/> in this conversion's format that another conversion made since <paramref name="confirmed"/>:
|
||||
/// a sequence filed under another job's session key for that source (<see cref="SessionKey"/>) whose sidecar says it was
|
||||
/// made since then and holds photos of that format. Null when there is none.
|
||||
/// made since then and holds photos of that format, and whether that conversion is done (only a done one's copy is whole).
|
||||
/// Null when there is none.
|
||||
/// </summary>
|
||||
private async Task<Guid?> LaterCopyAsync(Archive archive, ArchivePaths paths, Guid source, Guid jobId, ConvertOptions options, DateTimeOffset confirmed,
|
||||
private async Task<(Guid Id, bool Done)?> LaterCopyAsync(Archive archive, ArchivePaths paths, Guid source, Guid jobId, ConvertOptions options, DateTimeOffset confirmed,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
foreach (var (key, id) in await _db.Sequences.ListSessionKeysAsync(archive.Id, $"{KeyPrefix}%:{source:N}", cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
if (JobOfKey(key) is not { } other || other == jobId) continue;
|
||||
if (await _db.Sequences.GetAsync(id, cancellationToken).ConfigureAwait(false) is not { } copy || copy.ArchiveId != archive.Id) continue;
|
||||
if (Read(paths.Sequence(copy.Folder), id) is { } made && made.Created > confirmed && made.Frames.Any(f => f.Format == options.Format)) return id;
|
||||
if (Read(paths.Sequence(copy.Folder), id) is { } made && made.Created > confirmed && made.Frames.Any(f => f.Format == options.Format))
|
||||
return (id, await _db.Jobs.GetAsync(other, cancellationToken).ConfigureAwait(false) is { State: JobState.Done });
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ public sealed partial class SequenceTrash
|
||||
/// moves its conversions meanwhile, and only once what a writer left unsettled in the sequence is settled (an undo whose
|
||||
/// completion waited for this entry's lease takes photos out of it): the archive must tell where each conversion is (as
|
||||
/// the dry run said, which the fingerprint holds), and each must still match. A deleted sequence that a replaced entry
|
||||
/// still in the trash came from leaves a record of its erasing (<see cref="RecordErasure"/>). Returns null once erased,
|
||||
/// still in the trash came from leaves a record of its erasing (<see cref="RecordErasureAsync"/>). Returns null once erased,
|
||||
/// else why the entry is kept (logged).
|
||||
/// </summary>
|
||||
private async Task<TrashKeptReason?> EraseAsync(Archive archive, ArchivePaths paths, TrashEntry entry, string fingerprint, SidecarWalk walk,
|
||||
@@ -265,7 +265,7 @@ public sealed partial class SequenceTrash
|
||||
var aside = Path.Combine(TrashDirectory(paths), ErasingFolder, Guid.NewGuid().ToString("N"));
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(aside)!);
|
||||
// Before the folder goes: once it has, the archive alone tells a replaced entry of that sequence what became of it.
|
||||
if (entry.Kind == TrashKind.Sequence) RecordErasure(archive, paths, now, cancellationToken);
|
||||
if (entry.Kind == TrashKind.Sequence) await RecordErasureAsync(archive, paths, now, walk, cancellationToken).ConfigureAwait(false);
|
||||
Directory.Move(folder, aside);
|
||||
File.Delete(record);
|
||||
Erase(aside);
|
||||
|
||||
@@ -321,11 +321,16 @@ public sealed partial class SequenceTrash
|
||||
/// <summary>
|
||||
/// Records that the emptying erases deleted sequence <paramref name="entry"/> (written before its folder goes) when a
|
||||
/// replaced entry of that sequence stays in the trash: its emptying, later or on another host, then knows from the archive
|
||||
/// that the conversions of its originals went with the sequence (<see cref="Whereabouts.Gone"/>).
|
||||
/// that the conversions of its originals went with the sequence (<see cref="Whereabouts.Gone"/>). Never while the
|
||||
/// sequence also lives (this index has it, or a folder's sidecar names it: a folder copied back and adopted, a second
|
||||
/// deletion of the same id): the record would then outlive what it says and let a later emptying, whose walk misses the
|
||||
/// live folder, erase originals whose conversion is still there. Without the record such an entry is kept.
|
||||
/// </summary>
|
||||
private void RecordErasure(Archive archive, ArchivePaths paths, TrashEntry entry, CancellationToken cancellationToken)
|
||||
private async Task RecordErasureAsync(Archive archive, ArchivePaths paths, TrashEntry entry, SidecarWalk walk, CancellationToken cancellationToken)
|
||||
{
|
||||
if (!FrameTrash.List(archive, cancellationToken).Any(e => e.Kind == TrashKind.Replaced && e.SequenceId == entry.SequenceId)) return;
|
||||
if (await _db.Sequences.GetAsync(entry.SequenceId, cancellationToken).ConfigureAwait(false) is { } row && row.ArchiveId == archive.Id) return;
|
||||
if ((await walk.FindAsync(entry.SequenceId, again: false, cancellationToken).ConfigureAwait(false)).Folders.Count > 0) return;
|
||||
var path = ErasurePath(paths, entry.SequenceId);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||
AtomicFile.WriteAllText(path, JsonSerializer.Serialize(new ErasureRecord(entry.SequenceId, entry.Title, entry.Name, DateTimeOffset.UtcNow,
|
||||
@@ -479,8 +484,11 @@ public sealed partial class SequenceTrash
|
||||
return (_unhashed ? Holding.Unhashed : Holding.Unknown, []);
|
||||
}
|
||||
|
||||
/// <summary>Whether the sidecar has <paramref name="frame"/>'s file missing: no verify can hash it.</summary>
|
||||
private static bool Lost(SidecarFrame frame) => (frame.Flags & FrameFlags.Missing) != 0;
|
||||
/// <summary>
|
||||
/// Whether no verify can hash <paramref name="frame"/>: its file is missing, or it is flagged corrupt (a verify does not
|
||||
/// hash a file whose size differs from its record), so advising one would never settle the entry.
|
||||
/// </summary>
|
||||
private static bool Lost(SidecarFrame frame) => (frame.Flags & (FrameFlags.Missing | FrameFlags.Corrupt)) != 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user