fix(archive): the admin form reads archive.json; a poll never undoes an admin's edit

GET /api/v1/archive/settings refreshes the served archive from
archive.json first, so the admin form (which saves every field) starts
from a desktop's change made since the last poll instead of writing the
old templates back. ServerArchive.RefreshAsync replaces the served
archive only when the refresh registered a change, and only through a
compare-and-swap against the archive it read, so a poll racing an
admin's PUT no longer puts the pre-edit row back for ten minutes.

RefreshSettingsAsync now ignores an archive.json a newer Titano wrote,
as documented, instead of registering what this version reads of it.

AppServicesTests now points the folder at an archive the index does not
list first, and checks that the archive no longer chosen gets no scan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 16:33:56 +00:00
1 parent bf2183764f
commit c68590920f
7 files changed
+98 -20

No files matched your search

+20 -7
View File
@@ -163,15 +163,15 @@ public sealed class ArchiveService : IJobHandlerProvider
{
var archive = await LoadArchiveAsync(archiveId, cancellationToken).ConfigureAwait(false);
if (TryReadManifest(archive) is not { } manifest) return null;
if (manifest.Name != archive.Name || manifest.LayoutTemplates.Folder != archive.FolderTemplate || manifest.LayoutTemplates.File != archive.FileTemplate
|| manifest.ProxyPolicy.LongEdge != archive.ProxyLongEdge)
var settings = ArchiveSettings.Of(manifest);
if (!settings.IsRegisteredIn(archive))
{
// Read without the settings lease, as at open: an edit made meanwhile writes its own row, and the next refresh
// settles a file that changes again.
await RegisterAsync(new ArchivePaths(archive.RootPath), manifest, cancellationToken).ConfigureAwait(false);
Log.Info("archive", $"Settings of {archive.RootPath} changed elsewhere: {manifest.LayoutTemplates.Folder} · {manifest.LayoutTemplates.File}, proxies {manifest.ProxyPolicy.LongEdge}");
}
return ArchiveSettings.Of(manifest);
return settings;
}
/// <summary>
@@ -339,7 +339,10 @@ public sealed class ArchiveService : IJobHandlerProvider
return archive;
}
/// <summary>The archive's <c>archive.json</c>; null (logged) while it cannot be read or when it belongs to another archive.</summary>
/// <summary>
/// The archive's <c>archive.json</c>; null (logged) while it cannot be read, when a newer Titano wrote it (this one
/// would drop what it does not know) or when it belongs to another archive.
/// </summary>
private static ArchiveManifest? TryReadManifest(Archive archive)
{
var paths = new ArchivePaths(archive.RootPath);
@@ -347,10 +350,12 @@ public sealed class ArchiveService : IJobHandlerProvider
{
if (!File.Exists(paths.ManifestPath)) return null;
var manifest = ManifestStore.ReadArchive(paths.ManifestPath);
if (manifest.Id == archive.Id) return manifest;
Log.Warning("archive", $"{paths.ManifestPath} belongs to archive {manifest.Id}, not {archive.Id}; the index's settings are used");
if (manifest.SchemaVersion > ArchiveManifest.CurrentSchemaVersion)
Log.Warning("archive", $"{paths.ManifestPath} has schema version {manifest.SchemaVersion}, newer than this Titano's; the index's settings are used");
else if (manifest.Id == archive.Id) return manifest;
else Log.Warning("archive", $"{paths.ManifestPath} belongs to archive {manifest.Id}, not {archive.Id}; the index's settings are used");
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or NewerFormatException)
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException)
{
Log.Warning("archive", $"The settings of {paths.Root} cannot be read; the index's are used", ex);
}
@@ -381,6 +386,14 @@ public sealed record ArchiveSettings(string Name, LayoutTemplates Templates, Pro
public static ArchiveSettings Of(ArchiveManifest manifest) => new(manifest.Name, manifest.LayoutTemplates, manifest.ProxyPolicy, manifest.ThumbnailPolicy);
/// <summary>Whether the index row <paramref name="archive"/> holds these settings (all it keeps: not the thumbnail policy).</summary>
public bool IsRegisteredIn(Archive archive)
{
ArgumentNullException.ThrowIfNull(archive);
return Name == archive.Name && Templates.Folder == archive.FolderTemplate && Templates.File == archive.FileTemplate
&& Proxies.LongEdge == archive.ProxyLongEdge;
}
/// <summary>The first invalid field by its API name (<c>name</c>, <c>folderTemplate</c>, <c>fileTemplate</c>,
/// <c>proxyLongEdge</c>, <c>thumbnailLongEdge</c>); null when every field is valid.</summary>
public string? Problem()