fix(workspace): phase 5a fix round 2, workspace sync and copy
A Save both, a recorded conflict and a damaged version file could each leave a local version out of the chain or a copy half-made at the home. This round makes every one of these end with nothing lost and nothing half done. - Save both retry: a journaled copy somebody else sent a version to (or one deleted since) is left as it is, and a new copy takes every local version. A divergence met at the copy while sending also makes a new copy, once. - Keep mine, Take server, or a pull that settles a conflict after a Save both was cut short first send the rest of the journaled versions to that copy, if it is still this workspace's. The journal is cleared at the commit point. - A conflict of format met past local versions the home already stored (their answer lost) now moves the base onto them, like any other conflict. The conflict, the base and the chain then name one version. A save-both journal follows the base when it moves. - A conflict recorded before stays while the home holds no version after the base. A base that has reached the conflict's head clears it. - Take server no longer replays or sends the version it saves first when, replayed, that version holds only the server's values. It stays in versions/.replaced for the undo. The test checks the exact history again. - Version files after the base that cannot be read, or that do not follow from it, are listed (WorkspaceProject.UnreadableVersions). The new state WorkspaceState.Damaged shows them. Commit, push, pull and resolve refuse to go past them. A damaged file whose version the home holds takes the home's copy at the next sync, and the damaged file is kept aside. Remove local copy counts these files as unsent. - PushOutcome.TooLarge raises its own WorkspaceSyncException message. The desktop says Errors.Workspace.VersionTooLarge for it and for ProjectVersionTooLargeException when a local commit is too large. - The editor maps LeaseUnavailableException from opening a busy project to Errors.Workspace.Busy. - The copy job no longer deletes, during the pass, a proxy that the editor's current media name. RemoveStale removes it after the commit. A resumed run does not keep such a file as a frame whose photo changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8256b72913
commit
e23cba3ee1
18 files changed
+646
-88
No files matched your search
@@ -114,6 +114,8 @@ internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService
|
||||
var total = (long)frames.Count;
|
||||
var tally = new Tally();
|
||||
var entries = new WorkspaceFrame[frames.Count];
|
||||
// The media the editor reads until this copy commits: their files stay until then (RemoveStale).
|
||||
var current = TryReadMedia(project)?.Frames.Where(f => f.File is not null).ToDictionary(f => f.Id) ?? [];
|
||||
Directory.CreateDirectory(project.ProxiesDirectory);
|
||||
// The workspace is on this PC's own drive, with the index, the settings and the logs: the copy never fills it.
|
||||
var remaining = Remaining(project, folder, frames, policy);
|
||||
@@ -122,7 +124,7 @@ internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService
|
||||
for (var i = 0; i < frames.Count; i++)
|
||||
{
|
||||
ct.ThrowIfCancellationRequested();
|
||||
entries[i] = Copy(project, folder, paths, frames[i], policy, done: i < copied, tally, ct);
|
||||
entries[i] = Copy(project, folder, paths, frames[i], policy, done: i < copied, current.GetValueOrDefault(frames[i].Id), tally, ct);
|
||||
if (clock.Elapsed >= CheckpointEvery)
|
||||
{
|
||||
await context.CheckpointAsync(Checkpoint(Stage.Copy, i + 1, row.FramesVersion, row.Folder), i + 1, total).ConfigureAwait(false);
|
||||
@@ -205,17 +207,26 @@ internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService
|
||||
/// <summary>
|
||||
/// The frame's file in the workspace: kept when an earlier run copied it (before the checkpoint, or the same bytes as the
|
||||
/// archive's proxy), else the archive's current proxy, else one made from the original; none for a frame without either.
|
||||
/// The file the media the editor reads now name for the frame (<paramref name="current"/>) is never removed here: the
|
||||
/// editor keeps it while the copy runs and if it fails, and a copy that commits without it removes it then
|
||||
/// (<see cref="RemoveStale"/>). Nor is it taken as this run's copy of a frame whose photo changed since.
|
||||
/// </summary>
|
||||
private WorkspaceFrame Copy(WorkspaceProject project, SequencePaths folder, ArchivePaths paths, Frame frame, ProxyPolicy policy, bool done, Tally tally,
|
||||
CancellationToken cancellationToken)
|
||||
private WorkspaceFrame Copy(WorkspaceProject project, SequencePaths folder, ArchivePaths paths, Frame frame, ProxyPolicy policy, bool done,
|
||||
WorkspaceFrame? current, Tally tally, CancellationToken cancellationToken)
|
||||
{
|
||||
var name = WorkspaceProject.ProxyName(frame.Id);
|
||||
var target = project.MediaFile(name);
|
||||
var listed = current is not null && string.Equals(current.File, name, StringComparison.OrdinalIgnoreCase);
|
||||
if (done && File.Exists(target))
|
||||
{
|
||||
tally.Kept++;
|
||||
var kept = AtomicFile.ReadAllBytes(target);
|
||||
return WorkspaceFrame.Of(frame, name, Sha(kept), kept.Length);
|
||||
var keptSha = Sha(kept);
|
||||
// The editor's file of another photo of the frame (a conversion since) was left by an earlier copy, not this run.
|
||||
if (!listed || keptSha != current!.FileSha256 || SamePhoto(current, frame))
|
||||
{
|
||||
tally.Kept++;
|
||||
return WorkspaceFrame.Of(frame, name, keptSha, kept.Length);
|
||||
}
|
||||
}
|
||||
var source = folder.Proxy(frame.Index);
|
||||
byte[]? bytes = null;
|
||||
@@ -238,8 +249,8 @@ internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService
|
||||
if (bytes is null)
|
||||
{
|
||||
// A file an earlier copy left for the frame (of other frames, or another folder's) is never kept as its photo by a
|
||||
// resumed run: a regenerable copy, it goes.
|
||||
if (File.Exists(target)) TryDelete(target);
|
||||
// resumed run: a regenerable copy, it goes, unless the editor's media name it (it goes once this copy commits).
|
||||
if (!listed && File.Exists(target)) TryDelete(target);
|
||||
tally.Missing++;
|
||||
return WorkspaceFrame.Of(frame, null, null, 0);
|
||||
}
|
||||
@@ -321,6 +332,11 @@ internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService
|
||||
|
||||
private static FramePhoto Photo(WorkspaceFrame frame) => new(frame.Sha256, frame.Size, frame.CapturedAt);
|
||||
|
||||
/// <summary>Whether the media's entry of a frame is of the photo the frame holds now (a conversion gives it another file).</summary>
|
||||
private static bool SamePhoto(WorkspaceFrame held, Frame frame) =>
|
||||
held.Size == frame.Size && held.CapturedAt == frame.CapturedAt
|
||||
&& (string.IsNullOrEmpty(held.Sha256) || string.IsNullOrEmpty(frame.Sha256) || string.Equals(held.Sha256, frame.Sha256, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
/// <summary>Proxies of frames the sequence no longer has: regenerable copies, removed so the media folder holds the frames listed.</summary>
|
||||
private static void RemoveStale(WorkspaceProject project, WorkspaceMedia media)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user