fix(archive): settle conversions by content and keep their aliases through trash, undo, sync and ingest

Owner review 2, phase 4b, fix round 1 (trash, undo, recovery, sync and ingest).

- Replace journal: records a phase (moving, written, undoing) and the name each swapped
  frame is filed under. Recovery decides "sidecar written" by what the sidecar lists, not
  by the frames version any writer moves; a failed rollback stays undoing and its failure
  now stops the writer (as a photo deletion's recovery does). The ingest settles restores
  and replacements first, so an upload can no longer complete a swap that never happened.
- Emptying a Replaced entry re-verifies each replacement where it is now: in the sequence
  through later conversions (a second conversion no longer strands the first originals),
  or, when the conversion was deleted, its copy in the trash. The dry run marks such
  entries "conversion deleted" (fingerprinted, shown on the desktop and the panel), and
  the confirmed emptying may then erase them instead of keeping them forever.
- Undo of a conversion takes exactly the entries its job made (the job id is recorded on
  the entry), never entries found by time window.
- Project positions translated by photo use the sidecar's photo of every frame still
  there, so positions on a converted frame stay put when another frame went meanwhile.
- Sync aliases are equivalence classes: an original converted on both sides is one photo;
  link-by-content, proxy counting and proxy upload follow aliases; a download into a
  frame missing here swaps the other encoding into that frame instead of adding a frame.
- The ingest answers a converted photo's original (a card or folder imported again, a
  download) as a duplicate of its conversion and keeps the alias tombstone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 3341a2f845753fc4c5bcba51a3b645f126c95eaf)
This commit is contained in:
Alby96 committed 2026-10-27 22:13:36 +01:00
1 parent 67a6d51cbe
commit d0bbd77c92
31 files changed
+1326 -211

No files matched your search

@@ -86,6 +86,28 @@ internal sealed class SyncFixture : IAsyncDisposable
null, null), Ct);
}
/// <summary>
/// Replaces the file of the local frame at <paramref name="index"/> with <paramref name="converted"/>, as a conversion's
/// Replace does on this PC (owner review 2, R7): the same frame, a tombstone naming the new content.
/// </summary>
public async Task ReplaceLocalAsync(Guid sequenceId, int index, byte[] converted)
{
var sequence = (await Db.Sequences.GetAsync(sequenceId, Ct))!;
var frame = Chronos.Core.Archiving.ManifestStore.ReadSequence(Archive.Paths.Sequence(sequence.Folder).ManifestPath).Frames[index];
var staging = Path.Combine(Archive.Paths.StagingDirectory, "convert-test");
Directory.CreateDirectory(staging);
var path = Path.Combine(staging, $"{Guid.NewGuid():N}.jpeg");
await File.WriteAllBytesAsync(path, converted, Ct);
var sha = Convert.ToHexStringLower(System.Security.Cryptography.SHA256.HashData(converted));
var swap = new FrameSwap(frame.Id, Archive.Paths.ToRelative(path), [], (current, _) => Path.ChangeExtension(current.File, ".jpeg"), current => current with
{
Sha256 = sha,
Size = converted.Length,
Source = new Chronos.Core.Archiving.FrameSource { Sha256 = current.Sha256, Format = current.Format, File = current.File, Size = current.Size },
});
Assert.NotNull(await Archive.Service.FrameTrash.ReplaceAsync(Archive.Archive, sequenceId, null, [swap], null, null, null, null, Ct));
}
/// <summary>An edit on this PC, as the editor makes it (project file and index, settings version + 1).</summary>
public async Task<Sequence> EditLocalSettingsAsync(Guid id, string settingsJson)
{