feat(archive): lay out the archive's whole folder tree wherever its root is

The owner asked (2026-11-06) that whatever path is given as the archive
root, on the server in Docker or on Windows, Chronos creates inside it
every folder the archive keeps. Until now only .chronos was made up
front; locks, journal, staging, trash and its photos and videos areas
appeared on first use, and an archive copied or made by an older build
could lack them.

ArchiveStructure.Ensure (Core) creates the missing folders of BRIEF §7
idempotently, never touching existing folders or files, and reports why
it could not (drive or share unavailable, permission denied, read-only,
a file in the way) as one localized sentence. ArchiveService runs it
when it creates an archive (refused with the reason when the tree cannot
be made) and at every open. The server checks it at start-up and on
each dashboard read: it logs a warning, the dashboard shows an "Archive
incomplete" chip with the reason, and /health reports archive
"incomplete". The desktop runs it when an archive is created, adopted or
opened at start, and a folder typed in Settings that is not an archive
yet becomes one in place, as Welcome's Create does; a writable archive
whose tree cannot be completed is refused with the reason.

Refs #31

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-06 17:05:57 +01:00
1 parent fe50b87726
commit a5facf0b5b
24 files changed
+605 -21

No files matched your search

@@ -6,6 +6,21 @@ import { activityText } from "../audit.js";
const SCAN_BUTTON = `<button class="btn small" data-scan data-i18n="Admin.Archive.Scan" data-i18n-title="Admin.Archive.Scan.Tip"></button>`;
// Why a folder of the archive's layout could not be created (DashboardDto.ArchiveProblem), each with its tooltip.
const ARCHIVE_PROBLEM_TIPS = {
unavailable: "Admin.Dashboard.ArchiveIncomplete.Unavailable.Tip",
denied: "Admin.Dashboard.ArchiveIncomplete.Denied.Tip",
readOnly: "Admin.Dashboard.ArchiveIncomplete.ReadOnly.Tip",
failed: "Admin.Dashboard.ArchiveIncomplete.Failed.Tip",
};
/** The warning chip of an incomplete archive layout; empty when every folder is there. */
function archiveProblemChip(problem) {
if (!problem) return "";
const tip = t(ARCHIVE_PROBLEM_TIPS[problem.code] ?? ARCHIVE_PROBLEM_TIPS.failed, problem.folder);
return `<span class="chip warn" title="${attr(tip)}" data-i18n="Admin.Dashboard.ArchiveIncomplete"></span>`;
}
export async function render(root, { api, setMeta, actions, onEvent }) {
let timer = null;
const refresh = () => {
@@ -28,7 +43,7 @@ export async function render(root, { api, setMeta, actions, onEvent }) {
const tls = `Admin.Settings.Tls.${d.tlsMode.charAt(0).toUpperCase()}${d.tlsMode.slice(1)}`;
setMeta(t("Admin.Dashboard.Meta", formatDuration(d.uptimeSeconds), d.database, t(tls),
t(d.discovery ? "Admin.Dashboard.DiscoveryOn" : "Admin.Dashboard.DiscoveryOff")));
actions.innerHTML = d.proxyWarning ? PROXY_WARNING : "";
actions.innerHTML = (d.proxyWarning ? PROXY_WARNING : "") + archiveProblemChip(d.archiveProblem);
applyStrings(actions);
// The space volume's figures (the space path when the server has one), the write volume apart when it differs.
const a = d.archive;
+11 -1
View File
@@ -69,10 +69,20 @@ public static class AdminEndpoints
[.. uploads.Select(u => new UploadDayDto(u.Day, u.Count, u.Bytes))],
[.. activity.Items.Select(Dto.Audit)],
[.. running.Items.Concat(queued.Items.OrderByDescending(j => j.Priority).ThenBy(j => j.Created)).Take(10).Select(Dto.Job)],
AdminPanel.BypassesProxy(context, options)),
AdminPanel.BypassesProxy(context, options),
ArchiveProblem(archive.CheckStructure())),
ProtocolJson.Default.DashboardDto);
}
/// <summary>The dashboard's warning of an incomplete archive layout; null when every folder is there.</summary>
private static ArchiveProblemDto? ArchiveProblem(Core.Archiving.ArchiveStructureReport report) => report.IsComplete ? null : new(report.Problem switch
{
Core.Archiving.ArchiveStructureProblem.Unavailable => "unavailable",
Core.Archiving.ArchiveStructureProblem.Denied => "denied",
Core.Archiving.ArchiveStructureProblem.ReadOnly => "readOnly",
_ => "failed",
}, report.Folder ?? report.Root);
private static async Task<IResult> SaveSettingsAsync(HttpContext context, Caller caller, ServerSettingsDto request, ServerSettingsStore store, ServerOptions options,
AuditLog audit, JobEngineHost jobs, SchedulerHost schedules)
{
+7 -3
View File
@@ -72,12 +72,16 @@ public static class SystemEndpoints
}).AllowAnonymousCaller();
}
/// <summary>Liveness for the container health check: 503 while the database cannot be reached.</summary>
private static async Task<IResult> HealthAsync(HttpContext context, ServerOptions options, ChronosDatabase db)
/// <summary>
/// Liveness for the container health check: 503 while the database cannot be reached. An incomplete archive layout is
/// reported in the checks without failing the check: the server still serves what it can.
/// </summary>
private static async Task<IResult> HealthAsync(HttpContext context, ServerOptions options, ChronosDatabase db, Storage.ServerArchive archive)
{
var checks = new Dictionary<string, string>(StringComparer.Ordinal)
{
["archive"] = Directory.Exists(options.ArchivePath) ? "ok" : "missing",
// "incomplete": a folder of the archive's layout could not be created (the dashboard says which and why).
["archive"] = !Directory.Exists(options.ArchivePath) ? "missing" : archive.Structure is { IsComplete: false } ? "incomplete" : "ok",
["data"] = Directory.Exists(options.DataPath) ? "ok" : "missing",
};
using var timeout = CancellationTokenSource.CreateLinkedTokenSource(context.RequestAborted);
+5
View File
@@ -87,6 +87,11 @@ public static class ServerHost
+ "they could put a link in place of a folder and redirect the files the server moves. Let only those accounts change it (others may read it).",
options.ArchivePath);
}
if (archive.Structure is { IsComplete: false } structure)
{
app.Logger.LogWarning("The archive's folders are incomplete: {Problem} Uploads, deletions and conversions that need the missing folder fail "
+ "until it can be created; the dashboard shows the problem until then. {Detail}", structure.Message, structure.Detail ?? string.Empty);
}
// A space path that cannot be measured is warned about at start, not first when someone opens the dashboard.
if (!string.IsNullOrWhiteSpace(options.SpacePath)) app.Services.GetRequiredService<VolumeSpace>().Report(archive.Root);
if (options.FormerWorkersVariable)
+25 -2
View File
@@ -1,3 +1,4 @@
using Chronos.Core.Archiving;
using Chronos.Core.Model;
using Chronos.Data;
using Chronos.Data.Archiving;
@@ -46,14 +47,36 @@ public sealed class ServerArchive(Archive archive)
public string Root => _current.RootPath;
/// <summary>
/// What the last <see cref="CheckStructure"/> found of the archive's folders; null before the first. The dashboard and
/// the health check show an incomplete layout.
/// </summary>
public ArchiveStructureReport? Structure => _structure;
private volatile ArchiveStructureReport? _structure;
/// <summary>
/// Creates the folders of the archive's layout that are missing (BRIEF §7) and remembers what it found
/// (<see cref="Structure"/>): at start, and each time the dashboard is read, so a share that comes back heals.
/// </summary>
public ArchiveStructureReport CheckStructure()
{
var report = ArchiveStructure.Ensure(new ArchivePaths(Root));
_structure = report;
return report;
}
/// <summary>
/// Opens the archive at the configured root through the archive engine: an existing Chronos archive is registered
/// (and relinked if it moved), any other folder becomes a new archive with the default templates.
/// (and relinked if it moved), any other folder becomes a new archive with the default templates. Either way the
/// folders of the archive's layout are made (<see cref="CheckStructure"/>).
/// </summary>
public static async Task<ServerArchive> OpenAsync(ChronosDatabase db, ServerOptions options, CancellationToken cancellationToken)
{
var root = Path.TrimEndingDirectorySeparator(Path.GetFullPath(options.ArchivePath));
var archive = await new ArchiveService(db).AdoptAsync(root, options.ServerName, cancellationToken).ConfigureAwait(false);
return new ServerArchive(archive);
var served = new ServerArchive(archive);
served.CheckStructure();
return served;
}
}