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

+13 -8
View File
@@ -754,9 +754,10 @@ public sealed class SyncService
if (await positions.ToLocalAsync(payload.SettingsJson, local.SettingsVersion, cancellationToken).ConfigureAwait(false) is not { } current) return null;
var row = current.Local;
// The folder too: a Reorganize moves it and its row under this lease. One another index moved is found by the next
// scan; nothing is written until then, so the folder it left is not created again.
// scan; nothing is written until then, so the folder it left is not created again, nor written in when it holds
// another sequence now.
var folder = paths.Sequence(row.Folder);
if (!Directory.Exists(folder.Folder)) return null;
if (!SequenceFolders.Holds(folder, row.Id)) return null;
payload = payload with { SettingsJson = current.SettingsJson };
var metadata = !payload.SameMetadata(SyncPayload.Of(row));
var settings = !SyncRules.SameSettings(payload.SettingsJson, row.SettingsJson);
@@ -808,7 +809,8 @@ public sealed class SyncService
/// "Save both": this PC's project is kept next to <c>project.json</c> as <c>project.this-pc-&lt;local time&gt;.json</c>
/// before the server's replaces it; returns that file. Written under the sequence's lease into its folder as the index
/// has it then: a Reorganize may have moved it while the server was asked, and the folder it left is never created again.
/// Null, with nothing written, when the sequence is not in that folder (another index moved it; the next scan finds it).
/// Null, with nothing written, when the sequence is not in that folder (another index moved it, and maybe another
/// sequence into it; the next scan finds them, <see cref="SequenceFolders.Holds"/>).
/// </summary>
private async Task<string?> SaveCopyAsync(Sequence local, CancellationToken cancellationToken)
{
@@ -820,7 +822,7 @@ public sealed class SyncService
await using (await _writer.LockAsync(paths, local.Id, cancellationToken).ConfigureAwait(false))
{
var folder = await SequenceWriter.FolderAsync(_db, paths, local, cancellationToken).ConfigureAwait(false);
if (!Directory.Exists(folder.Folder)) return null;
if (!SequenceFolders.Holds(folder, local.Id)) return null;
Directory.CreateDirectory(folder.MetaDirectory);
path = Path.Combine(folder.MetaDirectory, SavedCopyName(DateTime.Now));
AtomicFile.WriteAllText(path, SyncRules.NormalizeSettings(local.SettingsJson));
@@ -831,7 +833,8 @@ public sealed class SyncService
/// <summary>
/// Whether the sequence is not in the folder the index has for it now, on an archive that is there: another index moved
/// it, and this index's next scan finds it. Read without the lease, to tell why a resolution wrote nothing.
/// it (and maybe another sequence into that folder), and this index's next scan finds it. Read without the lease, to
/// tell why a resolution wrote nothing.
/// </summary>
private async Task<bool> FolderMovedAsync(Sequence local, CancellationToken cancellationToken)
{
@@ -839,13 +842,14 @@ public sealed class SyncService
|| await _db.Archives.GetAsync(row.ArchiveId, cancellationToken).ConfigureAwait(false) is not { } archive)
return false;
var paths = new ArchivePaths(archive.RootPath);
return Directory.Exists(paths.Root) && !Directory.Exists(paths.Sequence(row.Folder).Folder);
return Directory.Exists(paths.Root) && !SequenceFolders.Holds(paths.Sequence(row.Folder), row.Id);
}
/// <summary>
/// Deletes a "Save both" copy of a version the user did not keep from the sequence's folder as the index has it now: a
/// Reorganize may have moved the folder, the copy with it, since the copy was written. Best effort: a copy that cannot
/// be reached (the folder gone, the sequence busy, the archive offline) stays, as one more copy of this PC's version.
/// be reached (the folder gone or another sequence's now, the sequence busy, the archive offline) stays, as one more
/// copy of this PC's version.
/// </summary>
private async Task DeleteCopyAsync(Sequence local, string saved, CancellationToken cancellationToken)
{
@@ -857,7 +861,8 @@ public sealed class SyncService
await using (await _writer.LockAsync(paths, local.Id, cancellationToken).ConfigureAwait(false))
{
var folder = await SequenceWriter.FolderAsync(_db, paths, local, cancellationToken).ConfigureAwait(false);
if (Directory.Exists(folder.MetaDirectory)) File.Delete(Path.Combine(folder.MetaDirectory, Path.GetFileName(saved)));
if (SequenceFolders.Holds(folder, local.Id) && Directory.Exists(folder.MetaDirectory))
File.Delete(Path.Combine(folder.MetaDirectory, Path.GetFileName(saved)));
}
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException)
+3 -2
View File
@@ -379,12 +379,13 @@ internal sealed class SyncTransfers(SyncService sync)
// Filed under the sequence's lease into its folder as the index has it then, as a server files a render: a
// Reorganize may have moved it since the sequence was read, and moves the row's path along when it moves it later.
// One another index moved is found by this index's next scan; until then nothing is filed (the download stays
// staged for the next attempt), so the folder it left is not created again.
// staged for the next attempt), so the folder it left is not created again, nor filed into when it holds another
// sequence now.
var filed = await sync.Archives.UnderLeaseAsync(local, async row =>
{
if (row is null) throw new InvalidOperationException(Loc.L("Errors.Sync.LocalMissing"));
var folder = paths.Sequence(row.Folder);
if (!Directory.Exists(folder.Folder)) return false;
if (!SequenceFolders.Holds(folder, row.Id)) return false;
Directory.CreateDirectory(folder.Exports);
var target = Unique(folder.Exports, name);
File.Move(part, target);