Skip to content

Commit

Permalink
Apply post_group_filter in rehash on all groups
Browse files Browse the repository at this point in the history
The filter was not applied on items matched by pre-filter
which in some cases led to incorrect reporting of unique files.

Fixes #148
  • Loading branch information
pkolaczk committed Aug 26, 2022
1 parent bfaccd6 commit c92b497
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fclones"
version = "0.27.0"
version = "0.27.1"
description = "Finds duplicate, unique, under- or over-replicated files"
authors = ["Piotr Kołaczkowski <[email protected]>"]
homepage = "https://github.com/pkolaczk/fclones"
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn is_positive_int(v: String) -> Result<(), String> {
return Ok(());
}
}
return Err(format!("Not a positive integer: {}", &*v));
Err(format!("Not a positive integer: {}", &*v))
}

#[derive(Clone, Copy, Debug)]
Expand Down
24 changes: 23 additions & 1 deletion src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,8 @@ where
file_hash: hash,
files: files.to_vec(),
})
.filter(group_post_filter)
.chain(groups_to_pass.into_iter())
.filter(group_post_filter)
.collect()
}

Expand Down Expand Up @@ -1790,6 +1790,28 @@ mod test {
})
}

#[test]
fn unique_files() {
with_dir("main/unique_files", |root| {
let file1 = root.join("file1");
let file2 = root.join("file2");
let file3 = root.join("file3");
write_test_file(&file1, b"duplicate", b"", b"");
write_test_file(&file2, b"duplicate", b"", b"");
write_test_file(&file3, b"unique", b"", b"");

let file3 = Path::from(file3);

let log = test_log();
let mut config = GroupConfig::default();
config.unique = true;
config.paths = vec![file1.into(), file2.into(), file3.clone()];
let results = group_files(&config, &log).unwrap();
assert_eq!(results.len(), 1);
assert_eq!(results[0].files[0].path, file3);
});
}

#[test]
fn report() {
with_dir("main/report", |root| {
Expand Down

0 comments on commit c92b497

Please sign in to comment.