Skip to main content

calculate_dir_hash

Function calculate_dir_hash 

Source
pub fn calculate_dir_hash(path: &Path) -> Result<String, Error>
Expand description

Calculates a recursive hash of an entire directory’s contents.

Deterministic Algorithm:

  • Collects all files in the directory.
  • Sorts files by their relative paths to ensure consistency.
  • Hashes each file’s relative path, its metadata length, and finally its raw content.

This provides a single SHA-512 “Snapshot” hash that represents the exact state of the directory, used for bit-for-bit reproducibility checks in Specification v2.