Files
Chronos/src/Chronos.App/Jobs/WorkspaceCleanStep.cs
T
Alby96andClaude Opus 5.5 db389a54f2
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
feat: owner review 2 phase 5c: originals, local render, clean-up and the workspace settings (#18)
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>
2026-11-04 20:03:52 +01:00

64 lines
3.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Chronos.App.Infrastructure;
using Chronos.App.Workspace;
using Chronos.Core.Localization;
using Chronos.Data.Archiving.Jobs;
using Chronos.Data.Housekeeping;
using Chronos.Data.Workspaces;
namespace Chronos.App.Jobs;
/// <summary>
/// The desktop's clean-up step <c>workspace-clean</c> (phase 5c): removes the media of workspace projects in step with their
/// home, those not opened for Settings › Workspace › Clean after, then the least recently used while the projects take more
/// than Size limit (<see cref="WorkspaceHost.CleanAsync"/>). Each project kept is logged with why. It needs no archive: the
/// <c>workspace-cleanup</c> schedule runs it whether one is open or not. The trash is never emptied here.
/// </summary>
public sealed class WorkspaceCleanStep(Func<WorkspaceHost?> workspace) : ICleanupStep
{
public const string StepName = "workspace-clean";
public string Name => StepName;
public async Task<string> RunAsync(CleanupContext context, CleanupParameters parameters)
{
ArgumentNullException.ThrowIfNull(context);
if (workspace() is not { } host || await host.CleanAsync(cleanAfter: true, cancellationToken: context.Cancellation).ConfigureAwait(false) is not { } report)
return Loc.L("Jobs.Log.WorkspaceUnavailable");
foreach (var kept in report.Kept)
context.Job.Log(Loc.L("Jobs.Log.WorkspaceKept", Named(kept.SequenceTitle, kept.Name, kept.IsMain), Reason(kept.Reason)));
if (report.Cleaned.Count == 0 && report.Kept.Count == 0) return Loc.L("Jobs.Log.WorkspaceNothing", Formatting.Bytes(report.UsedBefore));
foreach (var cleaned in report.Cleaned.Where(c => c.Trashed > 0))
context.Job.Log(Loc.L("Archive.Log.WorkspaceOriginalsTrashed", Named(cleaned.SequenceTitle, cleaned.Name, cleaned.IsMain), Formatting.Count(cleaned.Trashed)));
return Loc.L("Jobs.Log.WorkspaceCleaned", Formatting.Count(report.Cleaned.Count), Formatting.Bytes(report.Freed), Formatting.Count(report.Kept.Count));
}
/// <summary>"open in Edit", "renders not sent", …: why a project was kept, for the job log.</summary>
public static string Reason(WorkspaceKeep reason) => Loc.L("Jobs.Log.WorkspaceSkip." + reason);
/// <summary>"Harbour sunset · Main": a project as the job log names it (its sequence, then its name).</summary>
public static string Named(string sequenceTitle, string name, bool isMain)
{
var project = WorkspaceText.ProjectName(name, isMain);
return sequenceTitle is { Length: > 0 } title ? title + Loc.Separator + project : project;
}
}
/// <summary>
/// The desktop's clean-up step <c>workspace-trash</c> (phase 5c): reports what the workspace's trash holds (entries and
/// size); it never deletes, emptying it stays the user's Settings › Workspace › Trash › Empty….
/// </summary>
public sealed class WorkspaceTrashStep(Func<WorkspaceHost?> workspace) : ICleanupStep
{
public const string StepName = "workspace-trash";
public string Name => StepName;
public async Task<string> RunAsync(CleanupContext context, CleanupParameters parameters)
{
ArgumentNullException.ThrowIfNull(context);
if (workspace() is not { IsEnabled: true } host) return Loc.L("Jobs.Log.WorkspaceUnavailable");
var plan = await host.PlanTrashAsync(context.Cancellation).ConfigureAwait(false);
return Loc.L("Jobs.Log.WorkspaceTrash", Formatting.Count(plan.Items.Count), Formatting.Bytes(plan.Bytes));
}
}