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_dirmust contain aCargo.tomlat its root — returnsError::MissingCargoTomlotherwise
Exclusion rules:
- Directories named
.gitortarget(and all their contents) are excluded - Only regular files are added; directories themselves are not archived as entries
Implementation detail:
- Uses
walkdir::WalkDirto traverse the source directory - Each non-excluded file is added to a
tar::Builderwrapped in aflate2::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),
}Iocatches all filesystem, archive, and gzip errors via#[from]MissingCargoTomlis returned bycapturewhen the source directory lacks a manifestHashis reserved for hash-computation anomalies (currently unused in practice)StripPrefixoccurs if a walkdir entry cannot be made relative tosrc_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 |