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

Function remove_empty_ancestors

atomic-repository/src/repository/split.rs:45–60  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

43/// `std::fs::remove_dir` only succeeds on empty directories, so this is safe:
44/// a directory that still holds files is left untouched.
45fn 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)]

Callers 1

split_viewMethod · 0.85

Calls 3

parentMethod · 0.80
is_dirMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected