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

Function directory_content_hash

atomic-repository/src/repository/operation.rs:4941–4970  ·  view source on GitHub ↗
(path: &Path)

Source from the content-addressed store, hash-verified

4939}
4940
4941fn directory_content_hash(path: &Path) -> Result<Hash, RepositoryError> {
4942 let mut entries = fs::read_dir(path)?.collect::<Result<Vec<_>, _>>()?;
4943 entries.sort_by(|left, right| {
4944 os_str_bytes(left.file_name().as_os_str()).cmp(&os_str_bytes(right.file_name().as_os_str()))
4945 });
4946 let mut canonical = b"atomic:operation-directory:v1\0".to_vec();
4947 for entry in entries {
4948 let name = os_str_bytes(entry.file_name().as_os_str());
4949 let value = observe_path(&entry.path(), true)?;
4950 let EffectValue::File(state) = value else {
4951 return Err(RepositoryError::InvalidOperation {
4952 message: format!(
4953 "directory entry '{}' disappeared while hashing",
4954 entry.path().display()
4955 ),
4956 });
4957 };
4958 canonical.extend_from_slice(&(name.len() as u64).to_le_bytes());
4959 canonical.extend_from_slice(&name);
4960 canonical.push(match state.kind {
4961 FileKind::Regular => 1,
4962 FileKind::Directory => 2,
4963 FileKind::Symlink => 3,
4964 FileKind::Gitlink => 4,
4965 });
4966 canonical.extend_from_slice(&state.mode.to_le_bytes());
4967 canonical.extend_from_slice(state.content.as_bytes());
4968 }
4969 Ok(Hash::of(&canonical))
4970}
4971
4972fn copy_entry(source: &Path, destination: &Path) -> Result<(), RepositoryError> {
4973 let metadata = fs::symlink_metadata(source)?;

Callers 1

observe_pathFunction · 0.85

Calls 9

os_str_bytesFunction · 0.85
to_le_bytesMethod · 0.80
observe_pathFunction · 0.70
cmpMethod · 0.45
file_nameMethod · 0.45
pathMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45
as_bytesMethod · 0.45

Tested by

no test coverage detected