From 4e8cdef7d6d16aa7746165dfefc5fb9de4c4dedf Mon Sep 17 00:00:00 2001 From: santoshxshrestha Date: Wed, 10 Sep 2025 17:06:21 +0545 Subject: [PATCH 01/11] add: regex as deps --- Cargo.lock | 45 +++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + 2 files changed, 46 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 188d205..8f88e22 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -245,6 +254,12 @@ version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" +[[package]] +name = "memchr" +version = "2.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" + [[package]] name = "num-traits" version = "0.2.19" @@ -348,6 +363,35 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "regex" +version = "1.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d7fd106d8c02486a8d64e778353d1cffe08ce79ac2e82f540c86d0facf6912" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b9458fa0bfeeac22b5ca447c63aaf45f28439a709ccd244698632f9aa6394d6" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001" + [[package]] name = "rmxt" version = "0.1.11" @@ -355,6 +399,7 @@ dependencies = [ "chrono", "clap", "colored", + "regex", "tabled", "trash", ] diff --git a/Cargo.toml b/Cargo.toml index ef78fe3..159288d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,5 +14,6 @@ readme = "README.md" chrono = "0.4.41" clap = { version = "4.5.45", features = ["derive"] } colored = "3.0.0" +regex = "1.11.2" tabled = "0.20.0" trash = "5.2.3" From b9a75422cbfeb8aac2d5e42425d5ac2aa5b954e5 Mon Sep 17 00:00:00 2001 From: santoshxshrestha Date: Wed, 10 Sep 2025 17:44:01 +0545 Subject: [PATCH 02/11] feat: name conflict should be removed --- hello.txt | 0 src/main.rs | 22 +++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 hello.txt diff --git a/hello.txt b/hello.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/main.rs b/src/main.rs index 72a2096..7a84735 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use trash::os_limited::restore_all; mod args; use args::Args; use clap::Parser; -use std::fs; +use std::{fs, path::PathBuf}; use trash::os_limited; use trash::{TrashItem, delete}; @@ -104,6 +104,22 @@ pub fn tidy_trash(days: i64) -> Result<(), trash::Error> { Ok(()) } +pub fn check(path: &PathBuf) -> Result<(), Box> { + let trash_list = os_limited::list()?; + if trash_list.is_empty() { + return Ok(()); + }; + + if trash_list.into_iter().any(|item| { + item.name.to_string_lossy().to_string() == path.file_name().unwrap().to_string_lossy() + }) { + eprintln!("{}", format!("Error: An item with the name {:?} already exists in the trash.\nPlease rename the file or empty the trash before proceeding.", path.file_name().unwrap()).red()); + Err("trash name conflict".into()) + } else { + Ok(()) + } +} + fn main() { // parsing the args let args = Args::parse(); @@ -286,6 +302,10 @@ All the contents from the trash more then {days} days will be deleted permanentl } } (false, _, _, _, _) => { + if let Err(e) = check(&path) { + eprintln!("{}", format!("Error checking trash: {e}").red()); + return; + } if let Err(e) = delete(&path) { eprintln!("{}", format!("Error moving to trash: {e}").red()); } From f28e52f54d79eb26616a9d5d378c59c4480cb864 Mon Sep 17 00:00:00 2001 From: santoshxshrestha Date: Wed, 10 Sep 2025 21:27:10 +0545 Subject: [PATCH 03/11] feat: name conflit item will be now renamed --- CHANGELOG.md | 13 ++++++++++- hello.txt | 0 src/main.rs | 62 ++++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 62 insertions(+), 13 deletions(-) delete mode 100644 hello.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 012085f..a8ef5e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.1.12] - 2025-09-07 + +### Changed +- **Conflicting trash items**: Updated logic to handle conflicts when recovering files with the same name. + Now, if a file with the same name exists in the original location, the recovered file will be renamed with a timestamp suffix to avoid overwriting. + +### Fixed + +### Added + ## [0.1.11] - 2025-09-07 ### Changed @@ -17,11 +27,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [0.1.10] - 2025-09-07 ### Fixed + - **Critical ignore flag bug**: Fixed issue where `-i, --ignore` flag was not functioning correctly, causing errors while trying to ingore them while using `rmxt` commands ### Changed -- Imporved different cases handling in the ignore flag logic with match block +- Imporved different cases handling in the ignore flag logic with match block ## [0.1.9] - 2025-09-01 diff --git a/hello.txt b/hello.txt deleted file mode 100644 index e69de29..0000000 diff --git a/src/main.rs b/src/main.rs index 7a84735..df32252 100644 --- a/src/main.rs +++ b/src/main.rs @@ -105,19 +105,51 @@ pub fn tidy_trash(days: i64) -> Result<(), trash::Error> { } pub fn check(path: &PathBuf) -> Result<(), Box> { + let file_name = path + .file_name() + .ok_or("Path does not have a valid filename")? + .to_string_lossy(); + let trash_list = os_limited::list()?; - if trash_list.is_empty() { - return Ok(()); - }; - if trash_list.into_iter().any(|item| { - item.name.to_string_lossy().to_string() == path.file_name().unwrap().to_string_lossy() - }) { - eprintln!("{}", format!("Error: An item with the name {:?} already exists in the trash.\nPlease rename the file or empty the trash before proceeding.", path.file_name().unwrap()).red()); - Err("trash name conflict".into()) - } else { - Ok(()) + let has_conflict = trash_list + .iter() + .any(|item| item.name.to_string_lossy() == file_name); + + if has_conflict { + let timestamp = Local::now().format("%Y%m%d_%H%M%S"); + let stem = path + .file_stem() + .map(|s| s.to_string_lossy()) + .unwrap_or_else(|| file_name.clone()); + let extension = path + .extension() + .map(|ext| format!(".{}", ext.to_string_lossy())) + .unwrap_or_default(); + + let new_name = format!("{}_{}{}", stem, timestamp, extension); + + eprintln!( + "{}", + format!( + "Conflict detected: '{}' already exists in trash. Would be renamed to: '{}'", + file_name, new_name + ) + .yellow() + ); + fs::rename(path, &new_name)?; + + if let Err(e) = delete(&new_name) { + eprintln!( + "{}", + format!("Error moving {} to trash: {e}", path.display()).red() + ); + } + + return Err("Name conflict with existing trash item".into()); } + + Ok(()) } fn main() { @@ -303,11 +335,17 @@ All the contents from the trash more then {days} days will be deleted permanentl } (false, _, _, _, _) => { if let Err(e) = check(&path) { - eprintln!("{}", format!("Error checking trash: {e}").red()); + eprintln!( + "{}", + format!("Error checking trash for {}: {e}", path.display()).red() + ); return; } if let Err(e) = delete(&path) { - eprintln!("{}", format!("Error moving to trash: {e}").red()); + eprintln!( + "{}", + format!("Error moving {} to trash: {e}", path.display()).red() + ); } } _ => {} From af242b902de9440d288834a8b261d0e2793b4c26 Mon Sep 17 00:00:00 2001 From: santoshxshrestha Date: Wed, 10 Sep 2025 21:31:07 +0545 Subject: [PATCH 04/11] deps: I think regex is not need for now --- Cargo.lock | 45 --------------------------------------------- Cargo.toml | 1 - 2 files changed, 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8f88e22..188d205 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,15 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - [[package]] name = "android-tzdata" version = "0.1.1" @@ -254,12 +245,6 @@ version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" -[[package]] -name = "memchr" -version = "2.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" - [[package]] name = "num-traits" version = "0.2.19" @@ -363,35 +348,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "regex" -version = "1.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d7fd106d8c02486a8d64e778353d1cffe08ce79ac2e82f540c86d0facf6912" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b9458fa0bfeeac22b5ca447c63aaf45f28439a709ccd244698632f9aa6394d6" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001" - [[package]] name = "rmxt" version = "0.1.11" @@ -399,7 +355,6 @@ dependencies = [ "chrono", "clap", "colored", - "regex", "tabled", "trash", ] diff --git a/Cargo.toml b/Cargo.toml index 159288d..ef78fe3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,5 @@ readme = "README.md" chrono = "0.4.41" clap = { version = "4.5.45", features = ["derive"] } colored = "3.0.0" -regex = "1.11.2" tabled = "0.20.0" trash = "5.2.3" From f862b33fbffaf84460f8ecbf7a14b4a6b816dd85 Mon Sep 17 00:00:00 2001 From: santoshxshrestha Date: Wed, 10 Sep 2025 21:40:22 +0545 Subject: [PATCH 05/11] refactor: mod --- src/main.rs | 96 +++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/src/main.rs b/src/main.rs index df32252..1f9e07a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -103,53 +103,57 @@ pub fn tidy_trash(days: i64) -> Result<(), trash::Error> { } Ok(()) } - -pub fn check(path: &PathBuf) -> Result<(), Box> { +pub fn resolve_conflict(path: &PathBuf) { let file_name = path .file_name() - .ok_or("Path does not have a valid filename")? + .ok_or("Path does not have a valid filename") + .unwrap() .to_string_lossy(); - let trash_list = os_limited::list()?; - - let has_conflict = trash_list - .iter() - .any(|item| item.name.to_string_lossy() == file_name); + let timestamp = Local::now().format("%Y%m%d_%H%M%S"); + let stem = path + .file_stem() + .map(|s| s.to_string_lossy()) + .unwrap_or_else(|| file_name.clone()); + let extension = path + .extension() + .map(|ext| format!(".{}", ext.to_string_lossy())) + .unwrap_or_default(); - if has_conflict { - let timestamp = Local::now().format("%Y%m%d_%H%M%S"); - let stem = path - .file_stem() - .map(|s| s.to_string_lossy()) - .unwrap_or_else(|| file_name.clone()); - let extension = path - .extension() - .map(|ext| format!(".{}", ext.to_string_lossy())) - .unwrap_or_default(); + let new_name = format!("{}_{}{}", stem, timestamp, extension); - let new_name = format!("{}_{}{}", stem, timestamp, extension); + eprintln!( + "{}", + format!( + "Conflict detected: '{}' already exists in trash. Would be renamed to: '{}'", + file_name, new_name + ) + .yellow() + ); + fs::rename(path, &new_name).unwrap(); + if let Err(e) = delete(&new_name) { eprintln!( "{}", - format!( - "Conflict detected: '{}' already exists in trash. Would be renamed to: '{}'", - file_name, new_name - ) - .yellow() + format!("Error moving {} to trash: {e}", path.display()).red() ); - fs::rename(path, &new_name)?; + } +} - if let Err(e) = delete(&new_name) { - eprintln!( - "{}", - format!("Error moving {} to trash: {e}", path.display()).red() - ); - } +pub fn check_conflict(path: &PathBuf) -> bool { + let file_name = path + .file_name() + .ok_or("Path does not have a valid filename") + .unwrap() + .to_string_lossy(); - return Err("Name conflict with existing trash item".into()); - } + let trash_list = os_limited::list().unwrap(); - Ok(()) + let has_conflict = trash_list + .iter() + .any(|item| item.name.to_string_lossy() == file_name); + + return has_conflict; } fn main() { @@ -334,19 +338,17 @@ All the contents from the trash more then {days} days will be deleted permanentl } } (false, _, _, _, _) => { - if let Err(e) = check(&path) { - eprintln!( - "{}", - format!("Error checking trash for {}: {e}", path.display()).red() - ); - return; - } - if let Err(e) = delete(&path) { - eprintln!( - "{}", - format!("Error moving {} to trash: {e}", path.display()).red() - ); - } + match check_conflict(&path) { + true => resolve_conflict(&path), + false => { + if let Err(e) = delete(&path) { + eprintln!( + "{}", + format!("Error moving {} to trash: {e}", path.display()).red() + ); + } + } + }; } _ => {} } From 1d62e3088903911dee6376bfb91508d99e7e77cc Mon Sep 17 00:00:00 2001 From: santoshxshrestha Date: Wed, 10 Sep 2025 21:57:29 +0545 Subject: [PATCH 06/11] refactor: helper fns --- src/main.rs | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1f9e07a..fcfe665 100644 --- a/src/main.rs +++ b/src/main.rs @@ -104,17 +104,21 @@ pub fn tidy_trash(days: i64) -> Result<(), trash::Error> { Ok(()) } pub fn resolve_conflict(path: &PathBuf) { - let file_name = path - .file_name() - .ok_or("Path does not have a valid filename") - .unwrap() - .to_string_lossy(); + let file_name = match path.file_name() { + Some(name) => name.to_string_lossy(), + None => { + eprintln!("{}", "Path does not have a valid filename".red()); + return; + } + }; let timestamp = Local::now().format("%Y%m%d_%H%M%S"); + let stem = path .file_stem() .map(|s| s.to_string_lossy()) .unwrap_or_else(|| file_name.clone()); + let extension = path .extension() .map(|ext| format!(".{}", ext.to_string_lossy())) @@ -130,7 +134,11 @@ pub fn resolve_conflict(path: &PathBuf) { ) .yellow() ); - fs::rename(path, &new_name).unwrap(); + + if let Err(e) = fs::rename(path, &new_name) { + eprintln!("{}", format!("Error renaming file: {e}").red()); + return; + } if let Err(e) = delete(&new_name) { eprintln!( @@ -141,13 +149,21 @@ pub fn resolve_conflict(path: &PathBuf) { } pub fn check_conflict(path: &PathBuf) -> bool { - let file_name = path - .file_name() - .ok_or("Path does not have a valid filename") - .unwrap() - .to_string_lossy(); + let file_name = match path.file_name() { + Some(name) => name.to_string_lossy(), + None => { + eprintln!("{}", "Path does not have a valid filename".red()); + return false; + } + }; - let trash_list = os_limited::list().unwrap(); + let trash_list = match os_limited::list() { + Ok(items) => items, + Err(e) => { + eprintln!("{}", format!("Error listing trash items: {e}").red()); + return false; + } + }; let has_conflict = trash_list .iter() From 2204ec72f61cface53ed923610a6b8e388254294 Mon Sep 17 00:00:00 2001 From: santoshxshrestha Date: Wed, 10 Sep 2025 22:09:38 +0545 Subject: [PATCH 07/11] refactor: with the result --- src/main.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index fcfe665..aa31a36 100644 --- a/src/main.rs +++ b/src/main.rs @@ -103,12 +103,12 @@ pub fn tidy_trash(days: i64) -> Result<(), trash::Error> { } Ok(()) } -pub fn resolve_conflict(path: &PathBuf) { +pub fn resolve_conflict(path: &PathBuf) -> std::io::Result<()> { let file_name = match path.file_name() { Some(name) => name.to_string_lossy(), None => { eprintln!("{}", "Path does not have a valid filename".red()); - return; + return Ok(()); } }; @@ -135,10 +135,7 @@ pub fn resolve_conflict(path: &PathBuf) { .yellow() ); - if let Err(e) = fs::rename(path, &new_name) { - eprintln!("{}", format!("Error renaming file: {e}").red()); - return; - } + fs::rename(path, &new_name)?; if let Err(e) = delete(&new_name) { eprintln!( @@ -146,6 +143,8 @@ pub fn resolve_conflict(path: &PathBuf) { format!("Error moving {} to trash: {e}", path.display()).red() ); } + + Ok(()) } pub fn check_conflict(path: &PathBuf) -> bool { @@ -355,7 +354,11 @@ All the contents from the trash more then {days} days will be deleted permanentl } (false, _, _, _, _) => { match check_conflict(&path) { - true => resolve_conflict(&path), + true => { + if let Err(e) = resolve_conflict(&path) { + eprintln!("{}", format!("Error resolving conflict: {e}").red()); + } + } false => { if let Err(e) = delete(&path) { eprintln!( From b1921d67c8849d7e0b25c3603a02b77ff0888a26 Mon Sep 17 00:00:00 2001 From: santoshxshrestha Date: Wed, 10 Sep 2025 22:31:40 +0545 Subject: [PATCH 08/11] refactor: changed the name of the variable to make it meaning full --- src/args.rs | 26 +++++++++++++------------- src/main.rs | 19 +++++++++---------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/args.rs b/src/args.rs index 19262a7..4c50fb2 100644 --- a/src/args.rs +++ b/src/args.rs @@ -11,7 +11,7 @@ pub struct Args { #[command(subcommand)] pub command: Option, - /// Don't put the file in trash, remove it permanently + /// Don't put the item in trash, remove it permanently #[arg(short = 'p', long, global = false)] pub permanent: bool, @@ -19,7 +19,7 @@ pub struct Args { #[arg(short = 'r', long, global = false)] pub recursive: bool, - /// Force removal of files without prompt + /// Force removal of item without prompt #[arg(short = 'f', long, global = false)] pub force: bool, @@ -30,15 +30,15 @@ pub struct Args { #[derive(Debug, Subcommand)] pub enum Commands { - /// List files in the trash directory + /// List items in the trash directory #[command(name = "list")] List { - /// Specify time from which to list files (in days) + /// Specify time from which to list items (in days) #[arg(short = 't', long, global = false)] time: Option, }, - /// Clean up the trash directory by removing files older than 30 days + /// Clean up the trash directory by removing files/directories older than 30 days #[command(name = "tidy")] Tidy { /// Specify time to live for tidy command (in days) (default is 30 days) @@ -49,20 +49,20 @@ pub enum Commands { /// recover all the content of the trash #[command(name = "recover-all")] RecoverAll { - /// Specify time from which to recover files (in days) + /// Specify time from which to recover files/directories (in days) #[arg(short = 't', long, global = false)] time: Option, }, - /// Recover files from the trash directory + /// Recover items from the trash directory #[command(name = "recover")] Recover { - /// Name of the file to recover + /// Name of the file/directorie to recover #[arg(help = "Name of the file to recover from trash")] name: Vec, }, - /// Purge files from the trash directory + /// Purge files/directorie from the trash directory #[command(name = "purge")] Purge { /// Purge files from the trash directory @@ -72,8 +72,8 @@ pub enum Commands { } impl Args { - /// Get the files to remove, handling the default case - pub fn get_files(&self) -> Vec { + /// Get the items to remove, handling the default case + pub fn get_items(&self) -> Vec { match &self.command { Some(_) => Vec::new(), // No files for list/tidy/recover commands None => self.file.clone(), // Use the default file argument @@ -113,7 +113,7 @@ impl Args { matches!(self.command, Some(Commands::Purge { .. })) } - /// Get the name to purge (if purge command is active) + /// Get the name of the item to purge (if purge command is active) pub fn get_purge_name(&self) -> Vec { match &self.command { Some(Commands::Purge { name }) => name.clone(), @@ -143,7 +143,7 @@ impl Args { } } - /// Get the time from which to list files for list command + /// Get the time from which to list files/directories for list command pub fn get_time_list(&self) -> i64 { match &self.command { // Default to 0 days (which will be evaluated to all the content)if not specified diff --git a/src/main.rs b/src/main.rs index aa31a36..55bc3ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,8 @@ use chrono::{Local, TimeZone}; use colored::Colorize; -use tabled::{ - Table, Tabled, - settings::{Alignment, Style, object::Columns}, -}; +use tabled::settings::object::Columns; +use tabled::settings::{Alignment, Style}; +use tabled::{Table, Tabled}; use trash::os_limited::restore_all; mod args; use args::Args; @@ -104,7 +103,7 @@ pub fn tidy_trash(days: i64) -> Result<(), trash::Error> { Ok(()) } pub fn resolve_conflict(path: &PathBuf) -> std::io::Result<()> { - let file_name = match path.file_name() { + let name = match path.file_name() { Some(name) => name.to_string_lossy(), None => { eprintln!("{}", "Path does not have a valid filename".red()); @@ -117,7 +116,7 @@ pub fn resolve_conflict(path: &PathBuf) -> std::io::Result<()> { let stem = path .file_stem() .map(|s| s.to_string_lossy()) - .unwrap_or_else(|| file_name.clone()); + .unwrap_or_else(|| name.clone()); let extension = path .extension() @@ -130,7 +129,7 @@ pub fn resolve_conflict(path: &PathBuf) -> std::io::Result<()> { "{}", format!( "Conflict detected: '{}' already exists in trash. Would be renamed to: '{}'", - file_name, new_name + name, new_name ) .yellow() ); @@ -148,7 +147,7 @@ pub fn resolve_conflict(path: &PathBuf) -> std::io::Result<()> { } pub fn check_conflict(path: &PathBuf) -> bool { - let file_name = match path.file_name() { + let name = match path.file_name() { Some(name) => name.to_string_lossy(), None => { eprintln!("{}", "Path does not have a valid filename".red()); @@ -166,7 +165,7 @@ pub fn check_conflict(path: &PathBuf) -> bool { let has_conflict = trash_list .iter() - .any(|item| item.name.to_string_lossy() == file_name); + .any(|item| item.name.to_string_lossy() == name); return has_conflict; } @@ -175,7 +174,7 @@ fn main() { // parsing the args let args = Args::parse(); - let paths = args.get_files(); + let paths = args.get_items(); let recursive = args.recursive; let force = args.force; let dir = args.dir; From 90f1970a85344cc998b2d4573a3f3cd08db9f45f Mon Sep 17 00:00:00 2001 From: santoshxshrestha Date: Wed, 10 Sep 2025 22:38:19 +0545 Subject: [PATCH 09/11] docs: update CHANGELOG.md --- CHANGELOG.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8ef5e5..9424d92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,15 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.1.12] - 2025-09-07 +## [0.1.12] - 2025-09-10 ### Changed -- **Conflicting trash items**: Updated logic to handle conflicts when recovering files with the same name. - Now, if a file with the same name exists in the original location, the recovered file will be renamed with a timestamp suffix to avoid overwriting. +- **Improved variable naming**: Updated variable names to be more descriptive and consistent across the codebase. ### Fixed -### Added +- **Conflicting trash items**: Updated logic to handle conflicts when recovering files with the same name. + Now, if a file with the same name exists in the original location, the recovered file will be renamed with a timestamp suffix to avoid overwriting. + ## [0.1.11] - 2025-09-07 From decdd00cbdb9579ff78376af8535ae3d637789c7 Mon Sep 17 00:00:00 2001 From: santoshxshrestha Date: Wed, 10 Sep 2025 22:43:19 +0545 Subject: [PATCH 10/11] lint: PathBuf to Path as args --- src/main.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 55bc3ae..2e3d0a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use chrono::{Local, TimeZone}; use colored::Colorize; +use std::path::Path; use tabled::settings::object::Columns; use tabled::settings::{Alignment, Style}; use tabled::{Table, Tabled}; @@ -146,7 +147,7 @@ pub fn resolve_conflict(path: &PathBuf) -> std::io::Result<()> { Ok(()) } -pub fn check_conflict(path: &PathBuf) -> bool { +pub fn check_conflict(path: &Path) -> bool { let name = match path.file_name() { Some(name) => name.to_string_lossy(), None => { @@ -167,7 +168,8 @@ pub fn check_conflict(path: &PathBuf) -> bool { .iter() .any(|item| item.name.to_string_lossy() == name); - return has_conflict; + // only did this to make it meaning full for other fn + has_conflict } fn main() { From 1006cf2fcb74faf2a3be05326fe22fa5d76b8a7c Mon Sep 17 00:00:00 2001 From: santoshxshrestha Date: Wed, 10 Sep 2025 22:46:52 +0545 Subject: [PATCH 11/11] linted --- src/main.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2e3d0a1..0cc7bab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -164,12 +164,9 @@ pub fn check_conflict(path: &Path) -> bool { } }; - let has_conflict = trash_list + trash_list .iter() - .any(|item| item.name.to_string_lossy() == name); - - // only did this to make it meaning full for other fn - has_conflict + .any(|item| item.name.to_string_lossy() == name) } fn main() {