Skip to content

Commit c7ef79a

Browse files
authored
Merge pull request #9 from rohit13620h/main
fix: there was a bug in the -i flag where we could not delete the files and only directory delete option was there fixed that by handling the directory and files separately
2 parents f7da935 + b2fe59a commit c7ef79a

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/main.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,29 @@ All the contents from the trash more then {days} days will be deleted permanentl
260260
continue;
261261
}
262262

263-
if ignore {
264-
// not need of seperate function for this
265-
if let Err(e) = fs::remove_dir_all(&path) {
266-
eprintln!(
267-
"{}",
268-
format!("Error deleting with out moving to trash: {e}").red()
269-
)
263+
match (ignore, path.is_dir(), path.is_file()) {
264+
(true, true, _) => {
265+
if let Err(e) = fs::remove_dir_all(&path) {
266+
eprintln!(
267+
"{}",
268+
format!("Error deleting with out moving to trash: {e}").red()
269+
)
270+
}
271+
}
272+
(true, false, true) => {
273+
if let Err(e) = fs::remove_file(&path) {
274+
eprintln!(
275+
"{}",
276+
format!("Error deleting with out moving to trash: {e}").red()
277+
)
278+
}
279+
}
280+
(false, _, _) => {
281+
if let Err(e) = delete(&path) {
282+
eprintln!("{}", format!("Error moving to trash: {e}").red());
283+
}
270284
}
271-
} else if let Err(e) = delete(&path) {
272-
eprintln!("{}", format!("Error moving to trash: {e}").red());
285+
_ => {}
273286
}
274287
}
275288
}

0 commit comments

Comments
 (0)