Skip to content

Commit

Permalink
Windows implementation of filter_hard_links() function (#1316)
Browse files Browse the repository at this point in the history
* Windows implementation of filter_hard_links() function
Implementation of czkawka_core/src/duplicate.rs filter_hard_links(), with new crate file_id 0.2.1 (Don't update anymore! This crate has a bug. I've submitted a patch upstream, but the change is breaking. The current code relies on the bug to work correctly!)

* chore: Update the `Cargo.lock`

* Update Cargo.toml

* Update Cargo.lock

---------

Co-authored-by: BiDuang <[email protected]>
Co-authored-by: Rafał Mikrut <[email protected]>
  • Loading branch information
3 people authored Sep 26, 2024
1 parent c7ce0a4 commit ad832ea
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions czkawka_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ log = "0.4.22"
handsome_logger = "0.8"
fun_time = { version = "0.3", features = ["log"] }

[target.'cfg(windows)'.dependencies]
# Don't update anymore! This crate has a bug. I've submitted a patch upstream, but the change is breaking. The current code relies on the bug to work correctly!
# Warning by CalunVier 2024.7.15
file-id = "=0.2.1"

[build-dependencies]
rustc_version = "0.4"

Expand Down
14 changes: 13 additions & 1 deletion czkawka_core/src/duplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,19 @@ impl PrintResults for DuplicateFinder {

#[cfg(target_family = "windows")]
fn filter_hard_links(vec_file_entry: &[FileEntry]) -> Vec<FileEntry> {
vec_file_entry.to_vec()
let mut inodes: HashSet<u128> = HashSet::with_capacity(vec_file_entry.len());
let mut identical: Vec<FileEntry> = Vec::with_capacity(vec_file_entry.len());
for f in vec_file_entry {
if let Ok(meta) = file_id::get_low_res_file_id(&f.path) {
if let file_id::FileId::HighRes {file_id, ..} = meta {
if !inodes.insert(file_id) {
continue;
}
}
}
identical.push(f.clone());
}
identical
}

#[cfg(target_family = "unix")]
Expand Down

0 comments on commit ad832ea

Please sign in to comment.