fix(reorganize): a sequence still receiving photos keeps its file names and the job goes on
A Reorganize with a file template failed its job at the step of a sequence
a camera was still uploading into, and its retry gave the rest up. Photos
changed since the plan now never refuse a step: that sequence keeps its file
names (FilesKept), its folder and title change as planned, the other steps go
on and the job ends with ReorganizeKept. The fingerprint, the job's
confirmation and the check under the leases pin file renames by their digest
instead of the frames version, so photos filed under the names the plan gives
them no longer make a dry run or a queued job stale.
- A step whose folder or files a template names after {title} checks the
title as a retitle does (RenameStep.NamedByTitle): no name comes from a
title edited since the plan.
- Recovery sends a photo that already took its new name back together with a
companion whose new name was taken, so the two never end up apart.
- ArchiveService.OpenAsync logs a NewerFormatException from resuming a plan
and keeps its journal, so a server still boots.
- Once a step's folder moved, every index row of the step follows it even
when a sidecar cannot be read or written; the step then fails for a retry.
- Job log lines and errors give the real reason for files kept busy (in use
or a new name taken) and for a sidecar of a newer format (new Newer
outcome; strings en and it).
- A plan an archive open completes tells sequenceChanged; the docs that
promised more than that are corrected.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit f8554b8af0828ab9b0ff128e694abacdd53e6fd7)
This commit is contained in:
1 parent
59ee982e4d
commit
9e1f109b58
16 files changed
+560
-195
No files matched your search
@@ -125,9 +125,10 @@ public sealed record FileRenameJournal(int FramesVersion, int Phase, IReadOnlyLi
|
||||
/// the sidecar to write, or null when it is right as it is; the journal is left in place, <see cref="Delete"/> it once
|
||||
/// the result is written. Safe to run again from wherever it stopped (a failure, a crash, a sidecar that could not be
|
||||
/// written): once every file is at its temporary name the journal says phase 2, as <see cref="Run"/> does, so no file
|
||||
/// that reached its new name is ever moved again. A new name something else took meanwhile is never written over: the
|
||||
/// files of that frame go back to their old names, or to the first free <c>_2</c>, <c>_3</c>… of them, recorded in the
|
||||
/// journal before they move, and the frame names where its photo is (logged). A file found nowhere is logged, and its
|
||||
/// that reached its new name is ever moved again, but with its frame as follows. A new name something else took meanwhile
|
||||
/// is never written over: all the files of that frame, its photo and companions together, go back to their old names, or
|
||||
/// to the first free <c>_2</c>, <c>_3</c>… of them, recorded in the journal before they move on, and the frame names
|
||||
/// where its photo is (logged). A file found nowhere is logged, and its
|
||||
/// frame names the new file all the same (a verify then flags it missing, as it would have at its old name).
|
||||
/// </summary>
|
||||
/// <exception cref="IOException">A file could not be moved (open elsewhere); the journal stays, and the next recovery goes on from there.</exception>
|
||||
@@ -158,10 +159,11 @@ public sealed record FileRenameJournal(int FramesVersion, int Phase, IReadOnlyLi
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The journal with a new name for every file still at its temporary name of a frame one of whose new names something
|
||||
/// else took since (a file, or a folder): all the files of that frame (its photo and companions, which stay together) go
|
||||
/// back to their old names, or to the first <c>_2</c>, <c>_3</c>… of the photo's old name that is free for all of them,
|
||||
/// none ever a name the rename gives another file. Written before anything moves, so a recovery run again finds them.
|
||||
/// The journal with a new name for every file of a frame one of whose new names something else took since (a file, or a
|
||||
/// folder) while that file waits at its temporary name: all the files of that frame (its photo and companions, which stay
|
||||
/// together: one that reached its new name already goes back to its temporary name first) go back to their old names, or
|
||||
/// to the first <c>_2</c>, <c>_3</c>… of the photo's old name that is free for all of them, none ever a name the rename
|
||||
/// gives another file. Written before any of them moves on, so a recovery run again finds them.
|
||||
/// </summary>
|
||||
private static FileRenameJournal Redirected(SequencePaths sequence, FileRenameJournal journal)
|
||||
{
|
||||
@@ -169,8 +171,11 @@ public sealed record FileRenameJournal(int FramesVersion, int Phase, IReadOnlyLi
|
||||
List<FileRenameEntry>? files = null;
|
||||
foreach (var frame in journal.Files.Select((f, i) => (File: f, Index: i)).GroupBy(f => f.File.FrameId))
|
||||
{
|
||||
var taken = frame.Where(f => Exists(sequence, f.File.Temp) && Taken(sequence, f.File.To)).Select(f => f.File.To).ToList();
|
||||
if (taken.Count == 0) continue;
|
||||
// A photo whose companion's new name was taken never stays apart from it at its own new name, nor the other way round.
|
||||
foreach (var (file, _) in frame.Where(f => !Exists(sequence, f.File.Temp) && Exists(sequence, f.File.To))) Move(sequence, file.To, file.Temp);
|
||||
var waiting = frame.Where(f => Exists(sequence, f.File.Temp)).ToList();
|
||||
if (!waiting.Any(f => Taken(sequence, f.File.To))) continue;
|
||||
var photo = frame.FirstOrDefault(f => !f.File.Companion).File ?? frame.First().File;
|
||||
List<string> names;
|
||||
for (var n = 1; ; n++)
|
||||
@@ -185,7 +190,7 @@ public sealed record FileRenameJournal(int FramesVersion, int Phase, IReadOnlyLi
|
||||
claimed.Add(names[i]);
|
||||
files[index] = file with { To = names[i] };
|
||||
}
|
||||
Log.Error("archive", $"{string.Join(", ", waiting.Where(f => Taken(sequence, f.File.To)).Select(f => sequence.ArchiveRelative(f.File.To)))} taken while "
|
||||
Log.Error("archive", $"{string.Join(", ", taken.Select(sequence.ArchiveRelative))} taken while "
|
||||
+ $"a rename was interrupted; the files of that photo go to {string.Join(", ", names.Select(sequence.ArchiveRelative))}");
|
||||
}
|
||||
if (files is null) return journal;
|
||||
|
||||
@@ -44,7 +44,19 @@ public sealed record RenameStep(Guid SequenceId, string FromFolder, string ToFol
|
||||
/// <summary>Whether applying the step changes anything: the folder, the title or file names.</summary>
|
||||
public bool Changes => MovesFolder || Retitles || FileChanges > 0;
|
||||
|
||||
/// <summary>The sidecar's frames version the file names were planned at; 0 when no file gets a new name.</summary>
|
||||
/// <summary>
|
||||
/// The new folder or file names come from the sequence's title (the folder or file template uses <c>{title}</c>): a title
|
||||
/// edited since the plan would leave them named after the old one.
|
||||
/// </summary>
|
||||
public bool NamedByTitle { get; init; }
|
||||
|
||||
/// <summary>Whether what the step changes depends on the sequence's title: it changes it, or names the folder or files after it.</summary>
|
||||
public bool UsesTitle => Retitles || NamedByTitle;
|
||||
|
||||
/// <summary>
|
||||
/// The sidecar's frames version the file names were planned at; 0 when no file gets a new name. What the apply checks the
|
||||
/// files by only in a plan journaled without <see cref="FileDigest"/>.
|
||||
/// </summary>
|
||||
public int FramesVersion { get; init; }
|
||||
|
||||
/// <summary>Frames whose file gets a new name (their companions follow them).</summary>
|
||||
@@ -123,15 +135,18 @@ public sealed record RenamePlan(Guid Id, Guid ArchiveId, IReadOnlyList<RenameSte
|
||||
public IReadOnlyList<Guid> Subjects { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// A digest of what the plan changes (its steps in order, as a dry run shows them, and the file template), the same for
|
||||
/// two plans of the same archive state: what a confirmation sends back so the change made is the one that was shown.
|
||||
/// A digest of what the plan changes (its steps in order, as a dry run shows them, every file rename by its digest, and
|
||||
/// the file template), the same for two plans of the same archive state: what a confirmation sends back so the change
|
||||
/// made is the one that was shown. The frames version is not part of it: photos a sequence received since under the names
|
||||
/// the plan gives them (an upload filed with the same template) leave the plan as it was, and the apply renames the files
|
||||
/// only while they rename exactly as planned (<see cref="RenameStep.FileDigest"/>).
|
||||
/// </summary>
|
||||
public string Fingerprint()
|
||||
{
|
||||
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}|{s.FileDigest}|");
|
||||
text.Append(CultureInfo.InvariantCulture, $"{s.SequenceId:N}|{s.FromFolder}|{s.ToFolder}|{s.FromTitle}|{s.ToTitle}|{s.Carried}|{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');
|
||||
@@ -142,9 +157,10 @@ 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"/>).
|
||||
/// 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"/>) or their title and file
|
||||
/// names kept (<see cref="TitlesKept"/>); their file names kept because a photo was in use or a new name was taken
|
||||
/// (<see cref="FilesBusy"/>); their title and file names kept because a newer Chronos wrote their sidecar (<see cref="Newer"/>).
|
||||
/// </summary>
|
||||
public sealed record RenameTally
|
||||
{
|
||||
@@ -154,6 +170,7 @@ public sealed record RenameTally
|
||||
public IReadOnlyList<Guid> FilesKept { get; init; } = [];
|
||||
public IReadOnlyList<Guid> TitlesKept { get; init; } = [];
|
||||
public IReadOnlyList<Guid> FilesBusy { get; init; } = [];
|
||||
public IReadOnlyList<Guid> Newer { get; init; } = [];
|
||||
}
|
||||
|
||||
/// <summary>A plan being applied, with the steps already completed; lets an interrupted rename resume (BRIEF §7).</summary>
|
||||
@@ -204,7 +221,8 @@ public static class RenamePlanner
|
||||
/// name (<see cref="PathTemplate.ExpandText"/>). A target folder that is any current sequence folder, exists on disk or
|
||||
/// was given to an earlier subject (whatever its case) gets " (2)", " (3)"…. With <paramref name="fileTemplate"/> every
|
||||
/// subject's frames get their names from it as filing names them (<see cref="FileRenames.Plan"/>, with the new title),
|
||||
/// counted and sampled in its step, and the frames that keep their names are listed there with the reason. A subject
|
||||
/// counted and sampled in its step, and the frames that keep their names are listed there with the reason; a step whose
|
||||
/// new folder or file names come from <c>{title}</c> says so (<see cref="RenameStep.NamedByTitle"/>). A subject
|
||||
/// whose sidecar could not be read (<see cref="RenameSubject.Unreadable"/>, or no <see cref="RenameSubject.Files"/> for a
|
||||
/// file template) stays as it is, listed with the reason, and so does the folder of every subject it is inside. Null
|
||||
/// templates leave that part unchanged; subjects without a change produce no step, unless frames of theirs keep their
|
||||
@@ -220,6 +238,7 @@ public static class RenamePlanner
|
||||
var folder = folderTemplate is null ? null : PathTemplate.Parse(folderTemplate);
|
||||
var title = titleTemplate is null ? null : PathTemplate.Parse(titleTemplate);
|
||||
var file = fileTemplate is null ? null : PathTemplate.Parse(fileTemplate);
|
||||
bool folderByTitle = folder?.Uses("title") == true, filesByTitle = file?.Uses("title") == true;
|
||||
var taken = occupied.ToList();
|
||||
var claimed = new HashSet<string>(taken, StringComparer.OrdinalIgnoreCase);
|
||||
// The folders given in this plan so far: Kept never gives one twice (two folders that differ only in case).
|
||||
@@ -256,7 +275,8 @@ public static class RenamePlanner
|
||||
}
|
||||
}
|
||||
var step = new RenameStep(s.SequenceId, s.Folder, newFolder, s.Title, newTitle);
|
||||
own.Add(file is null ? step : WithFiles(step, s.Files!, file, newTitle));
|
||||
if (file is not null) step = WithFiles(step, s.Files!, file, newTitle);
|
||||
own.Add(step with { NamedByTitle = (folderByTitle && step.MovesFolder) || (filesByTitle && step.FileChanges > 0) });
|
||||
}
|
||||
|
||||
var moving = own.Where(s => s.MovesFolder).ToList();
|
||||
|
||||
Reference in new issue
Block a user