]> git.proxmox.com Git - pxar.git/commitdiff
encoder: add_symlink
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 5 Mar 2020 10:10:52 +0000 (11:10 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 5 Mar 2020 10:10:52 +0000 (11:10 +0100)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Cargo.toml
src/encoder.rs

index bbfc5ac4a61d7bf218fcebcffea4d8ee005459f5..37993a573b3f8c0be27a9e78646389ec014ec8b7 100644 (file)
@@ -25,6 +25,7 @@ tokio = { version = "0.2.10", optional = true, default-features = false }
 default = [ "futures-io", "tokio-io" ]
 futures-io = [ "futures" ]
 tokio-io = [ "tokio" ]
+
 async-example = [
     "failure",
     "futures-io",
index 97557e88aa52c61543bf4fcbf70a872c04497a77..0c9c1f7b0ed8ae9153b8d67499a716b7ba347b43 100644 (file)
@@ -303,6 +303,35 @@ impl<'a, T: SeqWrite + 'a> EncoderImpl<'a, T> {
         Ok(())
     }
 
+    pub async fn add_symlink(
+        &mut self,
+        metadata: &Metadata,
+        file_name: &Path,
+        target: &Path,
+    ) -> io::Result<()> {
+        self.check();
+
+        let file_offset = (&mut self.output as &mut dyn SeqWrite).position().await?;
+
+        let file_name = file_name.as_os_str().as_bytes();
+        let target = target.as_os_str().as_bytes();
+
+        self.start_file_do(metadata, file_name).await?;
+        (&mut self.output as &mut dyn SeqWrite)
+            .seq_write_pxar_entry_zero(format::PXAR_SYMLINK, target)
+            .await?;
+
+        let end_offset = (&mut self.output as &mut dyn SeqWrite).position().await?;
+
+        self.state.items.push(GoodbyeItem {
+            hash: format::hash_filename(file_name),
+            offset: file_offset,
+            size: end_offset - file_offset,
+        });
+
+        Ok(())
+    }
+
     /// Helper
     #[inline]
     async fn position(&mut self) -> io::Result<u64> {