feat: owner review 2 phase 4b: mass conversion after import (#13)
CI / Build and test (push) Failing after 3m1s
CI / PostgreSQL 16 integration (push) Skipped
CI / PostgreSQL 17 integration (push) Skipped
CI / Docker image (push) Skipped
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 10s
Release / Build, test and publish (push) Successful in 15m31s
Release / Server image (push) Successful in 1m13s

Convert photos already in the archive to JPEG, TIFF-16 or Linear DNG, from the panel's Library and the desktop's Archive and Library. Each run asks Replace (same frames, originals to the trash, recoverable) or New sequence. A dry run lists what converts, what is skipped and why, size before and after, and free space; the job converts exactly the confirmed photos, resumes, and commits all or nothing per sequence. A conversion never changes what Chronos reads from a photo. Replaced originals are erased only on the archive's own word that their conversion is gone. Desktop TIFFs that WIC showed black or as noise now go to the managed reader; the Edit picker no longer spins a core.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #13.
This commit is contained in:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-11-03 10:41:50 +01:00
1 parent 7e4a3b481d
commit efa87f68ce
354 files changed
+24530 -843

No files matched your search

+34 -22
View File
@@ -6,6 +6,7 @@ using Chronos.Core.IO;
using Chronos.Core.Localization;
using Chronos.Core.Model;
using Chronos.Data.Archiving.Jobs;
using Chronos.Data.Repositories;
namespace Chronos.Data.Archiving;
@@ -57,7 +58,7 @@ public enum TrashKind
/// <summary>Photos deleted from a sequence (<see cref="FrameTrash"/>).</summary>
Photos,
/// <summary>Originals a conversion replaced (a later phase): erased only while their replacements still match.</summary>
/// <summary>Originals a conversion replaced (owner review 2, R7): erased only while their replacements still match.</summary>
Replaced,
}
@@ -68,7 +69,19 @@ public enum TrashKind
/// <param name="Folder">Archive-relative folder the sequence came from (and returns to when it is free).</param>
/// <param name="Frames">Photos the entry holds.</param>
public sealed record TrashEntry(Guid ArchiveId, string Name, Guid SequenceId, string Title, string Folder, int Frames, int Files, long Bytes,
DateTimeOffset DeletedAt, string? DeletedBy, TrashKind Kind = TrashKind.Sequence);
DateTimeOffset DeletedAt, string? DeletedBy, TrashKind Kind = TrashKind.Sequence)
{
/// <summary>The job that made the entry (a conversion's Replace, owner review 2, R7); null for one a user's action made.</summary>
public Guid? JobId { get; init; }
/// <summary>
/// A <see cref="TrashKind.Replaced"/> entry whose conversion was deleted since: the archive shows a photo's replacement
/// (followed through later conversions) deleted from its sequence, or the sequence itself deleted, so erasing the entry may
/// erase the last copy of that photo. Set by the dry run of an emptying (<see cref="SequenceTrash.PlanEmptyAsync"/>), which
/// says so; false in a plain listing.
/// </summary>
public bool ConversionDeleted { get; init; }
}
/// <summary>The plan no longer matches the index or the jobs (a sequence moved, vanished or got busy since it was made); nothing was deleted.</summary>
public sealed class StaleDeletePlanException(Guid sequenceId) : InvalidOperationException(Loc.L("Archive.Error.StalePlan"))
@@ -103,7 +116,6 @@ public sealed partial class SequenceTrash
public const string FolderName = "trash";
private const string RecordExtension = ".json";
private const int JobPage = 200;
/// <summary>Bytes of a sidecar read to find its id (written second, after the schema version).</summary>
private const int SidecarHead = 4096;
@@ -373,15 +385,17 @@ public sealed partial class SequenceTrash
var folder = paths.Sequence(sequence.Folder);
if (!Directory.Exists(folder.Folder) || (File.Exists(folder.ManifestPath) && SidecarId(folder.ManifestPath) != sequence.Id))
throw new StaleDeletePlanException(sequence.Id);
// A photo deletion, a restore from the trash or an ingest a crash interrupted is settled first, as any writer does
// (SequenceWriter.ReadLocked): neither its journal nor the files it moved travel into this entry, where emptying it
// would erase them while their own entry still lists them. A restore whose entry is busy keeps the folder here.
// A photo deletion, a frame replacement, a restore from the trash or an ingest a crash interrupted is settled first,
// as any writer does (SequenceWriter.ReadLocked): neither its journal nor the files it moved travel into this entry,
// where emptying it would erase them while their own entry still lists them. A restore or a replacement whose entry
// is busy keeps the folder here.
var (files, bytes) = (step.Files, step.Bytes);
if (File.Exists(folder.ManifestPath) && (File.Exists(folder.RemovalJournalPath) || File.Exists(folder.RestoreJournalPath)
|| File.Exists(folder.IngestJournalPath)))
|| File.Exists(folder.ReplaceJournalPath) || File.Exists(folder.IngestJournalPath)))
{
SequenceWriter.ReadLocked(folder, sequence.Id);
FrameTrash.EnsureSettled(folder);
FrameTrash.EnsureReplaced(folder);
// Files came back into the folder, or left it: the record counts what moves.
(files, bytes) = Measure(folder.Folder, cancellationToken);
}
@@ -477,29 +491,25 @@ public sealed partial class SequenceTrash
/// archives of archive-wide ones (scan, rebuild, import, maintenance, a verify of everything). An import's folders
/// are known only to its plan, so it holds its whole archive; a verify of named sequences holds only those.
/// </summary>
internal async Task<IReadOnlySet<Guid>> BusyAsync(CancellationToken cancellationToken)
internal Task<IReadOnlySet<Guid>> BusyAsync(CancellationToken cancellationToken) => BusyAsync(null, cancellationToken);
/// <summary>
/// What running and paused jobs hold, but the job <paramref name="except"/> (the one asking), read from their targets
/// alone (<see cref="JobRepository.ListHoldsAsync"/>): nothing reads the parameters a conversion or an import keeps.
/// </summary>
internal async Task<IReadOnlySet<Guid>> BusyAsync(Guid? except, CancellationToken cancellationToken)
{
var busy = new HashSet<Guid>();
foreach (var state in new[] { JobState.Running, JobState.Paused })
{
string? cursor = null;
do
{
var page = await _db.Jobs.ListAsync(state, JobPage, cursor, cancellationToken).ConfigureAwait(false);
foreach (var job in page.Items) busy.UnionWith(Holds(job));
cursor = page.NextCursor;
}
while (cursor is not null);
}
foreach (var job in await _db.Jobs.ListHoldsAsync(except, cancellationToken).ConfigureAwait(false)) busy.UnionWith(Holds(job));
return busy;
}
private static IReadOnlyList<Guid> Holds(Job job)
private static IReadOnlyList<Guid> Holds(JobHold job)
{
if (job.Kind != JobKind.Verify) return job.TargetIds;
if (job is not { Kind: JobKind.Verify, ParametersJson: { Length: > 0 } json }) return job.TargetIds;
try
{
return ArchiveJobJson.Read(job, ArchiveJobJson.Default.VerifyParameters, new VerifyParameters(null)).SequenceIds ?? job.TargetIds;
return JsonSerializer.Deserialize(json, ArchiveJobJson.Default.VerifyParameters)?.SequenceIds ?? job.TargetIds;
}
catch (JsonException)
{
@@ -608,4 +618,6 @@ internal sealed record TrashRecord(Sequence Sequence, IReadOnlyList<Render> Rend
[JsonSerializable(typeof(TrashRecord))]
[JsonSerializable(typeof(PhotoTrashRecord))]
[JsonSerializable(typeof(FrameRestoreJournal))]
[JsonSerializable(typeof(FrameReplaceJournal))]
[JsonSerializable(typeof(ErasureRecord))]
internal sealed partial class TrashJson : JsonSerializerContext;