fix: projects and the workspace copy follow phase 4's folder and conversion rules

Phase 5a was written on an early phase 4a state. On top of phase 4b it now
keeps the rules every writer of a sequence's folder follows, and keeps
project versions intact through Reorganize and conversions:

- ProjectService writes project sidecars, project.json and the settings
  only under the sequence's lease and only in a folder that holds the
  sequence (SequenceFolders.Holds). A folder another index moved away, or
  one another sequence was moved into, is refused with
  SequenceFolderMovedException: reads answer from the index, so no
  project is taken for gone, nothing is written into the other sequence's
  folder and the old folder is never created again. The home reports it
  as out of reach. Full scans and rebuilds reconcile projects the same
  way, and a failure there is logged instead of failing the scan.
- Stored versions park positions by photo and now follow the encodings a
  Replace conversion (or its undo) joined through the sequence's Replaced
  tombstones (PhotoAlias, HomePhotos): Main's mirror, renders of a
  version and workspace media place them on the converted frames.
  ProjectContent.Rebind/SameChoices name parked photos as the frames hold
  them now, so a conversion or a hash since is no "external" Main version
  and no spurious "Modified" in a workspace, and merges see one photo.
- The workspace copy job only reads the archive: it no longer runs the
  archive's proxy pass, makes missing proxies in the workspace, reads
  only a folder that holds the sequence, starts again when the folder
  moved or files were renamed during the copy, resumes from a checkpoint
  of its frames version, and refuses a workspace folder inside any
  library before it writes anything (Errors.Workspace.InsideLibrary).
  The working state keeps its positions by frame where frames stay.
- ArchiveProjectHome looks for a project or version the index does not
  know yet in the sequence's sidecars first (an index taken back from a
  backup, a sequence back from the trash), instead of calling it gone.

Tests cover the moved and taken folder, conversions in the archive and in
the workspace, the copy refusing a workspace in a library, resuming on
other frames, the alias lookup and the rebinding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-02 10:14:39 +01:00
1 parent b9d1c396a1
commit 50e28fd63d
18 files changed
+596 -91

No files matched your search

@@ -54,6 +54,58 @@ public static class ProjectContent
return ProjectSettings.TranslateFramePositions(portableJson, null, frames) ?? portableJson;
}
/// <summary>
/// The portable text with each pending frame whose photo <paramref name="frames"/> hold named as they hold it now: an
/// encoding a conversion replaced by the one the frame holds (<see cref="PhotoAlias"/>, also its undo), a photo parked
/// before it was hashed by its SHA-256, size and capture time. The same choices on the same photos then read as the same
/// text (<see cref="SameChoices"/>), whichever encoding or hashing state they were saved against; a placement finds the
/// same frames either way. Canonical when anything is renamed; the text as it is otherwise, and for a newer format.
/// </summary>
/// <exception cref="JsonException">The text is not a project object.</exception>
public static string Rebind(string portableJson, FramePhotos frames)
{
ArgumentNullException.ThrowIfNull(portableJson);
ArgumentNullException.ThrowIfNull(frames);
if (frames.Count == 0 || !portableJson.Contains("pendingFrames", StringComparison.OrdinalIgnoreCase)) return portableJson;
if (FormatOf(portableJson) > ProjectSettings.CurrentVersion) return portableJson;
if (JsonNode.Parse(portableJson, new JsonNodeOptions { PropertyNameCaseInsensitive = true }) is not JsonObject project
|| project["pendingFrames"] is not JsonArray pending) return portableJson;
var renamed = false;
foreach (var entry in pending.OfType<JsonObject>())
{
var sha = entry["sha256"] is JsonValue s && s.TryGetValue<string>(out var text) ? text : null;
var size = entry["size"] is JsonValue z && z.TryGetValue<long>(out var bytes) ? bytes : -1;
DateTime? captured = entry["capturedAt"] is JsonValue t && t.TryGetValue<DateTime>(out var time) ? time : null;
if (string.IsNullOrEmpty(sha) && (captured is null || size < 0)) continue;
var occurrence = entry["occurrence"] is JsonValue o && o.TryGetValue<int>(out var n) && n > 0 ? n : 0;
// Only a frame that is hashed names a photo better than the entry does.
if (frames.IndexOf(new FramePhoto(sha, size, captured), occurrence) is not { } at || frames[at] is not { IsHashed: true } held) continue;
var sameTime = held.CapturedAt is { } heldAt
? captured is { } entryAt && FramePhoto.Millisecond(heldAt) == FramePhoto.Millisecond(entryAt)
: captured is null;
if (string.Equals(held.Sha256, sha, StringComparison.OrdinalIgnoreCase) && held.Size == size && sameTime) continue;
entry["sha256"] = held.Sha256!.ToLowerInvariant();
entry["size"] = held.Size;
if (held.CapturedAt is { } heldTime) entry["capturedAt"] = heldTime;
else entry.Remove("capturedAt");
renamed = true;
}
return renamed ? Canonical(project.ToJsonString()) : portableJson;
}
/// <summary>
/// Whether two portable texts hold the same choices on the frames of <paramref name="frames"/>: the same text, or the
/// same once their pending frames are named as the frames hold their photos now (<see cref="Rebind"/>).
/// </summary>
/// <exception cref="JsonException">A text is not a project object.</exception>
public static bool SameChoices(string portable, string other, FramePhotos frames)
{
ArgumentNullException.ThrowIfNull(portable);
ArgumentNullException.ThrowIfNull(other);
ArgumentNullException.ThrowIfNull(frames);
return portable == other || (frames.Count > 0 && Rebind(portable, frames) == Rebind(other, frames));
}
/// <summary>
/// The canonical text of a project: read (a newer Chronos's too, its unknown members kept) and written again, its
/// pending frames in a fixed order (by photo) and their capture times as wall-clock values.