fix(archive): a third sequence's export follows its file; resumed renders and restored originals stay out of folders a sequence left

Round 5 stopped clearing "behind" for rows of a third sequence (neither the one moving nor the
one now holding the old folder). Such a row, an export one sequence saved in another's exports
through the Export folder picker, then stayed at its old path whenever the sequence that moved
into the folder brought an export of the same name, and named that sequence's file (Send exports
would upload it). A file at the old path is never "behind" while the old folder holds another
sequence: it is that sequence's, so every row other than the holder's follows its file.

A resumed render job deleted the output its crashed attempt was writing at the absolute path in
the checkpoint. After another index moved the sequence away and another sequence into the folder
it left, and this index scanned, that path named the other sequence's export. The checkpoint now
keeps the sequence's folder when the output was chosen; a pending output there is rebased into the
folder the sequence is in now, one in the sequence's current exports or outside the archive (an
export folder chosen on a client) is discarded as before, and one anywhere else in the archive is
left alone (the entry renders under another name). Older checkpoints, without the folder, only
discard in the current exports.

Download originals put an original flagged missing back at the path read before the transfer,
with no lease and no check of the folder: after another index moved the sequence, it recreated
the folder it left or filed the photo among another sequence's originals. The restores now run
after the transfers under the sequence's lease, in the folder the index has then, which must hold
the sequence (SequenceFolders.Holds), at each frame's path read under that lease. Otherwise
nothing is restored, the copies stay staged for the next attempt and the job fails with
Errors.Archive.FolderMoved after its other work.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit ad46ef68180845de4b9b605a4ce2529a148c6f13)
This commit is contained in:
Alby96 committed 2026-10-27 21:07:06 +01:00
1 parent 23403f1c07
commit f8c445fac3
7 files changed
+210 -29

No files matched your search

@@ -6,6 +6,7 @@ using Chronos.Core.Model;
using Chronos.Core.Project;
using Chronos.Core.Render;
using Chronos.Data.Sync;
using Chronos.Data.Tests.Archiving;
using Chronos.Protocol;
using Chronos.Testing;
@@ -384,6 +385,54 @@ public sealed class SyncTransferTests(TestContext context)
Assert.Equal(SyncStatus.InSync, (await f.EntryAsync("Harbour")).Status);
}
[Test]
public async Task AnOriginalIsRestoredOnlyWhereTheSequenceIsNow()
{
// The folder the sequence left holds another sequence now, or nothing.
foreach (var taken in new[] { true, false })
{
await using var f = await SyncFixture.CreateAsync(context);
var photos = f.NewPhotos(3);
var local = await f.LocalAsync("Harbour", photos);
var stranger = taken ? await f.LocalAsync("Stranger", f.NewPhotos(2)) : null;
var lost = (await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct))[1];
File.Delete(f.Archive.Paths.FromRelative(lost.RelativePath));
await f.Archive.Service.Verifier.VerifyAsync(f.Archive.Archive, [local.Id], default, (_, _, _) => ValueTask.CompletedTask, cancellationToken: f.Ct);
var remote = f.Remote.Add("Harbour", photos);
await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct);
await f.RefreshAsync();
var engine = await f.StartEngineAsync();
// Another index moves the folder away, then the other sequence (first parked elsewhere: its folder is the same
// name with a number) into the folder it left; this index has scanned neither.
var folder = f.Archive.Paths.Sequence(local.Folder).Folder;
var (other, archive) = await f.Archive.OtherWriterAsync();
var moves = stranger is null ? [(local.Id, "moved/{title}")] : new[] { (local.Id, "moved/{title}"), (stranger.Id, "parked/{title}"), (stranger.Id, local.Folder) };
foreach (var (id, template) in moves)
await other.ApplyRenameAsync(await other.PlanRenameAsync(archive.Id, [id], template, null, f.Ct), null, f.Ct);
var before = taken ? ArchiveFixture.FilesOf(folder) : null;
var job = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Harbour", SyncDownloadMode.Originals, null);
var failed = await f.Archive.WaitForAsync(job.Id, JobState.Failed);
Assert.Equal(Loc.L("Errors.Archive.FolderMoved"), failed.Error, taken.ToString());
if (taken) Assert.SequenceEqual(before!, ArchiveFixture.FilesOf(folder), "the other sequence's files are untouched");
else Assert.False(Directory.Exists(folder), "the folder it left is not created again");
// Once this index's scan found it there, the original goes back into the folder the sequence is in now.
await f.Archive.ScanAsync();
job = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Harbour", SyncDownloadMode.Originals, null);
await f.Archive.WaitForAsync(job.Id, JobState.Done);
var moved = (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.Folder;
Assert.Equal("moved/Harbour", moved);
var restored = (await f.Db.Frames.GetAsync(lost.Id, f.Ct))!;
Assert.Equal(moved + lost.RelativePath[local.Folder.Length..], restored.RelativePath);
Assert.Equal(lost.Sha256, Sha(await File.ReadAllBytesAsync(f.Archive.Paths.FromRelative(restored.RelativePath), f.Ct)));
Assert.True((await f.Db.Frames.ListBySequenceAsync(local.Id, cancellationToken: f.Ct)).All(fr => (fr.Flags & FrameFlags.Missing) == 0), "nothing missing");
if (taken) Assert.SequenceEqual(before!, ArchiveFixture.FilesOf(folder), "the other sequence's files are still untouched");
else Assert.False(Directory.Exists(folder));
}
}
[Test]
public async Task OriginalsTheServerHasNotHashedAreDownloadedAndHashedHere()
{