feat: owner review 2 phase 4b: mass conversion after import #13

Merged
Alby96 merged 82 commits from claude/owner-review-2-p4b-rc7 into main 2026-11-03 10:41:59 +01:00
5 changed files with 59 additions and 8 deletions
Showing only changes of commit 0c2bdedfdf - Show all commits

No files matched your search

+3 -1
View File
@@ -484,7 +484,9 @@ step being one sequence and the sequences nested in a folder that moves with it:
- `journal/rename-<plan>.json` holds the plan (its steps, templates and the sequences it was
made for), the steps completed and what they did; it is written before the first step and
deleted after the last. A plan whose job was paused, cancelled or failed is marked held and
waits for that job; any other is completed at the next archive open.
waits for that job; any other is completed at the next archive open. A journal that cannot be
read is logged and left where it is: the archive opens, the plan is not resumed and its job
fails with the reason.
- Each step takes the leases of its sequences, then their thumbnail leases, and checks under
them, before anything of it moves, that the plan still fits: the sequences where the index
had them, nothing indexed since inside a folder that moves or at its new place, no sidecar of
+3 -2
View File
@@ -46,8 +46,9 @@ commits follow Conventional Commits (release notes are generated from them by `C
Reorganize comes back under its old name; a Reorganize job cancelled and never retried leaves its held plan in
`.chronos/journal` (only the file renames a step left half-way are completed at an archive open); deleting
sequences is refused while a Reorganize job runs or is paused; a render of another program whose folder moves while
it runs is not stopped, and its output can land in a folder created again at the old place; a plan journal damaged
by hand (not valid JSON) stops the archive from opening until it is removed.
it runs is not stopped, and its output can land in a folder created again at the old place; a plan journal that
cannot be read is logged and left in `.chronos/journal`: the archive opens, its plan is not resumed and its job
fails with the reason.
### Changed
- Import, upload and Reorganize name photos by one rule: every photo of a sequence is named with the sequence's camera
+32 -4
View File
@@ -2,6 +2,7 @@ using System.Globalization;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using Chronos.Core.Diagnostics;
using Chronos.Core.IO;
using Chronos.Core.Localization;
using Chronos.Core.Naming;
@@ -214,25 +215,52 @@ public sealed record RenameJournal(RenamePlan Plan, IReadOnlyList<Guid> Complete
AtomicFile.WriteAllBytes(PathFor(archive, journal.Plan.Id), JsonSerializer.SerializeToUtf8Bytes(journal, ArchiveJsonIndented.Default.RenameJournal));
}
/// <summary>Journals left by interrupted renames, held ones included.</summary>
/// <summary>
/// Journals left by interrupted renames, held ones included. A journal that cannot be read (damaged by hand, or by a
/// disk) is logged and left where it is, so the archive still opens; its plan is not resumed, and the file renames of
/// its steps are completed by their own journals (<see cref="FileRenameJournal"/>).
/// </summary>
public static IReadOnlyList<RenameJournal> ListPending(ArchivePaths archive)
{
if (!Directory.Exists(archive.JournalDirectory)) return [];
var list = new List<RenameJournal>();
foreach (var path in Directory.EnumerateFiles(archive.JournalDirectory, "rename-*.json").Order(StringComparer.Ordinal))
{
if (JsonSerializer.Deserialize(File.ReadAllBytes(path), ArchiveJson.Default.RenameJournal) is { } journal) list.Add(journal);
try
{
if (Parse(File.ReadAllBytes(path)) is { } journal) list.Add(journal);
else Log.Warning("archive", $"The rename journal {Path.GetFileName(path)} is empty or incomplete; its plan is not resumed");
}
catch (JsonException ex)
{
Log.Warning("archive", $"The rename journal {Path.GetFileName(path)} cannot be read; its plan is not resumed", ex);
}
}
return list;
}
/// <summary>The journal of the plan <paramref name="planId"/>; null when there is none (the plan completed, or never started).</summary>
/// <summary>
/// The journal of the plan <paramref name="planId"/>; null when there is none (the plan completed, or never started).
/// Throws <see cref="InvalidDataException"/> when the journal is there but cannot be read, so its job fails with the
/// reason instead of planning again over a half-applied plan.
/// </summary>
public static RenameJournal? Read(ArchivePaths archive, Guid planId)
{
var path = PathFor(archive, planId);
return File.Exists(path) ? JsonSerializer.Deserialize(File.ReadAllBytes(path), ArchiveJson.Default.RenameJournal) : null;
if (!File.Exists(path)) return null;
try
{
return Parse(File.ReadAllBytes(path)) ?? throw new InvalidDataException($"The rename journal {Path.GetFileName(path)} is incomplete.");
}
catch (JsonException ex)
{
throw new InvalidDataException($"The rename journal {Path.GetFileName(path)} cannot be read.", ex);
}
}
private static RenameJournal? Parse(byte[] bytes) =>
JsonSerializer.Deserialize(bytes, ArchiveJson.Default.RenameJournal) is { Plan: not null, Completed: not null } journal ? journal : null;
public static void Delete(ArchivePaths archive, Guid planId) => File.Delete(PathFor(archive, planId));
}
@@ -155,7 +155,7 @@ internal sealed class MoveJobHandler(ChronosDatabase db, MassRenamer renamer, Fu
Log.Info("archive", $"Reorganize {planId} held by its failed job {context.Job.Id}");
LogDone(context, journal.Plan, RenameResult.Of(journal.Done));
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or JsonException)
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or JsonException or InvalidDataException)
{
Log.Warning("archive", $"Reorganize {planId} could not be held after its job failed", ex);
}
@@ -751,4 +751,24 @@ public sealed class ReorganizeTests(TestContext context)
Assert.Equal("originals/A_2.CR2", Assert.NotNull(FileRenameJournal.Recover(sequence, manifest)).Frames.Single().File);
Assert.Equal(("photo", "sidecar"), (Read(sequence, "originals/A_2.CR2"), Read(sequence, "originals/A_2.xmp")));
}
[Test]
public void ADamagedPlanJournalIsSkippedAtOpenAndFailsItsOwnJob()
{
var archive = new ArchivePaths(context.CreateTempDirectory("archive"));
var good = new RenameJournal(new RenamePlan(Guid.NewGuid(), Guid.NewGuid(), []), []);
RenameJournal.Write(archive, good);
var damaged = Guid.NewGuid();
File.WriteAllText(RenameJournal.PathFor(archive, damaged), "{ \"plan\": ");
var empty = Guid.NewGuid();
File.WriteAllText(RenameJournal.PathFor(archive, empty), "{}");
// The archive still opens: the readable journal resumes, the others stay where they are.
Assert.Equal(good.Plan.Id, RenameJournal.ListPending(archive).Single().Plan.Id);
Assert.True(File.Exists(RenameJournal.PathFor(archive, damaged)));
// The job of a damaged plan fails with the reason instead of planning again.
Assert.Throws<InvalidDataException>(() => RenameJournal.Read(archive, damaged));
Assert.Throws<InvalidDataException>(() => RenameJournal.Read(archive, empty));
Assert.Null(RenameJournal.Read(archive, Guid.NewGuid()));
}
}