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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
1 file changed
+12
-2
@@ -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))
|
||||
|
||||
Reference in new issue
Block a user