Hash the contents of a file using Blake3. This is used to compute content hashes for modification detection. # Arguments `path` - Path to the file to hash # Returns The Blake3 hash of the file contents.
(path: &Path)
| 973 | /// |
| 974 | /// The Blake3 hash of the file contents. |
| 975 | pub fn hash_file_contents(path: &Path) -> StatusResult<Hash> { |
| 976 | let metadata = std::fs::symlink_metadata(path)?; |
| 977 | let contents = if metadata.file_type().is_symlink() { |
| 978 | #[cfg(unix)] |
| 979 | { |
| 980 | use std::os::unix::ffi::OsStrExt; |
| 981 | std::fs::read_link(path)?.as_os_str().as_bytes().to_vec() |
| 982 | } |
| 983 | #[cfg(not(unix))] |
| 984 | { |
| 985 | std::fs::read_link(path)? |
| 986 | .as_os_str() |
| 987 | .to_string_lossy() |
| 988 | .as_bytes() |
| 989 | .to_vec() |
| 990 | } |
| 991 | } else { |
| 992 | std::fs::read(path)? |
| 993 | }; |
| 994 | Ok(Hash::of(&contents)) |
| 995 | } |
| 996 | |
| 997 | /// Collect all files in a directory, respecting ignore patterns. |
| 998 | /// |