all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH v2 stable-2 proxmox-backup 2/2] client: pxar: bail on incompatible format versions
Date: Wed,  5 Jun 2024 17:41:55 +0200	[thread overview]
Message-ID: <20240605154155.2365-3-c.ebner@proxmox.com> (raw)
In-Reply-To: <20240605154155.2365-1-c.ebner@proxmox.com>

Implementing the change detection mode with reusable file payloads
required a breaking change in the pxar file format. Unfortunately,
there initial format does not encode a version for clients to check
compatibility to. Therefore, a pxar format version entry is
introduced in version 2 of the file format.

Add a compatibility check based on that entry also for the client,
making it possible to bail early when an incompatible archive is
encountered.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
 pbs-client/src/catalog_shell.rs |  2 +-
 pbs-client/src/pxar/extract.rs  |  3 +++
 pbs-client/src/pxar/tools.rs    | 14 ++++++++------
 pxar-bin/src/main.rs            |  6 +++++-
 4 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/pbs-client/src/catalog_shell.rs b/pbs-client/src/catalog_shell.rs
index 98af5699..8bb2f3e0 100644
--- a/pbs-client/src/catalog_shell.rs
+++ b/pbs-client/src/catalog_shell.rs
@@ -767,7 +767,7 @@ impl Shell {
 
         let file = Self::walk_pxar_archive(&self.accessor, &mut stack).await?;
         std::io::stdout()
-            .write_all(crate::pxar::format_multi_line_entry(file.entry()).as_bytes())?;
+            .write_all(crate::pxar::format_multi_line_entry(file.entry())?.as_bytes())?;
         Ok(())
     }
 
diff --git a/pbs-client/src/pxar/extract.rs b/pbs-client/src/pxar/extract.rs
index f6c1991f..e8412c3d 100644
--- a/pbs-client/src/pxar/extract.rs
+++ b/pbs-client/src/pxar/extract.rs
@@ -119,6 +119,9 @@ where
             None => current_match,
         };
         match (did_match, entry.kind()) {
+            (_, EntryKind::Version(_)) => {
+                bail!("got format version incompatible with this client");
+            }
             (_, EntryKind::Directory) => {
                 callback(entry.path());
 
diff --git a/pbs-client/src/pxar/tools.rs b/pbs-client/src/pxar/tools.rs
index 844a0f73..afc17dff 100644
--- a/pbs-client/src/pxar/tools.rs
+++ b/pbs-client/src/pxar/tools.rs
@@ -120,12 +120,13 @@ fn format_mtime(mtime: &StatxTimestamp) -> String {
     format!("{}.{}", mtime.secs, mtime.nanos)
 }
 
-pub fn format_single_line_entry(entry: &Entry) -> String {
+pub fn format_single_line_entry(entry: &Entry) -> Result<String, Error> {
     let mode_string = mode_string(entry);
 
     let meta = entry.metadata();
 
     let (size, link) = match entry.kind() {
+        EntryKind::Version(_) => bail!("got format version incompatible with this client"),
         EntryKind::File { size, .. } => (format!("{}", *size), String::new()),
         EntryKind::Symlink(link) => ("0".to_string(), format!(" -> {:?}", link.as_os_str())),
         EntryKind::Hardlink(link) => ("0".to_string(), format!(" -> {:?}", link.as_os_str())),
@@ -135,7 +136,7 @@ pub fn format_single_line_entry(entry: &Entry) -> String {
 
     let owner_string = format!("{}/{}", meta.stat.uid, meta.stat.gid);
 
-    format!(
+    Ok(format!(
         "{} {:<13} {} {:>8} {:?}{}",
         mode_string,
         owner_string,
@@ -143,15 +144,16 @@ pub fn format_single_line_entry(entry: &Entry) -> String {
         size,
         entry.path(),
         link,
-    )
+    ))
 }
 
-pub fn format_multi_line_entry(entry: &Entry) -> String {
+pub fn format_multi_line_entry(entry: &Entry) -> Result<String, Error> {
     let mode_string = mode_string(entry);
 
     let meta = entry.metadata();
 
     let (size, link, type_name) = match entry.kind() {
+        EntryKind::Version(_) => bail!("got format version incompatible with this client"),
         EntryKind::File { size, .. } => (format!("{}", *size), String::new(), "file"),
         EntryKind::Symlink(link) => (
             "0".to_string(),
@@ -185,7 +187,7 @@ pub fn format_multi_line_entry(entry: &Entry) -> String {
         Err(_) => std::borrow::Cow::Owned(format!("{:?}", entry.path())),
     };
 
-    format!(
+    Ok(format!(
         "  File: {}{}\n  \
            Size: {:<13} Type: {}\n\
          Access: ({:o}/{})  Uid: {:<5} Gid: {:<5}\n\
@@ -199,5 +201,5 @@ pub fn format_multi_line_entry(entry: &Entry) -> String {
         meta.stat.uid,
         meta.stat.gid,
         format_mtime(&meta.stat.mtime),
-    )
+    ))
 }
diff --git a/pxar-bin/src/main.rs b/pxar-bin/src/main.rs
index 90887321..9b7de8f4 100644
--- a/pxar-bin/src/main.rs
+++ b/pxar-bin/src/main.rs
@@ -13,6 +13,7 @@ use tokio::signal::unix::{signal, SignalKind};
 
 use pathpatterns::{MatchEntry, MatchType, PatternFlag};
 use pbs_client::pxar::{format_single_line_entry, Flags, PxarExtractOptions, ENCODER_MAX_ENTRIES};
+use pxar::EntryKind;
 
 use proxmox_router::cli::*;
 use proxmox_schema::api;
@@ -409,9 +410,12 @@ async fn mount_archive(archive: String, mountpoint: String, verbose: bool) -> Re
 fn dump_archive(archive: String) -> Result<(), Error> {
     for entry in pxar::decoder::Decoder::open(archive)? {
         let entry = entry?;
+        if let EntryKind::Version(_) = entry.kind() {
+            bail!("got format version incompatible with this client");
+        }
 
         if log::log_enabled!(log::Level::Debug) {
-            log::debug!("{}", format_single_line_entry(&entry));
+            log::debug!("{}", format_single_line_entry(&entry)?);
         } else {
             log::info!("{:?}", entry.path());
         }
-- 
2.30.2



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


      parent reply	other threads:[~2024-06-05 15:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-05 15:41 [pbs-devel] [PATCH v2 stable-2 pxar proxmox-backup 0/2] backport pxar format version check Christian Ebner
2024-06-05 15:41 ` [pbs-devel] [PATCH v2 stable-2 pxar 1/1] format/decoder/accessor: backport pxar entry type `Version` Christian Ebner
2024-06-06  8:21   ` Fabian Grünbichler
2024-06-06  8:49     ` Christian Ebner
2024-06-06  9:05       ` Fabian Grünbichler
2024-06-05 15:41 ` Christian Ebner [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240605154155.2365-3-c.ebner@proxmox.com \
    --to=c.ebner@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal