Skip to content

Commit

Permalink
fix(backup): run hooks before checking backup source dir
Browse files Browse the repository at this point in the history
  • Loading branch information
aawsome committed Dec 2, 2024
1 parent c571279 commit c17e584
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions src/commands/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,47 +184,47 @@ impl BackupCmd {
}
.to_indexed_ids()?;

let config_snapshot_sources: Vec<_> = snapshot_opts
.iter()
.map(|opt| -> Result<_> {
Ok(PathList::from_iter(&opt.sources)
.sanitize()
.with_context(|| {
format!(
"error sanitizing sources=\"{:?}\" in config file",
opt.sources
)
})?
.merge())
})
.filter_map(|p| match p {
Ok(paths) => Some(paths),
Err(err) => {
warn!("{err}");
None
let hooks = config.backup.hooks.with_context("backup");
hooks.use_with(|| -> Result<_> {
let config_snapshot_sources: Vec<_> = snapshot_opts
.iter()
.map(|opt| -> Result<_> {
Ok(PathList::from_iter(&opt.sources)
.sanitize()
.with_context(|| {
format!(
"error sanitizing sources=\"{:?}\" in config file",
opt.sources
)
})?
.merge())
})
.filter_map(|p| match p {
Ok(paths) => Some(paths),
Err(err) => {
warn!("{err}");
None
}
})
.collect();

let snapshot_sources = match (self.cli_sources.is_empty(), snapshot_opts.is_empty()) {
(false, _) => {
let item = PathList::from_iter(&self.cli_sources).sanitize()?;
vec![item]
}
})
.collect();

let snapshot_sources = match (self.cli_sources.is_empty(), snapshot_opts.is_empty()) {
(false, _) => {
let item = PathList::from_iter(&self.cli_sources).sanitize()?;
vec![item]
}
(true, false) => {
info!("using all backup sources from config file.");
config_snapshot_sources.clone()
}
(true, true) => {
bail!("no backup source given.");
(true, false) => {
info!("using all backup sources from config file.");
config_snapshot_sources.clone()
}
(true, true) => {
bail!("no backup source given.");
}
};
if snapshot_sources.is_empty() {
return Ok(());
}
};
if snapshot_sources.is_empty() {
return Ok(());
}

let hooks = config.backup.hooks.with_context("backup");
hooks.use_with(|| -> Result<_> {
let mut is_err = false;
for sources in snapshot_sources {
let mut opts = self.clone();
Expand Down

0 comments on commit c17e584

Please sign in to comment.