From 2283852f06e49b70f227802bdd5981b7cfe8d6aa Mon Sep 17 00:00:00 2001 From: Mike Panitz Date: Sat, 8 Nov 2025 13:31:20 -0800 Subject: [PATCH 1/2] Follow-up fixes for #112 --- src/fileops.rs | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/fileops.rs b/src/fileops.rs index f9136a1..630bf82 100644 --- a/src/fileops.rs +++ b/src/fileops.rs @@ -664,12 +664,19 @@ pub fn from_stow_cmd(ctx: &Context, stow_path: Option) -> Result<(), Exi None => std::env::current_dir().unwrap(), }; - if dotfiles_dir.exists() { + let old_dotfiles = { + let old_dirname = dotfiles_dir.file_name().unwrap().to_str().unwrap(); + let mut old_dotfiles = dotfiles_dir.clone(); + old_dotfiles.set_file_name(format!("{old_dirname}_old")); + old_dotfiles + }; + + if old_dotfiles.exists() { println!( "{}", format!( - "A dotfiles directory already exists at `{}`\nPlease move it elsewhere or delete it before continuing", - dotfiles_dir.display() + "A dotfiles_old directory already exists at `{}`\nPlease move it elsewhere or delete it before continuing", + old_dotfiles.display() ).red() ); return Err(ExitCode::FAILURE); @@ -701,9 +708,10 @@ pub fn from_stow_cmd(ctx: &Context, stow_path: Option) -> Result<(), Exi if file.is_dir() { if ctx.dry_run { eprintln!("Creating directory `{}`", tuckr_path.display()); + } else { + fs::create_dir_all(tuckr_path).unwrap(); + continue; } - fs::create_dir_all(tuckr_path).unwrap(); - continue; } if ctx.dry_run { @@ -713,17 +721,18 @@ pub fn from_stow_cmd(ctx: &Context, stow_path: Option) -> Result<(), Exi tuckr_path.display() ); } else { - fs::copy(file, tuckr_path).unwrap(); + if let Err(e) = fs::copy(&file, &tuckr_path) { + let error_message = format!( + "Failed to copy `{}` to `{}`: {}", + file.display(), + tuckr_path.display(), + e.to_string() + ); + eprintln!("{}", error_message.red()); + } } } - let old_dotfiles = { - let old_dirname = dotfiles_dir.file_name().unwrap().to_str().unwrap(); - let mut old_dotfiles = dotfiles_dir.clone(); - old_dotfiles.set_file_name(format!("{old_dirname}_old")); - old_dotfiles - }; - if ctx.dry_run { eprintln!( "Moving previous dotfiles (`{}`) to `{}`", @@ -750,11 +759,11 @@ pub fn from_stow_cmd(ctx: &Context, stow_path: Option) -> Result<(), Exi old_dotfiles.display() ); - println!( - "{}\n{}", - dotfiles_converted_msg.green(), - old_dotfiles_location_msg.yellow() - ); + println!("{}", dotfiles_converted_msg.green()); + + if old_dotfiles.exists() { + println!("{}", old_dotfiles_location_msg.yellow()); + } Ok(()) } From f6726413d980cc1765e5e22de78cad6f400a7057 Mon Sep 17 00:00:00 2001 From: Mike Panitz Date: Sun, 16 Nov 2025 18:32:32 -0800 Subject: [PATCH 2/2] Addressing issues --- src/fileops.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fileops.rs b/src/fileops.rs index 630bf82..c94f87d 100644 --- a/src/fileops.rs +++ b/src/fileops.rs @@ -675,7 +675,7 @@ pub fn from_stow_cmd(ctx: &Context, stow_path: Option) -> Result<(), Exi println!( "{}", format!( - "A dotfiles_old directory already exists at `{}`\nPlease move it elsewhere or delete it before continuing", + "A backup directory already exists at `{}`\nPlease move it elsewhere or delete it before continuing", old_dotfiles.display() ).red() ); @@ -710,8 +710,8 @@ pub fn from_stow_cmd(ctx: &Context, stow_path: Option) -> Result<(), Exi eprintln!("Creating directory `{}`", tuckr_path.display()); } else { fs::create_dir_all(tuckr_path).unwrap(); - continue; } + continue; } if ctx.dry_run {