[pbs-devel] [RFC proxmox-backup 13/20] fix #3174: archiver/extractor: impl appendix ref

Christian Ebner c.ebner at proxmox.com
Fri Sep 22 09:16:14 CEST 2023


Implements the functionality to create and extract appendix references
via the pbs client.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
 pbs-client/src/pxar/create.rs  | 13 +++++++++++++
 pbs-client/src/pxar/extract.rs | 16 ++++++++++++++++
 pbs-client/src/pxar/tools.rs   |  8 ++++++++
 3 files changed, 37 insertions(+)

diff --git a/pbs-client/src/pxar/create.rs b/pbs-client/src/pxar/create.rs
index 0f23ed2f..0468abe9 100644
--- a/pbs-client/src/pxar/create.rs
+++ b/pbs-client/src/pxar/create.rs
@@ -734,6 +734,19 @@ impl Archiver {
         Ok(out.file_offset())
     }
 
+    async fn add_appendix_ref<T: SeqWrite + Send>(
+        &mut self,
+        encoder: &mut Encoder<'_, T>,
+        file_name: &Path,
+        metadata: &Metadata,
+        appendix_offset: u64,
+        file_size: u64,
+    ) -> Result<(), Error> {
+        Ok(encoder
+            .add_appendix_ref(metadata, file_name, appendix_offset, file_size)
+            .await?)
+    }
+
     async fn add_symlink<T: SeqWrite + Send>(
         &mut self,
         encoder: &mut Encoder<'_, T>,
diff --git a/pbs-client/src/pxar/extract.rs b/pbs-client/src/pxar/extract.rs
index f78e06c2..d2d42749 100644
--- a/pbs-client/src/pxar/extract.rs
+++ b/pbs-client/src/pxar/extract.rs
@@ -74,6 +74,7 @@ struct ExtractorIterState {
     err_path_stack: Vec<OsString>,
     current_match: bool,
     end_reached: bool,
+    appendix_list: Vec<(PathBuf, u64, u64)>,
 }
 
 /// An [`Iterator`] that encapsulates the process of extraction in [extract_archive].
@@ -98,6 +99,7 @@ impl ExtractorIterState {
             err_path_stack: Vec::new(),
             current_match: options.extract_match_default,
             end_reached: false,
+            appendix_list: Vec::new(),
         }
     }
 }
@@ -373,6 +375,20 @@ where
                 }
                 .context(PxarExtractContext::ExtractFile)
             }
+            (
+                true,
+                EntryKind::AppendixRef {
+                    appendix_offset,
+                    file_size,
+                },
+            ) => {
+                self.state.appendix_list.push((
+                    entry.path().to_path_buf(),
+                    *appendix_offset,
+                    *file_size,
+                ));
+                Ok(())
+            }
             (false, _) => Ok(()), // skip this
         };
 
diff --git a/pbs-client/src/pxar/tools.rs b/pbs-client/src/pxar/tools.rs
index 0cfbaf5b..aac5a1e7 100644
--- a/pbs-client/src/pxar/tools.rs
+++ b/pbs-client/src/pxar/tools.rs
@@ -156,6 +156,14 @@ pub fn format_multi_line_entry(entry: &Entry) -> String {
 
     let (size, link, type_name) = match entry.kind() {
         EntryKind::File { size, .. } => (format!("{}", *size), String::new(), "file"),
+        EntryKind::AppendixRef {
+            appendix_offset,
+            file_size,
+        } => (
+            format!("{} {}", appendix_offset, file_size),
+            String::new(),
+            "appendix ref",
+        ),
         EntryKind::Symlink(link) => (
             "0".to_string(),
             format!(" -> {:?}", link.as_os_str()),
-- 
2.39.2






More information about the pbs-devel mailing list