fix(archive): polling follows the archive folder; the index follows an archive.json changed elsewhere

- The desktop's rescans run for the whole session and each one targets the archive at Settings › Archive's folder
  (as the Import and Archive screens do), so an archive created on the first run, chosen in Settings, relinked or
  imported with settings is rescanned from the next tick on, and Rescan every always reaches a live timer. The
  folder of the start is reopened (relink, interrupted renames) as soon as its archive.json is there, so an
  unplugged drive or a folder without an archive no longer stops polling for the session.
- ArchiveService.RefreshSettingsAsync reads archive.json and registers the archive again when its name, templates
  or proxy size changed elsewhere (a server's admin panel, another PC); null when the file cannot be read, is newer
  or belongs to another archive. Desktop rescans and the server's polling call it first, so imports, uploads and
  the admin panel follow the shared settings without a restart.

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:02:15 +00:00
1 parent 32a0e9bbc1
commit b344d2a527
6 files changed
+224 -31

No files matched your search

+41 -9
View File
@@ -147,17 +147,31 @@ public sealed class ArchiveService : IJobHandlerProvider
public async Task<ArchiveSettings> GetSettingsAsync(Guid archiveId, CancellationToken cancellationToken = default)
{
var archive = await LoadArchiveAsync(archiveId, cancellationToken).ConfigureAwait(false);
var paths = new ArchivePaths(archive.RootPath);
try
return TryReadManifest(archive) is { } manifest
? ArchiveSettings.Of(manifest)
: new ArchiveSettings(archive.Name, new LayoutTemplates { Folder = archive.FolderTemplate, File = archive.FileTemplate },
new ProxyPolicy { LongEdge = archive.ProxyLongEdge }, new ThumbnailPolicy());
}
/// <summary>
/// The settings in the archive's <c>archive.json</c>, with its index row brought up to them when another process
/// sharing the archive changed the file (a server's admin panel, another PC's Settings): imports and uploads take their
/// templates and proxy size from that row. Null while the file cannot be read (offline, damaged, newer, of another
/// archive): the row stays as it is, and only <see cref="GetSettingsAsync"/>'s stand-ins are known.
/// </summary>
public async Task<ArchiveSettings?> RefreshSettingsAsync(Guid archiveId, CancellationToken cancellationToken = default)
{
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)
{
if (File.Exists(paths.ManifestPath)) return ArchiveSettings.Of(ManifestStore.ReadArchive(paths.ManifestPath));
// 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}");
}
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);
}
return new ArchiveSettings(archive.Name, new LayoutTemplates { Folder = archive.FolderTemplate, File = archive.FileTemplate },
new ProxyPolicy { LongEdge = archive.ProxyLongEdge }, new ThumbnailPolicy());
return ArchiveSettings.Of(manifest);
}
/// <summary>
@@ -325,6 +339,24 @@ 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>
private static ArchiveManifest? TryReadManifest(Archive archive)
{
var paths = new ArchivePaths(archive.RootPath);
try
{
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");
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or NewerFormatException)
{
Log.Warning("archive", $"The settings of {paths.Root} cannot be read; the index's are used", ex);
}
return null;
}
private async Task<Archive> LoadArchiveAsync(Guid archiveId, CancellationToken cancellationToken) =>
await _db.Archives.GetAsync(archiveId, cancellationToken).ConfigureAwait(false) ?? throw new ArgumentException($"Unknown archive {archiveId}.", nameof(archiveId));