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

Function observe_path

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

Source from the content-addressed store, hash-verified

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