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

Function collect_filesystem

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

Source from the content-addressed store, hash-verified

3177}
3178
3179fn collect_filesystem(
3180 root: &Path,
3181 directory: &Path,
3182 files: &mut BTreeMap<String, Vec<u8>>,
3183) -> CliResult<()> {
3184 let entries = fs::read_dir(directory).map_err(|error| {
3185 git_error(format!(
3186 "cannot read working tree directory '{}': {error}",
3187 directory.display()
3188 ))
3189 })?;
3190 for entry in entries {
3191 let entry =
3192 entry.map_err(|error| git_error(format!("cannot read working tree: {error}")))?;
3193 let path = entry.path();
3194 let relative = path
3195 .strip_prefix(root)
3196 .expect("filesystem traversal remains below repository root");
3197 let relative = path_to_git_string(relative)?;
3198 if excluded_path(&relative) {
3199 continue;
3200 }
3201 let kind = entry
3202 .file_type()
3203 .map_err(|error| git_error(format!("cannot inspect '{relative}': {error}")))?;
3204 if kind.is_dir() {
3205 collect_filesystem(root, &path, files)?;
3206 } else if kind.is_file() {
3207 let content = fs::read(&path)
3208 .map_err(|error| git_error(format!("cannot read '{relative}': {error}")))?;
3209 files.insert(relative, content);
3210 } else {
3211 return Err(git_error(format!(
3212 "unsupported working tree entry '{relative}'"
3213 )));
3214 }
3215 }
3216 Ok(())
3217}
3218
3219fn path_to_git_string(path: &Path) -> CliResult<String> {
3220 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