From 5b72c9b4f71b069eeb88cb1372f45c8667eafc98 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 24 Jul 2019 12:21:25 +0200 Subject: [PATCH] src/pxar/encoder.rs: add new skip_lost_and_found parameter --- src/bin/proxmox-backup-client.rs | 9 ++++++++- src/bin/pxar.rs | 2 +- src/client/pxar_backup_stream.rs | 8 ++++---- src/pxar/encoder.rs | 7 ++++++- tests/catar.rs | 2 +- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index bd0ee15d..7ee43b98 100644 --- a/src/bin/proxmox-backup-client.rs +++ b/src/bin/proxmox-backup-client.rs @@ -153,10 +153,11 @@ fn backup_directory>( chunk_size: Option, device_set: Option>, verbose: bool, + skip_lost_and_found: bool, crypt_config: Option>, ) -> Result<(), Error> { - let pxar_stream = PxarBackupStream::open(dir_path.as_ref(), device_set, verbose)?; + let pxar_stream = PxarBackupStream::open(dir_path.as_ref(), device_set, verbose, skip_lost_and_found)?; let chunk_stream = ChunkStream::new(pxar_stream, chunk_size); let (tx, rx) = mpsc::channel(10); // allow to buffer 10 chunks @@ -419,6 +420,8 @@ fn create_backup( let all_file_systems = param["all-file-systems"].as_bool().unwrap_or(false); + let skip_lost_and_found = param["skip-lost-and-found"].as_bool().unwrap_or(false); + let verbose = param["verbose"].as_bool().unwrap_or(false); let chunk_size_opt = param["chunk-size"].as_u64().map(|v| (v*1024) as usize); @@ -543,6 +546,7 @@ fn create_backup( chunk_size_opt, devices.clone(), verbose, + skip_lost_and_found, crypt_config.clone(), )?; } @@ -1251,6 +1255,9 @@ fn main() { .optional( "verbose", BooleanSchema::new("Verbose output.").default(false)) + .optional( + "skip-lost-and-found", + BooleanSchema::new("Skip lost+found directory").default(false)) .optional( "host-id", StringSchema::new("Use specified ID for the backup group name ('host/'). The default is the system hostname.")) diff --git a/src/bin/pxar.rs b/src/bin/pxar.rs index 3f5aa535..9641b118 100644 --- a/src/bin/pxar.rs +++ b/src/bin/pxar.rs @@ -181,7 +181,7 @@ fn create_archive( feature_flags ^= pxar::CA_FORMAT_WITH_ACL; } - pxar::Encoder::encode(source, &mut dir, &mut writer, devices, verbose, feature_flags)?; + pxar::Encoder::encode(source, &mut dir, &mut writer, devices, verbose, false, feature_flags)?; writer.flush()?; diff --git a/src/client/pxar_backup_stream.rs b/src/client/pxar_backup_stream.rs index 1556ef1c..e80db69c 100644 --- a/src/client/pxar_backup_stream.rs +++ b/src/client/pxar_backup_stream.rs @@ -37,7 +37,7 @@ impl Drop for PxarBackupStream { impl PxarBackupStream { - pub fn new(mut dir: Dir, path: PathBuf, device_set: Option>, verbose: bool) -> Result { + pub fn new(mut dir: Dir, path: PathBuf, device_set: Option>, verbose: bool, skip_lost_and_found: bool) -> Result { let (rx, tx) = nix::unistd::pipe()?; @@ -49,7 +49,7 @@ impl PxarBackupStream { let child = thread::spawn(move|| { let mut writer = unsafe { std::fs::File::from_raw_fd(tx) }; - if let Err(err) = pxar::Encoder::encode(path, &mut dir, &mut writer, device_set, verbose, pxar::CA_FORMAT_DEFAULT) { + if let Err(err) = pxar::Encoder::encode(path, &mut dir, &mut writer, device_set, verbose, skip_lost_and_found, pxar::CA_FORMAT_DEFAULT) { let mut error = error2.lock().unwrap(); *error = Some(err.to_string()); } @@ -65,12 +65,12 @@ impl PxarBackupStream { }) } - pub fn open(dirname: &Path, device_set: Option>, verbose: bool) -> Result { + pub fn open(dirname: &Path, device_set: Option>, verbose: bool, skip_lost_and_found: bool) -> Result { let dir = nix::dir::Dir::open(dirname, OFlag::O_DIRECTORY, Mode::empty())?; let path = std::path::PathBuf::from(dirname); - Self::new(dir, path, device_set, verbose) + Self::new(dir, path, device_set, verbose, skip_lost_and_found) } } diff --git a/src/pxar/encoder.rs b/src/pxar/encoder.rs index 4ffe9064..94957be5 100644 --- a/src/pxar/encoder.rs +++ b/src/pxar/encoder.rs @@ -79,6 +79,7 @@ impl <'a, W: Write> Encoder<'a, W> { writer: &'a mut W, device_set: Option>, verbose: bool, + skip_lost_and_found: bool, // fixme: should be a feature flag ?? feature_flags: u64, ) -> Result<(), Error> { @@ -127,7 +128,11 @@ impl <'a, W: Write> Encoder<'a, W> { if verbose { println!("{:?}", me.full_path()); } - me.encode_dir(dir, &stat, magic, Vec::new())?; + let mut excludes = Vec::new(); + if skip_lost_and_found { + excludes.push(PxarExcludePattern::from_line(b"**/lost+found").unwrap().unwrap()); + } + me.encode_dir(dir, &stat, magic, excludes)?; Ok(()) } diff --git a/tests/catar.rs b/tests/catar.rs index 8f4cc033..cfb822a4 100644 --- a/tests/catar.rs +++ b/tests/catar.rs @@ -26,7 +26,7 @@ fn run_test(dir_name: &str) -> Result<(), Error> { let path = std::path::PathBuf::from(dir_name); - Encoder::encode(path, &mut dir, &mut writer, None, false, CA_FORMAT_DEFAULT)?; + Encoder::encode(path, &mut dir, &mut writer, None, false, false, CA_FORMAT_DEFAULT)?; Command::new("cmp") .arg("--verbose") -- 2.39.2