[pbs-devel] [PATCH v4 pxar 6/26] fix #3174: encoder: helper to add to encoder position

Christian Ebner c.ebner at proxmox.com
Thu Nov 9 19:45:54 CET 2023


Adds a helper to allow to increase the encoder position by a given
size. This is used to increase the position when adding an appendix
section to the pxar stream, as these bytes are never encoded directly
but rather referenced by already existing chunks.

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

Changes since v2:
- no changes

Changes since v1:
- add unsafe function signature in order to make it clear that calling
  `position_add` with incorrect size values will break the pxar
  archive encoding.

 src/encoder/aio.rs  | 5 +++++
 src/encoder/mod.rs  | 6 ++++++
 src/encoder/sync.rs | 5 +++++
 3 files changed, 16 insertions(+)

diff --git a/src/encoder/aio.rs b/src/encoder/aio.rs
index 9cc26e0..7379940 100644
--- a/src/encoder/aio.rs
+++ b/src/encoder/aio.rs
@@ -112,6 +112,11 @@ impl<'a, T: SeqWrite + 'a> Encoder<'a, T> {
         self.inner.finish().await
     }
 
+    /// Add size to encoders position and return new position.
+    pub unsafe fn position_add(&mut self, size: u64) -> u64 {
+        unsafe { self.inner.position_add(size) }
+    }
+
     /// Add reference to archive appendix
     pub async fn add_appendix_ref<PF: AsRef<Path>>(
         &mut self,
diff --git a/src/encoder/mod.rs b/src/encoder/mod.rs
index 1d5fe82..14a8262 100644
--- a/src/encoder/mod.rs
+++ b/src/encoder/mod.rs
@@ -676,6 +676,12 @@ impl<'a, T: SeqWrite + 'a> EncoderImpl<'a, T> {
         self.state.write_position
     }
 
+    #[inline]
+    pub unsafe fn position_add(&mut self, size: u64) -> u64 {
+        self.state.write_position += size;
+        self.state.write_position
+    }
+
     pub async fn create_directory(
         &mut self,
         file_name: &Path,
diff --git a/src/encoder/sync.rs b/src/encoder/sync.rs
index c7a7acb..48e4c96 100644
--- a/src/encoder/sync.rs
+++ b/src/encoder/sync.rs
@@ -110,6 +110,11 @@ impl<'a, T: SeqWrite + 'a> Encoder<'a, T> {
         poll_result_once(self.inner.finish())
     }
 
+    /// Add size to encoders position and return new position.
+    pub unsafe fn position_add(&mut self, size: u64) -> u64 {
+        unsafe { self.inner.position_add(size) }
+    }
+
     /// Add reference to archive appendix
     pub async fn add_appendix_ref<PF: AsRef<Path>>(
         &mut self,
-- 
2.39.2






More information about the pbs-devel mailing list