From fb0d8cceae3830e073b23c792e87672516f5cab9 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 3 Oct 2026 16:44:02 +0000 Subject: [PATCH] fix(data): keep no trash record when a sequence folder cannot move When the folder of a sequence could not be moved into the trash (a file open elsewhere, no permission), its record stayed behind as a stray file; it is removed again, and the index rows stay as they were. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC --- src/Titano.Data/Archiving/SequenceTrash.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Titano.Data/Archiving/SequenceTrash.cs b/src/Titano.Data/Archiving/SequenceTrash.cs index 5286fda4..87c72033 100644 --- a/src/Titano.Data/Archiving/SequenceTrash.cs +++ b/src/Titano.Data/Archiving/SequenceTrash.cs @@ -261,8 +261,18 @@ public sealed class SequenceTrash var record = new TrashRecord(row, await _db.Renders.ListBySequenceAsync(sequence.Id, cancellationToken).ConfigureAwait(false), step.Files, step.Bytes, DateTimeOffset.UtcNow, deletedBy); // The record first: a crash before the move leaves a record without a folder, which the listing ignores. - AtomicFile.WriteAllText(Path.Combine(trash, name + RecordExtension), JsonSerializer.Serialize(record, TrashJson.Default.TrashRecord)); - Directory.Move(folder.Folder, Path.Combine(trash, name)); + var recordPath = Path.Combine(trash, name + RecordExtension); + AtomicFile.WriteAllText(recordPath, JsonSerializer.Serialize(record, TrashJson.Default.TrashRecord)); + try + { + Directory.Move(folder.Folder, Path.Combine(trash, name)); + } + catch (Exception ex) when (ex is IOException or UnauthorizedAccessException) + { + // A file of the folder is open elsewhere: nothing moved, so the record goes and the rows stay. + File.Delete(recordPath); + throw; + } entry = Entry(archive.Id, name, record); } await using (var tx = await _db.BeginAsync(cancellationToken).ConfigureAwait(false))