crate-seq-snapshot

Overview

crate-seq-snapshot provides directory-to-tarball capture and extraction for non-git workflows ("snapshot mode"). It also includes SHA-256 content hashing for content-addressable tarball lookup.

Capture — capture.rs

capture

pub fn capture(
    src_dir: &Path,
    dest_path: &Path,
) -> Result<(), Error>

Captures src_dir as a gzip-compressed tarball at dest_path.

Prerequisites:

  • src_dir must contain a Cargo.toml at its root — returns Error::MissingCargoToml otherwise

Exclusion rules:

  • Directories named .git or target (and all their contents) are excluded
  • Only regular files are added; directories themselves are not archived as entries

Implementation detail:

  • Uses walkdir::WalkDir to traverse the source directory
  • Each non-excluded file is added to a tar::Builder wrapped in a flate2::GzEncoder (default compression)
  • File paths in the archive are relative to src_dir
  • The builder is finalized to flush the gzip footer

Extraction — extract.rs

extract

pub fn extract(
    tarball_path: &Path,
) -> Result<tempfile::TempDir, Error>

Extracts a .tar.gz tarball into a fresh temporary directory. The TempDir is cleaned up on drop.

Hashing — hash.rs

hash_tarball

pub fn hash_tarball(path: &Path) -> Result<String, Error>

Computes the SHA-256 hash of the file at path and returns it as a lowercase hex string. Streams the file in 64 KiB chunks to avoid loading it entirely into memory.

Content addressing

The SHA-256 hash of a snapshot tarball is used as the ref_ field in LedgerEntry objects (of type VersionSource::Snapshot). This enables the pipeline to locate the correct tarball in the snapshot store by hash during source resolution.

Error type — error.rs

#[derive(Debug, thiserror::Error)]
pub enum Error {
    Io(#[from] std::io::Error),
    MissingCargoToml(PathBuf),
    Hash(String),
    StripPrefix(#[from] std::path::StripPrefixError),
}
  • Io catches all filesystem, archive, and gzip errors via #[from]
  • MissingCargoToml is returned by capture when the source directory lacks a manifest
  • Hash is reserved for hash-computation anomalies (currently unused in practice)
  • StripPrefix occurs if a walkdir entry cannot be made relative to src_dir

Source files

File Responsibility
capture.rs Directory-to-gzip-tarball snapshot with exclusions
extract.rs Tarball extraction to temp directory
hash.rs Streaming SHA-256 content hashing
error.rs Crate error enum
lib.rs Module declarations and re-exports