fix: bug where hard links could be double counted

When running:
dust dir_a dir_b

if a file was hard linked in both dir_a and dir_b it would be double
counted.

This fix resolves this by keeping the shared hashmap around between runs
for the second and subsequent arguments.
https://github.com/bootandy/dust/issues/282
This commit is contained in:
andy.boot
2023-01-04 22:20:59 +00:00
parent a91aa62060
commit f546dbbede
2 changed files with 47 additions and 22 deletions
+2 -1
View File
@@ -31,12 +31,13 @@ pub struct WalkData<'a> {
pub fn walk_it(dirs: HashSet<PathBuf>, walk_data: WalkData) -> (Vec<Node>, bool) {
let permissions_flag = AtomicBool::new(false);
let mut inodes = HashSet::new();
let top_level_nodes: Vec<_> = dirs
.into_iter()
.filter_map(|d| {
clean_inodes(
walk(d, &permissions_flag, &walk_data, 0)?,
&mut HashSet::new(),
&mut inodes,
walk_data.use_apparent_size,
)
})