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:
Alby96 committed 2026-10-27 18:09:02 +01:00
1 parent 765f0ad36b
commit 6e99a4b269
20 files changed
+561 -160

No files matched your search

+11
View File
@@ -150,6 +150,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
session.Source.JobChanged += OnJobChanged;
session.Source.ReadOnlyChanged += OnReadOnlyChanged;
shell.Services.Sync.Changed += OnSyncChanged;
shell.Services.SequenceReorganized += OnSequenceReorganized;
UpdateMarkers();
RefreshSteps();
RequestCorrections();
@@ -708,6 +709,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
Session.Source.JobChanged -= OnJobChanged;
Session.Source.ReadOnlyChanged -= OnReadOnlyChanged;
Shell.Services.Sync.Changed -= OnSyncChanged;
Shell.Services.SequenceReorganized -= OnSequenceReorganized;
foreach (var tab in Tabs) tab.Dispose();
base.Dispose();
await Session.DisposeAsync();
@@ -1182,6 +1184,15 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
if (ServerJob is { } job) await Session.Source.CancelJobAsync(job.Id, CancellationToken.None);
}
/// <summary>
/// A Reorganize of this PC moved the folder of a sequence or renamed it or its files (any thread): the open sequence of
/// this PC is read again where it is now, so its frames decode and its project goes there.
/// </summary>
private void OnSequenceReorganized(Guid sequenceId) => _dispatcher.BeginInvoke(() =>
{
if (!_disposed && !IsRemote && sequenceId == Session.Content.Sequence.Id) _ = ReloadAsync(null);
});
/// <summary>The session, the sync links or the rights changed (any thread): whether the Export "Sync" option applies.</summary>
private void OnSyncChanged() => _dispatcher.BeginInvoke(() => _ = OnSyncChangedAsync());
@@ -179,6 +179,8 @@ public sealed class LocalSequenceSource : ISequenceSource
// it too: moved since the read, the project goes to the new folder once the editor read the sequence there,
// and the folder it left is never created again.
if (row.FramesVersion != framesVersion || row.Folder != relativeFolder) throw new FramesChangedException(Loc.L("Editor.Error.FramesArriving"));
// Moved by another index of the archive (a server's Reorganize), which this index finds at its next scan.
if (!Directory.Exists(folder.Folder)) throw Missing();
var stored = ReadProject(row, folder);
var merged = ProjectMerge.SameValues(stored, basis) ? project : ProjectMerge.Merge(basis, project, stored);
var json = merged.ToJson();
@@ -227,9 +229,10 @@ public sealed class LocalSequenceSource : ISequenceSource
/// <summary>
/// The sequence row with its frames as one state: the frames are listed between two reads of the row that find the
/// same frames version (an insertion renumbers the frames and moves the row's positions in one transaction, and
/// bumps the version), so the project's positions name these frames.
/// bumps the version), so the project's positions name these frames, and the same folder (a Reorganize moves the
/// folder and rewrites the frames' paths in one transaction, the version kept), so the files are where they were read.
/// </summary>
/// <exception cref="EditorException">The sequence is gone, or an insertion landed during every attempt.</exception>
/// <exception cref="EditorException">The sequence is gone, or an insertion or a move landed during every attempt.</exception>
private async Task<(Sequence Row, List<Frame> Frames)> ReadFramesAsync(CancellationToken cancellationToken)
{
for (var attempt = 0; attempt < ReadAttempts; attempt++)
@@ -243,7 +246,7 @@ public sealed class LocalSequenceSource : ISequenceSource
if (page.Count < PageSize) break;
}
var after = await _db.Sequences.GetAsync(_sequenceId, cancellationToken) ?? throw Missing();
if (after.FramesVersion == before.FramesVersion) return (after, frames);
if (after.FramesVersion == before.FramesVersion && after.Folder == before.Folder) return (after, frames);
}
throw new EditorException(Loc.L("Editor.Error.FramesArriving"));
}
@@ -111,6 +111,12 @@ public sealed class AppServices : IAsyncDisposable
/// <summary>Sync with the signed-in server: engine, job connection, background comparison.</summary>
public SyncHost Sync { get; }
/// <summary>
/// A job of this PC moved a sequence's folder or changed its title or file names (a Reorganize step), with the
/// sequence's id (any thread): an open editor reads it again where it is now.
/// </summary>
public event Action<Guid>? SequenceReorganized;
public IEncoderInventory Encoders { get; set; }
/// <summary>Decode tier per format on this PC and the missing codec extensions (Settings › Formats).</summary>
@@ -452,6 +458,12 @@ public sealed class AppServices : IAsyncDisposable
// The housekeeping schedule trims the cache to Settings › Storage › Cache limit (owner review 2, R10).
CleanupSteps = [new CacheTrimStep(() => CacheStore.Folder(Environment, Settings), () => Settings.CacheLimitGb * (1L << 30))],
BackupDirectory = Environment.BackupDirectory,
// Told after each step of a Reorganize, while the rest of the job runs.
SequenceChanged = (id, _, _) =>
{
SequenceReorganized?.Invoke(id);
return Task.CompletedTask;
},
};
Archives = new ArchiveService(database, archive);
Processing = new ProcessingService(database, ProcessingOptions(archive));