Remove now-empty parent directories of a just-deleted path, deepest-first. `std::fs::remove_dir` only succeeds on empty directories, so this is safe: a directory that still holds files is left untouched.
(root: &std::path::Path, removed_rel_path: &str)
| 43 | /// `std::fs::remove_dir` only succeeds on empty directories, so this is safe: |
| 44 | /// a directory that still holds files is left untouched. |
| 45 | fn remove_empty_ancestors(root: &std::path::Path, removed_rel_path: &str) { |
| 46 | let mut ancestor = std::path::Path::new(removed_rel_path).parent(); |
| 47 | while let Some(dir) = ancestor { |
| 48 | if dir.as_os_str().is_empty() || dir == std::path::Path::new(".") { |
| 49 | break; |
| 50 | } |
| 51 | let abs = root.join(dir); |
| 52 | if abs.is_dir() { |
| 53 | // Fails harmlessly if the directory is not empty. |
| 54 | if std::fs::remove_dir(&abs).is_err() { |
| 55 | break; |
| 56 | } |
| 57 | } |
| 58 | ancestor = dir.parent(); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | /// Options controlling a view split. |
| 63 | #[derive(Debug, Clone)] |
no test coverage detected