feat(app): workspace projects whose home is a server, pushed and pulled like this PC's archive
Owner review 2, R8, phase 5b (client part), ported onto the final phase 5a.
A Chronos Server with the "projects" capability is now the home of
workspace projects. A server sequence is edited in the workspace like a
local one, not inside the library, and its versions sync with the server
"like git".
- Data: ServerProjectHome is an IProjectHome over ChronosClient.
- These are HomeUnavailableException, so the workspace shows Offline: a
server out of reach, an expired sign-in, a 503 (lease, offline archive,
projects_unreadable), a 409 folder_in_use, and a server without projects.
- 404 sequence/project/version and refused names are ProjectException;
other refusals keep their meaning.
- A deleted project's head is 404 project, so final 5a's HeadAsync NotFound
rule reads it as Gone. The original 5b's IsLiveAsync and
WorkspaceStatus.Gone are dropped. IProjectHome gains rename and delete.
- Data: WorkspaceJobs.CopyFromServer downloads into the workspace, through
the desktop's session, the proxies of one frames version (or the
thumbnails standing in for them), with the aliases of the server's
conversions. It is rebuilt on final 5a's copy handler:
- the copy:frame:fv:folder checkpoint, EnsureSpace (from the server's proxy
sizes), WritingMedia, and the cancelled-copy clean-up;
- the editor's current file is never overwritten;
- each file is hashed as it arrives and checked on disk, four at a time.
It never writes this PC's archive. Originals are still refused until 5c.
- Data: SyncAgent passes on the server's projectChanged events, and after a
lost event stream it reports that changes may have been missed.
- App: SyncHost gives the server home over one session client. The Server
screen offers Open in workspace, disabled with its reason on older
servers, whose sequences keep opening with proxies.
- App: Edit opens or checks out server projects with final 5a's refusals:
unreadable copies, a disabled damaged or newer Main, a refused folder. The
"sequence left the index" refusal now applies only to projects of this
PC's archive.
- App: the picker and the chip follow projectChanged (Server newer, Not on
server). Every state, conflict, delete, remove and failure text uses its
".Server" form when one exists (WorkspaceText.ForHome). That includes 5a's
newer-format conflict, the save conflict, the taken-values toast, Gone and
version-too-large.
- App: a render of a server project first offers to send what is not on the
server, then renders the version the server holds. Offline, Gone, Damaged
and missing media hold the render. Analyses and renders run as server jobs
(ServerJobs, shared with RemoteSequenceSource).
- Pruning keeps final 5a's rule: a version is pruned only after HoldsAsync
reads it back.
- Strings in en and it; ARCHITECTURE, DECISIONS and CHANGELOG.
Tests:
- ServerProjectHome error mapping, using a fake handler.
- Against the in-process server:
- two workspaces on one project: fast-forward, replay and merge, keep mine,
take server, save both, restore;
- the copy job verifying, resuming and following new frames;
- a project deleted on the server (Gone from its head; a push sends
nothing);
- an offline server.
- SyncAgent project events.
- App tests for the host, the project menu and renders of a server home.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e2ecc409a3
commit
26bab759fe
48 files changed
+3243
-409
No files matched your search
@@ -774,32 +774,54 @@ internal sealed class SyncTransfers(SyncService sync)
|
||||
var cached = new FileInfo(path) is { Exists: true, Length: > 0 };
|
||||
if (cached && (cachedKind == ProxyCache.Proxy || !offered.Contains(ProxyCache.Proxy))) return (name, cachedKind ?? ProxyCache.Thumb);
|
||||
var part = path + ".part";
|
||||
foreach (var kind in offered)
|
||||
// The cached file is as good as the server's thumbnail.
|
||||
var kind = await DownloadFirstAsync(remote, frameId, offered.TakeWhile(k => !(cached && k == ProxyCache.Thumb)), part, null, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
if (kind is not null)
|
||||
{
|
||||
File.Move(part, path, overwrite: true);
|
||||
return (name, kind);
|
||||
}
|
||||
return cached ? (name, ProxyCache.Thumb) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Downloads the first of <paramref name="kinds"/> a frame has on the server (a 404 tries the next) into a fresh
|
||||
/// <paramref name="part"/> file, written through <paramref name="through"/> when given (a hash of what arrives, which
|
||||
/// leaves the file open) and flushed to the disk when <paramref name="durable"/>; the kind it got, or null when the server
|
||||
/// has none of them, no part file left then. The proxy cache and the workspace copy of a server project (owner review 2,
|
||||
/// R8) download alike.
|
||||
/// </summary>
|
||||
internal static async Task<string?> DownloadFirstAsync(ISyncRemote remote, Guid frameId, IEnumerable<string> kinds, string part, Func<Stream, Stream>? through,
|
||||
CancellationToken cancellationToken, bool durable = false)
|
||||
{
|
||||
foreach (var kind in kinds)
|
||||
{
|
||||
// The cached file is as good as the server's thumbnail.
|
||||
if (cached && kind == ProxyCache.Thumb) break;
|
||||
try
|
||||
{
|
||||
await using (var file = new FileStream(part, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
|
||||
await remote.DownloadFrameAsync(frameId, kind, file, cancellationToken).ConfigureAwait(false);
|
||||
File.Move(part, path, overwrite: true);
|
||||
return (name, kind);
|
||||
{
|
||||
await remote.DownloadFrameAsync(frameId, kind, through?.Invoke(file) ?? file, cancellationToken).ConfigureAwait(false);
|
||||
if (durable) file.Flush(flushToDisk: true);
|
||||
}
|
||||
return kind;
|
||||
}
|
||||
catch (ChronosApiException ex) when (ex.Status == HttpStatusCode.NotFound)
|
||||
{
|
||||
File.Delete(part);
|
||||
}
|
||||
}
|
||||
return cached ? (name, ProxyCache.Thumb) : null;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A frame missing or damaged on the server: its manifest never asks for its proxy and a pass makes none of a missing
|
||||
/// one, so the thumbnail (or the lack of a file) that stands in for it does not keep the cache stale.
|
||||
/// </summary>
|
||||
private static bool NeverProxied(FrameDto frame) => ((FrameFlags)frame.Flags & (FrameFlags.Missing | FrameFlags.Corrupt)) != 0;
|
||||
internal static bool NeverProxied(FrameDto frame) => ((FrameFlags)frame.Flags & (FrameFlags.Missing | FrameFlags.Corrupt)) != 0;
|
||||
|
||||
private static string[] Kinds(ManifestFrame frame) => (frame.HasProxy, frame.HasThumb) switch
|
||||
/// <summary>The kinds of a frame's assets the server offers, the proxy before the thumbnail that stands in while it has none.</summary>
|
||||
internal static string[] Kinds(ManifestFrame frame) => (frame.HasProxy, frame.HasThumb) switch
|
||||
{
|
||||
(true, true) => [ProxyCache.Proxy, ProxyCache.Thumb],
|
||||
(true, false) => [ProxyCache.Proxy],
|
||||
@@ -867,3 +889,68 @@ internal sealed class SyncTransfers(SyncService sync)
|
||||
public ValueTask ReportAsync() => context.ReportAsync(done, total);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A write-only stream that hashes (SHA-256) what passes through it into <paramref name="inner"/>, which it leaves open: the
|
||||
/// hash of a download as it arrived, to check the file it was written to against (owner review 2, R8). It cannot seek,
|
||||
/// so a download through it always starts from the beginning.
|
||||
/// </summary>
|
||||
internal sealed class HashingStream(Stream inner) : Stream
|
||||
{
|
||||
private readonly System.Security.Cryptography.IncrementalHash _hash = System.Security.Cryptography.IncrementalHash.CreateHash(
|
||||
System.Security.Cryptography.HashAlgorithmName.SHA256);
|
||||
|
||||
private long _written;
|
||||
|
||||
/// <summary>The bytes written through.</summary>
|
||||
public long Written => _written;
|
||||
|
||||
/// <summary>The lower-case hex SHA-256 of what was written through (once; it resets the hash).</summary>
|
||||
public string Sha256() => Convert.ToHexStringLower(_hash.GetHashAndReset());
|
||||
|
||||
public override bool CanRead => false;
|
||||
public override bool CanSeek => false;
|
||||
public override bool CanWrite => true;
|
||||
public override long Length => throw new NotSupportedException();
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get => throw new NotSupportedException();
|
||||
set => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void Flush() => inner.Flush();
|
||||
|
||||
public override Task FlushAsync(CancellationToken cancellationToken) => inner.FlushAsync(cancellationToken);
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count) => throw new NotSupportedException();
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException();
|
||||
|
||||
public override void SetLength(long value) => throw new NotSupportedException();
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count) => Write(buffer.AsSpan(offset, count));
|
||||
|
||||
public override void Write(ReadOnlySpan<byte> buffer)
|
||||
{
|
||||
_hash.AppendData(buffer);
|
||||
_written += buffer.Length;
|
||||
inner.Write(buffer);
|
||||
}
|
||||
|
||||
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) =>
|
||||
WriteAsync(buffer.AsMemory(offset, count), cancellationToken).AsTask();
|
||||
|
||||
public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
|
||||
{
|
||||
_hash.AppendData(buffer.Span);
|
||||
_written += buffer.Length;
|
||||
return inner.WriteAsync(buffer, cancellationToken);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing) _hash.Dispose();
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user