Merge pull request #47 from bootandy/ab-bug-fix

Ab bug fix
This commit is contained in:
andy boot
2019-12-30 21:12:37 +00:00
committed by GitHub
3 changed files with 21 additions and 3 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ path = "src/main.rs"
[dependencies] [dependencies]
ansi_term = "=0.11" ansi_term = "=0.11"
clap = "=2.33" clap = "=2.33"
jwalk = "0.4" jwalk = "0.4.0"
[dev-dependencies] [dev-dependencies]
assert_cli = "=0.5" assert_cli = "=0.5"
-1
View File
@@ -133,7 +133,6 @@ fn build_tree(biggest_ones: Vec<(String, u64)>, depth: Option<u64>) -> Node {
children: Vec::default(), children: Vec::default(),
}; };
recursively_build_tree(&mut top_parent, n, depth); recursively_build_tree(&mut top_parent, n, depth);
top_parent.children.sort_unstable()
} }
top_parent top_parent
} }
+20 -1
View File
@@ -37,7 +37,7 @@ impl PartialEq for Node {
} }
pub fn is_a_parent_of(parent: &str, child: &str) -> bool { pub fn is_a_parent_of(parent: &str, child: &str) -> bool {
child.starts_with(parent) && child.chars().nth(parent.chars().count()) == Some('/') (child.starts_with(parent) && child.chars().nth(parent.chars().count()) == Some('/')) || parent == "/"
} }
pub fn simplify_dir_names(filenames: Vec<&str>) -> HashSet<String> { pub fn simplify_dir_names(filenames: Vec<&str>) -> HashSet<String> {
@@ -125,6 +125,11 @@ fn examine_dir(
} }
// This path and all its parent paths have their counter incremented // This path and all its parent paths have their counter incremented
for path_name in e.path().ancestors() { for path_name in e.path().ancestors() {
// This is required due to bug in Jwalk that adds '/' to all sub dir lists
// see: https://github.com/jessegrosjean/jwalk/issues/13
if path_name.to_string_lossy() == "/" && top_dir != "/" {
continue
}
let path_name = path_name.to_string_lossy(); let path_name = path_name.to_string_lossy();
let s = data.entry(path_name.to_string()).or_insert(0); let s = data.entry(path_name.to_string()).or_insert(0);
*s += size; *s += size;
@@ -232,4 +237,18 @@ mod tests {
correct.insert("src_v2".to_string()); correct.insert("src_v2".to_string());
assert_eq!(simplify_dir_names(vec!["src/", "src_v2"]), correct); assert_eq!(simplify_dir_names(vec!["src/", "src_v2"]), correct);
} }
#[test]
fn test_is_a_parent_of() {
assert!(is_a_parent_of("/usr", "/usr/andy"));
assert!(is_a_parent_of("/usr", "/usr/andy/i/am/descendant"));
assert!(!is_a_parent_of("/usr/andy", "/usr"));
assert!(!is_a_parent_of("/usr/andy", "/usr/sibling"));
}
#[test]
fn test_is_a_parent_of_root() {
assert!(is_a_parent_of("/", "/usr/andy"));
assert!(is_a_parent_of("/", "/usr"));
}
} }