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

Function observe_path

atomic-repository/src/repository/operation.rs:4906–4943  ·  view source on GitHub ↗
(path: &Path, recursive_directory: bool)

Source from the content-addressed store, hash-verified

4904}
4905
4906fn observe_path(path: &Path, recursive_directory: bool) -> Result<EffectValue, RepositoryError> {
4907 let metadata = match fs::symlink_metadata(path) {
4908 Ok(metadata) => metadata,
4909 Err(error) if is_absent_path_error(&error) => {
4910 return Ok(EffectValue::Absent);
4911 }
4912 Err(error) => return Err(RepositoryError::Io(error)),
4913 };
4914 let file_type = metadata.file_type();
4915 let kind = if file_type.is_symlink() {
4916 FileKind::Symlink
4917 } else if file_type.is_file() {
4918 FileKind::Regular
4919 } else if file_type.is_dir() && path.join(".git").is_file() && !recursive_directory {
4920 FileKind::Gitlink
4921 } else if file_type.is_dir() {
4922 FileKind::Directory
4923 } else {
4924 return Err(RepositoryError::InvalidOperation {
4925 message: format!(
4926 "operation cannot classify special filesystem entry '{}'",
4927 path.display()
4928 ),
4929 });
4930 };
4931 let content = match kind {
4932 FileKind::Regular => Hash::of(&fs::read(path)?),
4933 FileKind::Symlink => Hash::of(&os_str_bytes(fs::read_link(path)?.as_os_str())),
4934 FileKind::Directory if recursive_directory => directory_content_hash(path)?,
4935 FileKind::Directory => Hash::of(b"atomic:filesystem-directory-entry:v1\0"),
4936 FileKind::Gitlink => Hash::of(&fs::read(path.join(".git"))?),
4937 };
4938 Ok(EffectValue::File(FileState {
4939 kind,
4940 mode: metadata_mode(&metadata),
4941 content,
4942 }))
4943}
4944
4945fn directory_content_hash(path: &Path) -> Result<Hash, RepositoryError> {
4946 let mut entries = fs::read_dir(path)?.collect::<Result<Vec<_>, _>>()?;

Callers 6

verify_backupMethod · 0.70
directory_content_hashFunction · 0.70

Calls 8

is_absent_path_errorFunction · 0.85
os_str_bytesFunction · 0.85
directory_content_hashFunction · 0.85
metadata_modeFunction · 0.85
is_dirMethod · 0.80
readFunction · 0.50
FileClass · 0.50
is_fileMethod · 0.45

Tested by

no test coverage detected