From dcabbdea4c0b5c74d98d26c8317d2f90b3a43d38 Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Sat, 19 Feb 2022 21:55:19 +0100 Subject: [PATCH] use absolute path for backup --- Cargo.toml | 1 + src/commands/backup.rs | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 741572c..01fc629 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ rpassword = "5" prettytable-rs = {version = "0.8", default-features = false } itertools = "0.10" ignore = "0.4" +path-absolutize = "3" # usefule crates: diff --git a/src/commands/backup.rs b/src/commands/backup.rs index f04b58b..d3826ac 100644 --- a/src/commands/backup.rs +++ b/src/commands/backup.rs @@ -1,12 +1,13 @@ use std::cell::RefCell; use std::fs::File; use std::io::BufReader; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::rc::Rc; use anyhow::Result; use clap::Parser; use ignore::WalkBuilder; +use path_absolutize::*; use crate::backend::{DecryptWriteBackend, ReadBackend}; use crate::blob::{BlobType, Node, Packer, Tree}; @@ -29,12 +30,13 @@ pub(super) fn execute( let config = ConfigFile::from_backend_no_id(be)?; let poly = u64::from_str_radix(config.chunker_polynomial(), 16)?; - backup_file(opts.sources, &poly, be, key)?; + let path = PathBuf::from(&opts.sources[0]); + backup_file(path.absolutize()?, &poly, be, key)?; Ok(()) } fn backup_file( - paths: Vec, + path: impl AsRef, poly: &u64, be: &(impl ReadBackend + DecryptWriteBackend), key: &Key, @@ -46,7 +48,6 @@ fn backup_file( let mut data_packer = Packer::new(be.clone(), indexer.clone(), key.clone())?; let mut tree_packer = Packer::new(be.clone(), indexer.clone(), key.clone())?; - let path = &paths[0]; let mut wb = WalkBuilder::new(path); /* for path in paths[1..].into_iter() { @@ -155,7 +156,7 @@ fn backup_file( // save snapshot let snap = SnapshotFile::new( id, - paths, + vec![path.to_str().unwrap().to_string()], "host".to_string(), "user".to_string(), 0,