fix(workspace): a deleted project asks nothing, prunes and copies clean up only after what ended well
Owner review 2, phase 5a (R8), fix round 4. A project the library no longer has now reads as Gone with no conflict to answer. The conflict stays recorded in sync.json, so Save both on a deleted project says Gone once and offers its copy. It no longer reopens the conflict dialog. Keep mine and Take the library's first check that the home still has the project. Neither is merged onto the last version a deleted project had, so the working state and the unsent versions stay as they were. Old files in versions/.replaced are pruned only after a push that ended well, never after one that stopped at a conflict. A file an earlier build set aside kept the time its version was written. It now counts as set aside no earlier than when this build first knew the folder (versions/.replaced.since), so an upgrade does not prune it by an old mtime. The Merge mark goes on the replayed version whose own change met a setting the conflict listed. A version that only rides along with a working-state conflict stays a commit. A first copy cancelled while paused or failed, which no handler runs, now has its partial media removed under the project's lease, as a running one does (ICancelledJobHandler). The space estimate counts a proxy held under its <id>-<sha16>.jpg name. The frames stamp carries a weighted SQL checksum of the hashes, so a hash replaced in place (a Verify) makes the workspace read the frames again. Desktop: a removal that cannot move a file puts back what it moved, so the copy stays whole and listed, and the failure is said. The Removed toast names a damaged copy as it is known, never by its folder id. One copy that cannot be listed no longer hides the others. A Main this Chronos cannot read (newer or damaged) is refused at once with the reason, and a damaged one offers Remove local copy. Save version is off on a Gone project, and Send/Delete there say the project was deleted in the library. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c5ed31bced
commit
279ebf437f
14 files changed
+729
-57
No files matched your search
@@ -273,6 +273,8 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
{
|
||||
var pushed = new List<ProjectVersion>();
|
||||
var pulled = new List<ProjectVersion>();
|
||||
// Ended well: every local version sent, no conflict met, no attempt left over.
|
||||
var sent = false;
|
||||
try
|
||||
{
|
||||
await SettleAsync(project, home, cancellationToken).ConfigureAwait(false);
|
||||
@@ -307,7 +309,11 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!diverged) break;
|
||||
if (!diverged)
|
||||
{
|
||||
sent = true;
|
||||
break;
|
||||
}
|
||||
var (_, conflict, taken) = await ReplayAsync(project, bundle, home, null, cancellationToken).ConfigureAwait(false);
|
||||
pulled.AddRange(taken);
|
||||
if (conflict is not null) break;
|
||||
@@ -319,7 +325,8 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
if (!await GoneAsync(project, home, ex, cancellationToken).ConfigureAwait(false)) throw;
|
||||
return new WorkspaceSyncResult(await StatusLockedAsync(project, home, cancellationToken).ConfigureAwait(false), pushed, pulled);
|
||||
}
|
||||
PruneReplaced(project);
|
||||
// A push stopped at a conflict, or by a home that kept moving, leaves versions/.replaced as it is.
|
||||
if (sent && project.ReadSync().Conflict is null) PruneReplaced(project);
|
||||
return new WorkspaceSyncResult(await StatusLockedAsync(project, home, cancellationToken).ConfigureAwait(false), pushed, pulled);
|
||||
}
|
||||
}
|
||||
@@ -346,6 +353,7 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
EnsureChained(project, bundle, Unpushed(project, bundle));
|
||||
if (project.ReadSync().Conflict is not null)
|
||||
{
|
||||
await EnsureAtHomeAsync(project, home, cancellationToken).ConfigureAwait(false);
|
||||
(_, var conflict, pulled) = await ReplayAsync(project, bundle, home, null, cancellationToken).ConfigureAwait(false);
|
||||
if (conflict is null) project.WriteSync(project.ReadSync() with { Conflict = null });
|
||||
}
|
||||
@@ -381,7 +389,8 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
/// <see cref="ConflictChoice.SaveBoth"/> saves the working state as a version, sends this workspace's versions to a new
|
||||
/// project at the home (<paramref name="saveBothName"/>, else this project's name with a number) made from the base,
|
||||
/// and moves this project onto the home's head; a project deleted at the home meanwhile keeps its versions here, the
|
||||
/// copy holding them too (<see cref="WorkspaceState.Gone"/>).
|
||||
/// copy holding them too (<see cref="WorkspaceState.Gone"/>). Keep mine and Take the server's on a project deleted at the
|
||||
/// home change nothing here (it reads as Gone): nothing is merged onto the last version it had there.
|
||||
/// </summary>
|
||||
/// <exception cref="HomeUnavailableException">The home cannot be reached; the conflict stays.</exception>
|
||||
public async Task<WorkspaceSyncResult> ResolveAsync(Guid projectId, IProjectHome home, ConflictChoice choice, IReadOnlySet<string>? takeServer = null,
|
||||
@@ -400,6 +409,8 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
EnsureChained(project, bundle, Unpushed(project, bundle));
|
||||
if (choice == ConflictChoice.SaveBoth)
|
||||
return await SaveBothAsync(project, bundle, home, saveBothName, cancellationToken).ConfigureAwait(false);
|
||||
// Never merged onto the last version of a project deleted at the home: it reads as Gone, everything here kept.
|
||||
await EnsureAtHomeAsync(project, home, cancellationToken).ConfigureAwait(false);
|
||||
// Nothing is committed first: a version of the working state would be replayed into one that only repeats the
|
||||
// head, and sent. What the take replaces of the working state is kept aside by the replay instead.
|
||||
IReadOnlySet<string> takeTheirs = choice == ConflictChoice.TakeServer ? AllPaths : takeServer ?? new HashSet<string>();
|
||||
@@ -563,6 +574,9 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
}
|
||||
var rebased = new List<ProjectVersion>(locals.Count);
|
||||
ProjectVersion parent = head;
|
||||
// The last replayed version that carries the merge: its own commit met a setting the conflict listed.
|
||||
var merged = -1;
|
||||
var listed = Paths(differences);
|
||||
for (var i = 0; i < locals.Count; i++)
|
||||
{
|
||||
var local = locals[i];
|
||||
@@ -574,6 +588,7 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
Log.Info("workspace", $"Version {local.Number} of project {project.ProjectId} changes nothing once replayed on version {head.Number}: it is not sent");
|
||||
continue;
|
||||
}
|
||||
if (listed.Count > 0 && ProjectMerge.Conflicts(basisSettings, mine[i], headSettings).Any(d => listed.Contains(d.Path))) merged = rebased.Count;
|
||||
parent = local with
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
@@ -586,7 +601,8 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
};
|
||||
rebased.Add(parent);
|
||||
}
|
||||
if (differences.Count > 0 && rebased.Count > 0) rebased[^1] = rebased[^1] with { Kind = ProjectVersionKind.Merge };
|
||||
// Marked on the version that holds the choice made, never on an earlier one a skipped version leaves last.
|
||||
if (merged >= 0) rebased[merged] = rebased[merged] with { Kind = ProjectVersionKind.Merge };
|
||||
var placed = ProjectSettings.FromJson(ProjectContent.Place(ProjectContent.Canonical(merge.Merged.ToJson()), photos), allowNewer: true);
|
||||
var moved = WithBase(bundle, head) with { Project = placed, Saved = DateTimeOffset.UtcNow };
|
||||
await FinishCopyAsync(project, home, chain, cancellationToken).ConfigureAwait(false);
|
||||
@@ -1095,7 +1111,8 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
/// when it cannot). The home's frames are read again only when its stamp of them moved (<see cref="IProjectHome.FramesStampAsync"/>).
|
||||
/// Without the lease, a version file that reads as damaged is read again under it before the state says so: another
|
||||
/// operation between two of its writes is no damage; while that one holds the project, it is not reported (that
|
||||
/// operation stops at it itself). A home that answers it no longer has the project reads as <see cref="WorkspaceState.Gone"/>.
|
||||
/// operation stops at it itself). A home that answers it no longer has the project reads as <see cref="WorkspaceState.Gone"/>,
|
||||
/// with no conflict to answer (<see cref="WorkspaceStatus.Conflict"/> null; the one recorded stays in <c>sync.json</c>).
|
||||
/// </summary>
|
||||
private async Task<WorkspaceStatus> StatusLockedAsync(WorkspaceProject project, IProjectHome? home, CancellationToken cancellationToken, bool leased = true)
|
||||
{
|
||||
@@ -1150,7 +1167,9 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
: locals.Count > 0 ? WorkspaceState.Ahead
|
||||
: modified ? WorkspaceState.Modified
|
||||
: WorkspaceState.InSync;
|
||||
return new WorkspaceStatus(state, modified, locals.Count, behind, offline, media is null, bundle.IsReadOnly, conflict, workspace.Base, head)
|
||||
// A project the home no longer has holds no conflict to answer (nothing can be merged with it): the one recorded stays
|
||||
// in sync.json, for the record and for a project the home holds again.
|
||||
return new WorkspaceStatus(state, modified, locals.Count, behind, offline, media is null, bundle.IsReadOnly, gone ? null : conflict, workspace.Base, head)
|
||||
{
|
||||
MediaOutdated = outdated,
|
||||
Damaged = damaged,
|
||||
@@ -1263,6 +1282,14 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
if (removed > 0) Log.Info("workspace", $"{removed} old file(s) of project {project.ProjectId} left versions/.replaced");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The home still has the project: asked before a choice or a recorded conflict is replayed, so nothing is merged onto
|
||||
/// the last version of a project deleted there (whose history the home may still read back).
|
||||
/// </summary>
|
||||
/// <exception cref="ProjectException">The home no longer has the project or its sequence (<see cref="GoneAsync"/>).</exception>
|
||||
private static async Task EnsureAtHomeAsync(WorkspaceProject project, IProjectHome home, CancellationToken cancellationToken) =>
|
||||
await home.HeadAsync(project.ProjectId, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
/// <summary>Whether a sync stopped because the home does not know a project or a version (<see cref="GoneAsync"/> tells which).</summary>
|
||||
private static bool NotFoundAtHome(ProjectException ex) => ex.Reason is ProjectError.NotFound or ProjectError.SequenceNotFound;
|
||||
|
||||
|
||||
Reference in new issue
Block a user