fix(upload): repairs charge no quota and another sequence's copy no longer blocks them
A re-upload that repairs a missing or damaged frame is now reported as IngestResult.Repaired and adds nothing to the uploader's used bytes; the quota checks at start and completion skip uploads whose target sequence already holds the content. The start shortcut and crash recovery share one rule (UploadRules.StandIn): an intact copy stands for the upload, the target sequence's own copy first, except when the target holds the content only in damaged copies, which the upload's bytes then repair. A sequence adopted at the archive root that holds frames is never given a new folder when its root sidecar is missing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
8 files changed
+150
-39
No files matched your search
@@ -136,11 +136,12 @@ public sealed class ArchiveIngest : IArchiveIngest
|
||||
|
||||
/// <summary>
|
||||
/// A sequence created without photos (<c>POST /api/v1/sequences</c>, BRIEF §14.3) has no folder until its first frame.
|
||||
/// An empty folder otherwise means the archive root itself, adopted in place, whose sidecar names the sequence.
|
||||
/// An empty folder otherwise means the archive root itself, adopted in place, whose sidecar names the sequence; one
|
||||
/// that holds frames is never moved elsewhere, even while its root sidecar is missing.
|
||||
/// </summary>
|
||||
internal static bool AwaitsFolder(Sequence sequence, ArchivePaths paths)
|
||||
{
|
||||
if (sequence.Folder.Length > 0) return false;
|
||||
if (sequence.Folder.Length > 0 || sequence.FrameCount > 0) return false;
|
||||
var root = paths.Sequence(string.Empty);
|
||||
if (!File.Exists(root.ManifestPath)) return true;
|
||||
try
|
||||
@@ -363,7 +364,7 @@ public sealed class ArchiveIngest : IArchiveIngest
|
||||
foreach (var (p, frame) in accepted.Where(a => byId.ContainsKey(a.Frame.Id)))
|
||||
p.Completion.TrySetResult(Result(sequenceId, sequence, byId[frame.Id], false));
|
||||
foreach (var (p, frame) in repairs.Where(r => repaired.Contains(r.Frame.Id)))
|
||||
p.Completion.TrySetResult(Result(sequenceId, sequence, byId[frame.Id], false));
|
||||
p.Completion.TrySetResult(Result(sequenceId, sequence, byId[frame.Id], false) with { Repaired = true });
|
||||
var unrepaired = repairs.Select(r => r.Frame.Id).Where(id => !repaired.Contains(id)).ToHashSet();
|
||||
foreach (var (p, frameId) in duplicates)
|
||||
{
|
||||
|
||||
@@ -19,9 +19,10 @@ public sealed record IngestRequest(
|
||||
|
||||
/// <summary>
|
||||
/// The committed frame; <see cref="Duplicate"/> when an intact frame of the sequence already held that SHA-256 (the file
|
||||
/// stays in staging). A frame with that SHA-256 that was missing or damaged is repaired with the file instead (not a duplicate).
|
||||
/// stays in staging). A frame with that SHA-256 that was missing or damaged is repaired with the file instead:
|
||||
/// <see cref="Repaired"/>, not a duplicate, and the archive holds no more bytes than before.
|
||||
/// </summary>
|
||||
public sealed record IngestResult(Guid SequenceId, Guid FrameId, int Index, string RelativePath, bool Duplicate);
|
||||
public sealed record IngestResult(Guid SequenceId, Guid FrameId, int Index, string RelativePath, bool Duplicate, bool Repaired = false);
|
||||
|
||||
/// <summary>
|
||||
/// Commits staged files into the archive layout (originals folder, naming templates, <c>sequence.json</c> written
|
||||
|
||||
@@ -65,18 +65,10 @@ public sealed class FrameRepository
|
||||
_db.ListAsync($"SELECT {Columns} FROM frames WHERE sequence_id = $1 AND idx > $2 ORDER BY idx LIMIT $3",
|
||||
[sequenceId, afterIndex, Cursor.ClampLimit(limit)], Map, cancellationToken);
|
||||
|
||||
/// <summary>Every frame with this content hash (duplicate detection).</summary>
|
||||
/// <summary>Every frame with this content hash (duplicate detection, upload short-circuit).</summary>
|
||||
public Task<IReadOnlyList<Frame>> FindBySha256Async(string sha256, CancellationToken cancellationToken = default) =>
|
||||
_db.ListAsync($"SELECT {Columns} FROM frames WHERE sha256 = $1 ORDER BY sequence_id, idx", [sha256.ToLowerInvariant()], Map, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Frames with this content hash that are not flagged missing or corrupt: only such a copy may stand for an upload
|
||||
/// (the upload short-circuit, a commit settled after a crash), so an upload of the same content repairs a damaged one.
|
||||
/// </summary>
|
||||
public Task<IReadOnlyList<Frame>> FindIntactBySha256Async(string sha256, CancellationToken cancellationToken = default) =>
|
||||
_db.ListAsync($"SELECT {Columns} FROM frames WHERE sha256 = $1 AND (flags & $2) = 0 ORDER BY sequence_id, idx",
|
||||
[sha256.ToLowerInvariant(), (int)(FrameFlags.Missing | FrameFlags.Corrupt)], Map, cancellationToken);
|
||||
|
||||
/// <summary>Id and index of every frame of a sequence, in index order.</summary>
|
||||
public Task<IReadOnlyList<FramePosition>> ListPositionsAsync(Guid sequenceId, CancellationToken cancellationToken = default) =>
|
||||
_db.ListAsync("SELECT id, idx FROM frames WHERE sequence_id = $1 ORDER BY idx", [sequenceId], r => new FramePosition(r.GetGuid(0), r.GetInt32(1)),
|
||||
|
||||
Reference in new issue
Block a user