fix(archive): stable Reorganize folders, settle trash restores first, retranslate Reorganize

Integrating owner review 2 phase 4a (R7) onto the reviewed phase 3 code.

- RenamePlanner: a sequence already at its expanded folder, or at the " (n)" of it that
  filing or an earlier Reorganize gave it, keeps that folder (in the template's case, unless
  another sequence holds that exact name). The planner seeded its claimed folders with the
  sequence's own, so "2026-09-28 (2)" was planned to "(3)" and back to "(2)" by the next
  run; a second Reorganize with the same templates now plans nothing.
- MassRenamer: each step settles what a crash or a busy trash entry left in its sequences
  (SequenceWriter.ReadLocked) and waits, as a sequence deletion does, while a restore from
  the trash is not settled (FrameTrash.EnsureSettled), before its folder or any file name
  changes: that restore's journal names files by the names they had. Trash records keep
  restoring after a Reorganize: into the sequence where it is now, under the record's own
  name made free (_2) with its companion following.
- Jobs.Kind.Move and Admin.Job.Kind.Move now mean "Reorganize": their old "Move archive"
  translations are removed from the 36 other cultures so they are translated again.
- Tests: a second run plans nothing (planner and archive), companions found alike by the
  trash and Reorganize whatever their case, a photo deleted before a Reorganize comes back
  beside the new names, a Reorganize waits for a busy restore and settles it first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-10-27 14:23:32 +01:00
1 parent ad72501f11
commit 950524929c
78 files changed
+183 -75

No files matched your search

@@ -82,6 +82,22 @@ public sealed class ReorganizeTests(TestContext context)
Assert.Count(2, plan.Samples);
}
[Test]
public void TheTrashAndReorganizeFindTheSameCompanionsWhateverTheirCase()
{
var sequence = Folder(out _);
var manifest = Sequence("originals/A.CR2", "originals/B.CR2");
foreach (var file in new[] { "originals/A.CR2", "originals/B.CR2", "originals/a.XMP", "originals/b.cr2.Xmp", "originals/c.xmp" }) Write(sequence, file, file);
var present = FileRenames.ListPresent(sequence, manifest);
var plan = FileRenames.Plan(manifest, null, PathTemplate.Parse("{n:0000}"), present);
Assert.SequenceEqual(["originals/A.CR2>originals/0001.CR2", "originals/a.XMP>originals/0001.XMP", "originals/B.CR2>originals/0002.CR2",
"originals/b.cr2.Xmp>originals/0002.cr2.Xmp"], plan.Moves.Select(m => $"{m.From}>{m.To}"));
var index = new FrameCompanions.Index(sequence);
Assert.SequenceEqual(["originals/a.XMP"], index.Of("originals/A.CR2"));
Assert.SequenceEqual(["originals/b.cr2.Xmp"], index.Of("originals/B.CR2"));
Assert.SequenceEqual(plan.Moves.Where(m => m.Companion).Select(m => m.From), manifest.Frames.SelectMany(f => FrameCompanions.Of(sequence, f.File)));
}
[Test]
public void NamesGivenOnceStayAsTheyAre()
{
@@ -124,6 +140,28 @@ public sealed class ReorganizeTests(TestContext context)
Assert.False(keptOnly.Steps.Single().Changes);
}
[Test]
public void FoldersTheTemplateGaveAlreadyStayAndASecondRunPlansNothing()
{
// Two sequences of one day filed by the template, the second beside the first; a third elsewhere, a fourth whose
// folder differs only in case, a fifth with a number filing never gives.
const string Template = "{year}/{date} {title}";
RenameSubject At(string folder) => new(Guid.NewGuid(), folder, "Sunset", Start, null, null, null);
RenameSubject[] subjects = [At("2026/2026-09-28 Sunset"), At("2026/2026-09-28 Sunset (2)"), At("inbox/c"), At("2026/2026-09-28 sunset (4)"),
At("2026/2026-09-28 Sunset (03)")];
var plan = RenamePlanner.Plan(Guid.NewGuid(), subjects, Template, null, subjects.Select(s => s.Folder), _ => false);
Assert.SequenceEqual([(subjects[2].SequenceId, "2026/2026-09-28 Sunset (3)"), (subjects[3].SequenceId, "2026/2026-09-28 Sunset (4)"),
(subjects[4].SequenceId, "2026/2026-09-28 Sunset (5)")], plan.Steps.Select(s => (s.SequenceId, s.ToFolder)));
// Where the plan put them, the same template changes nothing.
var moved = plan.Steps.ToDictionary(s => s.SequenceId, s => s.ToFolder);
RenameSubject[] after = [.. subjects.Select(s => moved.TryGetValue(s.SequenceId, out var to) ? s with { Folder = to } : s)];
var onDisk = after.Select(s => s.Folder).ToHashSet(StringComparer.OrdinalIgnoreCase);
Assert.Empty(RenamePlanner.Plan(Guid.NewGuid(), after, Template, null, onDisk, onDisk.Contains).Steps);
// Nor in another order.
Assert.Empty(RenamePlanner.Plan(Guid.NewGuid(), [.. after.Reverse()], Template, null, onDisk, onDisk.Contains).Steps);
}
[Test]
public void TheFingerprintFollowsWhatThePlanChanges()
{