fix(archive): Reorganize checks each step before it moves, holds a failed plan, recovers file renames safely
Owner review 2, phase 4a review findings on the renamer. - File rename recovery is safe to run again from wherever it stopped: once every file is at its temporary name the journal says phase 2, as Run does, so a second recovery (after a failure, a crash or a sidecar that could not be written) never moves a file that reached its new name. A new name something else took meanwhile is never written over: that photo and its companions go back to their old names, or to the first free _2, _3, recorded in the journal before they move, and the frame names where its photo is. A journal is never deleted while a temporary file of it is still there. - Every check that can refuse a step runs under the step's leases before anything of it moves: where its sequences are, strangers inside, its new folder taken since the plan (a restore, an upload), a sidecar of a newer format, a title edited since the plan (compare-and-set against the planned from-title, sidecar and index), and its file renames, compared by a digest of every move at the planned frames version (a verify that hashes photos does not bump the version). Once the folder moved, every index row follows it before any file is renamed, and a photo in use or files found changed keep their names: the step completes. - The same checks run up front for a held plan, so its retry either fits or is given up. - A failed move job holds its plan, as a pause does: an archive open no longer applies the rest unasked; only the job's retry does. File renames a step left half-way are still completed at an archive open. - Each sequence changed is told as its step is journaled, so a pause or a failure never keeps it untold; the plan's journal keeps the tally of every run, so the job log counts the whole plan. - A selected sequence deleted while the job waited is named in the log and the plan refused with the localized stale-plan error, not a raw ArgumentException. - The dry run renames no file of a newer-format sidecar. New log lines and error (en, it): title and file names kept, file names kept because a photo was in use. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 1d1c888120edd709dbb5341c1922bf85085c4857)
This commit is contained in:
1 parent
44e5b9da9e
commit
13c2ac321c
10 files changed
+961
-135
No files matched your search
@@ -41,6 +41,12 @@ public sealed record RenameStep(Guid SequenceId, string FromFolder, string ToFol
|
||||
/// <summary>The first renamed frames (<see cref="FileRenames.SampleCount"/>), old and new name relative to the sequence folder.</summary>
|
||||
public IReadOnlyList<FileRename> FileSamples { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Every file rename of the step, as a digest (<see cref="FileRenamePlan.Digest"/>): the apply renames the files only
|
||||
/// while they plan to exactly these. Null when no file gets a new name (or in a plan journaled before it existed).
|
||||
/// </summary>
|
||||
public string? FileDigest { get; init; }
|
||||
|
||||
/// <summary>Frames that keep their file names, and why.</summary>
|
||||
public IReadOnlyList<RenameBlocked> Blocked { get; init; } = [];
|
||||
}
|
||||
@@ -124,7 +130,7 @@ public sealed record RenamePlan(Guid Id, Guid ArchiveId, IReadOnlyList<RenameSte
|
||||
var text = new StringBuilder(FileTemplate).Append('\n');
|
||||
foreach (var s in Steps)
|
||||
{
|
||||
text.Append(CultureInfo.InvariantCulture, $"{s.SequenceId:N}|{s.FromFolder}|{s.ToFolder}|{s.FromTitle}|{s.ToTitle}|{s.Carried}|{s.FramesVersion}|{s.FileChanges}|");
|
||||
text.Append(CultureInfo.InvariantCulture, $"{s.SequenceId:N}|{s.FromFolder}|{s.ToFolder}|{s.FromTitle}|{s.ToTitle}|{s.Carried}|{s.FramesVersion}|{s.FileChanges}|{s.FileDigest}|");
|
||||
foreach (var sample in s.FileSamples) text.Append(sample.From).Append('>').Append(sample.To).Append(';');
|
||||
foreach (var blocked in s.Blocked) text.Append(CultureInfo.InvariantCulture, $"{blocked.Reason}:{blocked.Frames};");
|
||||
text.Append('\n');
|
||||
@@ -133,11 +139,30 @@ public sealed record RenamePlan(Guid Id, Guid ArchiveId, IReadOnlyList<RenameSte
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What the completed steps of a plan did, over every run that applied them (<see cref="RenameJournal.Done"/>): the
|
||||
/// sequences changed, the frames whose file got a new name, and the sequences not changed as planned because they changed
|
||||
/// since: left as they were (<see cref="Dropped"/>), their file names kept (<see cref="FilesKept"/>), their title and file
|
||||
/// names kept (<see cref="TitlesKept"/>), or their file names kept because a photo was in use (<see cref="FilesBusy"/>).
|
||||
/// </summary>
|
||||
public sealed record RenameTally
|
||||
{
|
||||
public IReadOnlyList<Guid> Changed { get; init; } = [];
|
||||
public int Files { get; init; }
|
||||
public IReadOnlyList<Guid> Dropped { get; init; } = [];
|
||||
public IReadOnlyList<Guid> FilesKept { get; init; } = [];
|
||||
public IReadOnlyList<Guid> TitlesKept { get; init; } = [];
|
||||
public IReadOnlyList<Guid> FilesBusy { get; init; } = [];
|
||||
}
|
||||
|
||||
/// <summary>A plan being applied, with the steps already completed; lets an interrupted rename resume (BRIEF §7).</summary>
|
||||
/// <param name="Held">The job applying the plan was paused or cancelled between two steps: an archive open leaves the plan to
|
||||
/// that job, which completes it when it runs again.</param>
|
||||
/// <param name="Held">The job applying the plan was paused, cancelled or failed between two steps: an archive open leaves the
|
||||
/// plan to that job, which completes it when it is resumed or retried.</param>
|
||||
public sealed record RenameJournal(RenamePlan Plan, IReadOnlyList<Guid> Completed, bool Held = false)
|
||||
{
|
||||
/// <summary>What the completed steps did, so a resumed run reports the whole plan.</summary>
|
||||
public RenameTally Done { get; init; } = new();
|
||||
|
||||
public static string PathFor(ArchivePaths archive, Guid planId) => Path.Combine(archive.JournalDirectory, $"rename-{planId:N}.json");
|
||||
|
||||
public static void Write(ArchivePaths archive, RenameJournal journal)
|
||||
@@ -252,6 +277,7 @@ public static class RenamePlanner
|
||||
FramesVersion = plan.Frames > 0 ? files.Manifest.Versions.Frames : 0,
|
||||
FileChanges = plan.Frames,
|
||||
FileSamples = plan.Samples,
|
||||
FileDigest = plan.Frames > 0 ? plan.Digest() : null,
|
||||
Blocked = plan.Blocked,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user