fix(archive): an unreadable root sidecar names no sequence waiting for its first frame
The index's own predicate for sequences created without photos reads the archive root's sidecar once per call and treats a damaged or unreadable one as naming nobody. A torn root sidecar is therefore rebuilt under the root-adopted sequence instead of a later POST /sequences row, and a sidecar the server may not read fails the root folder alone instead of every scan, rebuild, orphan check and scan follow-up. Maintenance leaves these rows out of temporary-file purging and pack compaction, so the root's thumbs.pack is compacted under the leases of the root's own sequence. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
3 files changed
+149
-6
No files matched your search
@@ -219,21 +219,43 @@ public sealed class ArchiveIndexer
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The sequences among <paramref name="locations"/> created without photos that still wait for their first frame
|
||||
/// (<see cref="ArchiveIngest.AwaitsFolder"/>). Their empty folder is not the archive root: scans do not adopt the root
|
||||
/// under their id, a rebuild keeps them although they have no sidecar yet, and orphan checks do not count them missing.
|
||||
/// The sequences among <paramref name="locations"/> created without photos that still wait for their first frame: no
|
||||
/// folder, no frames, and not the sequence the archive root's sidecar names. Their empty folder is not the archive
|
||||
/// root: scans do not adopt or rebuild the root under their id, a rebuild keeps them although they have no sidecar yet,
|
||||
/// orphan checks do not count them missing, and maintenance leaves the root's files to the root's own sequence. Unlike
|
||||
/// <see cref="ArchiveIngest.AwaitsFolder"/>, whose commit reports it, a root sidecar that cannot be read names nobody
|
||||
/// here: a scan rebuilds a damaged one under the id of the sequence that holds the root's frames, and one it may not
|
||||
/// read fails the root folder alone rather than the whole scan or rebuild.
|
||||
/// </summary>
|
||||
internal async Task<HashSet<Guid>> AwaitingFolderAsync(ArchivePaths paths, IEnumerable<SequenceLocation> locations, CancellationToken cancellationToken)
|
||||
{
|
||||
var awaiting = new HashSet<Guid>();
|
||||
(Guid? Id, bool Read) root = (null, false);
|
||||
foreach (var location in locations.Where(l => l.Folder.Length == 0))
|
||||
{
|
||||
if (await _db.Sequences.GetAsync(location.Id, cancellationToken).ConfigureAwait(false) is { } sequence && ArchiveIngest.AwaitsFolder(sequence, paths))
|
||||
awaiting.Add(sequence.Id);
|
||||
if (await _db.Sequences.GetAsync(location.Id, cancellationToken).ConfigureAwait(false) is not { Folder.Length: 0, FrameCount: 0 } sequence) continue;
|
||||
// Read once, and only when a row may be waiting: a root sidecar can list a hundred thousand frames.
|
||||
if (!root.Read) root = (RootSidecarId(paths), true);
|
||||
if (root.Id != sequence.Id) awaiting.Add(sequence.Id);
|
||||
}
|
||||
return awaiting;
|
||||
}
|
||||
|
||||
/// <summary>The id the archive root's sidecar names; null when there is none or it cannot be read.</summary>
|
||||
private static Guid? RootSidecarId(ArchivePaths paths)
|
||||
{
|
||||
var sidecar = paths.Sequence(string.Empty).ManifestPath;
|
||||
try
|
||||
{
|
||||
return File.Exists(sidecar) ? ManifestStore.ReadSequence(sidecar).Id : null;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or InvalidDataException or UnauthorizedAccessException)
|
||||
{
|
||||
// Indexing the root reports it (a damaged sidecar is rebuilt, an unreadable one fails that folder alone).
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The index holds a project for this sequence and other frames than the sidecar: its positions may move.</summary>
|
||||
private async Task<bool> MayMovePositionsAsync(SequenceManifest manifest, CancellationToken cancellationToken) =>
|
||||
await _db.Sequences.GetAsync(manifest.Id, cancellationToken).ConfigureAwait(false) is { SettingsJson: not null } indexed
|
||||
|
||||
@@ -123,7 +123,11 @@ public sealed class ArchiveMaintenance
|
||||
{
|
||||
var paths = new ArchivePaths(archive.RootPath);
|
||||
if (!dryRun) ArchiveVolume.EnsureWritable(paths);
|
||||
var locations = await _db.Sequences.ListLocationsAsync(archive.Id, cancellationToken).ConfigureAwait(false);
|
||||
var all = await _db.Sequences.ListLocationsAsync(archive.Id, cancellationToken).ConfigureAwait(false);
|
||||
// A sequence waiting for its first frame has no folder yet: the archive root's pack is compacted under the leases of
|
||||
// the root's own sequence, which its thumbnail passes hold, never under another id's.
|
||||
var awaiting = await _indexer.AwaitingFolderAsync(paths, all, cancellationToken).ConfigureAwait(false);
|
||||
var locations = all.Where(l => !awaiting.Contains(l.Id)).ToList();
|
||||
IReadOnlyList<string> leases = [], temps = [], packs = [];
|
||||
int groups = 0, flagChanges = 0;
|
||||
long? reclaimable = null;
|
||||
|
||||
Reference in new issue
Block a user