fix: conversions on the released phase 4a keep out of folders a sequence left

Phase 4b and its first fix round were written on phase 4a before its rounds 4-6. Moved onto the
released 4a, the conversion now follows 4a's rule for writers into a sequence's folder
(SequenceFolders.Holds), and the parallel fixes meet:

- The job leaves a sequence another index moved away (its folder missing, or holding another
  sequence's sidecar) as Blocked with Errors.Archive.FolderMoved, nothing settled, staged or
  replaced there; the retry after this index's scan converts it where it is. It read the
  sidecar there and reported the reader's technical text.
- New sequence reads the source's project under the source's lease, where its sidecar was just
  read as its own, and writes the new sequence's project under that sequence's lease only into
  a folder that holds it. It read the project from the folder the row named afterwards, without
  a lease, and wrote through the store without the check.
- Download originals (resolved in the cherry-pick of the trash and sync fix, tested here) swaps
  a copy fetched in another encoding into its missing frame after the transfers, as round 6
  restores originals, and only once the sequence is found in the folder the index has;
  otherwise the copies stay staged and the job fails with FolderMoved after its other work.
  The swap ran inside the transfer loop and failed the job at the first refusal.
- The New sequence wording of the three skip reasons the codecs fix added (Archive.Convert.
  NotCopied.EightBit, ColorProfile, TooLarge, en and it): the server and the desktop look them
  up by reason.
- The server's free space test sets the staging folder's figures too: the job fix measures the
  tighter of the archive root's and the staging folder's volumes.

Tests: a conversion of a sequence another index moved (its folder taken or empty), and a
download whose missing frame takes the server's conversion where the sequence is now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-10-27 22:33:11 +01:00
1 parent 8174852a2c
commit e3cbe30b29
6 files changed
+144 -28

No files matched your search

+39 -24
View File
@@ -306,6 +306,9 @@ public sealed class MassConverter
return new StepDone(Result(row, ConvertOutcome.Changed));
row = now;
folder = paths.Sequence(row.Folder);
// Moved away by another index of the archive, maybe with another sequence in the folder it left (this index's next
// scan finds both): nothing of it is settled, staged or replaced there; the retry after that scan converts it.
if (!SequenceFolders.Holds(folder, row.Id)) return new StepDone(Result(row, ConvertOutcome.Blocked, error: Loc.L("Errors.Archive.FolderMoved")));
manifest = SequenceWriter.ReadLocked(folder, row.Id);
FrameTrash.EnsureReplaced(folder);
var pin = pins.Of(step.Id);
@@ -596,13 +599,18 @@ public sealed class MassConverter
Dictionary<Guid, StagedConversion> ready, string staging, ConvertOptions options, string key, Guid? requestedBy, CancellationToken cancellationToken)
{
SequenceManifest manifest;
string? project;
await using (await _writer.LockAsync(paths, row.Id, cancellationToken).ConfigureAwait(false))
{
if (await _db.Sequences.GetAsync(row.Id, cancellationToken).ConfigureAwait(false) is not { } now || now.ArchiveId != archive.Id)
return new StepDone(Result(row, ConvertOutcome.Changed));
row = now;
manifest = SequenceWriter.ReadLocked(paths.Sequence(row.Folder), row.Id);
var folder = paths.Sequence(row.Folder);
manifest = SequenceWriter.ReadLocked(folder, row.Id);
if (!Holds(manifest, planned)) return new StepDone(Result(row, ConvertOutcome.Changed));
// The source's project, read where its sidecar was just read as its own: another index may move the sequence away
// later, and maybe another one into this folder, whose project the new sequence must not take.
project = row.SettingsJson ?? (File.Exists(folder.ProjectPath) ? AtomicFile.ReadAllText(folder.ProjectPath) : null);
}
var frames = manifest.Frames.ToDictionary(f => f.Id);
var filed = await FiledAsync(archive, key, cancellationToken).ConfigureAwait(false);
@@ -627,7 +635,7 @@ public sealed class MassConverter
await _ingest.CommitSessionAsync(archive, new SequenceTarget(key, title, null, owner), pending, CancellationToken.None).ConfigureAwait(false);
var id = await _db.Sequences.FindBySessionKeyAsync(archive.Id, key, CancellationToken.None).ConfigureAwait(false)
?? throw new IOException($"No converted photo of {row.DisplayTitle} could be filed into a new sequence.");
await CopyAsync(paths, row, manifest, ready, id, cancellationToken).ConfigureAwait(false);
await CopyAsync(paths, row, manifest, project, ready, id, cancellationToken).ConfigureAwait(false);
var made = await _db.Sequences.GetAsync(id, CancellationToken.None).ConfigureAwait(false)
?? throw new InvalidOperationException($"The new sequence {id} is not indexed.");
var leftOut = manifest.Frames.Count - planned.Frames.Count;
@@ -651,35 +659,42 @@ public sealed class MassConverter
}
/// <summary>
/// Gives the new sequence the source's tags, rating and notes, and its project with the frame positions (exclusions,
/// hero, keyframes) moved from the source's frames to the copies of them; a project that cannot be read is left out
/// (logged).
/// Gives the new sequence the source's tags, rating and notes, and its project (<paramref name="json"/>, read under the
/// source's lease) with the frame positions (exclusions, hero, keyframes) moved from the source's frames to the copies of
/// them; a project that cannot be read is left out (logged). The project is written under the new sequence's lease into
/// its folder as the index has it then, which must hold it (<see cref="SequenceFolders.Holds"/>).
/// </summary>
private async Task CopyAsync(ArchivePaths paths, Sequence source, SequenceManifest manifest, Dictionary<Guid, StagedConversion> ready, Guid id,
/// <exception cref="InvalidOperationException">Another index moved the new sequence away meanwhile; its project is not written.</exception>
private async Task CopyAsync(ArchivePaths paths, Sequence source, SequenceManifest manifest, string? json, Dictionary<Guid, StagedConversion> ready, Guid id,
CancellationToken cancellationToken)
{
await _service.EditSequenceInfoAsync(id, info => info with { Tags = source.Tags, Rating = source.Rating, Notes = source.Notes }, cancellationToken)
.ConfigureAwait(false);
var folder = paths.Sequence(source.Folder);
var json = source.SettingsJson ?? (File.Exists(folder.ProjectPath) ? AtomicFile.ReadAllText(folder.ProjectPath) : null);
if (string.IsNullOrWhiteSpace(json)) return;
var made = await _db.Sequences.GetAsync(id, cancellationToken).ConfigureAwait(false) ?? throw new InvalidOperationException($"The new sequence {id} is not indexed.");
var copy = Read(paths.Sequence(made.Folder), id) ?? throw new InvalidDataException($"The sidecar of the new sequence {made.DisplayTitle} cannot be read.");
// The source's frames as the copies the conversion made of them; a frame not converted keeps its own photo, which the
// new sequence lacks (its positions wait as pending frames).
var from = new FramePhotos(manifest.Frames.Select(f => (f.I, ready.TryGetValue(f.Id, out var c)
? new FramePhoto(c.Sha256.ToLowerInvariant(), c.Size, f.CapturedAt)
: new FramePhoto(f.Sha256, f.Size, f.CapturedAt))));
var to = new FramePhotos(copy.Frames.Select(f => (f.I, new FramePhoto(f.Sha256, f.Size, f.CapturedAt))));
try
await using (await _writer.LockAsync(paths, id, cancellationToken).ConfigureAwait(false))
{
var translated = ProjectSettings.TranslateFramePositions(json, from, to) ?? json;
var project = ProjectStore.Parse(translated);
await new ProjectStore(_db, _writer).UpdateAsync(paths, made, _ => project, cancellationToken).ConfigureAwait(false);
}
catch (InvalidDataException ex)
{
Core.Diagnostics.Log.Warning("archive", $"{source.DisplayTitle}: its project cannot be read; the new sequence {made.DisplayTitle} starts without it", ex);
var made = await _db.Sequences.GetAsync(id, cancellationToken).ConfigureAwait(false) ?? throw new InvalidOperationException($"The new sequence {id} is not indexed.");
var folder = paths.Sequence(made.Folder);
// Another index of the archive moved it away, and maybe another sequence into its folder (this index's next scan finds
// both): its project goes nowhere, as every writer into a sequence's folder decides.
if (!SequenceFolders.Holds(folder, id)) throw new InvalidOperationException(Loc.L("Errors.Archive.FolderMoved"));
var copy = Read(folder, id) ?? throw new InvalidDataException($"The sidecar of the new sequence {made.DisplayTitle} cannot be read.");
// The source's frames as the copies the conversion made of them; a frame not converted keeps its own photo, which the
// new sequence lacks (its positions wait as pending frames).
var from = new FramePhotos(manifest.Frames.Select(f => (f.I, ready.TryGetValue(f.Id, out var c)
? new FramePhoto(c.Sha256.ToLowerInvariant(), c.Size, f.CapturedAt)
: new FramePhoto(f.Sha256, f.Size, f.CapturedAt))));
var to = new FramePhotos(copy.Frames.Select(f => (f.I, new FramePhoto(f.Sha256, f.Size, f.CapturedAt))));
try
{
var translated = ProjectSettings.TranslateFramePositions(json, from, to) ?? json;
var project = ProjectStore.Parse(translated);
await new ProjectStore(_db, _writer).UpdateLockedAsync(paths, made, _ => project, cancellationToken).ConfigureAwait(false);
}
catch (InvalidDataException ex)
{
Core.Diagnostics.Log.Warning("archive", $"{source.DisplayTitle}: its project cannot be read; the new sequence {made.DisplayTitle} starts without it", ex);
}
}
}