feat(core): archive layout, sidecars, leases and thumbnail packs
archive.json and sequence.json with source-generated JSON, forward-compatible reading (unknown fields kept, unknown enum names tolerated) and atomic writes; lease files with expiry and stale takeover; thumbs.pack with index, crash-safe append and random access; folder scanning, in-place adoption, reconcile, verify, index snapshot, rename planning and thumbnail/proxy rendering. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
24 files changed
+2556
No files matched your search
@@ -0,0 +1,54 @@
|
||||
using Titano.Core.Model;
|
||||
|
||||
namespace Titano.Core.Archiving;
|
||||
|
||||
public enum FrameHealth
|
||||
{
|
||||
/// <summary>Same size and SHA-256 as recorded.</summary>
|
||||
Ok,
|
||||
|
||||
/// <summary>No hash was recorded (adopted file); it has been computed now.</summary>
|
||||
Hashed,
|
||||
|
||||
Missing,
|
||||
|
||||
/// <summary>A different size: the file was replaced or edited.</summary>
|
||||
Changed,
|
||||
|
||||
/// <summary>Same size, different content: bit rot or a damaged copy.</summary>
|
||||
Corrupt,
|
||||
}
|
||||
|
||||
/// <param name="Sha256">The hash computed now (null when the file is missing or changed size).</param>
|
||||
public sealed record FrameCheck(SidecarFrame Frame, FrameHealth Health, string? Sha256)
|
||||
{
|
||||
/// <summary>Frame flags after this check: <see cref="FrameFlags.Missing"/>/<see cref="FrameFlags.Corrupt"/> set or cleared.</summary>
|
||||
public FrameFlags Flags => Health switch
|
||||
{
|
||||
FrameHealth.Missing => (Frame.Flags & ~FrameFlags.Corrupt) | FrameFlags.Missing,
|
||||
FrameHealth.Changed or FrameHealth.Corrupt => (Frame.Flags & ~FrameFlags.Missing) | FrameFlags.Corrupt,
|
||||
_ => Frame.Flags & ~(FrameFlags.Missing | FrameFlags.Corrupt),
|
||||
};
|
||||
|
||||
/// <summary>The sidecar record after this check (flags, and the hash of a newly hashed file).</summary>
|
||||
public SidecarFrame Updated => Frame with { Flags = Flags, Sha256 = Health == FrameHealth.Hashed ? Sha256 : Frame.Sha256 };
|
||||
|
||||
public bool ChangesRecord => Updated != Frame;
|
||||
}
|
||||
|
||||
/// <summary>Re-hashes originals against their sidecar records (BRIEF §12.5 Verify).</summary>
|
||||
public static class FrameVerifier
|
||||
{
|
||||
public static async Task<FrameCheck> CheckAsync(SequencePaths sequence, SidecarFrame frame, Action<long>? bytesRead = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var info = new FileInfo(sequence.File(frame.File));
|
||||
if (!info.Exists) return new FrameCheck(frame, FrameHealth.Missing, null);
|
||||
if (info.Length != frame.Size) return new FrameCheck(frame, FrameHealth.Changed, null);
|
||||
var sha = await ContentHash.Sha256Async(info.FullName, bytesRead, cancellationToken).ConfigureAwait(false);
|
||||
var health = frame.Sha256 is null ? FrameHealth.Hashed
|
||||
: sha.Equals(frame.Sha256, StringComparison.OrdinalIgnoreCase) ? FrameHealth.Ok
|
||||
: FrameHealth.Corrupt;
|
||||
return new FrameCheck(frame, health, sha);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user