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:
Alby96andClaude Opus 5.5 committed 2026-11-03 14:07:35 +01:00
1 parent c5ed31bced
commit 279ebf437f
14 files changed
+729 -57

No files matched your search

+43 -4
View File
@@ -288,6 +288,13 @@ public sealed class WorkspaceProject
/// </summary>
public const string ReplacedFolder = ".replaced";
/// <summary>
/// Beside <see cref="ReplacedFolder"/> in <c>versions/</c>: when this Chronos first set a file aside there or pruned it
/// (an ISO-8601 time). A file dated before it was set aside by an earlier build, which kept the time it was written: it
/// counts as set aside then, at the earliest (<see cref="PruneReplaced"/>).
/// </summary>
public const string ReplacedSinceFile = ".replaced.since";
private const string LeaseName = ".lock";
internal WorkspaceProject(WorkspaceStore store, Guid projectId)
@@ -443,6 +450,7 @@ public sealed class WorkspaceProject
if (!File.Exists(path)) return;
var aside = Path.Combine(VersionsDirectory, ReplacedFolder);
Directory.CreateDirectory(aside);
ReplacedSince(DateTime.UtcNow);
var target = Path.Combine(aside, Path.GetFileName(path));
if (File.Exists(target)) target += "." + DateTime.UtcNow.Ticks.ToString(System.Globalization.CultureInfo.InvariantCulture);
for (var attempt = 1; ; attempt++)
@@ -469,6 +477,7 @@ public sealed class WorkspaceProject
{
ArgumentNullException.ThrowIfNull(version);
ProjectSidecars.WriteVersion(Path.Combine(VersionsDirectory, ReplacedFolder, Path.GetFileName(VersionPath(version))), version);
ReplacedSince(DateTime.UtcNow);
}
/// <summary>Files <see cref="PruneReplaced"/> keeps in <c>versions/.replaced</c> whatever their age.</summary>
@@ -481,19 +490,24 @@ public sealed class WorkspaceProject
/// Removes from <c>versions/.replaced</c> the files set aside more than <see cref="ReplacedMaxAge"/> ago and those past
/// the newest <see cref="ReplacedKept"/>, never one of a version in <paramref name="referenced"/> (a journal's). Every
/// file there is a copy of what the chain or the home holds, or what a take of the server's values replaced (its undo):
/// called only after a sync that ended well. How many went.
/// called only after a sync that ended well. A file is set aside when this Chronos dated it (it touches what it sets
/// aside), and no earlier than this Chronos first knew the folder (<see cref="ReplacedSinceFile"/>): one an earlier build
/// set aside keeps the time its version was written, which says nothing of when it went aside. How many went.
/// </summary>
internal int PruneReplaced(IReadOnlySet<Guid> referenced, DateTime nowUtc)
{
ArgumentNullException.ThrowIfNull(referenced);
var aside = Path.Combine(VersionsDirectory, ReplacedFolder);
if (!Directory.Exists(aside)) return 0;
var files = new DirectoryInfo(aside).EnumerateFiles().OrderByDescending(f => f.LastWriteTimeUtc).ThenByDescending(f => f.Name, StringComparer.Ordinal).ToList();
var since = ReplacedSince(nowUtc);
var files = new DirectoryInfo(aside).EnumerateFiles()
.Select(f => (File: f, Aside: f.LastWriteTimeUtc > since ? f.LastWriteTimeUtc : since))
.OrderByDescending(f => f.Aside).ThenByDescending(f => f.File.LastWriteTimeUtc).ThenByDescending(f => f.File.Name, StringComparer.Ordinal).ToList();
var removed = 0;
for (var i = 0; i < files.Count; i++)
{
var file = files[i];
if (i < ReplacedKept && nowUtc - file.LastWriteTimeUtc <= ReplacedMaxAge) continue;
var (file, set) = files[i];
if (i < ReplacedKept && nowUtc - set <= ReplacedMaxAge) continue;
if (VersionIdOf(file.Name) is { } id && referenced.Contains(id)) continue;
try
{
@@ -515,6 +529,31 @@ public sealed class WorkspaceProject
}
}
/// <summary>
/// When this Chronos first knew <c>versions/.replaced</c> (<see cref="ReplacedSinceFile"/>): read, else written as
/// <paramref name="nowUtc"/> (also over a file that cannot be read). One that cannot be written counts as now: nothing
/// set aside by an earlier build goes by its age then.
/// </summary>
private DateTime ReplacedSince(DateTime nowUtc)
{
var path = Path.Combine(VersionsDirectory, ReplacedSinceFile);
try
{
if (File.Exists(path)
&& DateTime.TryParse(File.ReadAllText(path).Trim(), System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.RoundtripKind,
out var known)
&& known.Kind == DateTimeKind.Utc && known <= nowUtc)
return known;
Directory.CreateDirectory(VersionsDirectory);
AtomicFile.WriteAllText(path, nowUtc.ToString("O", System.Globalization.CultureInfo.InvariantCulture));
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
Log.Debug("workspace", $"{path} could not be kept: {ex.Message}");
}
return nowUtc;
}
private static void TryTouch(string path)
{
try