(path: &Path)
| 4939 | } |
| 4940 | |
| 4941 | fn 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 | |
| 4972 | fn copy_entry(source: &Path, destination: &Path) -> Result<(), RepositoryError> { |
| 4973 | let metadata = fs::symlink_metadata(source)?; |
no test coverage detected