From 44a5f003cfd009de3033be29febfb7f78d8a4364 Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Wed, 8 Mar 2023 22:32:53 +0100 Subject: [PATCH] Fix paths in snapshot for multiple paths --- src/commands/backup.rs | 23 ++++++----------------- src/repofile/snapshotfile.rs | 12 ++++++++++++ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/commands/backup.rs b/src/commands/backup.rs index 5bd4d85..9ca831b 100644 --- a/src/commands/backup.rs +++ b/src/commands/backup.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use std::str::FromStr; -use anyhow::{anyhow, bail, Result}; +use anyhow::{bail, Result}; use chrono::Local; use clap::{AppSettings, Parser}; use log::*; @@ -172,23 +172,12 @@ pub(super) fn execute( None => None, Some(p) => Some(p.parse_dot()?.to_path_buf()), }; - let backup_path_str = match &as_path { - Some(as_path) => vec![as_path], - None => backup_path.iter().collect(), - }; - let backup_path_str = backup_path_str - .iter() - .map(|p| { - Ok(p.to_str() - .ok_or_else(|| anyhow!("non-unicode path {:?}", backup_path_str))? - .to_string()) - }) - .collect::>>()? - .join("\n"); let mut snap = SnapshotFile::new_from_options(opts.snap_opts, time, command.clone())?; - - snap.paths.add(backup_path_str.clone()); + match &as_path { + Some(p) => snap.paths.set_paths(&[p.to_path_buf()])?, + None => snap.paths.set_paths(&backup_path)?, + }; // get suitable snapshot group from snapshot and opts.group_by. This is used to filter snapshots for the parent detection let group = SnapshotGroup::from_sn( @@ -226,7 +215,7 @@ pub(super) fn execute( archiver.backup_reader( std::io::stdin(), Node::new( - backup_path_str, + opts.stdin_filename, NodeType::File, Metadata::default(), None, diff --git a/src/repofile/snapshotfile.rs b/src/repofile/snapshotfile.rs index 24d44df..e66079d 100644 --- a/src/repofile/snapshotfile.rs +++ b/src/repofile/snapshotfile.rs @@ -550,6 +550,18 @@ impl StringList { } } + pub fn set_paths(&mut self, paths: &[PathBuf]) -> Result<()> { + self.0 = paths + .iter() + .map(|p| { + Ok(p.to_str() + .ok_or_else(|| anyhow!("non-unicode path {:?}", p))? + .to_string()) + }) + .collect::>>()?; + Ok(()) + } + pub fn remove_all(&mut self, string_lists: Vec) { self.0 .retain(|s| !string_lists.iter().any(|sl| sl.contains(s)));