fix(documents): clean up only snapshots created by the current copy
(cherry picked from commit fa8154da9e)
This commit is contained in:
@@ -30,6 +30,17 @@ public sealed class SubmittedApplicationPackageTests
|
||||
|
||||
Assert.Equal("exact submitted bytes", await File.ReadAllTextAsync(destination));
|
||||
Assert.Equal("32283fd0838392ef9d8c707f521096966432939d5d83624bbfce150cde3ce26c", result.Sha256);
|
||||
|
||||
await File.WriteAllTextAsync(source, "a later draft");
|
||||
await Assert.ThrowsAsync<IOException>(() => storage.SnapshotAsync(source, destination, default));
|
||||
Assert.Equal("exact submitted bytes", await File.ReadAllTextAsync(destination));
|
||||
|
||||
var next = storage.CreatePackagePath(7, 2, "source.txt");
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() =>
|
||||
storage.SnapshotAsync(source, next, new CancellationToken(canceled: true)));
|
||||
Assert.False(File.Exists(next));
|
||||
await storage.SnapshotAsync(source, next, default);
|
||||
Assert.Equal("a later draft", await File.ReadAllTextAsync(next));
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -92,10 +92,12 @@ public sealed class AttachmentStorage : IAttachmentStorage
|
||||
var destination = EnsureManagedPath(destinationPath, allowMissingLeaf: true);
|
||||
if (File.Exists(destination)) throw new IOException("A submitted package file already exists at the destination.");
|
||||
|
||||
var created = false;
|
||||
try
|
||||
{
|
||||
await using var input = new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
await using var output = new FileStream(destination, FileMode.CreateNew, FileAccess.Write, FileShare.None);
|
||||
created = true;
|
||||
using var hash = System.Security.Cryptography.IncrementalHash.CreateHash(System.Security.Cryptography.HashAlgorithmName.SHA256);
|
||||
var buffer = new byte[81920];
|
||||
int read;
|
||||
@@ -111,7 +113,7 @@ public sealed class AttachmentStorage : IAttachmentStorage
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (File.Exists(destination)) File.Delete(destination);
|
||||
if (created) File.Delete(destination);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,9 @@ The first build could not execute tests because C: was full. Only this run's fre
|
||||
Remaining investigation:concurrent Career Profile changes during render may require their own snapshot binding. AttachmentStorage.SnapshotAsync has a separate source-backed destination-ownership cleanup concern; no deterministic race reproduction or fix is claimed here. MariaDB, actual HTTP/browser capture, real models/providers, native device/AT, physical PDF acceptance, integrated security and recovery were not rerun. Existing accepted PDF metrics/visuals remain source-bound.
|
||||
|
||||
Rollback:revert the source commit, rebuild on the isolated development branch and rerun the affected suite. No migration/data repair is involved. UI callers retain the existing revision-conflict/review flow; an aborted capture publishes no package. This does not establish atomic consistency across every package source entity or filesystem race.
|
||||
|
||||
## Submitted attachment cleanup ownership
|
||||
|
||||
On 19 November, review of `AttachmentStorage.SnapshotAsync` found that its exception path treated the presence of a file as permission to delete it. The destination may already have been claimed by another writer. The snapshotter now records success of its own exclusive `FileMode.CreateNew` open. Only that invocation's partial destination is eligible for cleanup. The existing early duplicate rejection and error message are preserved.
|
||||
|
||||
The storage lifecycle test uses real files under a disposable fixture root. It verifies the captured bytes and hash, a refused duplicate following a change to the source, preservation of the first capture, cancellation cleanup and a successful retry into the second destination. All 29 selected submitted-package, attachment consistency and attachment-controller tests passed on the dedicated Release build. The package service still records a path for outer rollback only after a successful snapshot. No customer data, migration or exporter was involved. There was no forced two-writer interleaving or live store rehearsal.
|
||||
|
||||
Reference in New Issue
Block a user