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:
1 parent
b9d1c396a1
commit
50e28fd63d
18 files changed
+596
-91
No files matched your search
@@ -317,13 +317,20 @@ public sealed class ProjectService
|
||||
{
|
||||
await UnderLeaseAsync(sequenceId, (_, _) => Task.FromResult(true), cancellationToken, ReadWait).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) when (ex is ArchiveOfflineException or LeaseUnavailableException)
|
||||
catch (Exception ex) when (ex is ArchiveOfflineException or LeaseUnavailableException or SequenceFolderMovedException)
|
||||
{
|
||||
Log.Info("projects", $"The projects of sequence {sequenceId} are read from the index: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Runs <paramref name="work"/> under the sequence's lease, after catching its projects up.</summary>
|
||||
/// <summary>
|
||||
/// Runs <paramref name="work"/> under the sequence's lease, after catching its projects up, in the folder the index has
|
||||
/// for the sequence as read under the lease (a Reorganize moves it under the same lease), which must hold it.
|
||||
/// </summary>
|
||||
/// <exception cref="SequenceFolderMovedException">
|
||||
/// The folder does not hold the sequence (another index of the archive moved it, maybe another sequence in): nothing is
|
||||
/// read from it or written into it, so no project is taken for gone and no file lands in another sequence's folder.
|
||||
/// </exception>
|
||||
private async Task<T> UnderLeaseAsync<T>(Guid sequenceId, Func<LeaseContext, CancellationToken, Task<T>> work, CancellationToken cancellationToken,
|
||||
TimeSpan? wait = null)
|
||||
{
|
||||
@@ -334,7 +341,9 @@ public sealed class ProjectService
|
||||
await using (await _writer.LockAsync(paths, sequenceId, wait, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
var row = await _db.Sequences.GetAsync(sequenceId, cancellationToken).ConfigureAwait(false) ?? throw SequenceMissing(sequenceId);
|
||||
var context = new LeaseContext(paths.Sequence(row.Folder), row);
|
||||
var folder = paths.Sequence(row.Folder);
|
||||
if (!SequenceFolders.Holds(folder, sequenceId)) throw new SequenceFolderMovedException();
|
||||
var context = new LeaseContext(folder, row);
|
||||
await CatchUpAsync(context, cancellationToken).ConfigureAwait(false);
|
||||
return await work(context, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
@@ -359,7 +368,8 @@ public sealed class ProjectService
|
||||
await _db.Projects.SetMirroredAsync(main.Id, main.HeadVersionId, context.Row.SettingsVersion, cancellationToken).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
var sameAsHead = ProjectContent.Hash(current) == head.ContentHash;
|
||||
// The head parks its photos as the frames held them when it was made: a conversion or a hash since names them anew.
|
||||
var sameAsHead = ProjectContent.SameChoices(head.SettingsJson, current, frames.Photos);
|
||||
if (main.MirroredVersionId == main.HeadVersionId || main.MirroredVersionId is null)
|
||||
{
|
||||
// Only the sequence's settings version moved (settings another path wrote, or only its title or tags), or the index
|
||||
@@ -375,14 +385,16 @@ public sealed class ProjectService
|
||||
return;
|
||||
}
|
||||
var mirrored = await _db.Projects.GetVersionAsync(main.MirroredVersionId.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (main.MirroredSettingsVersion == context.Row.SettingsVersion || mirrored is null || ProjectContent.Hash(current) == mirrored.ContentHash)
|
||||
if (main.MirroredSettingsVersion == context.Row.SettingsVersion || mirrored is null || ProjectContent.SameChoices(mirrored.SettingsJson, current, frames.Photos))
|
||||
{
|
||||
// Nobody changed the settings since the last mirror: the mirror completes.
|
||||
await MirrorAsync(context, main, head, cancellationToken).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
// Both moved: the settings written meanwhile merge with the head (the version made in a workspace wins where both changed).
|
||||
var merged = ProjectMerge.Merge(ProjectMerge.Read(mirrored.SettingsJson), ProjectMerge.Read(head.SettingsJson), ProjectMerge.Read(current));
|
||||
// Both moved: the settings written meanwhile merge with the head (the version made in a workspace wins where both changed),
|
||||
// each photo named as the frames hold it now so the same photo merges as one.
|
||||
var merged = ProjectMerge.Merge(ProjectMerge.Read(ProjectContent.Rebind(mirrored.SettingsJson, frames.Photos)),
|
||||
ProjectMerge.Read(ProjectContent.Rebind(head.SettingsJson, frames.Photos)), ProjectMerge.Read(ProjectContent.Rebind(current, frames.Photos)));
|
||||
var version = await AppendDerivedAsync(context, main, head, ProjectContent.Canonical(merged.ToJson()), ProjectVersionKind.Merge, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
main = (await _db.Projects.GetAsync(main.Id, cancellationToken).ConfigureAwait(false))!;
|
||||
@@ -550,7 +562,8 @@ public sealed class ProjectService
|
||||
if (page.Count < PageSize) break;
|
||||
after = page[^1].Index;
|
||||
}
|
||||
return (frames, new FramePhotos(frames.Select(f => (f.Index, new FramePhoto(f.Sha256, f.Size, f.CapturedAt)))));
|
||||
// With the encodings conversions joined: a version parked on a photo before its file was converted still finds its frame.
|
||||
return (frames, HomePhotos.Of(frames, await HomePhotos.AliasesAsync(_db, sequenceId, cancellationToken).ConfigureAwait(false)));
|
||||
}
|
||||
|
||||
private async Task EnsureNameFreeAsync(Guid sequenceId, Guid? projectId, string name, CancellationToken cancellationToken)
|
||||
|
||||
Reference in new issue
Block a user