fix(workspace): settle conflicts in one answer and give refused folders a way on
Phase 5a fix round 2 of owner review 2 (desktop):
- Take library's no longer commits the working state first, so a take that
leaves only the library's values sends no empty version; the working state
it replaces is kept aside in versions/.replaced, outside the chain.
- Conflicts list this side's value as the working state holds it, so one
answer settles them instead of asking again for the newer value.
- A conflict of format (library saved by a newer Chronos) offers only Save
both and Later, says why in its tooltip and shows no raw format numbers.
- Conflict lines count the photos a setting differs on ("Excluded frames
(3)") instead of dropping the duplicates.
- A read-only library is named as such, not as offline; checkouts from it
stay editable and their versions wait in the workspace.
- A workspace folder refused inside a library offers Choose folder, and
Settings > Workspace gets Change...: a plan (projects left, projects found)
is confirmed before the folder changes; nothing is moved.
- Open in workspace shows the copy's size and the drive's free space, and
warns when the copy would not fit with its 0.5 GB reserve.
- A cancelled first copy removes the half media it wrote.
- A copy whose project.chronos cannot be read is listed as damaged instead of
hidden, and goes only through Remove local copy > Discard, after a plan.
- Pruning keeps a version whose archive file is damaged (test added).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8256b72913
commit
64fc5521c0
30 files changed
+1017
-98
No files matched your search
@@ -102,8 +102,9 @@ public sealed class WorkspaceSyncException(PushOutcome outcome, string message)
|
||||
/// (hashed or converted there since the copy), so every side names one photo alike. Settings of a newer Chronos are never
|
||||
/// merged with this one's: a project with nothing of its own moves onto them read-only, any other waits on a conflict of
|
||||
/// format that only Save both settles (<see cref="WorkspaceConflict.NewerFormat"/>). Every operation holds the project's
|
||||
/// lease; nothing is ever deleted: a restore, a save-both or taking the server's values first saves uncommitted changes as
|
||||
/// a version.
|
||||
/// lease; nothing is ever deleted: a restore or a save-both first saves uncommitted changes as a version, and taking the
|
||||
/// server's values keeps the working state they replace aside (<c>versions/.replaced</c>). A conflict lists this side's
|
||||
/// values as the working state holds them, so it is asked and settled against what the user sees.
|
||||
/// Every write sequence survives a cut at any step: the working state's base is the commit point. A push moves the base
|
||||
/// before its local file reads as sent; a replay journals itself in <c>sync.json</c> (<see cref="WorkspaceReplay"/>), writes
|
||||
/// the replayed versions, then the base, and only then sets the old ones aside; a save-both journals its copy and the ids
|
||||
@@ -310,8 +311,9 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
/// <paramref name="takeServer"/>), <see cref="ConflictChoice.TakeServer"/> takes the server's on the settings listed;
|
||||
/// either way the local versions are replayed on the home's head and wait to be pushed. A choice applies only to the
|
||||
/// conflicts listed: when what differs now is not that (the home moved on, or this side was edited meanwhile), nothing
|
||||
/// is settled, and the conflict found now is recorded and returned to be asked again. Taking the server's first saves
|
||||
/// uncommitted changes as a version, so the values it replaces are kept (its file in <c>versions/.replaced</c>).
|
||||
/// is settled, and the conflict found now is recorded and returned to be asked again. Taking the server's keeps the
|
||||
/// working state it replaces as a version file in <c>versions/.replaced</c>, outside the chain: nothing is committed,
|
||||
/// replayed or sent for it, so a take that leaves only the server's values sends nothing.
|
||||
/// <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.
|
||||
@@ -330,8 +332,8 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
if (sync.Conflict is not { } recorded) return new WorkspaceSyncResult(await StatusLockedAsync(project, home, cancellationToken).ConfigureAwait(false), [], []);
|
||||
if (choice == ConflictChoice.SaveBoth)
|
||||
return await SaveBothAsync(project, bundle, home, saveBothName, cancellationToken).ConfigureAwait(false);
|
||||
// A conflict of format refuses the choice (nothing is merged with a newer Chronos's settings): nothing is saved first.
|
||||
if (choice == ConflictChoice.TakeServer && !bundle.IsReadOnly && !recorded.NewerFormat) CommitLocked(project, bundle, null, null);
|
||||
// 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>();
|
||||
ProjectSettings? kept = null;
|
||||
var (_, conflict, pulled) = await ReplayAsync(project, bundle, home, takeTheirs, cancellationToken, shown ?? recorded, k => kept = k).ConfigureAwait(false);
|
||||
@@ -463,7 +465,8 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
var merge = ProjectMerge.MergeWithConflicts(tip, working, newTip, choice);
|
||||
var keptMine = takeTheirs is EveryPath ? ProjectMerge.MergeWithConflicts(tip, working, keptTip).Merged : merge.Merged;
|
||||
if (takeTheirs is EveryPath) merge = ProjectMerge.MergeWithConflicts(tip, working, newTip, Paths(merge.Conflicts));
|
||||
var differences = replay.Conflicts.Concat(merge.Conflicts).DistinctBy(d => d.Path).ToList();
|
||||
var differences = AsInTheWorkingState(replay.Conflicts.Concat(merge.Conflicts).DistinctBy(d => d.Path),
|
||||
ProjectMerge.Conflicts(basisSettings, working, headSettings));
|
||||
if (differences.Count > 0 && (takeTheirs is null || (shown is not null && !SameDifferences(shown.Differences, differences))))
|
||||
{
|
||||
var conflict = new WorkspaceConflict(head.Id, head.Number, basis?.Id ?? Guid.Empty, [.. locals.Select(v => v.Id)], differences, DateTimeOffset.UtcNow);
|
||||
@@ -503,6 +506,10 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
}
|
||||
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 };
|
||||
// Taking the server's values over changes no version holds yet: the working state is kept aside first, never in the chain.
|
||||
if (takeTheirs is EveryPath && differences.Count > 0 && Portable(bundle.Project, media) is { } unsaved
|
||||
&& (tipVersion is null || !ProjectContent.SameChoices(tipVersion.SettingsJson, unsaved, photos)))
|
||||
project.WriteAside(VersionOf(project, unsaved, tipVersion, ProjectVersionKind.Commit, null, null, null, media?.FramesVersion ?? bundle.Workspace!.Media.FramesVersion));
|
||||
var journal = new WorkspaceReplay(head.Id, [.. locals.Select(v => v.Id)], [.. rebased.Select(v => v.Id)], [.. held.Select(v => v.Id)]);
|
||||
project.WriteSync(project.ReadSync() with { Replay = journal });
|
||||
Step("replay.journal");
|
||||
@@ -710,7 +717,7 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
return new WorkspaceSyncResult(await StatusLockedAsync(project, home, cancellationToken).ConfigureAwait(false), pushed, [head], copy);
|
||||
}
|
||||
|
||||
/// <summary>A new project at the home named <paramref name="name"/>, else "<paramref name="source"/> (2)", "(3)"… whichever is free.</summary>
|
||||
/// <summary>A new project at the home named <paramref name="name"/>, else "<paramref name="source"/> (2)", "(3)"… whichever is free.</summary>
|
||||
private static async Task<SequenceProject> CreateNamedAsync(IProjectHome home, string? name, string source, Guid? from, CancellationToken cancellationToken)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(name)) return await home.CreateAsync(name, from, null, cancellationToken).ConfigureAwait(false);
|
||||
@@ -745,28 +752,37 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
var restoredFrom = sync.RestoredFrom is { } restored && StillRestores(project, restored, Tip(project, bundle, locals), portable, media?.Photos ?? NoFrames)
|
||||
? sync.RestoredFrom
|
||||
: null;
|
||||
var version = new ProjectVersion
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
ProjectId = project.ProjectId,
|
||||
ParentId = tipId,
|
||||
Number = tipNumber + 1,
|
||||
Kind = restoredFrom is null ? ProjectVersionKind.Commit : ProjectVersionKind.Restore,
|
||||
Author = author,
|
||||
ClientName = clientName,
|
||||
Note = string.IsNullOrWhiteSpace(note) ? null : note.Trim(),
|
||||
SettingsJson = portable,
|
||||
ContentHash = hash,
|
||||
SettingsFormat = ProjectContent.FormatOf(portable),
|
||||
FramesVersion = media?.FramesVersion ?? workspace.Media.FramesVersion,
|
||||
RestoredFrom = restoredFrom,
|
||||
CreatedAt = DateTimeOffset.UtcNow,
|
||||
};
|
||||
var version = VersionOf(project, portable, (tipId, tipNumber), restoredFrom is null ? ProjectVersionKind.Commit : ProjectVersionKind.Restore, note, author,
|
||||
restoredFrom, media?.FramesVersion ?? workspace.Media.FramesVersion);
|
||||
project.WriteVersion(version);
|
||||
if (sync.RestoredFrom is not null) project.WriteSync(sync with { RestoredFrom = null });
|
||||
return version;
|
||||
}
|
||||
|
||||
/// <summary>A version of this workspace holding <paramref name="portable"/>, the child of <paramref name="parent"/> (null: the first).</summary>
|
||||
private ProjectVersion VersionOf(WorkspaceProject project, string portable, ProjectVersion? parent, ProjectVersionKind kind, string? note, string? author,
|
||||
Guid? restoredFrom, int framesVersion) =>
|
||||
VersionOf(project, portable, (parent?.Id, parent?.Number ?? 0), kind, note, author, restoredFrom, framesVersion);
|
||||
|
||||
private ProjectVersion VersionOf(WorkspaceProject project, string portable, (Guid? Id, int Number) parent, ProjectVersionKind kind, string? note, string? author,
|
||||
Guid? restoredFrom, int framesVersion) => new()
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
ProjectId = project.ProjectId,
|
||||
ParentId = parent.Id,
|
||||
Number = parent.Number + 1,
|
||||
Kind = kind,
|
||||
Author = author,
|
||||
ClientName = clientName,
|
||||
Note = string.IsNullOrWhiteSpace(note) ? null : note.Trim(),
|
||||
SettingsJson = portable,
|
||||
ContentHash = ProjectContent.Hash(portable),
|
||||
SettingsFormat = ProjectContent.FormatOf(portable),
|
||||
FramesVersion = framesVersion,
|
||||
RestoredFrom = restoredFrom,
|
||||
CreatedAt = DateTimeOffset.UtcNow,
|
||||
};
|
||||
|
||||
private async Task<WorkspaceStatus> StatusLockedAsync(WorkspaceProject project, IProjectHome? home, CancellationToken cancellationToken)
|
||||
{
|
||||
var bundle = project.ReadBundle();
|
||||
@@ -843,6 +859,17 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
return merge.Conflicts.Count == 0 && ProjectContent.Canonical(merge.Merged.ToJson()) == ProjectContent.Canonical(now);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The conflicts found as the user sees them: where the working state holds a value of its own against the home's
|
||||
/// (<paramref name="working"/>: edited since the last local version), that value is this side's, not the version's.
|
||||
/// Keeping mine keeps it, and taking the server's replaces it, so one answer settles what was listed.
|
||||
/// </summary>
|
||||
private static List<SettingsDifference> AsInTheWorkingState(IEnumerable<SettingsDifference> found, IReadOnlyList<SettingsDifference> working)
|
||||
{
|
||||
var now = working.DistinctBy(d => d.Path).ToDictionary(d => d.Path, StringComparer.Ordinal);
|
||||
return [.. found.Select(d => now.TryGetValue(d.Path, out var held) ? held : d)];
|
||||
}
|
||||
|
||||
/// <summary>Whether two conflicts list the same settings with the same values on each side (in any order).</summary>
|
||||
private static bool SameDifferences(IReadOnlyList<SettingsDifference> shown, IReadOnlyList<SettingsDifference> found) =>
|
||||
shown.Count == found.Count && shown.ToHashSet().SetEquals(found);
|
||||
|
||||
Reference in new issue
Block a user