fix: full verification against the brief — 137 confirmed findings fixed over six passes #4
No files matched your search
@@ -130,10 +130,30 @@ public sealed class ArchiveIndexer
|
|||||||
var paths = new ArchivePaths(archive.RootPath);
|
var paths = new ArchivePaths(archive.RootPath);
|
||||||
ArchiveVolume.EnsureWritable(paths);
|
ArchiveVolume.EnsureWritable(paths);
|
||||||
var folder = paths.Sequence(sequence.Folder);
|
var folder = paths.Sequence(sequence.Folder);
|
||||||
var manifest = await _writer.UpdateAsync(paths, sequence.Id, sequence.Folder, m => SequenceAdopter.Reconcile(folder, m, cancellationToken),
|
return await UpdateAndSyncAsync(archive, paths, folder, sequence.Id, m => SequenceAdopter.Reconcile(folder, m, cancellationToken), cancellationToken)
|
||||||
cancellationToken).ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
await SyncAsync(archive, folder, manifest, cancellationToken).ConfigureAwait(false);
|
}
|
||||||
return manifest;
|
|
||||||
|
/// <summary>
|
||||||
|
/// Applies <paramref name="edit"/> to the sidecar (null writes nothing) and indexes the result, both under the sequence
|
||||||
|
/// lease. Frames inserted before indexed ones move the project's positions (<see cref="ProjectPositions"/>) without a
|
||||||
|
/// new settings version; an editor saving its project holds the same lease, so it reads them moved and merges onto
|
||||||
|
/// them rather than writing its old positions back.
|
||||||
|
/// </summary>
|
||||||
|
private async Task<SequenceManifest> UpdateAndSyncAsync(Archive archive, ArchivePaths paths, SequencePaths sequence, Guid sequenceId,
|
||||||
|
Func<SequenceManifest, SequenceManifest?> edit, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await using (await _writer.LockAsync(paths, sequenceId, cancellationToken).ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
var manifest = SequenceWriter.ReadLocked(sequence, sequenceId);
|
||||||
|
if (edit(manifest) is { } updated)
|
||||||
|
{
|
||||||
|
ManifestStore.WriteSequence(sequence.ManifestPath, updated);
|
||||||
|
manifest = updated;
|
||||||
|
}
|
||||||
|
await SyncAsync(archive, sequence, manifest, cancellationToken).ConfigureAwait(false);
|
||||||
|
return manifest;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Indexes one folder; returns the sidecar bytes when they were read and not rewritten since (for the snapshot).</summary>
|
/// <summary>Indexes one folder; returns the sidecar bytes when they were read and not rewritten since (for the snapshot).</summary>
|
||||||
@@ -169,20 +189,33 @@ public sealed class ArchiveIndexer
|
|||||||
}
|
}
|
||||||
if (reconcile || File.Exists(sequence.IngestJournalPath))
|
if (reconcile || File.Exists(sequence.IngestJournalPath))
|
||||||
{
|
{
|
||||||
var before = manifest;
|
|
||||||
// Photos added, gone or back: the light analysis no longer describes the frames, so the scan's follow-up runs it again.
|
// Photos added, gone or back: the light analysis no longer describes the frames, so the scan's follow-up runs it again.
|
||||||
manifest = await _writer.UpdateAsync(paths, manifest.Id, folder.RelativeFolder,
|
manifest = await UpdateAndSyncAsync(archive, paths, sequence, manifest.Id,
|
||||||
m => SequenceAdopter.Reconcile(sequence, m, cancellationToken) is { } reconciled
|
m => SequenceAdopter.Reconcile(sequence, m, cancellationToken) is { } reconciled
|
||||||
? reconciled with { Status = reconciled.Status & ~SequenceStatus.AnalyzedLight }
|
? reconciled with { Status = reconciled.Status & ~SequenceStatus.AnalyzedLight }
|
||||||
: null,
|
: null,
|
||||||
cancellationToken).ConfigureAwait(false);
|
cancellationToken).ConfigureAwait(false);
|
||||||
if (!ReferenceEquals(before, manifest)) bytes = null;
|
bytes = null;
|
||||||
|
}
|
||||||
|
else if (await MayMovePositionsAsync(manifest, cancellationToken).ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
// Another process changed the frames: the sidecar is read again under the lease the project moves under.
|
||||||
|
manifest = await UpdateAndSyncAsync(archive, paths, sequence, manifest.Id, _ => null, cancellationToken).ConfigureAwait(false);
|
||||||
|
bytes = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await SyncAsync(archive, sequence, manifest, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
await SyncAsync(archive, sequence, manifest, cancellationToken).ConfigureAwait(false);
|
|
||||||
locations.Set(manifest.Id, folder.RelativeFolder);
|
locations.Set(manifest.Id, folder.RelativeFolder);
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>The index holds a project for this sequence and other frames than the sidecar: its positions may move.</summary>
|
||||||
|
private async Task<bool> MayMovePositionsAsync(SequenceManifest manifest, CancellationToken cancellationToken) =>
|
||||||
|
await _db.Sequences.GetAsync(manifest.Id, cancellationToken).ConfigureAwait(false) is { SettingsJson: not null } indexed
|
||||||
|
&& indexed.FramesVersion != manifest.Versions.Frames;
|
||||||
|
|
||||||
/// <summary>A sidecar for a folder that has none; ids of a sequence the index already knew at this folder are kept.</summary>
|
/// <summary>A sidecar for a folder that has none; ids of a sequence the index already knew at this folder are kept.</summary>
|
||||||
private async Task<SequenceManifest> AdoptAsync(SequencePaths sequence, Locations locations, CancellationToken cancellationToken)
|
private async Task<SequenceManifest> AdoptAsync(SequencePaths sequence, Locations locations, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -298,4 +298,37 @@ public sealed class ArchiveIngestTests(TestContext context)
|
|||||||
Assert.Contains("futureOption", settings);
|
Assert.Contains("futureOption", settings);
|
||||||
Assert.True(JsonNode.DeepEquals(JsonNode.Parse(settings), JsonNode.Parse(File.ReadAllText(folder.ProjectPath))), "project.json mirrors the index");
|
Assert.True(JsonNode.DeepEquals(JsonNode.Parse(settings), JsonNode.Parse(File.ReadAllText(folder.ProjectPath))), "project.json mirrors the index");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task AScanMovesTheProjectPositionsOnlyBetweenProjectSaves()
|
||||||
|
{
|
||||||
|
await using var fx = await CreateAsync(context);
|
||||||
|
var late = await fx.Service.Ingest.CommitAsync(Request(fx, fx.Stage(Start.AddMinutes(1), 1)), fx.Ct);
|
||||||
|
await fx.Service.Ingest.CommitAsync(Request(fx, fx.Stage(Start.AddMinutes(2), 2)), fx.Ct);
|
||||||
|
var id = late.SequenceId;
|
||||||
|
var folder = fx.Paths.Sequence((await fx.Db.Sequences.GetAsync(id))!.Folder);
|
||||||
|
var version = (await fx.Db.Sequences.EditAsync(id, new SequenceEdit { SettingsJson = "{ \"excludedFrames\": [1] }" }, null, fx.Ct)).Sequence!.SettingsVersion;
|
||||||
|
|
||||||
|
// Another process files a photo captured before both into the sidecar; this index learns of it from a scan.
|
||||||
|
var photos = ArchiveScanner.PhotoDirectory(folder);
|
||||||
|
var stamp = Directory.GetLastWriteTimeUtc(photos);
|
||||||
|
File.WriteAllBytes(folder.File("originals/early.JPG"), Photos.Jpeg(Start, 3));
|
||||||
|
ManifestStore.WriteSequence(folder.ManifestPath, SequenceAdopter.Reconcile(folder, ManifestStore.ReadSequence(folder.ManifestPath), fx.Ct)!);
|
||||||
|
Directory.SetLastWriteTimeUtc(photos, stamp);
|
||||||
|
|
||||||
|
// An editor saving the project holds the sequence lease (LocalSequenceSource.SaveProjectAsync).
|
||||||
|
var save = await LeaseFile.AcquireAsync(fx.Paths.LocksDirectory, $"seq-{id:N}", "editor", TimeSpan.FromSeconds(5), cancellationToken: fx.Ct);
|
||||||
|
var scan = Task.Run(() => fx.ScanAsync());
|
||||||
|
await Task.Delay(500, fx.Ct);
|
||||||
|
Assert.False(scan.IsCompleted, "the scan waits for the save");
|
||||||
|
// The save stores the positions its editor knew, as of the frames before the scan.
|
||||||
|
Assert.Equal(SequenceEditOutcome.Updated,
|
||||||
|
(await fx.Db.Sequences.EditAsync(id, new SequenceEdit { SettingsJson = "{ \"excludedFrames\": [0, 1] }" }, version, fx.Ct)).Outcome);
|
||||||
|
save.Dispose();
|
||||||
|
Assert.Equal(1, (await scan).Indexed);
|
||||||
|
|
||||||
|
var row = (await fx.Db.Sequences.GetAsync(id))!;
|
||||||
|
Assert.Equal(3, row.FrameCount);
|
||||||
|
Assert.SequenceEqual([1, 2], ProjectSettings.FromJson(row.SettingsJson!).ExcludedFrames);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user