fix(reorganize): never name a folder or title after a photo no longer first, and retry a kept job honestly
A Reorganize step whose photos changed after the plan kept its file names but still moved its folder and wrote the title the plan had computed from the old first photo, so a trashed first photo or an earlier photo filed since left the sequence named after a photo that is no longer first. The plan now journals its folder and title templates, and under the step's leases each folder move or retitle is expanded again from the settled sidecar: it is applied only when it gives what the plan gives (the folder itself or its " (n)"); otherwise the sequence stays as it was (Dropped, "changed after the plan"), or keeps its title and file names when an interrupted run moved its folder already (TitlesKept). Plans journaled before this change are applied as made. A Move job that ended failed with sequences kept, or whose held plan was given up, kept its plan:<id> checkpoint after the plan's journal was gone, so a retry logged "completed when the archive was opened" and ended done. Such a job now saves the checkpoint "applied": a retry plans again and applies only a plan that is still the one confirmed. A job that succeeds keeps plan:<id>, so a crash before it is marked done still finds the plan completed. Sequences a folder was to carry when that folder stayed (dropped, its title edited, its names no longer given, or a newer sidecar) were reported as "changed after the plan", and a newer-format carrier failed the job with ReorganizeKept. They are now a separate outcome, CarriedKept (journaled), logged with the new Archive.Log.ReorganizeCarriedKept (en+it) and not counted in the job's error, which follows the carrier's own reason. When a step's sidecar cannot be read or written after its folder moved, every sequence of the step is told (sequenceChanged "reorganized") before the failure is thrown, since the retry that would tell them may never come. Tests: Core APlanKeepsItsTemplatesSoTheNamesOfAFirstPhotoNoLongerFirstAreTold; Data AFolderOrTitleNamedAfterAPhotoNoLongerFirstIsNeverGiven, ARetryOfAJobThatKeptSequencesPlansAgain, ASequenceAFolderWasToCarryIsToldItStayedWithIt, AnArchiveOpensWhenAnInterruptedRenameMeetsASidecarOfANewerFormat, AResumedStepWhoseFolderMovedKeepsATitleEditedSinceAndTheNamesFromIt, and AMovedFolderWhoseSidecarCannotBeReadThereHasItsIndexRowFollowAndIsTold, which breaks the sidecar with a relative symbolic link instead of a read-only file, so it also runs on the Linux runner as root. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 130701afab224d47ea066eb7cc8debb16d1fb432)
This commit is contained in:
1 parent
37800b28ef
commit
8127373fd5
9 files changed
+455
-77
No files matched your search
@@ -194,6 +194,37 @@ public sealed class ReorganizeTests(TestContext context)
|
||||
Assert.True(Step("moved/{date}", "{n:000}") is { MovesFolder: true, FileChanges: 1, NamedByTitle: false, UsesTitle: false });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void APlanKeepsItsTemplatesSoTheNamesOfAFirstPhotoNoLongerFirstAreTold()
|
||||
{
|
||||
const string Folder = "moved/{date} {title}", Title = "{title} {time}";
|
||||
var manifest = Sequence("originals/a.JPG", "originals/b.JPG");
|
||||
// Another sequence holds the folder the template gives: this one takes its " (2)".
|
||||
var plan = RenamePlanner.Plan(Guid.NewGuid(), [new RenameSubject(manifest.Id, "s", "Roof", Start, null, null, null)
|
||||
{ Files = new SequenceFiles(manifest, [.. manifest.Frames.Select(f => f.File)]) }], Folder, Title, ["s", "moved/2026-09-28 Roof 18-00-00"], _ => false);
|
||||
Assert.Equal((Folder, Title, (string?)null), (plan.FolderTemplate, plan.TitleTemplate, plan.FileTemplate));
|
||||
var step = plan.Steps.Single();
|
||||
Assert.Equal(("moved/2026-09-28 Roof 18-00-00 (2)", "Roof 18-00-00"), (step.ToFolder, step.ToTitle));
|
||||
|
||||
// From the sidecar as it was, the templates give what the plan gives; with its first photo gone, they name it otherwise.
|
||||
var (title, folder) = RenamePlanner.Names(manifest, "Roof", Folder, Title);
|
||||
Assert.Equal(("Roof 18-00-00", "moved/2026-09-28 Roof 18-00-00"), (title, folder));
|
||||
Assert.True(RenamePlanner.Gives(folder!, step.ToFolder));
|
||||
var (laterTitle, laterFolder) = RenamePlanner.Names(manifest with { Frames = [manifest.Frames[1]] }, "Roof", Folder, Title);
|
||||
Assert.Equal(("Roof 18-00-10", "moved/2026-09-28 Roof 18-00-10"), (laterTitle, laterFolder));
|
||||
Assert.False(RenamePlanner.Gives(laterFolder!, step.ToFolder));
|
||||
// Without templates, the title stays and no folder is given.
|
||||
Assert.Equal(("Roof", (string?)null), RenamePlanner.Names(manifest, "Roof", null, null));
|
||||
|
||||
// Only the folder itself or a number filing gives.
|
||||
Assert.True(RenamePlanner.Gives("a/b", "a/b"));
|
||||
Assert.True(RenamePlanner.Gives("a/b", "a/b (12)"));
|
||||
Assert.False(RenamePlanner.Gives("a/b", "a/b (1)"));
|
||||
Assert.False(RenamePlanner.Gives("a/b", "a/b (02)"));
|
||||
Assert.False(RenamePlanner.Gives("a/b", "A/b"));
|
||||
Assert.False(RenamePlanner.Gives("a/b", "a/b (2) x"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TemplatesAreCheckedAsTheArchiveSettingsAre()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user