fix(archive): exports follow a Reorganize folder move; writers resolve the folder under the lease

A Reorganize step that moves a sequence folder carries its exports/ with it, but only
the sequences and frames rows followed: renders.output_path kept naming the old folder,
so the server answered 404 for the export, Get/Send exports and Reveal lost it, and no
scan or trash restore could repair it. RenderRepository.RebaseFolderAsync now rewrites
the archive-relative output paths of the step's sequence in the same transaction as the
frames (idempotent on resume; absolute outputs and the archive root are untouched).

Writers that read a sequence row before taking its lease wrote into the folder a
Reorganize had moved meanwhile, creating it again (project.json from the editor or a
sync, a thumbnail pack) or failing on its missing sidecar. They now take the folder from
the index row read under the lease (SequenceWriter.FolderAsync): the editor's save
refuses with FramesChangedException and reloads at the new folder, FramesCurrentAsync
reports a moved folder, and the sync apply, project store, thumbnail pass and its
status, decode tiers, analyses, verify, info edits, ingest, duplicate flags, pack
compaction and photo restores write where the sequence is now; a photo deletion planned
before the move is refused as stale.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit be28d8acf0d96012c94a266f8af61e9bbafaa28d)
This commit is contained in:
Alby96 committed 2026-10-27 16:29:59 +01:00
1 parent b253cac8d4
commit 9ce201cd70
22 files changed
+343 -35

No files matched your search

@@ -215,6 +215,44 @@ public sealed class ProjectStoreTests(TestContext context)
}
}
[Test]
public async Task AnEditorOpenWhileAReorganizeMovesItsFolderSavesWhereTheSequenceIsNow()
{
var (db, sequenceId, root) = await ArchiveAsync(6);
await using (db)
{
var options = new ArchiveServiceOptions { Owner = "test", LeaseWait = TimeSpan.FromSeconds(20) };
await using var source = new LocalSequenceSource(db, sequenceId, DecoderFactory.CreateClient(null), null, options);
var content = await source.LoadAsync(context.Cancellation);
var session = new EditorSession(source, content, [], TimeSpan.FromMilliseconds(20));
await using (session)
{
Assert.True(session.SetHero(2));
Assert.True(await session.FlushAsync());
// Only the folder template changed: the Reorganize moves the folder and keeps the frames version.
var service = new ArchiveService(db, options);
var plan = await service.PlanRenameAsync(content.Sequence.ArchiveId, [sequenceId], "Moved/{title}", null, context.Cancellation);
await service.ApplyRenameAsync(plan, null, context.Cancellation);
var moved = new ArchivePaths(root).Sequence(plan.Steps.Single().ToFolder);
Assert.Equal(content.Sequence.FramesVersion, (await db.Sequences.GetAsync(sequenceId))!.FramesVersion);
Assert.False(await source.FramesCurrentAsync(context.Cancellation), "the files are no longer where the editor read them");
session.Edit(p => p with { Exposure = p.Exposure with { ExposureOffsetEv = 0.4 } });
Assert.True(await session.FlushAsync());
var row = (await db.Sequences.GetAsync(sequenceId))!;
Assert.Equal(0.4, ProjectSettings.FromJson(row.SettingsJson!).Exposure.ExposureOffsetEv);
Assert.Equal(row.SettingsJson, File.ReadAllText(moved.ProjectPath), "the moved folder's project has the edit");
Assert.False(Directory.Exists(Path.Combine(root, "Synthetic")), "the folder it left is not created again");
Assert.True(await source.FramesCurrentAsync(context.Cancellation));
Assert.Equal(moved.Exports, session.Content.ExportsFolder);
using var frame = await source.DecodeAsync(1, 32, DecodePurpose.Thumbnail, context.Cancellation);
Assert.NotNull(frame, "the frames are read where they are now");
}
}
}
[Test]
public async Task ASaveThatDoesNotReachTheIndexThrows()
{