(
file: &ObservedFile,
path: &RepoPath,
filter: &dyn ContentFilter,
)
| 719 | } |
| 720 | |
| 721 | fn read_canonical_content( |
| 722 | file: &ObservedFile, |
| 723 | path: &RepoPath, |
| 724 | filter: &dyn ContentFilter, |
| 725 | ) -> Result<CanonicalContentId, ChangeSourceError> { |
| 726 | let bytes = match file.kind { |
| 727 | ObservedKind::Regular => fs::read(&file.native_path), |
| 728 | ObservedKind::Symlink => read_link_bytes(&file.native_path), |
| 729 | ObservedKind::Directory => match fs::read(file.native_path.join(".git")) { |
| 730 | Ok(bytes) => Ok(bytes), |
| 731 | Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(Vec::new()), |
| 732 | Err(error) => Err(error), |
| 733 | }, |
| 734 | ObservedKind::Other => Ok(Vec::new()), |
| 735 | } |
| 736 | .map_err(|error| ChangeSourceError::Io { |
| 737 | path: path.escaped(), |
| 738 | message: error.to_string(), |
| 739 | })?; |
| 740 | let raw = Hash::of(&bytes); |
| 741 | let canonical = if file.kind == ObservedKind::Regular { |
| 742 | let native = path |
| 743 | .to_native() |
| 744 | .map_err(|error| ChangeSourceError::Path(error.to_string()))?; |
| 745 | filter |
| 746 | .clean(&native, &bytes) |
| 747 | .map_err(|error| ChangeSourceError::Filter { |
| 748 | path: path.escaped(), |
| 749 | message: error.to_string(), |
| 750 | })? |
| 751 | .bytes |
| 752 | } else { |
| 753 | bytes |
| 754 | }; |
| 755 | Ok(CanonicalContentId { |
| 756 | cleaned: Hash::of(&canonical), |
| 757 | raw, |
| 758 | }) |
| 759 | } |
| 760 | |
| 761 | #[cfg(unix)] |
| 762 | fn read_link_bytes(path: &Path) -> std::io::Result<Vec<u8>> { |
no test coverage detected