fix(archive): move sequences nested in a renamed folder with it
A mass rename or move of a sequence whose folder holds other sequences moved their files without updating their index rows, and a target inside another sequence's folder could nest one sequence in another. The plan now carries the nested sequences (listed in the dry run, moved with the folder that holds them, inner folders leaving first) and refuses a target inside a sequence folder with a localized NestedRenameException (CD-4). The Archive screen counts only the selected sequences in its summary. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
7 files changed
+134
-12
No files matched your search
@@ -105,6 +105,69 @@ public sealed class MassRenameTests(TestContext context)
|
||||
Assert.True(Directory.Exists(fx.Paths.FromRelative(other.Steps[0].ToFolder)));
|
||||
}
|
||||
|
||||
/// <summary>"trips" with photos of its own, "trips/day2" inside it and "trips/day2/dawn" inside that: three nested sequences.</summary>
|
||||
private static async Task<List<Guid>> NestedAsync(ArchiveFixture fx)
|
||||
{
|
||||
Photos.WriteSeries(Path.Combine(fx.Paths.Root, "trips"), Start, 2);
|
||||
Photos.WriteSeries(Path.Combine(fx.Paths.Root, "trips", "day2"), Start.AddDays(1), 2, firstSeed: 10);
|
||||
Photos.WriteSeries(Path.Combine(fx.Paths.Root, "trips", "day2", "dawn"), Start.AddDays(2), 2, firstSeed: 20);
|
||||
await fx.ScanAsync();
|
||||
var locations = (await fx.Db.Sequences.ListLocationsAsync(fx.Archive.Id)).OrderBy(l => l.Folder, StringComparer.Ordinal).ToList();
|
||||
Assert.SequenceEqual(["trips", "trips/day2", "trips/day2/dawn"], locations.Select(l => l.Folder));
|
||||
return [.. locations.Select(l => l.Id)];
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SequencesInsideAMovedFolderAreInTheDryRunAndMoveWithIt()
|
||||
{
|
||||
await using var fx = await CreateAsync(context);
|
||||
var ids = await NestedAsync(fx);
|
||||
var before = await StateAsync(fx, ids);
|
||||
|
||||
var plan = await fx.Service.PlanRenameAsync(fx.Archive.Id, [ids[0]], "moved/{date}", null, fx.Ct);
|
||||
Assert.SequenceEqual(["moved/2026-09-28", "moved/2026-09-28/day2", "moved/2026-09-28/day2/dawn"], plan.Steps.Select(s => s.ToFolder));
|
||||
Assert.SequenceEqual([false, true, true], plan.Steps.Select(s => s.Carried));
|
||||
Assert.SequenceEqual(before, await StateAsync(fx, ids));
|
||||
|
||||
await fx.Service.ApplyRenameAsync(plan, null, fx.Ct);
|
||||
Assert.SequenceEqual(Expected(plan, before), await StateAsync(fx, ids));
|
||||
Assert.Empty(RenameJournal.ListPending(fx.Paths));
|
||||
Assert.Equal(0, (await fx.ScanAsync()).Indexed);
|
||||
Assert.Empty((await fx.Service.FindOrphansAsync(fx.Archive.Id, fx.Ct)).MissingSequences);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task NestedSequencesMovedTogetherLeaveTheirFolderFirst()
|
||||
{
|
||||
await using var fx = await CreateAsync(context);
|
||||
var ids = await NestedAsync(fx);
|
||||
var before = await StateAsync(fx, ids);
|
||||
|
||||
var plan = await fx.Service.PlanRenameAsync(fx.Archive.Id, ids, "moved/{date}", null, fx.Ct);
|
||||
Assert.SequenceEqual([ids[2], ids[1], ids[0]], plan.Steps.Select(s => s.SequenceId));
|
||||
Assert.True(plan.Steps.All(s => !s.Carried));
|
||||
|
||||
await fx.Service.ApplyRenameAsync(plan, null, fx.Ct);
|
||||
Assert.SequenceEqual(["moved/2026-09-28", "moved/2026-09-29", "moved/2026-09-30"], (await fx.Db.Sequences.ListLocationsAsync(fx.Archive.Id))
|
||||
.Select(l => l.Folder).Order(StringComparer.Ordinal));
|
||||
Assert.SequenceEqual(Expected(plan, before), await StateAsync(fx, ids));
|
||||
Assert.Equal(0, (await fx.ScanAsync()).Indexed);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AFolderInsideASequenceFolderIsRefused()
|
||||
{
|
||||
await using var fx = await CreateAsync(context);
|
||||
var ids = await PopulateAsync(fx);
|
||||
var before = await StateAsync(fx, ids);
|
||||
|
||||
var into = await Assert.ThrowsAsync<NestedRenameException>(() => fx.Service.PlanRenameAsync(fx.Archive.Id, [ids[1]], "inbox/a/{date}", null, fx.Ct));
|
||||
Assert.Equal("inbox/a", into.Folder);
|
||||
var itself = await Assert.ThrowsAsync<NestedRenameException>(() => fx.Service.PlanRenameAsync(fx.Archive.Id, [ids[0]], "inbox/a/{date}", null, fx.Ct));
|
||||
Assert.Equal("inbox/a/2026-09-28", itself.Target);
|
||||
Assert.SequenceEqual(before, await StateAsync(fx, ids));
|
||||
}
|
||||
|
||||
/// <summary>Reports synchronously (Progress<T> would post to the thread pool).</summary>
|
||||
private sealed class SyncProgress(Action<int> report) : IProgress<int>
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user