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

Function collect_filesystem

atomic-cli/src/commands/git/shim.rs:3135–3173  ·  view source on GitHub ↗
(
    root: &Path,
    directory: &Path,
    files: &mut BTreeMap<String, Vec<u8>>,
)

Source from the content-addressed store, hash-verified

3133}
3134
3135fn collect_filesystem(
3136 root: &Path,
3137 directory: &Path,
3138 files: &mut BTreeMap<String, Vec<u8>>,
3139) -> CliResult<()> {
3140 let entries = fs::read_dir(directory).map_err(|error| {
3141 git_error(format!(
3142 "cannot read working tree directory '{}': {error}",
3143 directory.display()
3144 ))
3145 })?;
3146 for entry in entries {
3147 let entry =
3148 entry.map_err(|error| git_error(format!("cannot read working tree: {error}")))?;
3149 let path = entry.path();
3150 let relative = path
3151 .strip_prefix(root)
3152 .expect("filesystem traversal remains below repository root");
3153 let relative = path_to_git_string(relative)?;
3154 if excluded_path(&relative) {
3155 continue;
3156 }
3157 let kind = entry
3158 .file_type()
3159 .map_err(|error| git_error(format!("cannot inspect '{relative}': {error}")))?;
3160 if kind.is_dir() {
3161 collect_filesystem(root, &path, files)?;
3162 } else if kind.is_file() {
3163 let content = fs::read(&path)
3164 .map_err(|error| git_error(format!("cannot read '{relative}': {error}")))?;
3165 files.insert(relative, content);
3166 } else {
3167 return Err(git_error(format!(
3168 "unsupported working tree entry '{relative}'"
3169 )));
3170 }
3171 }
3172 Ok(())
3173}
3174
3175fn path_to_git_string(path: &Path) -> CliResult<String> {
3176 let components: Result<Vec<_>, _> = path

Callers 1

read_filesystemFunction · 0.85

Calls 8

path_to_git_stringFunction · 0.85
excluded_pathFunction · 0.85
is_dirMethod · 0.80
git_errorFunction · 0.70
readFunction · 0.50
pathMethod · 0.45
is_fileMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected