fix(data): restore a sequence whose folder lost its sidecar

Restore left a folder without a sidecar out of the index until the next scan,
so Undo and the trash's Restore seemed to do nothing; such a folder is now
adopted under the sequence's own id, as a scan would adopt it, and comes back
at once with its settings and renders.

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-03 16:49:10 +00:00
1 parent b17d008f65
commit f4e1d02c1d
3 files changed
+39 -14

No files matched your search

+2 -2
View File
@@ -178,8 +178,8 @@ public sealed class ArchiveService : IJobHandlerProvider
public async Task<IReadOnlyList<TrashEntry>> ListTrashAsync(Guid archiveId, CancellationToken cancellationToken = default) =>
await Trash.ListAsync(await LoadArchiveAsync(archiveId, cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false);
/// <summary>Moves a sequence back from the trash and indexes it again; null when its folder has no sidecar (a scan adopts it).</summary>
public async Task<Sequence?> RestoreAsync(Guid archiveId, string entryName, CancellationToken cancellationToken = default) =>
/// <summary>Moves a sequence back from the trash and indexes it again.</summary>
public async Task<Sequence> RestoreAsync(Guid archiveId, string entryName, CancellationToken cancellationToken = default) =>
await Trash.RestoreAsync(await LoadArchiveAsync(archiveId, cancellationToken).ConfigureAwait(false), entryName, cancellationToken).ConfigureAwait(false);
/// <summary>Plans a card or folder import into an archive (nothing is copied).</summary>
+15 -10
View File
@@ -185,12 +185,12 @@ public sealed class SequenceTrash
/// <summary>
/// Moves a sequence back from the trash into its folder (or, when that is taken, a free one next to it) and indexes
/// it again from its sidecar with its ids, settings and renders. Returns the restored row; null when the folder has
/// no sidecar (the next scan adopts it).
/// it again from its sidecar with its ids, settings and renders. A folder without a sidecar is adopted under the
/// sequence's id, as a scan would adopt it. Returns the restored row.
/// </summary>
/// <exception cref="InvalidOperationException">The index already holds that sequence.</exception>
/// <exception cref="DirectoryNotFoundException">The entry is not in the trash.</exception>
public async Task<Sequence?> RestoreAsync(Archive archive, string name, CancellationToken cancellationToken = default)
public async Task<Sequence> RestoreAsync(Archive archive, string name, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(archive);
ArgumentException.ThrowIfNullOrWhiteSpace(name);
@@ -214,12 +214,7 @@ public sealed class SequenceTrash
Directory.CreateDirectory(Path.GetDirectoryName(sequence.Folder)!);
Directory.Move(source, sequence.Folder);
Log.Info("archive", $"{record.Sequence.DisplayTitle} restored from the trash to {folder}");
if (!File.Exists(sequence.ManifestPath))
{
File.Delete(recordPath);
return null;
}
var manifest = SequenceWriter.ReadLocked(sequence, id);
var manifest = File.Exists(sequence.ManifestPath) ? SequenceWriter.ReadLocked(sequence, id) : Adopt(sequence, id, cancellationToken);
var kept = record.Sequence with { ArchiveId = archive.Id, Folder = folder, RenderedCount = 0 };
await using (var tx = await _db.BeginAsync(cancellationToken).ConfigureAwait(false))
{
@@ -233,7 +228,17 @@ public sealed class SequenceTrash
await _indexer.RecordStampsAsync(archive, sequence, id, cancellationToken).ConfigureAwait(false);
File.Delete(recordPath);
}
return await _db.Sequences.GetAsync(id, cancellationToken).ConfigureAwait(false);
return await _db.Sequences.GetAsync(id, cancellationToken).ConfigureAwait(false)
?? throw new InvalidOperationException($"{record.Sequence.DisplayTitle} was restored but is not in the index.");
}
/// <summary>A sidecar for a restored folder that had none (its frames get new ids; the sequence keeps its own).</summary>
private SequenceManifest Adopt(SequencePaths sequence, Guid id, CancellationToken cancellationToken)
{
var manifest = SequenceAdopter.Build(id, sequence, _writer.Options.Owner, cancellationToken);
Directory.CreateDirectory(sequence.MetaDirectory);
ManifestStore.WriteSequence(sequence.ManifestPath, manifest);
return manifest;
}
private async Task<TrashEntry?> DeleteOneAsync(DeleteStep step, string? deletedBy, CancellationToken cancellationToken)