From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id B012B1FF394 for ; Mon, 3 Jun 2024 15:57:14 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id AF2D62E61; Mon, 3 Jun 2024 15:57:41 +0200 (CEST) Date: Mon, 03 Jun 2024 15:57:35 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox Backup Server development discussion References: <20240528094303.309806-1-c.ebner@proxmox.com> <20240528094303.309806-65-c.ebner@proxmox.com> In-Reply-To: <20240528094303.309806-65-c.ebner@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.16.0 (https://github.com/astroidmail/astroid) Message-Id: <1717421421.rzd54jizb2.astroid@yuna.none> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.059 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: Re: [pbs-devel] [PATCH v8 proxmox-backup 64/69] client: pxar: allow to restore prelude to optional path X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" On May 28, 2024 11:42 am, Christian Ebner wrote: > Pxar archives allow to store additional information in a prelude > entry since pxar format version 2. > > Add an optional parameter to `pxar` and `proxmox-backup-client` to > specify the path to restore the prelude to and pass this to the > archive extraction by extending the `PxarExtractOptions` by a > corresponding field. If none is given, the prelude is simply skipped > during restore. > > Signed-off-by: Christian Ebner > --- > changes since version 7: > - no changes > > changes since version 6: > - remove binding to now not returned version return value > > pbs-client/src/pxar/extract.rs | 23 +++++++++++++++++++++-- > proxmox-backup-client/src/main.rs | 12 +++++++++++- > pxar-bin/src/main.rs | 6 ++++++ > 3 files changed, 38 insertions(+), 3 deletions(-) > > diff --git a/pbs-client/src/pxar/extract.rs b/pbs-client/src/pxar/extract.rs > index e22390606..99c0d0e10 100644 > --- a/pbs-client/src/pxar/extract.rs > +++ b/pbs-client/src/pxar/extract.rs > @@ -2,7 +2,8 @@ > > use std::collections::HashMap; > use std::ffi::{CStr, CString, OsStr, OsString}; > -use std::io; > +use std::fs::OpenOptions; > +use std::io::{self, Write}; > use std::os::unix::ffi::OsStrExt; > use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; > use std::path::{Path, PathBuf}; > @@ -37,6 +38,7 @@ pub struct PxarExtractOptions<'a> { > pub allow_existing_dirs: bool, > pub overwrite_flags: OverwriteFlags, > pub on_error: Option, > + pub prelude_path: Option, > } > > bitflags! { > @@ -125,9 +127,26 @@ where > // we use this to keep track of our directory-traversal > decoder.enable_goodbye_entries(true); > > - let (root, _) = handle_root_with_optional_format_version_prelude(&mut decoder) > + let (root, prelude) = handle_root_with_optional_format_version_prelude(&mut decoder) > .context("error reading pxar archive")?; > > + if let Some(ref path) = options.prelude_path { > + if let Some(entry) = prelude { > + let mut prelude_file = OpenOptions::new() > + .create(true) > + .write(true) > + .open(path) > + .with_context(|| format!("error creating prelude file '{path:?}'"))?; > + if let pxar::EntryKind::Prelude(ref prelude) = entry.kind() { > + prelude_file.write_all(prelude.as_os_str().as_bytes())?; > + } else { > + log::info!("unexpected entry kind for prelude"); > + } > + } else { > + log::info!("No prelude entry found, skip prelude restore."); > + } > + } > + > if !root.is_dir() { > bail!("pxar archive does not start with a directory entry!"); > } > diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs > index 87dbb63d5..ad9042857 100644 > --- a/proxmox-backup-client/src/main.rs > +++ b/proxmox-backup-client/src/main.rs > @@ -1433,7 +1433,12 @@ We do not extract '.pxar' archives when writing to standard output. > description: "ignore errors that occur during device node extraction", > optional: true, > default: false, > - } > + }, > + "restore-prelude-to": { > + description: "Path to restore prelude to, (pxar v2 archives only).", > + type: String, > + optional: true, > + }, I don't think we have any other CLI parameters that follow this pattern, maybe something like --prelude-target is a better fit? and in any case, it's lacking completion :) > } > } > )] > @@ -1595,12 +1600,17 @@ async fn restore( > overwrite_flags.insert(pbs_client::pxar::OverwriteFlags::all()); > } > > + let prelude_path = param["restore-prelude-to"] > + .as_str() > + .map(|path| PathBuf::from(path)); > + > let options = pbs_client::pxar::PxarExtractOptions { > match_list: &[], > extract_match_default: true, > allow_existing_dirs, > overwrite_flags, > on_error, > + prelude_path, > }; > > let mut feature_flags = pbs_client::pxar::Flags::DEFAULT; > diff --git a/pxar-bin/src/main.rs b/pxar-bin/src/main.rs > index 8040e5ff4..6aa7d21f0 100644 > --- a/pxar-bin/src/main.rs > +++ b/pxar-bin/src/main.rs > @@ -131,6 +131,10 @@ fn extract_archive_from_reader( > description: "'ppxar' payload input data file to restore split archive.", > optional: true, > }, > + "restore-prelude-to": { > + description: "Path to restore pxar archive prelude to.", > + optional: true, > + }, same applies here > }, > }, > )] > @@ -154,6 +158,7 @@ fn extract_archive( > no_sockets: bool, > strict: bool, > payload_input: Option, > + restore_prelude_to: Option, > ) -> Result<(), Error> { > let mut feature_flags = Flags::DEFAULT; > if no_xattrs { > @@ -227,6 +232,7 @@ fn extract_archive( > overwrite_flags, > extract_match_default, > on_error, > + prelude_path: restore_prelude_to.map(|path| PathBuf::from(path)), > }; > > if archive == "-" { > -- > 2.39.2 > > > > _______________________________________________ > pbs-devel mailing list > pbs-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel > > > _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel