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:
1 parent
a1c1c21ebd
commit
341fb77507
22 files changed
+345
-91
No files matched your search
@@ -152,10 +152,10 @@ public sealed class ConvertTests(TestContext context)
|
||||
Assert.Equal(before.Versions.Frames + 1, row.FramesVersion);
|
||||
Assert.SequenceEqual(originals.Select(f => (f.Id, f.Index)), frames.Select(f => (f.Id, f.Index)));
|
||||
var after = Sidecar(fx, row);
|
||||
var options = new ConvertOptions(ConvertTarget.LinearDng);
|
||||
foreach (var (was, now) in before.Frames.Zip(after.Frames))
|
||||
{
|
||||
Assert.Equal((options.NameFor(was.File), ImageFileFormat.Dng, DecodeTier.Native, 1), (now.File, now.Format, now.Tier, now.Orientation));
|
||||
// Named as filing named the original, with the target's extension: the same template, frame and sequence.
|
||||
Assert.Equal((Path.ChangeExtension(was.File, ".dng"), ImageFileFormat.Dng, DecodeTier.Native, 1), (now.File, now.Format, now.Tier, now.Orientation));
|
||||
Assert.Equal((was.CapturedAt, was.Original, was.Flags), (now.CapturedAt, now.Original, now.Flags));
|
||||
var source = Assert.NotNull(now.Source);
|
||||
Assert.Equal((was.Sha256, was.Format, was.File, was.Size), (source.Sha256, source.Format, source.File, source.Size));
|
||||
@@ -282,7 +282,9 @@ public sealed class ConvertTests(TestContext context)
|
||||
var frames = await FramesAsync(fx, made);
|
||||
Assert.SequenceEqual(originals.Select(f => f.CapturedAt), frames.Select(f => f.CapturedAt));
|
||||
Assert.True(frames.All(f => f.Format == ImageFileFormat.Tiff));
|
||||
Assert.SequenceEqual(originals.Select(f => Path.ChangeExtension(f.FileName, ".tif")), frames.Select(f => Path.ChangeExtension(f.FileName, ".tif")));
|
||||
// Filed as the ingest files every photo: the archive's template in the new sequence, {name} the card's, {ext} the target's.
|
||||
Assert.SequenceEqual(originals.Select(f => Path.ChangeExtension(f.FileName, ".tif")), frames.Select(f => f.FileName));
|
||||
Assert.SequenceEqual(originals.Select(f => f.OriginalFileName), frames.Select(f => f.OriginalFileName));
|
||||
var settings = ProjectSettings.FromJson(copy.SettingsJson!);
|
||||
Assert.SequenceEqual([1], settings.ExcludedFrames);
|
||||
Assert.Equal((2, frames[2].Id), (settings.HeroFrame, copy.HeroFrameId));
|
||||
@@ -577,4 +579,96 @@ public sealed class ConvertTests(TestContext context)
|
||||
_ = JsonSerializer.Serialize(new ConvertJobParameters(fx.Archive.Id, ConvertTarget.Jpeg, 80, ConvertMode.NewSequence, [new ConvertSequence(first, 2)], "f"),
|
||||
ArchiveJobJson.Default.ConvertJobParameters);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ConvertedFilesAreNamedAsFilingNamesThemAndNothingIsOverwritten()
|
||||
{
|
||||
await using var fx = await FixtureAsync();
|
||||
await fx.Service.UpdateSettingsAsync(fx.Archive.Id, s => s with { Templates = s.Templates with { File = "{name}_{n:00}" } }, fx.Ct);
|
||||
var roof = await UploadedAsync(fx, 2);
|
||||
var lake = await UploadedAsync(fx, 2, "upload-2", seed: 200);
|
||||
Assert.SequenceEqual(["IMG_0001_01.JPG", "IMG_0002_02.JPG"], (await FramesAsync(fx, roof)).Select(f => f.FileName));
|
||||
await fx.Service.SetSequenceInfoAsync(roof, "Roof", [], 0, null, fx.Ct);
|
||||
await fx.Service.SetSequenceInfoAsync(lake, "Lake", [], 0, null, fx.Ct);
|
||||
// Filing names a photo with the template of the moment: a conversion names its files as filing would now.
|
||||
await fx.Service.UpdateSettingsAsync(fx.Archive.Id, s => s with { Templates = s.Templates with { File = "{title}_{n:00}" } }, fx.Ct);
|
||||
// A file that is no frame holds the first name: it is never written over, the converted file takes the next.
|
||||
var stray = fx.Paths.Sequence((await fx.Db.Sequences.GetAsync(roof))!.Folder).File("originals/Roof_01.dng");
|
||||
File.WriteAllBytes(stray, [1, 2, 3]);
|
||||
var engine = await fx.StartEngineAsync();
|
||||
|
||||
await RunAsync(fx, engine, await PlanAsync(fx, ConvertTarget.LinearDng, ConvertMode.Replace, roof));
|
||||
var replaced = await FramesAsync(fx, roof);
|
||||
Assert.SequenceEqual(["Roof_01_2.dng", "Roof_02.dng"], replaced.Select(f => f.FileName));
|
||||
Assert.SequenceEqual(["IMG_0001.JPG", "IMG_0002.JPG"], replaced.Select(f => f.OriginalFileName));
|
||||
Assert.SequenceEqual(new byte[] { 1, 2, 3 }, File.ReadAllBytes(stray));
|
||||
|
||||
var job = await RunAsync(fx, engine, await PlanAsync(fx, ConvertTarget.Tiff16, ConvertMode.NewSequence, lake));
|
||||
var made = Assert.NotNull(await fx.Db.Sequences.FindBySessionKeyAsync(fx.Archive.Id, MassConverter.SessionKey(job.Id, lake)));
|
||||
var copies = await FramesAsync(fx, made);
|
||||
Assert.SequenceEqual(["Lake (TIFF)_01.tif", "Lake (TIFF)_02.tif"], copies.Select(f => f.FileName));
|
||||
Assert.SequenceEqual(["IMG_0001.JPG", "IMG_0002.JPG"], copies.Select(f => f.OriginalFileName));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AFolderMovedWhileTheJobWaitsForItsLeaseIsWhereTheConvertedFilesGo()
|
||||
{
|
||||
await using var fx = await FixtureAsync();
|
||||
var id = await UploadedAsync(fx, 2);
|
||||
var engine = await fx.StartEngineAsync();
|
||||
var plan = await PlanAsync(fx, ConvertTarget.Tiff16, ConvertMode.Replace, id);
|
||||
var row = (await fx.Db.Sequences.GetAsync(id))!;
|
||||
var from = fx.Paths.Sequence(row.Folder).Folder;
|
||||
Job job;
|
||||
var planned = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
void OnProgress(JobProgressInfo info)
|
||||
{
|
||||
if (info.Kind == JobKind.Convert && info.Total == 2) planned.TrySetResult();
|
||||
}
|
||||
engine.Progress += OnProgress;
|
||||
using (await LeaseFile.AcquireAsync(fx.Paths.LocksDirectory, $"seq-{id:N}", "editor", TimeSpan.FromSeconds(5), cancellationToken: fx.Ct))
|
||||
{
|
||||
job = await engine.EnqueueAsync(ArchiveJobs.Convert(fx.Archive, plan), cancellationToken: fx.Ct);
|
||||
// Planned again where the index had the sequence then: the job now waits for its lease to convert it.
|
||||
await planned.Task.WaitAsync(TimeSpan.FromSeconds(TestTiming.Budget(30)), fx.Ct);
|
||||
// What a Reorganize step does under that lease meanwhile: the folder moves, and its index row follows.
|
||||
var to = fx.Paths.Sequence("moved/Roof").Folder;
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(to)!);
|
||||
Directory.Move(from, to);
|
||||
Assert.True(await fx.Db.Sequences.RelocateAsync(id, "moved/Roof", null, fx.Ct));
|
||||
}
|
||||
engine.Progress -= OnProgress;
|
||||
|
||||
await fx.WaitForAsync(job.Id, JobState.Done, (int)TestTiming.Budget(60));
|
||||
var frames = await FramesAsync(fx, id);
|
||||
Assert.True(frames.All(f => f.Format == ImageFileFormat.Tiff && f.RelativePath.StartsWith("moved/Roof/", StringComparison.Ordinal)));
|
||||
Assert.False(Directory.Exists(from), "the folder the sequence left is never made again");
|
||||
Assert.Equal("moved/Roof", (await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct)).Single().Folder);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AReorganizeTheArchiveWaitsForKeepsTheConversionOffItsSequences()
|
||||
{
|
||||
await using var fx = await FixtureAsync();
|
||||
var id = await UploadedAsync(fx, 2);
|
||||
var originals = await FramesAsync(fx, id);
|
||||
var plan = await PlanAsync(fx, ConvertTarget.Tiff16, ConvertMode.Replace, id);
|
||||
// A Reorganize paused by its user holds the archive: its plan waits for it.
|
||||
await fx.Db.Jobs.EnqueueAsync(new Job
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
Kind = JobKind.Move,
|
||||
TargetIds = [fx.Archive.Id],
|
||||
State = JobState.Paused,
|
||||
Created = DateTimeOffset.UtcNow,
|
||||
});
|
||||
Assert.SequenceEqual([ConvertBlock.Busy], (await PlanAsync(fx, ConvertTarget.Tiff16, ConvertMode.Replace, id)).Sequences.Single().Blocked);
|
||||
|
||||
var engine = await fx.StartEngineAsync();
|
||||
var job = await RunAsync(fx, engine, plan, JobState.Failed);
|
||||
Assert.Equal(Loc.Plural("Archive.Error.ConvertKept", 1), job.Error);
|
||||
Assert.Contains(Loc.L("Archive.Log.ConvertBlocked", (await fx.Db.Sequences.GetAsync(id))!.DisplayTitle), job.LogTail);
|
||||
Assert.SequenceEqual(originals.Select(f => (f.Id, f.Sha256, f.RelativePath)), (await FramesAsync(fx, id)).Select(f => (f.Id, f.Sha256, f.RelativePath)));
|
||||
Assert.Empty(await fx.Service.ListTrashAsync(fx.Archive.Id, fx.Ct));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user