fix(convert): the job converts exactly the photos its preview listed, once

A conversion job could still do something its confirmed dry run did not show,
or refuse what it should have converted:

- An upload landing between the confirmation and the sequence's turn made the
  sequence Changed at every retry. Each ConvertSequence now names the photos
  the plan converts (Photos, their frame ids); the job takes those from its
  re-plan, checks their content against the confirmed digest and leaves photos
  that came in since as they are. A photo the plan did not list is never
  converted, whatever changed on disk or in the index since the dry run.
- A file another program held during the dry run was planned as Missing and
  then converted or not depending on the re-plan. It is now its own reason
  (inaccessible, "held open or cannot be opened"); a truncated file reads as
  undecodable. At job time a confirmed photo that cannot be opened leaves the
  sequence Blocked for the retry; a held photo the job does not convert does
  not hide a real change.
- The same sequences could be converted twice (two dialogs or tabs, a lost
  answer, no dry run at all). MassConverter.QueueAsync checks the queued,
  running and paused conversions and queues under one lock, in the caller's
  context (the desktop's enqueue shows a toast on the UI thread); a job's own
  re-plan treats sequences of conversions queued before it as busy.
- The per-photo space check reserved a full batch of photos even when fewer
  were left, so a job whose preview had the space could stop at every retry.
  It now reserves the photo and those after it that may convert at once.
- New sequence now says in the dry run, the panel's totals and confirmation,
  and a new desktop confirmation, how many photos each new sequence lacks;
  only sequences that are copied use those words.
- On the server, a confirmation takes only the plan kept for the index as it
  is now (503 plan_dropped otherwise, never a plan made inside the request),
  and busy sequences and free space are as they are at every request. The
  panel's Apply asks the dry run again first, with Close still available,
  and confirms only the same fingerprint.
- Maintenance keeps another host's conversion staging as long as its journal
  and purges both together; the unstaged-copy failure and blocked sequences
  are logged in catalog sentences.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit fefd9c34ebfeed1f9e84161610ef286026d38355)
This commit is contained in:
Alby96 committed 2026-11-02 10:33:34 +01:00
1 parent 5b5acaf307
commit c669d0504d
25 files changed
+1307 -226

No files matched your search

+62 -11
View File
@@ -26,7 +26,8 @@ public sealed record ConvertSpaceLine(string Text, bool IsShort);
/// <summary>
/// The words of a mass conversion (owner review 2, R7; BRIEF §12.5): the engine's dry run (<see cref="ConvertPlan"/>) as
/// rows, a summary and the free space line, and the typed confirmation a Replace asks for.
/// rows, a summary and the free space line, the typed confirmation a Replace asks for, and the one New sequence asks for,
/// which says which photos the new sequences lack.
/// </summary>
public static class ConvertPlans
{
@@ -53,32 +54,47 @@ public static class ConvertPlans
}
/// <summary>
/// One sequence of a plan: what converts, then what blocks it, then the photos skipped with why. With
/// <see cref="ConvertMode.NewSequence"/> those are not copied into the new sequence, which holds the converted copies
/// alone; with <see cref="ConvertMode.Replace"/> they stay as they are.
/// One sequence of a plan: what converts, then what blocks it, then the photos skipped with why. Of a sequence
/// <see cref="ConvertMode.NewSequence"/> copies, those are not copied into the new sequence, which holds the converted
/// copies alone; otherwise (a Replace, or a sequence that converts nothing now, of which no new sequence is made) they
/// stay as they are.
/// </summary>
public static ConvertRow Row(ConvertSequencePlan step, ConvertMode mode = ConvertMode.Replace)
{
ArgumentNullException.ThrowIfNull(step);
var named = !string.IsNullOrWhiteSpace(step.Title);
var name = named ? step.Title : step.Folder.Length > 0 ? step.Folder : step.SequenceId.ToString("N")[..8];
var (name, named) = NameOf(step);
var note = step.Converts
? Loc.Plural("Shell.Status.Photos", step.Frames.Count) + Loc.Separator + Sizes(step.BytesBefore, step.BytesAfter)
: string.Empty;
// What blocks the whole sequence comes first: the photos it would skip anyway do not matter until it can convert.
List<string> kept = [.. step.Blocked.Distinct().Select(b => Loc.L("Archive.Convert.Blocked." + b))];
var why = mode == ConvertMode.NewSequence ? "Archive.Convert.NotCopied." : "Archive.Convert.Skipped.";
var why = mode == ConvertMode.NewSequence && step.Converts ? "Archive.Convert.NotCopied." : "Archive.Convert.Skipped.";
kept.AddRange(step.Skipped.Select(s => Loc.L(why + s.Reason) + Loc.Separator + Loc.Plural("Shell.Status.Photos", s.Frames)));
return new ConvertRow(step.SequenceId, name, !named, note, kept, step.Blocked.Count > 0);
}
/// <summary>A sequence's title, else its folder (a path), else the start of its id; and whether it has a title.</summary>
private static (string Name, bool Named) NameOf(ConvertSequencePlan step)
{
var named = !string.IsNullOrWhiteSpace(step.Title);
return (named ? step.Title : step.Folder.Length > 0 ? step.Folder : step.SequenceId.ToString("N")[..8], named);
}
/// <summary>The photos a conversion into new sequences leaves out of them: those the sequences it copies skip.</summary>
public static int LeftOut(ConvertPlan plan)
{
ArgumentNullException.ThrowIfNull(plan);
return plan.Converted.Sum(s => s.SkippedFrames);
}
/// <summary>"12.4 GB → 9.8 GB".</summary>
public static string Sizes(long before, long after) => Loc.L("Archive.Convert.Sizes", Formatting.Bytes(before), Formatting.Bytes(after));
/// <summary>
/// "12 of 36 change · 3,600 photos · 41 GB → 32 GB · 20 skipped": the sequences converted of those planned, then the
/// photos and their sizes when something converts, the photos skipped when there are any ("20 not copied" with
/// <see cref="ConvertMode.NewSequence"/>: the new sequences lack them).
/// photos and their sizes when something converts, the photos skipped when there are any. With
/// <see cref="ConvertMode.NewSequence"/>, those of the sequences copied first ("20 not copied": the new sequences lack
/// them), then those of the sequences that convert nothing now ("4 skipped").
/// </summary>
public static string Summary(ConvertPlan plan)
{
@@ -89,8 +105,9 @@ public static class ConvertPlans
parts.Add(Loc.Plural("Shell.Status.Photos", plan.Frames));
parts.Add(Sizes(plan.BytesBefore, plan.BytesAfter));
}
if (plan.Skipped > 0)
parts.Add(Loc.Plural(plan.Mode == ConvertMode.NewSequence ? "Archive.Convert.NotCopiedPhotos" : "Archive.Convert.SkippedPhotos", plan.Skipped));
var leftOut = plan.Mode == ConvertMode.NewSequence ? LeftOut(plan) : 0;
if (leftOut > 0) parts.Add(Loc.Plural("Archive.Convert.NotCopiedPhotos", leftOut));
if (plan.Skipped - leftOut > 0) parts.Add(Loc.Plural("Archive.Convert.SkippedPhotos", plan.Skipped - leftOut));
return string.Join(Loc.Separator, parts);
}
@@ -138,4 +155,38 @@ public static class ConvertPlans
TypedPrompt = Loc.L("Archive.Delete.Type", count),
};
}
/// <summary>
/// The confirmation of a conversion into new sequences: the photos converted into copies beside their sources, the
/// originals untouched, how many photos the new sequences lack (those the plan skips there, for the reasons its rows
/// give), and each sequence copied with its photos, their size and the photos its new sequence lacks; null when the plan
/// converts nothing.
/// </summary>
public static ConfirmRequest? NewRequest(ConvertPlan plan)
{
ArgumentNullException.ThrowIfNull(plan);
var converted = plan.Converted.ToList();
if (converted.Count == 0) return null;
var lines = converted.Take(DeletePlans.ListedLines).Select(s =>
{
var line = Loc.L("Archive.Delete.Line", NameOf(s).Name, Loc.Plural("Shell.Status.Photos", s.Frames.Count), Sizes(s.BytesBefore, s.BytesAfter));
return s.SkippedFrames > 0 ? line + Loc.Separator + Loc.Plural("Archive.Convert.NotCopiedPhotos", s.SkippedFrames) : line;
}).ToList();
if (converted.Count > DeletePlans.ListedLines) lines.Add(Loc.Plural("Archive.Delete.More", converted.Count - DeletePlans.ListedLines));
var message = Loc.L("Archive.Convert.NewMessage", Loc.Plural("Shell.Status.Photos", plan.Frames), Formatting.Bytes(plan.BytesBefore),
TargetText(plan.Options.Target));
if (LeftOut(plan) is > 0 and var leftOut) message += " " + Loc.Plural("Archive.Convert.NewLeftOut", leftOut);
return new ConfirmRequest
{
Heading = Loc.Plural("Archive.Convert.NewHeading", converted.Count),
Message = message,
Detail = string.Join(Environment.NewLine, lines),
IsDetailMonospaced = false,
DetailToolTip = Loc.L("Tooltips.Archive.ConvertPlanNew"),
SafeText = Loc.L("Archive.Dialog.Cancel"),
SafeToolTip = Loc.L("Tooltips.Archive.ConvertBack"),
ActionText = Loc.L("Archive.Convert.Confirm"),
ActionToolTip = Loc.L("Tooltips.Archive.ConvertNew"),
};
}
}