fix(archive): verify writes only the integrity flags of files still as checked
A verify's flush replaced every flag of a pending frame, in the sidecar and the index, with the flags it computed from the frame as read without the lease, possibly hours earlier. A preview-only or undecodable tier, a duplicate flag or a repair recorded meanwhile was reverted, and a photo an upload repaired during the run was flagged missing again, so the next copy moved the good file aside. Under the lease the flush now merges only Missing and Corrupt into the frame's current flags, and the index sets and clears only those bits with the hash, after locking the sequence row. A check whose sidecar record or file (size and modification time taken before it was read) changed since is left for the next verify. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
3 files changed
+121
-16
No files matched your search
@@ -4,7 +4,10 @@ using Titano.Core.Model;
|
||||
|
||||
namespace Titano.Data.Repositories;
|
||||
|
||||
/// <summary>Integrity fields a verify rewrites: the flags and the hash of a newly hashed file.</summary>
|
||||
/// <summary>
|
||||
/// Integrity fields a verify rewrites: <see cref="FrameFlags.Missing"/> and <see cref="FrameFlags.Corrupt"/> as found (other
|
||||
/// bits of <paramref name="Flags"/> are ignored) and the hash of a newly hashed file.
|
||||
/// </summary>
|
||||
public readonly record struct FrameIntegrity(Guid FrameId, FrameFlags Flags, string? Sha256);
|
||||
|
||||
/// <summary>A frame and the sequence it belongs to.</summary>
|
||||
@@ -258,15 +261,20 @@ public sealed class FrameRepository
|
||||
[sequenceId, newFolder, length, length, prefix], cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>Writes flags and hashes found by a verify, in one transaction; returns the number of frames updated.</summary>
|
||||
/// <summary>
|
||||
/// Writes what a verify found, in one transaction: the <see cref="FrameFlags.Missing"/> and <see cref="FrameFlags.Corrupt"/>
|
||||
/// bits and new hashes. Every other flag stays as stored: decode tiers, duplicates and exclusions belong to other
|
||||
/// writers, which may have changed them since the verify read the frame. Returns the number of frames updated.
|
||||
/// </summary>
|
||||
public Task<int> UpdateIntegrityAsync(IReadOnlyList<FrameIntegrity> frames, CancellationToken cancellationToken = default) =>
|
||||
_db.InTransactionAsync(async session =>
|
||||
{
|
||||
const FrameFlags integrity = FrameFlags.Missing | FrameFlags.Corrupt;
|
||||
var updated = 0;
|
||||
foreach (var f in frames)
|
||||
{
|
||||
updated += await session.ExecuteAsync("UPDATE frames SET flags = $2, sha256 = COALESCE($3, sha256) WHERE id = $1",
|
||||
[f.FrameId, (int)f.Flags, f.Sha256?.ToLowerInvariant()], cancellationToken).ConfigureAwait(false);
|
||||
updated += await session.ExecuteAsync("UPDATE frames SET flags = (flags & ~$4) | $2, sha256 = COALESCE($3, sha256) WHERE id = $1",
|
||||
[f.FrameId, (int)(f.Flags & integrity), f.Sha256?.ToLowerInvariant(), (int)integrity], cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
return updated;
|
||||
}, cancellationToken);
|
||||
|
||||
Reference in new issue
Block a user