[pbs-devel] [PATCH backup v3 3/3] pxar: extract: Follow overwrite_flags when opening file

Maximiliano Sandoval m.sandoval at proxmox.com
Mon Jan 27 13:10:16 CET 2025


Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
---
 pbs-client/src/pxar/extract.rs | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/pbs-client/src/pxar/extract.rs b/pbs-client/src/pxar/extract.rs
index 64754006..6b0e6302 100644
--- a/pbs-client/src/pxar/extract.rs
+++ b/pbs-client/src/pxar/extract.rs
@@ -133,9 +133,18 @@ where
 
         if let Some(ref path) = options.prelude_path {
             if let Some(entry) = prelude {
-                let mut prelude_file = OpenOptions::new()
-                    .create(true)
-                    .write(true)
+                let overwrite = options.overwrite_flags.contains(OverwriteFlags::FILE);
+
+                let mut open_options = OpenOptions::new();
+                open_options.write(true);
+                if overwrite {
+                    open_options.create(true);
+                    open_options.truncate(true);
+                } else {
+                    open_options.create_new(true);
+                }
+
+                let mut prelude_file = open_options
                     .open(path)
                     .with_context(|| format!("error creating prelude file '{path:?}'"))?;
                 if let pxar::EntryKind::Prelude(ref prelude) = entry.kind() {
-- 
2.39.5





More information about the pbs-devel mailing list