fix(projects): sidecars stay the truth when they cannot be read, are missing or newer
A project record that could not be read once, or a missing .chronos/projects, marked projects deleted for good and made a second Main; an index meeting Main with no mirror state took its own stale settings column as an outside change and reverted the pushed head; a newer-format or unreadable head made every project call fail or rewrote the record's head over the real history. Now: - Deletion is never inferred from absence or a read failure: an unreadable record holds its project back (listed as indexed, nothing written for it, no second Main), a row marked deleted is revived when its live record says so, and projects the archive has no folder for are written back from the index. - Appends re-read the record under the lease and refuse when its head is not the index's; Main is only made when the sequence has none anywhere. - An index with no mirror state decides from project.json and the record's new mirrored member (older records: the head's ancestry), never from its own column. - A newer-format Main head is listed and pulled but never mirrored, merged or built on; pushes must parse strictly and fit the one 64 MB version limit (TooLarge otherwise). - Duplicate version numbers and name/Main clashes are contained per project, so a scan or rebuild never stops. - Delete moves the folder first, then writes the deleted record in the trash. - The home's read-back for workspace pruning and Remove local copy reads the version files (IProjectHome.HoldsAsync), not the index. - A read-only archive is read without writing: its projects open from the sidecars and a sequence with no Main gets one in the index only, written back once writable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
50e28fd63d
commit
d940fc7c61
6 files changed
+1247
-158
No files matched your search
@@ -491,10 +491,8 @@ public sealed class WorkspaceHost
|
||||
var removed = 0;
|
||||
foreach (var version in stored.Where(v => v.Id != basis?.VersionId && !kept.Contains(v.Id)))
|
||||
{
|
||||
if (await home.GetVersionAsync(projectId, version.Id, cancellationToken).ConfigureAwait(false) is not { } atHome
|
||||
|| !string.Equals(atHome.ContentHash, version.ContentHash, StringComparison.OrdinalIgnoreCase)
|
||||
|| !ProjectContent.Verifies(atHome.SettingsJson, atHome.ContentHash))
|
||||
continue;
|
||||
// Read back from where the home keeps it, not from an index of it.
|
||||
if (!await home.HoldsAsync(projectId, version, cancellationToken).ConfigureAwait(false)) continue;
|
||||
File.Delete(project.VersionPath(version));
|
||||
removed++;
|
||||
}
|
||||
@@ -528,16 +526,20 @@ public sealed class WorkspaceHost
|
||||
var home = HomeOf(workspace.Home) ?? throw new WorkspaceException(Loc.L("Errors.Workspace.Offline"));
|
||||
ProjectVersion head;
|
||||
ProjectVersion? basis;
|
||||
bool held;
|
||||
try
|
||||
{
|
||||
head = await home.HeadAsync(projectId, cancellationToken).ConfigureAwait(false);
|
||||
basis = workspace.Base is { } b ? await home.GetVersionAsync(projectId, b.VersionId, cancellationToken).ConfigureAwait(false) : head;
|
||||
// Read back from where the home keeps them, not from an index of them.
|
||||
held = basis is not null && await home.HoldsAsync(projectId, head, cancellationToken).ConfigureAwait(false)
|
||||
&& (basis.Id == head.Id || await home.HoldsAsync(projectId, basis, cancellationToken).ConfigureAwait(false));
|
||||
}
|
||||
catch (Exception ex) when (ex is HomeUnavailableException or ProjectException or DatabaseException)
|
||||
{
|
||||
throw new WorkspaceException(Loc.L("Errors.Workspace.Offline"), ex);
|
||||
}
|
||||
if (!ProjectContent.Verifies(head.SettingsJson, head.ContentHash) || basis is null || !ProjectContent.Verifies(basis.SettingsJson, basis.ContentHash)
|
||||
if (!held || !ProjectContent.Verifies(head.SettingsJson, head.ContentHash) || basis is null || !ProjectContent.Verifies(basis.SettingsJson, basis.ContentHash)
|
||||
|| (workspace.Base is { } known && !string.Equals(known.ContentHash, basis.ContentHash, StringComparison.OrdinalIgnoreCase)))
|
||||
throw new WorkspaceException(Loc.L("Errors.Workspace.HomeCheck"));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user