(
root: &Path,
directory: &Path,
files: &mut BTreeMap<String, Vec<u8>>,
)
| 3177 | } |
| 3178 | |
| 3179 | fn 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 | |
| 3219 | fn path_to_git_string(path: &Path) -> CliResult<String> { |
| 3220 | let components: Result<Vec<_>, _> = path |
no test coverage detected