Skip to content

Commit 85fcf8f

Browse files
authored
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
1 parent a477e74 commit 85fcf8f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/commands/copy.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! `copy` subcommand
22
33
use crate::{
4-
commands::{get_repository, open_repository},
4+
commands::{get_repository, init::init_password, open_repository},
55
config::AllRepositoryOptions,
66
helpers::table_with_titles,
77
status_err, Application, RUSTIC_APP,
@@ -69,6 +69,7 @@ impl CopyCmd {
6969
for target_opt in &config.copy.targets {
7070
let repo_dest = get_repository(target_opt)?;
7171

72+
info!("copying to target {}...", repo_dest.name);
7273
let repo_dest = if self.init && repo_dest.config_id()?.is_none() {
7374
if config.global.dry_run {
7475
error!(
@@ -79,13 +80,12 @@ impl CopyCmd {
7980
}
8081
let mut config_dest = repo.config().clone();
8182
config_dest.id = Id::random();
82-
let pass = repo_dest.password()?.unwrap();
83+
let pass = init_password(&repo_dest)?;
8384
repo_dest.init_with_config(&pass, &self.key_opts, config_dest)?
8485
} else {
8586
open_repository(target_opt)?
8687
};
8788

88-
info!("copying to target {}...", repo_dest.name);
8989
if poly != repo_dest.config().poly()? {
9090
bail!("cannot copy to repository with different chunker parameter (re-chunking not implemented)!");
9191
}

src/commands/init.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ pub(crate) fn init<P, S>(
8383
key_opts: &KeyOptions,
8484
config_opts: &ConfigOptions,
8585
) -> Result<Repository<P, OpenStatus>> {
86+
let pass = init_password(&repo)?;
87+
Ok(repo.init_with_password(&pass, key_opts, config_opts)?)
88+
}
89+
90+
pub(crate) fn init_password<P, S>(repo: &Repository<P, S>) -> Result<String> {
8691
let pass = repo.password()?.unwrap_or_else(|| {
8792
match Password::new()
8893
.with_prompt("enter password for new key")
@@ -98,5 +103,5 @@ pub(crate) fn init<P, S>(
98103
}
99104
});
100105

101-
Ok(repo.init_with_password(&pass, key_opts, config_opts)?)
106+
Ok(pass)
102107
}

0 commit comments

Comments
 (0)