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

Function read_canonical_content

atomic-repository/src/change_source/scan.rs:721–759  ·  view source on GitHub ↗
(
    file: &ObservedFile,
    path: &RepoPath,
    filter: &dyn ContentFilter,
)

Source from the content-addressed store, hash-verified

719}
720
721fn 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)]
762fn read_link_bytes(path: &Path) -> std::io::Result<Vec<u8>> {

Callers 1

canonical_content_idMethod · 0.85

Calls 6

read_link_bytesFunction · 0.85
escapedMethod · 0.80
to_nativeMethod · 0.80
readFunction · 0.50
kindMethod · 0.45
cleanMethod · 0.45

Tested by

no test coverage detected