(
root: &Path,
directory: &Path,
files: &mut BTreeMap<String, Vec<u8>>,
)
| 3133 | } |
| 3134 | |
| 3135 | fn 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 | |
| 3175 | fn path_to_git_string(path: &Path) -> CliResult<String> { |
| 3176 | let components: Result<Vec<_>, _> = path |
no test coverage detected