Skip to content

Commit c84d2ee

Browse files
committed
Code improvement
Signed-off-by: Kasun <[email protected]>
1 parent 374a3e0 commit c84d2ee

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

Cargo.toml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
[package]
22
name = "duplicate-checker"
3-
version = "2.0.0"
3+
version = "2.0.1"
44
edition = "2021"
55
description = "A duplicate file checker"
66
license = "MIT OR Apache-2.0"
77

88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

1010
[dependencies]
11-
rayon = "1.6"
12-
futures = "0.3.0"
13-
ring = "0.16.20"
14-
data-encoding = "2.3.3"
11+
rayon = "1.10.0"
12+
futures = "0.3.30"
13+
ring = "0.17.8"
14+
data-encoding = "2.6.0"
1515
fuzzy-matcher = "0.3.7"
16-
colored = "2.0.0"
17-
spinners = "4.1.0"
18-
clap = { version = "4.3.10", features = ["derive"] }
19-
tokio = { version = "1.32.0", features = ["macros","rt","rt-multi-thread","sync","io-std","io-util","fs"]}
16+
colored = "2.1.0"
17+
spinners = "4.1.1"
18+
clap = { version = "4.5.11", features = ["derive"] }
19+
tokio = { version = "1.39.2", features = [
20+
"macros",
21+
"rt",
22+
"rt-multi-thread",
23+
"sync",
24+
"io-std",
25+
"io-util",
26+
"fs",
27+
] }

src/lib.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub mod searcher {
2424

2525
pub type ResultAsync<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
2626

27-
#[derive(Debug, PartialEq, Eq, Ord)]
27+
#[derive(Debug, PartialEq, Eq)]
2828
pub struct FileData {
2929
pub path: String,
3030
pub file_name: String,
@@ -59,21 +59,27 @@ pub mod searcher {
5959
Self {
6060
path: self.path.clone(),
6161
file_name: self.file_name.clone(),
62-
size: self.size.clone(),
63-
last_modified: self.last_modified.clone(),
64-
is_readonly: self.is_readonly.clone(),
62+
size: self.size,
63+
last_modified: self.last_modified,
64+
is_readonly: self.is_readonly,
6565
sha: self.sha.clone(),
6666
}
6767
}
6868
}
6969

7070
impl PartialOrd for FileData {
7171
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
72+
Some(self.cmp(other))
73+
}
74+
}
75+
76+
impl Ord for FileData {
77+
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
7278
if self.file_name.eq(&other.file_name) {
73-
return Some(self.size.cmp(&other.size));
79+
return self.size.cmp(&other.size);
7480
}
7581

76-
Some(self.file_name.cmp(&other.file_name))
82+
self.file_name.cmp(&other.file_name)
7783
}
7884
}
7985

@@ -91,7 +97,7 @@ pub mod searcher {
9197

9298
pub async fn search_duplicates(cmds: &CmdArgs) {
9399
let msg = format!("Looking in to path {:?}", cmds.root_folder);
94-
let mut sp = Spinner::new(Spinners::Aesthetic, msg.into());
100+
let mut sp = Spinner::new(Spinners::Aesthetic, msg);
95101

96102
let path = PathBuf::from(cmds.root_folder.clone());
97103
let file_data: Vec<FileData> = vec![];
@@ -165,8 +171,7 @@ pub mod searcher {
165171

166172
if !duplicates.is_empty() {
167173
println!(
168-
"{} {} size {}",
169-
"File ",
174+
"File {} size {}",
170175
a_file_date.file_name.bold().green(),
171176
a_file_date.size.to_string().cyan()
172177
);
@@ -194,7 +199,7 @@ pub mod searcher {
194199
if is_score_ok {
195200
return a_file_date.sha.eq_ignore_ascii_case(&file.sha);
196201
}
197-
return false;
202+
false
198203
}
199204
}
200205
}
@@ -310,7 +315,7 @@ pub mod searcher {
310315
size,
311316
last_modified,
312317
is_readonly,
313-
sha: sha,
318+
sha,
314319
};
315320
the_file_data
316321
}
@@ -319,7 +324,7 @@ pub mod searcher {
319324
match fs::metadata(path).await {
320325
Err(err) => {
321326
eprintln!("Error reading metadata {:?} error {:?}", path, err);
322-
return Option::None;
327+
Option::None
323328
}
324329
Ok(metadata) => Option::Some(metadata),
325330
}

0 commit comments

Comments
 (0)