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:
1 parent
23403f1c07
commit
f8c445fac3
7 files changed
+210
-29
No files matched your search
@@ -25,7 +25,8 @@ namespace Chronos.Data.Sync;
|
||||
/// original the server has not hashed yet, its size, and hash it here) and commit them through the archive ingest,
|
||||
/// which names them and writes the sidecar; the first original creates the local
|
||||
/// sequence, which then takes the server's settings. Frames of the local copy not hashed yet are hashed first (so the
|
||||
/// server's copies of them are recognised), and originals flagged missing here are restored to their recorded place.
|
||||
/// server's copies of them are recognised), and originals flagged missing here are restored to their recorded place in
|
||||
/// the folder the sequence is in (never one it left).
|
||||
/// Proxy downloads fill the proxy cache. Renders travel on request: this PC's to the server (hash-verified chunked
|
||||
/// upload) and the server's into the local copy's exports. A resumed job skips what is already on the other side, so
|
||||
/// pausing or a crash loses at most the files in flight.
|
||||
@@ -244,14 +245,14 @@ internal sealed class SyncTransfers(SyncService sync)
|
||||
await progress.StepAsync().ConfigureAwait(false);
|
||||
}
|
||||
var sequenceId = local?.Id;
|
||||
int restored = 0, refused = 0;
|
||||
var refused = 0;
|
||||
var restores = new ConcurrentBag<(string Staged, Guid FrameId)>();
|
||||
await Parallel.ForEachAsync(rest, Workers(sync.Options.Downloads, ct), async (frame, token) =>
|
||||
{
|
||||
var (staged, sha) = await FetchOriginalAsync(remote, frame, staging, token).ConfigureAwait(false);
|
||||
if (restore.TryGetValue(sha, out var place))
|
||||
if (restore.TryGetValue(sha, out var frameId))
|
||||
{
|
||||
Restore(staged, place);
|
||||
Interlocked.Increment(ref restored);
|
||||
restores.Add((staged, frameId));
|
||||
}
|
||||
else if (frame.Sha256.Length == 0 && (tombstones.DeletedLocally(sha) || have.Contains(tombstones.Canonical(sha)!)))
|
||||
{
|
||||
@@ -267,26 +268,30 @@ internal sealed class SyncTransfers(SyncService sync)
|
||||
}
|
||||
await progress.StepAsync().ConfigureAwait(false);
|
||||
}).ConfigureAwait(false);
|
||||
TryDeleteDirectory(staging);
|
||||
// Null when the sequence is not in the folder the index has: the copies stay staged for the next attempt.
|
||||
var restored = restores.IsEmpty ? 0 : await RestoreAsync(local!, paths, restores, ct).ConfigureAwait(false);
|
||||
if (restored is not null) TryDeleteDirectory(staging);
|
||||
// Restored originals are checked against their records, which clears their missing flag.
|
||||
if (restored > 0) await VerifyAsync(archive, local!.Id, ct).ConfigureAwait(false);
|
||||
|
||||
if (created) await sync.TakeAllAsync(remote, remoteId, ct).ConfigureAwait(false);
|
||||
await sync.RecompareAsync(remote, remoteId, ct).ConfigureAwait(false);
|
||||
if (sequenceId is { } downloaded && wanted.Count > restored + refused)
|
||||
if (sequenceId is { } downloaded && wanted.Count > restores.Count + refused)
|
||||
{
|
||||
var label = local!.DisplayTitle;
|
||||
await EnqueueFollowUpAsync(context, ArchiveJobs.Thumbnails([downloaded], label)).ConfigureAwait(false);
|
||||
await EnqueueFollowUpAsync(context, ProcessingJobs.LightAnalysis([downloaded], label)).ConfigureAwait(false);
|
||||
}
|
||||
if (restored is null) throw new InvalidOperationException(Loc.L("Errors.Archive.FolderMoved"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The originals a local copy holds (lower-case SHA-256, and their photos for server frames not hashed yet) and where
|
||||
/// each original flagged missing belongs. Frames not hashed yet (an adopted folder never verified) are hashed first
|
||||
/// through the archive's verify, so the server's copies of them are recognised instead of committed again as duplicates.
|
||||
/// The originals a local copy holds (lower-case SHA-256, and their photos for server frames not hashed yet) and the
|
||||
/// frame each original flagged missing restores. Frames not hashed yet (an adopted folder never verified) are hashed
|
||||
/// first through the archive's verify, so the server's copies of them are recognised instead of committed again as
|
||||
/// duplicates.
|
||||
/// </summary>
|
||||
private async Task<(HashSet<string> Have, Dictionary<string, string> Restore, FramePhotos Photos)> LocalContentAsync(Archive archive, Sequence local,
|
||||
private async Task<(HashSet<string> Have, Dictionary<string, Guid> Restore, FramePhotos Photos)> LocalContentAsync(Archive archive, Sequence local,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var frames = await SequenceFrames.ListAsync(sync.Database, local.Id, ct).ConfigureAwait(false);
|
||||
@@ -297,12 +302,11 @@ internal sealed class SyncTransfers(SyncService sync)
|
||||
}
|
||||
var have = frames.Where(f => (f.Flags & FrameFlags.Missing) == 0 && f.Sha256 is not null).Select(f => f.Sha256!.ToLowerInvariant())
|
||||
.ToHashSet(StringComparer.Ordinal);
|
||||
var paths = new ArchivePaths(archive.RootPath);
|
||||
var restore = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
var restore = new Dictionary<string, Guid>(StringComparer.Ordinal);
|
||||
foreach (var frame in frames.Where(f => (f.Flags & FrameFlags.Missing) != 0 && f.Sha256 is not null))
|
||||
{
|
||||
var sha = frame.Sha256!.ToLowerInvariant();
|
||||
if (!have.Contains(sha)) restore.TryAdd(sha, paths.FromRelative(frame.RelativePath));
|
||||
if (!have.Contains(sha)) restore.TryAdd(sha, frame.Id);
|
||||
}
|
||||
var photos = SyncRules.Photos([.. frames.Where(f => (f.Flags & FrameFlags.Missing) == 0)]);
|
||||
return (have, restore, photos);
|
||||
@@ -311,6 +315,35 @@ internal sealed class SyncTransfers(SyncService sync)
|
||||
private Task VerifyAsync(Archive archive, Guid sequenceId, CancellationToken ct) =>
|
||||
sync.Archives.Verifier.VerifyAsync(archive, [sequenceId], default, (_, _, _) => ValueTask.CompletedTask, cancellationToken: ct);
|
||||
|
||||
/// <summary>
|
||||
/// Puts the verified copies of originals flagged missing (<paramref name="staged"/>, each with the frame it restores)
|
||||
/// back where their records say, under the sequence's lease in its folder as the index has it then: a Reorganize moves
|
||||
/// the folder and the frames' paths under that lease. Returns how many went back; a file that reappeared meanwhile is
|
||||
/// kept, and the copy of a frame that left the index is dropped. Null, with nothing restored and every copy kept in
|
||||
/// staging for the next attempt, when the sequence is not in that folder (another index moved it, and maybe another
|
||||
/// sequence into it; this index's next scan finds them): the folder it left is not created again, nor given an
|
||||
/// original of this sequence when it holds another one now.
|
||||
/// </summary>
|
||||
private Task<int?> RestoreAsync(Sequence local, ArchivePaths paths, IReadOnlyCollection<(string Staged, Guid FrameId)> staged, CancellationToken ct) =>
|
||||
sync.Archives.UnderLeaseAsync(local, async row =>
|
||||
{
|
||||
if (row is null) throw new InvalidOperationException(Loc.L("Errors.Sync.LocalMissing"));
|
||||
if (!SequenceFolders.Holds(paths.Sequence(row.Folder), row.Id)) return (int?)null;
|
||||
var restored = 0;
|
||||
foreach (var (copy, frameId) in staged)
|
||||
{
|
||||
// Read under the lease, as the folder: where the photo belongs in the folder the sequence is in now.
|
||||
if (await sync.Database.Frames.GetAsync(frameId, ct).ConfigureAwait(false) is not { } frame || frame.SequenceId != row.Id)
|
||||
{
|
||||
File.Delete(copy);
|
||||
continue;
|
||||
}
|
||||
Restore(copy, paths.FromRelative(frame.RelativePath));
|
||||
restored++;
|
||||
}
|
||||
return restored;
|
||||
}, ct);
|
||||
|
||||
/// <summary>Puts a verified copy of an original flagged missing back where its record says; a file that reappeared meanwhile is kept.</summary>
|
||||
private static void Restore(string staged, string place)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user