Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/commands/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
status_err,
};
use abscissa_core::{Command, FrameworkError, Runnable, Shutdown, config::Override};
use anyhow::{Result, bail};
use anyhow::{Result, anyhow, bail};
use conflate::Merge;
use log::{Level, error, info, log};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -87,6 +87,7 @@ impl CopyCmd {
// sort for nicer output
snapshots.sort_unstable();

let mut is_err = false;
for target in &config.copy.targets {
let mut merge_logs = Vec::new();
let mut target_config = RusticConfig::default();
Expand All @@ -100,9 +101,14 @@ impl CopyCmd {
target_opt.run(|target_repo| self.copy(&repo, target_repo, target_opt, &snapshots))
{
error!("error copying to target: {err}");
is_err = true;
}
}
Ok(())
if is_err {
Err(anyhow!("Copying failed for at least one target!"))
} else {
Ok(())
}
}

fn copy(
Expand Down
32 changes: 32 additions & 0 deletions tests/backup_restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,35 @@ fn test_backup_and_restore_passes() -> TestResult<()> {

Ok(())
}

#[test]
fn test_copy_to_failing_target_fails() -> TestResult<()> {
let temp_dir = setup()?;
let backup = src_snapshot()?.into_path();

rustic_runner(&temp_dir)?
.arg("backup")
.arg(backup.path())
.assert()
.success();

// a target profile whose repository doesn't exist
let target = temp_dir.path().join("target");
std::fs::write(
target.with_extension("toml"),
format!(
"[repository]\nrepository = {:?}\npassword = \"test\"\n",
temp_dir.path().join("nowhere")
),
)?;

rustic_runner(&temp_dir)?
.arg("copy")
.arg("--target")
.arg(&target)
.assert()
.failure()
.stderr(predicate::str::contains("error copying to target"));

Ok(())
}