fix: conversions name, lock and settle as phase 4a's writers do

Phase 4b was built on phase 4a before its review fixes. Integrated on the reviewed 4a, the
conversion now follows the same rules as filing and the other writers.

- Names: a converted file is named as filing names a photo of its sequence (FrameNaming: the
  archive's file template, the frame's context in the sequence with its camera, lens, number
  and title, {name} the card's, {ext} the target's, a long name keeping its extension).
  Replace through ConvertOptions.FileName; New sequence through the ingest itself
  (StagedFrame.NamedAs), which numbers and names the copies in the new sequence. Names stay
  unique against every file present, those leaving included, so a Replace never moves onto a
  file; a test pins a stray file that keeps its bytes.
- Leases: stage A starts from the sidecar settled under the sequence's lease where the index
  has it then (SequenceWriter.ReadLocked), and FrameTrash.ReplaceAsync reads the row again
  under the lease, so a folder a Reorganize moved meanwhile is followed, never made again.
  A Reorganize the archive waits for keeps the conversion off its sequences (pinned).
- Journals: the replace journal is settled with the others. MassRenamer steps, restores into
  a sequence and sequence deletions wait for an unsettled replacement as they wait for a
  restore, and so do photo deletions, whose frames version the recovery reads
  (FrameTrash.EnsureReplaced); a scan settles it and reconciles nothing meanwhile; a restore
  settles its sequence's replace journal first, at the folder the index has under the lease.
- The convert job tells each sequence converted or made as it completes, as a Reorganize
  tells each step, so an editor open on it reads it again while the rest of the job runs.
- Desktop: JobKind.Convert gets its row in the settings' job priority list. A click on Apply
  that commits the quality no longer starts the same dry run again under the click (as 4a
  fixed for Reorganize).
- Panel: a dry run answered during the confirmation with the same plan no longer drops the
  confirmed Apply; a different plan is shown with Admin.Convert.PlanChanged (en, it).
- Tests: TrashDialogTests.EmptyQueuesTheJobOfTheConfirmedPlanOnly waits for the command to
  end before running it again (a running AsyncRelayCommand ignored the second Execute).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 2e0d1d6dcc10575734970bb9c77749f00777c859)
This commit is contained in:
Alby96 committed 2026-10-27 22:03:07 +01:00
1 parent a1c1c21ebd
commit 341fb77507
22 files changed
+345 -91

No files matched your search

@@ -15,13 +15,14 @@ namespace Chronos.Data.Archiving;
/// <param name="Incoming">The file that comes in, relative to the archive root: a staged conversion, or an original in a
/// trash entry.</param>
/// <param name="Companions">Files that come in with it (the XMP companions of an original back from the trash).</param>
/// <param name="Name">The name it is filed under, from the frame as the sidecar has it under the lease, relative to the
/// sequence folder; made unique with <c>_2</c>, <c>_3</c>… when it, or one of its companions' names, is taken.</param>
/// <param name="Name">The name it is filed under, from the frame and the sequence as the sidecar has them under the lease,
/// relative to the sequence folder; made unique with <c>_2</c>, <c>_3</c>… when it, or one of its companions' names, is
/// taken.</param>
/// <param name="Record">The frame's record after the swap, from the frame as the sidecar has it under the lease (its
/// <see cref="SidecarFrame.Sha256"/> names the incoming file): the replacement keeps the frame's id and index, files it
/// under its name, and keeps the flags a user or the capture set (<see cref="FrameTrash.ContentFlags"/> come from the
/// record).</param>
internal sealed record FrameSwap(Guid FrameId, string Incoming, IReadOnlyList<IncomingCompanion> Companions, Func<SidecarFrame, string> Name,
internal sealed record FrameSwap(Guid FrameId, string Incoming, IReadOnlyList<IncomingCompanion> Companions, Func<SidecarFrame, SequenceManifest, string> Name,
Func<SidecarFrame, SidecarFrame> Record);
/// <summary>A companion that comes in with its photo: where it is (relative to the archive root), and what its name adds to the photo's stem.</summary>
@@ -124,14 +125,20 @@ public sealed partial class FrameTrash
if (swaps.Count == 0) throw new ArgumentException("No frame is swapped.", nameof(swaps));
var paths = new ArchivePaths(archive.RootPath);
ArchiveVolume.EnsureWritable(paths);
if (await _db.Sequences.GetAsync(sequenceId, cancellationToken).ConfigureAwait(false) is not { } row || row.ArchiveId != archive.Id) return null;
var folder = paths.Sequence(row.Folder);
var had = row.Status;
if (await _db.Sequences.GetAsync(sequenceId, cancellationToken).ConfigureAwait(false) is not { } listed || listed.ArchiveId != archive.Id) return null;
Sequence row;
SequencePaths folder;
SequenceStatus had;
TrashEntry entry;
SequenceManifest updated;
bool indexed;
await using (await _writer.LockAsync(paths, sequenceId, cancellationToken).ConfigureAwait(false))
{
// Where the sequence is now: a Reorganize moves its folder and row under this lease, maybe while this waited for it.
if (await _db.Sequences.GetAsync(sequenceId, cancellationToken).ConfigureAwait(false) is not { } moved || moved.ArchiveId != archive.Id) return null;
row = moved;
folder = paths.Sequence(row.Folder);
had = row.Status;
var manifest = SequenceWriter.ReadLocked(folder, sequenceId, consumed?.Lease);
EnsureSettled(folder);
EnsureReplaced(folder);
@@ -275,7 +282,7 @@ public sealed partial class FrameTrash
var names = new Dictionary<Guid, string>();
foreach (var swap in swaps)
{
var file = unique.Claim(swap.Name(frames[swap.FrameId]), c => swap.Companions.All(t => !taken.Contains(StemOf(c) + t.Tail)));
var file = unique.Claim(swap.Name(frames[swap.FrameId], manifest), c => swap.Companions.All(t => !taken.Contains(StemOf(c) + t.Tail)));
names[swap.FrameId] = file;
moves.Add(new SwapMove(file, swap.Incoming));
foreach (var companion in swap.Companions)
@@ -499,7 +506,7 @@ public sealed partial class FrameTrash
if (record.Photos.Count == 0 || record.Photos.Any(p => p.Files.Count == 0 || p.Frame.Sha256 is null || p.Replacement is null)) return null;
var swaps = record.Photos.Select(p => new FrameSwap(p.Frame.Id, paths.ToRelative(Path.Combine(entryFolder, p.Files[0].Path)),
[.. p.Files.Skip(1).Select(c => new IncomingCompanion(paths.ToRelative(Path.Combine(entryFolder, c.Path)), FrameCompanions.Tail(c.From, p.Files[0].From)))],
_ => p.Files[0].From, _ => p.Frame)).ToList();
(_, _) => p.Files[0].From, _ => p.Frame)).ToList();
var copy = Path.Combine(entryFolder, AnalysisCopy);
var analysis = record.Leftovers?.Any(f => f.Path == AnalysisCopy) == true && File.Exists(copy) ? paths.ToRelative(copy) : null;
var consumed = new ConsumedEntry(paths.ToRelative(recordPath), paths.ToRelative(entryFolder), lease, [.. record.Photos.Select(p => p.Frame.Id)], analysis);