| 1261 | } |
| 1262 | |
| 1263 | fn collect_locks_recursive( |
| 1264 | directory: &Path, |
| 1265 | locks: &mut BTreeSet<PathBuf>, |
| 1266 | ) -> Result<(), ObservationError> { |
| 1267 | let entries = match fs::read_dir(directory) { |
| 1268 | Ok(entries) => entries, |
| 1269 | Err(error) if error.kind() == io::ErrorKind::NotFound => return Ok(()), |
| 1270 | Err(error) => { |
| 1271 | return Err(ObservationError::new(format!( |
| 1272 | "cannot inspect Git refs directory '{}': {error}", |
| 1273 | directory.display() |
| 1274 | ))); |
| 1275 | } |
| 1276 | }; |
| 1277 | for entry in entries { |
| 1278 | let entry = entry.map_err(|error| { |
| 1279 | ObservationError::new(format!( |
| 1280 | "cannot inspect entry under '{}': {error}", |
| 1281 | directory.display() |
| 1282 | )) |
| 1283 | })?; |
| 1284 | let file_type = entry.file_type().map_err(|error| { |
| 1285 | ObservationError::new(format!( |
| 1286 | "cannot inspect Git administrative path '{}': {error}", |
| 1287 | entry.path().display() |
| 1288 | )) |
| 1289 | })?; |
| 1290 | let path = entry.path(); |
| 1291 | if file_type.is_dir() { |
| 1292 | collect_locks_recursive(&path, locks)?; |
| 1293 | } else if path.extension().and_then(|extension| extension.to_str()) == Some("lock") { |
| 1294 | locks.insert(path); |
| 1295 | } |
| 1296 | } |
| 1297 | Ok(()) |
| 1298 | } |
| 1299 | |
| 1300 | fn observe_operation( |
| 1301 | repository: &GitRepository, |