fix(data): trash moves finish whatever is cancelled, archive-wide jobs hold their sequences

Once a folder has moved into the trash (or back), its index step runs to the
end with no cancellation and a failed step moves the folder back, so trash and
index never disagree. Running or paused archive-wide jobs (scan, rebuild,
import, maintenance, a verify of everything) block a delete of every sequence
of their archive; a verify of named sequences blocks those. A row whose folder
is gone is refused (FolderMissing) instead of losing its settings. Delete
revalidates the plan cheaply (index row, jobs, sidecar id from its head)
instead of measuring every folder again; the dry run reports progress. A
restored folder without a sidecar gets the record's title, tags, rating and
notes and drops a hero frame it no longer has. EditSequenceInfoAsync changes
one field from the current sidecar values.

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-05 22:06:31 +00:00
1 parent 69d33b6dd3
commit 2b2d341497
4 files changed
+475 -135

No files matched your search

+32 -12
View File
@@ -115,20 +115,37 @@ public sealed class ArchiveService : IJobHandlerProvider
public static ArchiveAvailability GetAvailability(Archive archive) => ArchiveVolume.Probe(new ArchivePaths(archive.RootPath));
/// <summary>Changes title, tags, rating and notes in the sidecar and the index together (settings version + 1).</summary>
public async Task<Sequence> SetSequenceInfoAsync(Guid sequenceId, string? title, IReadOnlyList<string> tags, int rating, string? notes,
CancellationToken cancellationToken = default)
public Task<Sequence> SetSequenceInfoAsync(Guid sequenceId, string? title, IReadOnlyList<string> tags, int rating, string? notes,
CancellationToken cancellationToken = default) =>
EditSequenceInfoAsync(sequenceId, _ => new SequenceInfo(title, tags, rating, notes), cancellationToken);
/// <summary>
/// Changes some of title, tags, rating and notes from their current values — read under the sequence's lease from
/// the sidecar, or from the index when it is ahead (an edit made there only) — so fields <paramref name="edit"/>
/// leaves alone keep any change made since the caller read the sequence. Sidecar and index change together
/// (settings version + 1).
/// </summary>
public async Task<Sequence> EditSequenceInfoAsync(Guid sequenceId, Func<SequenceInfo, SequenceInfo> edit, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(edit);
var (archive, sequence) = await LoadSequenceAsync(sequenceId, cancellationToken).ConfigureAwait(false);
var paths = new ArchivePaths(archive.RootPath);
ArchiveVolume.EnsureWritable(paths);
var manifest = await _writer.UpdateAsync(paths, sequenceId, sequence.Folder, m => m with
var manifest = await _writer.UpdateAsync(paths, sequenceId, sequence.Folder, m =>
{
Title = string.IsNullOrWhiteSpace(title) ? null : title.Trim(),
Tags = tags,
Rating = rating,
Notes = notes,
Versions = m.Versions with { Settings = System.Math.Max(m.Versions.Settings, sequence.SettingsVersion) + 1 },
UpdatedAt = DateTimeOffset.UtcNow,
var current = sequence.SettingsVersion > m.Versions.Settings
? new SequenceInfo(sequence.Title, sequence.Tags, sequence.Rating, sequence.Notes)
: new SequenceInfo(m.Title, m.Tags, m.Rating, m.Notes);
var info = edit(current);
return m with
{
Title = string.IsNullOrWhiteSpace(info.Title) ? null : info.Title.Trim(),
Tags = info.Tags,
Rating = info.Rating,
Notes = info.Notes,
Versions = m.Versions with { Settings = System.Math.Max(m.Versions.Settings, sequence.SettingsVersion) + 1 },
UpdatedAt = DateTimeOffset.UtcNow,
};
}, cancellationToken).ConfigureAwait(false);
var folder = paths.Sequence(sequence.Folder);
var updated = SequenceMapping.ToSequence(manifest, archive.Id, folder, sequence);
@@ -165,9 +182,9 @@ public sealed class ArchiveService : IJobHandlerProvider
await Renamer.ApplyAsync(await LoadArchiveAsync(plan.ArchiveId, cancellationToken).ConfigureAwait(false), plan, progress, cancellationToken)
.ConfigureAwait(false);
/// <summary>Dry run of moving sequences to their archive's trash.</summary>
public Task<DeletePlan> PlanDeleteAsync(IReadOnlyList<Guid> sequenceIds, CancellationToken cancellationToken = default) =>
Trash.PlanAsync(sequenceIds, cancellationToken);
/// <summary>Dry run of moving sequences to their archive's trash; <paramref name="progress"/> counts the sequences checked.</summary>
public Task<DeletePlan> PlanDeleteAsync(IReadOnlyList<Guid> sequenceIds, IProgress<int>? progress = null, CancellationToken cancellationToken = default) =>
Trash.PlanAsync(sequenceIds, progress, cancellationToken);
/// <summary>Moves exactly the planned sequences to the trash; returns the trash entries made.</summary>
public Task<IReadOnlyList<TrashEntry>> DeleteAsync(DeletePlan plan, string? deletedBy = null, IProgress<int>? progress = null,
@@ -222,6 +239,9 @@ public sealed class ArchiveService : IJobHandlerProvider
}
}
/// <summary>The fields of a sequence the user describes it with (sidecar and index).</summary>
public sealed record SequenceInfo(string? Title, IReadOnlyList<string> Tags, int Rating, string? Notes);
/// <summary>Builds the archive jobs; enqueue with <see cref="EnqueueAsync"/>.</summary>
public static class ArchiveJobs
{