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
@@ -48,6 +48,9 @@ public sealed record WorkspaceSaveBoth(Guid CopyId, Guid CopyBaseId, int CopyBas
|
||||
/// <summary>A local version (<paramref name="LocalId"/>) and the id it is sent under to a save-both's copy.</summary>
|
||||
public sealed record WorkspaceMove(Guid LocalId, Guid CopyVersionId);
|
||||
|
||||
/// <summary>A version file of a workspace that cannot be read (<see cref="WorkspaceProject.UnreadableVersions"/>): the number and id its name carries, and why.</summary>
|
||||
public sealed record UnreadableVersion(int Number, Guid Id, string Path, string Reason);
|
||||
|
||||
/// <summary>
|
||||
/// A pull or push that met real conflicts (owner review 2, R8): the home's head it met, the version the local commits were
|
||||
/// made from, the local commits (oldest first) and the members both sides changed (mine, theirs). Settled by keeping mine,
|
||||
@@ -342,11 +345,24 @@ public sealed class WorkspaceProject
|
||||
AtomicFile.WriteAllText(MediaIndexPath, JsonSerializer.Serialize(media, WorkspaceJson.Default.WorkspaceMedia));
|
||||
}
|
||||
|
||||
/// <summary>The versions this workspace holds, oldest first; one that cannot be read is left out (and logged).</summary>
|
||||
public IReadOnlyList<ProjectVersion> Versions()
|
||||
/// <summary>
|
||||
/// The versions this workspace holds, oldest first. One that cannot be read is left out here, logged, and listed by
|
||||
/// <see cref="UnreadableVersions"/>: the sync treats one above the base as a gap in the chain of versions to send, never
|
||||
/// as a version that is not there (<see cref="WorkspaceSync"/>).
|
||||
/// </summary>
|
||||
public IReadOnlyList<ProjectVersion> Versions() => ReadVersions(log: true).Versions;
|
||||
|
||||
/// <summary>
|
||||
/// The version files of the workspace that cannot be read now (damaged, held open, over the size a version may be, of
|
||||
/// a newer Chronos), by the number and id their names carry, oldest first.
|
||||
/// </summary>
|
||||
public IReadOnlyList<UnreadableVersion> UnreadableVersions() => ReadVersions(log: false).Unreadable;
|
||||
|
||||
private (List<ProjectVersion> Versions, List<UnreadableVersion> Unreadable) ReadVersions(bool log)
|
||||
{
|
||||
var versions = new List<ProjectVersion>();
|
||||
foreach (var (_, _, path) in ProjectSidecars.ListVersions(VersionsDirectory))
|
||||
var unreadable = new List<UnreadableVersion>();
|
||||
foreach (var (number, id, path) in ProjectSidecars.ListVersions(VersionsDirectory))
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -355,12 +371,21 @@ public sealed class WorkspaceProject
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or InvalidDataException or UnauthorizedAccessException)
|
||||
{
|
||||
Log.Warning("workspace", $"Version file {path} cannot be read", ex);
|
||||
// Said once per file as it is now: every sync step lists the versions again.
|
||||
if (log && (!Reported.TryGetValue(path, out var said) || said != ex.Message))
|
||||
{
|
||||
Reported[path] = ex.Message;
|
||||
Log.Warning("workspace", $"Version file {path} cannot be read", ex);
|
||||
}
|
||||
unreadable.Add(new UnreadableVersion(number, id, path, ex.Message));
|
||||
}
|
||||
}
|
||||
return versions;
|
||||
return (versions, unreadable);
|
||||
}
|
||||
|
||||
/// <summary>The version files whose read failure was logged, with why (logged again when the reason changes).</summary>
|
||||
private static readonly System.Collections.Concurrent.ConcurrentDictionary<string, string> Reported = new(StringComparer.Ordinal);
|
||||
|
||||
/// <summary>The path of a version in <see cref="VersionsDirectory"/>.</summary>
|
||||
public string VersionPath(ProjectVersion version) => Path.Combine(VersionsDirectory, ArchiveLayout.ProjectVersionFileName(version.Number, version.Id));
|
||||
|
||||
@@ -370,9 +395,11 @@ public sealed class WorkspaceProject
|
||||
/// Moves a version file aside into <c>versions/.replaced</c> (a local commit replayed under another id), trying again
|
||||
/// for a moment while another program (an indexer, an antivirus) holds it open.
|
||||
/// </summary>
|
||||
internal void SetAside(ProjectVersion version)
|
||||
internal void SetAside(ProjectVersion version) => SetAside(VersionPath(version));
|
||||
|
||||
/// <summary>Moves the version file at <paramref name="path"/> aside into <c>versions/.replaced</c> (see <see cref="SetAside(ProjectVersion)"/>).</summary>
|
||||
internal void SetAside(string path)
|
||||
{
|
||||
var path = VersionPath(version);
|
||||
if (!File.Exists(path)) return;
|
||||
var aside = Path.Combine(VersionsDirectory, ReplacedFolder);
|
||||
Directory.CreateDirectory(aside);
|
||||
|
||||
Reference in new issue
Block a user