(path: &Path, recursive_directory: bool)
| 4900 | } |
| 4901 | |
| 4902 | fn 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 | |
| 4941 | fn directory_content_hash(path: &Path) -> Result<Hash, RepositoryError> { |
| 4942 | let mut entries = fs::read_dir(path)?.collect::<Result<Vec<_>, _>>()?; |
no test coverage detected