[pbs-devel] [PATCH v9 proxmox-backup 30/58] client: pxar: refactor catalog encoding for directories

Christian Ebner c.ebner at proxmox.com
Wed Jun 5 12:53:48 CEST 2024


Move the catalog directory start and end encoding from `add_entry`
to the `add_directory`, the latter being called by the previous.

By this, the `add_entry` method can be reused to walk the filesystem
tree in the context of an enabled lookahead cache without encoding
anything.

No functional change intended.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
changes since version 8:
- no changes

 pbs-client/src/pxar/create.rs | 38 +++++++++++++++++------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/pbs-client/src/pxar/create.rs b/pbs-client/src/pxar/create.rs
index 1961b9b54..d126b2777 100644
--- a/pbs-client/src/pxar/create.rs
+++ b/pbs-client/src/pxar/create.rs
@@ -690,24 +690,15 @@ impl Archiver {
             }
             mode::IFDIR => {
                 let dir = Dir::from_fd(fd.into_raw_fd())?;
-
-                if let Some(ref catalog) = self.catalog {
-                    catalog.lock().unwrap().start_directory(c_file_name)?;
-                }
-                let result = self
-                    .add_directory(
-                        encoder,
-                        previous_metadata,
-                        dir,
-                        c_file_name,
-                        &metadata,
-                        stat,
-                    )
-                    .await;
-                if let Some(ref catalog) = self.catalog {
-                    catalog.lock().unwrap().end_directory()?;
-                }
-                result
+                self.add_directory(
+                    encoder,
+                    previous_metadata,
+                    dir,
+                    c_file_name,
+                    &metadata,
+                    stat,
+                )
+                .await
             }
             mode::IFSOCK => {
                 if let Some(ref catalog) = self.catalog {
@@ -757,12 +748,15 @@ impl Archiver {
         encoder: &mut Encoder<'_, T>,
         previous_metadata_accessor: &mut Option<Directory<MetadataArchiveReader>>,
         dir: Dir,
-        dir_name: &CStr,
+        c_dir_name: &CStr,
         metadata: &Metadata,
         stat: &FileStat,
     ) -> Result<(), Error> {
-        let dir_name = OsStr::from_bytes(dir_name.to_bytes());
+        let dir_name = OsStr::from_bytes(c_dir_name.to_bytes());
 
+        if let Some(ref catalog) = self.catalog {
+            catalog.lock().unwrap().start_directory(c_dir_name)?;
+        }
         encoder.create_directory(dir_name, metadata).await?;
 
         let old_fs_magic = self.fs_magic;
@@ -804,6 +798,10 @@ impl Archiver {
         self.current_st_dev = old_st_dev;
 
         encoder.finish().await?;
+        if let Some(ref catalog) = self.catalog {
+            catalog.lock().unwrap().end_directory()?;
+        }
+
         result
     }
 
-- 
2.39.2





More information about the pbs-devel mailing list