fix(archive): a rebase moves no row of the sequence that took the old folder; writers refuse a folder another sequence holds

Round 4 let every row under the old folder follow when that folder holds another sequence
now. When the scan took the new holder first, its own row (already rebased into the old
folder) then followed the moving sequence too and named that sequence's file, leaving its
own export without a row; a second scan did not repair it. Only the moving sequence's own
rows now follow because the old folder is taken, and a row of the sequence holding the old
folder never follows: its export is in its own folder whatever the other one took along
under the same name. The rebase callback now gets the owner of each row.

Writers that file into the folder the index has for a sequence checked only that the folder
existed. After another index moved the sequence away and another one into that folder, Take
server wrote the server's settings into the other sequence's project.json, Save both wrote
this PC's copy into its .chronos, and a render sent for the sequence was filed among its
exports. SequenceFolders.Holds treats a folder whose sidecar names another sequence exactly
like a missing one, and every such writer asks it: settings sync and conflict resolution
(Errors.Archive.FolderMoved), Save both's copy and its clean-up, server render filing (503
folder_moved, the upload kept), export downloads, render jobs as they start, proxies sent and
proxy passes, the deep analysis checkpoint and the editor's project save. A thumbnail pass
refuses a sidecar of another sequence before it opens the pack.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit b406a4f6a9a7a3121e9e40289663fb62ee31948e)
This commit is contained in:
Alby96 committed 2026-10-27 20:36:20 +01:00
1 parent 26b03d1c6d
commit 8c2b9f1bfe
17 files changed
+260 -57

No files matched your search

@@ -170,6 +170,41 @@ public sealed class ReorganizeTests(TestContext context)
Assert.Empty(await server.Database.Renders.ListBySequenceAsync(id));
}
[Test]
public async Task AnExportIsNeverFiledAmongThoseOfAnotherSequenceMovedIntoItsFolder()
{
await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register);
var (editor, _, _) = await server.UserAsync("alberto", "editor");
var id = (await Uploads.UploadAsync(editor, Photo(1), "IMG_0001.JPG", sessionKey: "roof")).SequenceId;
var other = (await Uploads.UploadAsync(editor, Photo(2), "IMG_0002.JPG", sessionKey: "cam")).SequenceId;
await UntilIdleAsync(server);
var sequence = (await server.Database.Sequences.GetAsync(id))!;
var stranger = (await server.Database.Sequences.GetAsync(other))!;
// A desktop sharing the archive moved the folder away, then the other sequence into the folder it left; this server's
// index still has both where they were.
var folder = Path.Combine(server.Options.ArchivePath, sequence.Folder);
Directory.Move(folder, Path.Combine(server.Options.ArchivePath, "elsewhere"));
Directory.Move(Path.Combine(server.Options.ArchivePath, stranger.Folder), folder);
var before = Files(folder);
var video = Uploads.Photo(4096, 31);
var staged = Path.Combine(context.CreateTempDirectory("staged"), "render.mp4");
await File.WriteAllBytesAsync(staged, video);
await Assert.ThrowsAsync<FolderMovedException>(() => server.Services.GetRequiredService<RenderStore>().CommitAsync(sequence, staged,
new RenderResultRequest("Roof - 4K.mp4", video.Length, Uploads.Sha(video), "4K HEVC", "hevc", 3840, 2160, 25, 4), "studio-pc", CancellationToken.None));
Assert.FileExists(staged);
Assert.SequenceEqual(before, Files(folder), "the other sequence's files are untouched");
Assert.Empty(await server.Database.Renders.ListBySequenceAsync(id));
}
/// <summary>Every file under <paramref name="folder"/> with the hash of its content, in path order.</summary>
private static List<string> Files(string folder) =>
[
.. Directory.EnumerateFiles(folder, "*", SearchOption.AllDirectories).Order(StringComparer.Ordinal)
.Select(p => $"{Path.GetRelativePath(folder, p).Replace('\\', '/')} {Uploads.Sha(File.ReadAllBytes(p))}"),
];
[Test]
public async Task AReorganizeAsksForTheArchiveAndAValidRequest()
{