fix(workspace): join the phase 5c packages at their seams
The local render, the send home, the clean-up, the settings page and the folder move were built apart; together they left gaps: - A local render to an image sequence writes a folder, which the send took for a missing file. The archive home now files the folder whole (checked by its listing hash, as the render recorded it) and the clean-up removes a sent folder; a server, which takes one file per render, refuses it with Errors.Workspace.SendSequence. - Rename, delete and Remove local copy are refused while the folder is being moved, so no project folder changes under the move. - Settings > Workspace shows the folder, usage, Move... and Change... again when a move ends (WorkspaceHost.MoveEnded). - Empty... uses the Settings typed confirmation; the separate trash dialog, never shown, is removed. The move plan counts unsent renders with the clean-up's helper. - Tests: the follow-up send now runs in the render tests; an end-to-end archive-home test (originals, version on render, local render, send with project and version, clean-up) and an image-sequence send test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6daf5fa056
commit
09fcff4eb2
13 files changed
+210
-226
No files matched your search
@@ -109,7 +109,7 @@ internal sealed class WorkspaceSendJobHandler(ChronosDatabase db, ArchiveService
|
||||
if (held) await WhileHeldAsync(context).ConfigureAwait(false);
|
||||
var entry = entries[i];
|
||||
var file = project.ExportFile(entry.File);
|
||||
var refusal = await CheckAsync(project, entry, file, ct).ConfigureAwait(false);
|
||||
var refusal = await CheckAsync(project, entry, file, folders: !held, ct).ConfigureAwait(false);
|
||||
if (refusal is null)
|
||||
{
|
||||
if (entry.ProjectVersionId is { } versionId && !versions.Contains(versionId))
|
||||
@@ -141,13 +141,27 @@ internal sealed class WorkspaceSendJobHandler(ChronosDatabase db, ArchiveService
|
||||
if (refused > 0) throw new InvalidOperationException(Loc.L("Errors.Workspace.SendFailed", refused, entries.Count));
|
||||
}
|
||||
|
||||
/// <summary>Why the render cannot be sent as it is (gone from the exports, or another file than the one rendered); null when it can.</summary>
|
||||
private static async Task<string?> CheckAsync(WorkspaceProject project, WorkspaceRenderEntry entry, string file, CancellationToken ct)
|
||||
/// <summary>
|
||||
/// Why the render cannot be sent as it is (gone from the exports, another file than the one rendered, or an image
|
||||
/// sequence's folder for a home that takes one file per render); null when it can. A folder (an image sequence, only
|
||||
/// when <paramref name="folders"/>: this PC's archive files folders as its own renders do) is checked by its total size
|
||||
/// and the hash of its listing, as the render recorded it (<see cref="WorkspaceRenderJobHandler.HashAsync"/>).
|
||||
/// </summary>
|
||||
private static async Task<string?> CheckAsync(WorkspaceProject project, WorkspaceRenderEntry entry, string file, bool folders, CancellationToken ct)
|
||||
{
|
||||
var name = Path.GetFileName(entry.File);
|
||||
var exports = Path.TrimEndingDirectorySeparator(Path.GetFullPath(project.ExportsDirectory)) + Path.DirectorySeparatorChar;
|
||||
// A ledger names files inside the exports only; one pointing elsewhere is never read.
|
||||
if (!Path.GetFullPath(file).StartsWith(exports, StringComparison.OrdinalIgnoreCase) || !File.Exists(file)) return Loc.L("Errors.Workspace.SendMissing", name);
|
||||
if (!Path.GetFullPath(file).StartsWith(exports, StringComparison.OrdinalIgnoreCase)) return Loc.L("Errors.Workspace.SendMissing", name);
|
||||
if (Directory.Exists(file))
|
||||
{
|
||||
if (!folders) return Loc.L("Errors.Workspace.SendSequence", name);
|
||||
return WorkspaceCleaner.Measure(file).Bytes != entry.Size
|
||||
|| !string.Equals(await WorkspaceRenderJobHandler.HashAsync(file).ConfigureAwait(false), entry.Sha256, StringComparison.OrdinalIgnoreCase)
|
||||
? Loc.L("Errors.Workspace.SendHashMismatch", name)
|
||||
: null;
|
||||
}
|
||||
if (!File.Exists(file)) return Loc.L("Errors.Workspace.SendMissing", name);
|
||||
if (new FileInfo(file).Length != entry.Size
|
||||
|| !string.Equals(await ChronosClient.HashFileAsync(file, ct).ConfigureAwait(false), entry.Sha256, StringComparison.OrdinalIgnoreCase))
|
||||
return Loc.L("Errors.Workspace.SendHashMismatch", name);
|
||||
@@ -192,16 +206,27 @@ internal sealed class WorkspaceSendJobHandler(ChronosDatabase db, ArchiveService
|
||||
SyncTransfers.EnsureSpace(paths.Root, entry.Size);
|
||||
Directory.CreateDirectory(paths.StagingDirectory);
|
||||
var staged = Path.Combine(paths.StagingDirectory, "workspace-render-" + entry.RenderId.ToString("N") + ".part");
|
||||
var folder = Directory.Exists(file);
|
||||
try
|
||||
{
|
||||
await using (var source = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read, 1 << 20, FileOptions.Asynchronous | FileOptions.SequentialScan))
|
||||
await using (var target = new FileStream(staged, FileMode.Create, FileAccess.Write, FileShare.None, 1 << 20, FileOptions.Asynchronous))
|
||||
TryDelete(staged);
|
||||
if (folder)
|
||||
{
|
||||
await source.CopyToAsync(target, ct).ConfigureAwait(false);
|
||||
target.Flush(flushToDisk: true);
|
||||
// An image sequence: every file of its folder, the folder filed whole as the archive's own renders are.
|
||||
foreach (var source in Directory.EnumerateFiles(file, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
var target = Path.Combine(staged, Path.GetRelativePath(file, source));
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(target)!);
|
||||
await CopyAsync(source, target, ct).ConfigureAwait(false);
|
||||
}
|
||||
Directory.CreateDirectory(staged);
|
||||
}
|
||||
else await CopyAsync(file, staged, ct).ConfigureAwait(false);
|
||||
// Read back from the archive's volume: what is filed is the render as it was written.
|
||||
if (!string.Equals(await ChronosClient.HashFileAsync(staged, ct).ConfigureAwait(false), entry.Sha256, StringComparison.OrdinalIgnoreCase))
|
||||
var readBack = folder
|
||||
? await WorkspaceRenderJobHandler.HashAsync(staged).ConfigureAwait(false)
|
||||
: await ChronosClient.HashFileAsync(staged, ct).ConfigureAwait(false);
|
||||
if (!string.Equals(readBack, entry.Sha256, StringComparison.OrdinalIgnoreCase))
|
||||
throw new IOException(Loc.L("Errors.Workspace.CopyMismatch", staged));
|
||||
var name = SyncTransfers.SafeFileName(Path.GetFileName(entry.File)) ?? entry.RenderId.ToString("N");
|
||||
var filed = await SyncTransfers.FileRenderAsync(archives, db, sequence, paths, staged, name, new Render
|
||||
@@ -228,6 +253,15 @@ internal sealed class WorkspaceSendJobHandler(ChronosDatabase db, ArchiveService
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Copies <paramref name="source"/> to <paramref name="target"/>, flushed to the disk.</summary>
|
||||
private static async Task CopyAsync(string source, string target, CancellationToken ct)
|
||||
{
|
||||
await using var from = new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.Read, 1 << 20, FileOptions.Asynchronous | FileOptions.SequentialScan);
|
||||
await using var to = new FileStream(target, FileMode.Create, FileAccess.Write, FileShare.None, 1 << 20, FileOptions.Asynchronous);
|
||||
await from.CopyToAsync(to, ct).ConfigureAwait(false);
|
||||
to.Flush(flushToDisk: true);
|
||||
}
|
||||
|
||||
/// <summary>The project the entry names is one of the sequence's, and its version (when it names one) one of that project's.</summary>
|
||||
private async Task<bool> ProjectOfAsync(Guid sequenceId, WorkspaceRenderEntry entry, CancellationToken ct)
|
||||
{
|
||||
@@ -290,7 +324,8 @@ internal sealed class WorkspaceSendJobHandler(ChronosDatabase db, ArchiveService
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(path)) File.Delete(path);
|
||||
if (Directory.Exists(path)) Directory.Delete(path, recursive: true);
|
||||
else if (File.Exists(path)) File.Delete(path);
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user