feat: owner review 2 phase 5c: originals, local render, clean-up and the workspace settings (#18)
CI / Build and test (push) Successful in 9m26s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 8s
Release / Build, test and publish (push) Successful in 14m31s
CI / PostgreSQL 16 integration (push) Successful in 9m53s
CI / PostgreSQL 17 integration (push) Successful in 9m22s
CI / Docker image (push) Successful in 44s
Release / Server image (push) Successful in 1m36s

Originals in the workspace, local render and send home with provenance, the workspace clean-up, size limit and trash, moving the workspace folder, and the complete Settings › Workspace page (owner review 2, R8, phase 5c). One adversarial review round (35 findings, 32 fixed), a copy-cancel race fixed, 184 strings in all 38 languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #18.
This commit is contained in:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-11-04 20:03:52 +01:00
1 parent 81c303f484
commit db389a54f2
364 files changed
+17417 -595

No files matched your search

+60 -36
View File
@@ -500,44 +500,68 @@ internal sealed class SyncTransfers(SyncService sync)
foreach (var render in wanted)
{
var (part, name) = await FetchRenderAsync(remote, render, staging, ct).ConfigureAwait(false);
// Filed under the sequence's lease into its folder as the index has it then, as a server files a render: a
// Reorganize may have moved it since the sequence was read, and moves the row's path along when it moves it later.
// One another index moved is found by this index's next scan; until then nothing is filed (the download stays
// staged for the next attempt), so the folder it left is not created again, nor filed into when it holds another
// sequence now.
var filed = await sync.Archives.UnderLeaseAsync(local, async row =>
var filed = await FileRenderAsync(sync.Archives, db, local, paths, part, name, new Render
{
if (row is null) throw new InvalidOperationException(Loc.L("Errors.Sync.LocalMissing"));
var folder = paths.Sequence(row.Folder);
if (!SequenceFolders.Holds(folder, row.Id)) return false;
Directory.CreateDirectory(folder.Exports);
var target = Unique(folder.Exports, name);
File.Move(part, target);
// Recorded even if the job is being cancelled: a filed export is never left without its row.
await db.Renders.InsertAsync(new Render
{
Id = render.Id,
SequenceId = row.Id,
PresetName = render.PresetName,
OutputPath = paths.ToRelative(target),
Codec = render.Codec,
Width = render.Width,
Height = render.Height,
Fps = render.Fps,
DurationSeconds = render.DurationSeconds,
Bytes = new FileInfo(target).Length,
Created = render.Created,
ProducedBy = render.ProducedBy,
}, CancellationToken.None).ConfigureAwait(false);
return true;
Id = render.Id,
SequenceId = local.Id,
PresetName = render.PresetName,
OutputPath = string.Empty,
Codec = render.Codec,
Width = render.Width,
Height = render.Height,
Fps = render.Fps,
DurationSeconds = render.DurationSeconds,
Created = render.Created,
ProducedBy = render.ProducedBy,
}, ct).ConfigureAwait(false);
if (!filed) throw new InvalidOperationException(Loc.L("Errors.Archive.FolderMoved"));
if (filed is null) throw new InvalidOperationException(Loc.L("Errors.Archive.FolderMoved"));
await progress.StepAsync().ConfigureAwait(false);
}
TryDeleteDirectory(staging);
await sync.RecompareAsync(remote, remoteId, ct).ConfigureAwait(false);
}
/// <summary>
/// Files the render staged at <paramref name="part"/> (on the archive's volume) into the exports of
/// <paramref name="local"/> under its lease, into its folder as the index has it then, as a server files a render: a
/// Reorganize may have moved it since the sequence was read, and moves the row's path along when it moves it later. The
/// file takes <paramref name="name"/>, or "name (2)" and so on (an export is never replaced), and the index records
/// <paramref name="render"/> for it, with the sequence, the path and the size it has there (recorded even if the job is
/// being cancelled: a filed export is never left without its row). Used by the sync's downloads of a server's exports and
/// by a workspace's renders sent home (<see cref="Workspaces.WorkspaceJobs.Send"/>). Returns the archive-relative path
/// it was filed at; null when the folder does not hold the sequence now (another index moved it; this index's next scan
/// finds it): nothing is filed then, the staged file stays for the next attempt, and the folder it left is not created
/// again, nor filed into when it holds another sequence now.
/// </summary>
/// <exception cref="InvalidOperationException">The sequence left the index.</exception>
/// <exception cref="ArchiveOfflineException">The archive is offline or read-only.</exception>
/// <exception cref="LeaseUnavailableException">Another writer held the sequence for longer than the lease wait.</exception>
internal static Task<string?> FileRenderAsync(ArchiveService archives, ChronosDatabase db, Sequence local, ArchivePaths paths, string part, string name,
Render render, CancellationToken cancellationToken) =>
archives.UnderLeaseAsync(local, async row =>
{
if (row is null) throw new InvalidOperationException(Loc.L("Errors.Sync.LocalMissing"));
var folder = paths.Sequence(row.Folder);
if (!SequenceFolders.Holds(folder, row.Id)) return null;
Directory.CreateDirectory(folder.Exports);
var target = Unique(folder.Exports, name);
// An image sequence's folder (a workspace's local render) is filed whole, sized by its files, as the archive's own.
long bytes;
if (Directory.Exists(part))
{
Directory.Move(part, target);
bytes = new DirectoryInfo(target).EnumerateFiles("*", SearchOption.AllDirectories).Sum(f => f.Length);
}
else
{
File.Move(part, target);
bytes = new FileInfo(target).Length;
}
var relative = paths.ToRelative(target);
await db.Renders.InsertAsync(render with { SequenceId = row.Id, OutputPath = relative, Bytes = bytes }, CancellationToken.None).ConfigureAwait(false);
return (string?)relative;
}, cancellationToken);
/// <summary>A render's file in staging (resumed with Range; started over once if the partial copy no longer fits) and the name the server gives it.</summary>
private static async Task<(string Part, string Name)> FetchRenderAsync(ISyncRemote remote, RenderDto render, string staging, CancellationToken cancellationToken)
{
@@ -558,19 +582,19 @@ internal sealed class SyncTransfers(SyncService sync)
}
}
private static string? SafeFileName(string? name)
internal static string? SafeFileName(string? name)
{
var file = Path.GetFileName(name?.Trim());
return string.IsNullOrEmpty(file) || file.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0 || file is "." or ".." ? null : file;
}
/// <summary>"name.mp4", else "name (2).mp4", … — an existing export is never replaced.</summary>
private static string Unique(string folder, string fileName)
/// <summary>"name.mp4", else "name (2).mp4", … — an existing export (a file, or an image sequence's folder) is never replaced.</summary>
internal static string Unique(string folder, string fileName)
{
var candidate = Path.Combine(folder, fileName);
var stem = Path.GetFileNameWithoutExtension(fileName);
var extension = Path.GetExtension(fileName);
for (var n = 2; File.Exists(candidate); n++) candidate = Path.Combine(folder, string.Create(CultureInfo.InvariantCulture, $"{stem} ({n}){extension}"));
for (var n = 2; File.Exists(candidate) || Directory.Exists(candidate); n++) candidate = Path.Combine(folder, string.Create(CultureInfo.InvariantCulture, $"{stem} ({n}){extension}"));
return candidate;
}
@@ -693,7 +717,7 @@ internal sealed class SyncTransfers(SyncService sync)
/// manifest's SHA-256 (two attempts). A part as long as the file (a job stopped while hashing it) is only hashed again;
/// a part the server can no longer resume (416) starts over.
/// </summary>
private static async Task<(string Path, string Sha256)> FetchOriginalAsync(ISyncRemote remote, ManifestFrame frame, string staging,
internal static async Task<(string Path, string Sha256)> FetchOriginalAsync(ISyncRemote remote, ManifestFrame frame, string staging,
CancellationToken cancellationToken)
{
if (frame.Sha256.Length == 0) return await FetchUnhashedAsync(remote, frame, staging, cancellationToken).ConfigureAwait(false);
@@ -833,7 +857,7 @@ internal sealed class SyncTransfers(SyncService sync)
private static Task<Job?> EnqueueFollowUpAsync(JobContext context, ArchiveJobRequest request, CancellationToken cancellationToken) =>
context.EnqueueFollowUpAsync(request.Kind, request.Targets, request.Label, request.ParametersJson, request.Priority, cancellationToken);
private static void EnsureSpace(string root, long bytes)
internal static void EnsureSpace(string root, long bytes)
{
long? free;
try