fix(archive): exports follow a folder any index moved; proxies, exports and copies no longer recreate it
Second review of owner review 2, phase 4a (Reorganize), cross-cutting findings. - A second index of the archive (a desktop sharing a server's archive, or a folder moved by hand) moved the sequence row at its next scan but left renders.output_path at the old folder: the export answered 404 there. The scan now rebases the render rows in the same transaction when it finds a sequence in another folder. - The rebase covers every render of the archive under the old folder: the sequence's own exports always, and another sequence's export saved inside it (through the Export folder picker) when its file moved with the folder. That check keeps the exports of a sequence that took the old folder since (a later Reorganize on the other index) where they are. A change of case only counts as a move. - The desktop now tells an open editor after each Reorganize step (ArchiveServiceOptions.SequenceChanged -> AppServices.SequenceReorganized), and the editor reads its sequence again where it is now, so frames no longer decode blank until the next save. LocalSequenceSource.LoadAsync also requires the same folder on both row reads, so a move that commits during the frame listing is never taken as current. - Writers that wrote without the lease, or trusted a row another index had moved, could create the old folder again. A proxy sent by a client is now filed under the sequence's lease into the folder the index has then, and a gone sequence or folder answers 404 (sequence_busy 503 after the lease wait). The server files a render a client or render node sends under the lease (ArchiveService.UnderLeaseAsync). "Save both" keeps its copy under the lease. The proxy pass holds the thumbnail lease, as the thumbnail pass does. The deep analysis opens its checkpoint under the sequence lock only while the folder is still there, and a pass whose folder another process moved records nothing (the job logs Advisor.Log.FramesChangedElsewhere). Editor saves and sync applies refuse when the folder is gone. - ARCHITECTURE.md no longer claims more than this: a render of another process whose folder moves while it runs is still not stopped. - ArchiveVerifier.FlushAsync: corrected the comment. A move keeps each file's stamp, so only a check that found the file missing no longer applies. Tests cover the scan path with a later swap into the vacated folder, another sequence's export inside a moving folder, a photo deletion refused when the folder moved while it waited for the lease, proxies sent and made after a move, Save both during a move, a deep analysis whose folder another index moved, a render filed after a move on the server, and an open editor reloaded by a Move job. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit c857b98f795b22956c060f1c5acf4d94b6d1c994)
This commit is contained in:
1 parent
765f0ad36b
commit
6e99a4b269
20 files changed
+561
-160
No files matched your search
@@ -241,23 +241,30 @@ public sealed class MassRenameTests(TestContext context)
|
||||
{
|
||||
await using var fx = await CreateAsync(context);
|
||||
var ids = await NestedAsync(fx);
|
||||
// Exports of "trips" and of "trips/day2" in their folders, one of "trips" outside the archive, and a row whose
|
||||
// path only starts with the same letters.
|
||||
// Exports of "trips" and of "trips/day2" in their folders, one of "trips/day2/dawn" saved in the exports of "trips"
|
||||
// (the Export tab's folder picker), one of "trips" outside the archive, a row whose path only starts with the same
|
||||
// letters, and one of "trips/day2" in "trips" whose file is gone.
|
||||
var outside = Path.Combine(context.CreateTempDirectory("exports"), "Trips elsewhere.mp4");
|
||||
List<Guid> renders =
|
||||
[
|
||||
await RenderAsync(fx, ids[0], "trips/exports/Trips.mp4"),
|
||||
await RenderAsync(fx, ids[1], "trips/day2/exports/Day 2.mp4"),
|
||||
await RenderAsync(fx, ids[2], "trips/exports/Dawn.mp4"),
|
||||
await RenderAsync(fx, ids[0], outside),
|
||||
await RenderAsync(fx, ids[0], "trips 2/exports/Other.mp4", write: false),
|
||||
await RenderAsync(fx, ids[1], "trips/exports/Gone.mp4", write: false),
|
||||
];
|
||||
var plan = await fx.Service.PlanRenameAsync(fx.Archive.Id, [ids[0]], "moved/{date}", null, fx.Ct);
|
||||
Assert.SequenceEqual([false, true, true], plan.Steps.Select(s => s.Carried));
|
||||
|
||||
await fx.Service.ApplyRenameAsync(plan, null, fx.Ct);
|
||||
string[] expected = ["moved/2026-09-28/exports/Trips.mp4", "moved/2026-09-28/day2/exports/Day 2.mp4", outside, "trips 2/exports/Other.mp4"];
|
||||
string[] expected =
|
||||
[
|
||||
"moved/2026-09-28/exports/Trips.mp4", "moved/2026-09-28/day2/exports/Day 2.mp4", "moved/2026-09-28/exports/Dawn.mp4", outside,
|
||||
"trips 2/exports/Other.mp4", "trips/exports/Gone.mp4",
|
||||
];
|
||||
Assert.SequenceEqual(expected, await OutputsAsync(fx, renders));
|
||||
foreach (var path in expected[..3]) Assert.FileExists(Path.IsPathRooted(path) ? path : fx.Paths.FromRelative(path));
|
||||
foreach (var path in expected[..4]) Assert.FileExists(Path.IsPathRooted(path) ? path : fx.Paths.FromRelative(path));
|
||||
|
||||
// A crash after the steps were recorded but before the journal said so: completed again, and again, nothing moves twice.
|
||||
RenameJournal.Write(fx.Paths, new RenameJournal(plan, []));
|
||||
@@ -266,6 +273,71 @@ public sealed class MassRenameTests(TestContext context)
|
||||
Assert.SequenceEqual(expected, await OutputsAsync(fx, renders));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnotherIndexFindsTheExportsWhereAReorganizeMovedTheirFolder()
|
||||
{
|
||||
await using var fx = await CreateAsync(context);
|
||||
var ids = await PopulateAsync(fx);
|
||||
// This index's exports: of "inbox/a" in its folder, of "inbox/b" saved in the exports of "inbox/a", of "inbox/c" in its own.
|
||||
List<Guid> renders =
|
||||
[
|
||||
await RenderAsync(fx, ids[0], "inbox/a/exports/A.mp4"),
|
||||
await RenderAsync(fx, ids[1], "inbox/a/exports/B.mp4"),
|
||||
await RenderAsync(fx, ids[2], "inbox/c/exports/C.mp4"),
|
||||
];
|
||||
var (server, archive) = await fx.OtherWriterAsync();
|
||||
|
||||
// The other index (a server sharing this desktop's archive) moves "inbox/a", then "inbox/c" into the folder it left.
|
||||
var first = await server.PlanRenameAsync(archive.Id, [ids[0]], "moved/{date}", null, fx.Ct);
|
||||
await server.ApplyRenameAsync(first, null, fx.Ct);
|
||||
var second = await server.PlanRenameAsync(archive.Id, [ids[2]], "inbox/a", null, fx.Ct);
|
||||
Assert.Equal("inbox/a", second.Steps.Single().ToFolder);
|
||||
await server.ApplyRenameAsync(second, null, fx.Ct);
|
||||
|
||||
// A scan here finds both where they are now (the new "inbox/a" first): each export follows the folder its file moved with.
|
||||
await fx.ScanAsync();
|
||||
Assert.Equal("moved/2026-09-28", (await fx.Db.Sequences.GetAsync(ids[0], fx.Ct))!.Folder);
|
||||
Assert.Equal("inbox/a", (await fx.Db.Sequences.GetAsync(ids[2], fx.Ct))!.Folder);
|
||||
string[] expected = ["moved/2026-09-28/exports/A.mp4", "moved/2026-09-28/exports/B.mp4", "inbox/a/exports/C.mp4"];
|
||||
Assert.SequenceEqual(expected, await OutputsAsync(fx, renders));
|
||||
foreach (var path in expected) Assert.FileExists(fx.Paths.FromRelative(path));
|
||||
Assert.Equal(0, (await fx.ScanAsync()).Indexed);
|
||||
Assert.SequenceEqual(expected, await OutputsAsync(fx, renders));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task APhotoDeletionWhoseFolderMovedWhileItWaitedForTheLeaseIsRefused()
|
||||
{
|
||||
await using var fx = await CreateAsync(context);
|
||||
var ids = await PopulateAsync(fx);
|
||||
var frames = await fx.Db.Frames.ListBySequenceAsync(ids[0], cancellationToken: fx.Ct);
|
||||
var deletion = await fx.Service.FrameTrash.PlanDeleteAsync(ids[0], [frames[1].Id], cancellationToken: fx.Ct);
|
||||
Assert.True(deletion.CanDelete);
|
||||
var pause = TimeSpan.FromSeconds(TestTiming.Budget(0.5));
|
||||
|
||||
// Another process holds the sequence and moves its folder (a Reorganize), while the deletion waits for the lease.
|
||||
Task<FrameDeleteResult> delete;
|
||||
using (await LeaseFile.AcquireAsync(fx.Paths.LocksDirectory, $"seq-{ids[0]:N}", "other", TimeSpan.FromSeconds(5), cancellationToken: fx.Ct))
|
||||
{
|
||||
delete = fx.Service.FrameTrash.DeleteAsync(deletion, cancellationToken: fx.Ct);
|
||||
await Task.Delay(pause, fx.Ct);
|
||||
Assert.False(delete.IsCompleted, "the deletion waits for the other process");
|
||||
Directory.CreateDirectory(fx.Paths.FromRelative("moved"));
|
||||
Directory.Move(fx.Paths.FromRelative("inbox/a"), fx.Paths.FromRelative("moved/a"));
|
||||
await using var tx = await fx.Db.BeginAsync(fx.Ct);
|
||||
await tx.Sequences.RelocateAsync(ids[0], "moved/a", null, fx.Ct);
|
||||
await tx.Frames.RebaseFolderAsync(ids[0], "inbox/a", "moved/a", fx.Ct);
|
||||
await tx.CommitAsync(fx.Ct);
|
||||
}
|
||||
|
||||
await Assert.ThrowsAsync<StaleDeletePlanException>(() => delete);
|
||||
Assert.Count(3, await fx.Db.Frames.ListBySequenceAsync(ids[0], cancellationToken: fx.Ct));
|
||||
Assert.Count(3, ManifestStore.ReadSequence(fx.Paths.Sequence("moved/a").ManifestPath).Frames);
|
||||
foreach (var f in frames) Assert.FileExists(fx.Paths.FromRelative(f.RelativePath.Replace("inbox/a/", "moved/a/", StringComparison.Ordinal)));
|
||||
Assert.Empty(await fx.Service.Trash.ListAsync(fx.Archive, fx.Ct));
|
||||
Assert.False(Directory.Exists(fx.Paths.FromRelative("inbox/a")), "the folder it left is not created again");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnInterruptedMoveTakesTheExportsAlongWhenItResumes()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user