From 85fcf8faabe2f17aca32f6dfcc02eec884d083be Mon Sep 17 00:00:00 2001 From: aawsome <37850842+aawsome@users.noreply.github.com> Date: Wed, 14 Feb 2024 01:58:19 +0100 Subject: [PATCH] fix(commands): Ask for missing password in copy when initializing (#1063) `rustic copy --init` now supports asking for the destination password when initializing the destination repository --- src/commands/copy.rs | 6 +++--- src/commands/init.rs | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/commands/copy.rs b/src/commands/copy.rs index c26e746..5306a00 100644 --- a/src/commands/copy.rs +++ b/src/commands/copy.rs @@ -1,7 +1,7 @@ //! `copy` subcommand use crate::{ - commands::{get_repository, open_repository}, + commands::{get_repository, init::init_password, open_repository}, config::AllRepositoryOptions, helpers::table_with_titles, status_err, Application, RUSTIC_APP, @@ -69,6 +69,7 @@ impl CopyCmd { for target_opt in &config.copy.targets { let repo_dest = get_repository(target_opt)?; + info!("copying to target {}...", repo_dest.name); let repo_dest = if self.init && repo_dest.config_id()?.is_none() { if config.global.dry_run { error!( @@ -79,13 +80,12 @@ impl CopyCmd { } let mut config_dest = repo.config().clone(); config_dest.id = Id::random(); - let pass = repo_dest.password()?.unwrap(); + let pass = init_password(&repo_dest)?; repo_dest.init_with_config(&pass, &self.key_opts, config_dest)? } else { open_repository(target_opt)? }; - info!("copying to target {}...", repo_dest.name); if poly != repo_dest.config().poly()? { bail!("cannot copy to repository with different chunker parameter (re-chunking not implemented)!"); } diff --git a/src/commands/init.rs b/src/commands/init.rs index 718cbf4..0f7ddb4 100644 --- a/src/commands/init.rs +++ b/src/commands/init.rs @@ -83,6 +83,11 @@ pub(crate) fn init( key_opts: &KeyOptions, config_opts: &ConfigOptions, ) -> Result> { + let pass = init_password(&repo)?; + Ok(repo.init_with_password(&pass, key_opts, config_opts)?) +} + +pub(crate) fn init_password(repo: &Repository) -> Result { let pass = repo.password()?.unwrap_or_else(|| { match Password::new() .with_prompt("enter password for new key") @@ -98,5 +103,5 @@ pub(crate) fn init( } }); - Ok(repo.init_with_password(&pass, key_opts, config_opts)?) + Ok(pass) }