MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / hash_file_contents

Function hash_file_contents

atomic-repository/src/status.rs:975–995  ·  view source on GitHub ↗

Hash the contents of a file using Blake3. This is used to compute content hashes for modification detection. # Arguments `path` - Path to the file to hash # Returns The Blake3 hash of the file contents.

(path: &Path)

Source from the content-addressed store, hash-verified

973///
974/// The Blake3 hash of the file contents.
975pub fn hash_file_contents(path: &Path) -> StatusResult<Hash> {
976 let metadata = std::fs::symlink_metadata(path)?;
977 let contents = if metadata.file_type().is_symlink() {
978 #[cfg(unix)]
979 {
980 use std::os::unix::ffi::OsStrExt;
981 std::fs::read_link(path)?.as_os_str().as_bytes().to_vec()
982 }
983 #[cfg(not(unix))]
984 {
985 std::fs::read_link(path)?
986 .as_os_str()
987 .to_string_lossy()
988 .as_bytes()
989 .to_vec()
990 }
991 } else {
992 std::fs::read(path)?
993 };
994 Ok(Hash::of(&contents))
995}
996
997/// Collect all files in a directory, respecting ignore patterns.
998///

Callers 2

test_hash_file_contentsFunction · 0.85
status_innerMethod · 0.85

Calls 2

readFunction · 0.50
as_bytesMethod · 0.45

Tested by 1

test_hash_file_contentsFunction · 0.68