public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH backup v3 1/3] use truncate whenever we create files
@ 2025-01-27 12:10 Maximiliano Sandoval
  2025-01-27 12:10 ` [pbs-devel] [PATCH backup v3 2/3] remove create & truncate when create_new is used Maximiliano Sandoval
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Maximiliano Sandoval @ 2025-01-27 12:10 UTC (permalink / raw)
  To: pbs-devel

Fixes the suspicious_open_options clippy lint, for example:

```
warning: file opened with `create`, but `truncate` behavior not defined
    --> src/api2/tape/restore.rs:1713:18
     |
1713 |                 .create(true)
     |                  ^^^^^^^^^^^^- help: add: `.truncate(true)`
     |
     = help: if you intend to overwrite an existing file entirely, call `.truncate(true)`
     = help: if you instead know that you may want to keep some parts of the old file, call `.truncate(false)`
     = help: alternatively, use `.append(true)` to append to the file instead of overwriting it
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_open_options
```

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
---
Differences from v1:
 - Follow overwrite_flags in pxar extract

 src/api2/tape/restore.rs | 1 +
 src/server/sync.rs       | 1 +
 2 files changed, 2 insertions(+)

diff --git a/src/api2/tape/restore.rs b/src/api2/tape/restore.rs
index 93a6053b..2cc1baab 100644
--- a/src/api2/tape/restore.rs
+++ b/src/api2/tape/restore.rs
@@ -1711,6 +1711,7 @@ fn try_restore_snapshot_archive<R: pxar::decoder::SeqRead>(
             let mut tmpfile = std::fs::OpenOptions::new()
                 .write(true)
                 .create(true)
+                .truncate(true)
                 .read(true)
                 .open(&tmp_path)
                 .map_err(|err| format_err!("restore {:?} failed - {}", tmp_path, err))?;
diff --git a/src/server/sync.rs b/src/server/sync.rs
index 5e3fbdcd..4dd46c5a 100644
--- a/src/server/sync.rs
+++ b/src/server/sync.rs
@@ -159,6 +159,7 @@ impl SyncSourceReader for RemoteSourceReader {
         let tmpfile = std::fs::OpenOptions::new()
             .write(true)
             .create(true)
+            .truncate(true)
             .read(true)
             .open(&tmp_path)?;
 
-- 
2.39.5



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pbs-devel] [PATCH backup v3 2/3] remove create & truncate when create_new is used
  2025-01-27 12:10 [pbs-devel] [PATCH backup v3 1/3] use truncate whenever we create files Maximiliano Sandoval
@ 2025-01-27 12:10 ` Maximiliano Sandoval
  2025-01-27 12:27   ` Fabian Grünbichler
  2025-01-27 12:10 ` [pbs-devel] [PATCH backup v3 3/3] pxar: extract: Follow overwrite_flags when opening file Maximiliano Sandoval
  2025-01-27 12:27 ` [pbs-devel] applied: [PATCH backup v3 1/3] use truncate whenever we create files Fabian Grünbichler
  2 siblings, 1 reply; 7+ messages in thread
From: Maximiliano Sandoval @ 2025-01-27 12:10 UTC (permalink / raw)
  To: pbs-devel

As per its documentation [1]:

> If .create_new(true) is set, .create() and .truncate() are ignored.

This gets rid of the "file opened with `create`, but `truncate`
behavior not defined " clippy warnings.

[1] https://doc.rust-lang.org/std/fs/struct.OpenOptions.html#method.create_new

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
---
 pbs-datastore/src/datastore.rs    | 2 +-
 proxmox-backup-client/src/main.rs | 2 --
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
index fd3990d6..75c0c16a 100644
--- a/pbs-datastore/src/datastore.rs
+++ b/pbs-datastore/src/datastore.rs
@@ -749,9 +749,9 @@ impl DataStore {
 
         let mut open_options = std::fs::OpenOptions::new();
         open_options.write(true);
-        open_options.truncate(true);
 
         if force {
+            open_options.truncate(true);
             open_options.create(true);
         } else {
             open_options.create_new(true);
diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs
index 632a2917..589a097b 100644
--- a/proxmox-backup-client/src/main.rs
+++ b/proxmox-backup-client/src/main.rs
@@ -1598,7 +1598,6 @@ async fn restore(
         if let Some(target) = target {
             let mut writer = std::fs::OpenOptions::new()
                 .write(true)
-                .create(true)
                 .create_new(true)
                 .open(target)
                 .map_err(|err| {
@@ -1724,7 +1723,6 @@ async fn restore(
         let mut writer = if let Some(target) = target {
             std::fs::OpenOptions::new()
                 .write(true)
-                .create(true)
                 .create_new(true)
                 .open(target)
                 .map_err(|err| format_err!("unable to create target file {:?} - {}", target, err))?
-- 
2.39.5



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pbs-devel] [PATCH backup v3 3/3] pxar: extract: Follow overwrite_flags when opening file
  2025-01-27 12:10 [pbs-devel] [PATCH backup v3 1/3] use truncate whenever we create files Maximiliano Sandoval
  2025-01-27 12:10 ` [pbs-devel] [PATCH backup v3 2/3] remove create & truncate when create_new is used Maximiliano Sandoval
@ 2025-01-27 12:10 ` Maximiliano Sandoval
  2025-01-27 12:27   ` [pbs-devel] applied: " Fabian Grünbichler
  2025-01-27 12:27 ` [pbs-devel] applied: [PATCH backup v3 1/3] use truncate whenever we create files Fabian Grünbichler
  2 siblings, 1 reply; 7+ messages in thread
From: Maximiliano Sandoval @ 2025-01-27 12:10 UTC (permalink / raw)
  To: pbs-devel

Signed-off-by: Maximiliano Sandoval <m.sandoval@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



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pbs-devel] applied: [PATCH backup v3 1/3] use truncate whenever we create files
  2025-01-27 12:10 [pbs-devel] [PATCH backup v3 1/3] use truncate whenever we create files Maximiliano Sandoval
  2025-01-27 12:10 ` [pbs-devel] [PATCH backup v3 2/3] remove create & truncate when create_new is used Maximiliano Sandoval
  2025-01-27 12:10 ` [pbs-devel] [PATCH backup v3 3/3] pxar: extract: Follow overwrite_flags when opening file Maximiliano Sandoval
@ 2025-01-27 12:27 ` Fabian Grünbichler
  2 siblings, 0 replies; 7+ messages in thread
From: Fabian Grünbichler @ 2025-01-27 12:27 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion

On January 27, 2025 1:10 pm, Maximiliano Sandoval wrote:
> Fixes the suspicious_open_options clippy lint, for example:
> 
> ```
> warning: file opened with `create`, but `truncate` behavior not defined
>     --> src/api2/tape/restore.rs:1713:18
>      |
> 1713 |                 .create(true)
>      |                  ^^^^^^^^^^^^- help: add: `.truncate(true)`
>      |
>      = help: if you intend to overwrite an existing file entirely, call `.truncate(true)`
>      = help: if you instead know that you may want to keep some parts of the old file, call `.truncate(false)`
>      = help: alternatively, use `.append(true)` to append to the file instead of overwriting it
>      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_open_options
> ```
> 
> Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
> ---
> Differences from v1:
>  - Follow overwrite_flags in pxar extract
> 
>  src/api2/tape/restore.rs | 1 +
>  src/server/sync.rs       | 1 +
>  2 files changed, 2 insertions(+)
> 
> diff --git a/src/api2/tape/restore.rs b/src/api2/tape/restore.rs
> index 93a6053b..2cc1baab 100644
> --- a/src/api2/tape/restore.rs
> +++ b/src/api2/tape/restore.rs
> @@ -1711,6 +1711,7 @@ fn try_restore_snapshot_archive<R: pxar::decoder::SeqRead>(
>              let mut tmpfile = std::fs::OpenOptions::new()
>                  .write(true)
>                  .create(true)
> +                .truncate(true)
>                  .read(true)
>                  .open(&tmp_path)
>                  .map_err(|err| format_err!("restore {:?} failed - {}", tmp_path, err))?;
> diff --git a/src/server/sync.rs b/src/server/sync.rs
> index 5e3fbdcd..4dd46c5a 100644
> --- a/src/server/sync.rs
> +++ b/src/server/sync.rs
> @@ -159,6 +159,7 @@ impl SyncSourceReader for RemoteSourceReader {
>          let tmpfile = std::fs::OpenOptions::new()
>              .write(true)
>              .create(true)
> +            .truncate(true)
>              .read(true)
>              .open(&tmp_path)?;
>  
> -- 
> 2.39.5
> 
> 
> 
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
> 
> 
> 


_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [pbs-devel] [PATCH backup v3 2/3] remove create & truncate when create_new is used
  2025-01-27 12:10 ` [pbs-devel] [PATCH backup v3 2/3] remove create & truncate when create_new is used Maximiliano Sandoval
@ 2025-01-27 12:27   ` Fabian Grünbichler
  2025-01-27 12:37     ` Maximiliano Sandoval
  0 siblings, 1 reply; 7+ messages in thread
From: Fabian Grünbichler @ 2025-01-27 12:27 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion

this one I already applied in v2?

On January 27, 2025 1:10 pm, Maximiliano Sandoval wrote:
> As per its documentation [1]:
> 
>> If .create_new(true) is set, .create() and .truncate() are ignored.
> 
> This gets rid of the "file opened with `create`, but `truncate`
> behavior not defined " clippy warnings.
> 
> [1] https://doc.rust-lang.org/std/fs/struct.OpenOptions.html#method.create_new
> 
> Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
> ---
>  pbs-datastore/src/datastore.rs    | 2 +-
>  proxmox-backup-client/src/main.rs | 2 --
>  2 files changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
> index fd3990d6..75c0c16a 100644
> --- a/pbs-datastore/src/datastore.rs
> +++ b/pbs-datastore/src/datastore.rs
> @@ -749,9 +749,9 @@ impl DataStore {
>  
>          let mut open_options = std::fs::OpenOptions::new();
>          open_options.write(true);
> -        open_options.truncate(true);
>  
>          if force {
> +            open_options.truncate(true);
>              open_options.create(true);
>          } else {
>              open_options.create_new(true);
> diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs
> index 632a2917..589a097b 100644
> --- a/proxmox-backup-client/src/main.rs
> +++ b/proxmox-backup-client/src/main.rs
> @@ -1598,7 +1598,6 @@ async fn restore(
>          if let Some(target) = target {
>              let mut writer = std::fs::OpenOptions::new()
>                  .write(true)
> -                .create(true)
>                  .create_new(true)
>                  .open(target)
>                  .map_err(|err| {
> @@ -1724,7 +1723,6 @@ async fn restore(
>          let mut writer = if let Some(target) = target {
>              std::fs::OpenOptions::new()
>                  .write(true)
> -                .create(true)
>                  .create_new(true)
>                  .open(target)
>                  .map_err(|err| format_err!("unable to create target file {:?} - {}", target, err))?
> -- 
> 2.39.5
> 
> 
> 
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
> 
> 
> 


_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [pbs-devel] applied: [PATCH backup v3 3/3] pxar: extract: Follow overwrite_flags when opening file
  2025-01-27 12:10 ` [pbs-devel] [PATCH backup v3 3/3] pxar: extract: Follow overwrite_flags when opening file Maximiliano Sandoval
@ 2025-01-27 12:27   ` Fabian Grünbichler
  0 siblings, 0 replies; 7+ messages in thread
From: Fabian Grünbichler @ 2025-01-27 12:27 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion

On January 27, 2025 1:10 pm, Maximiliano Sandoval wrote:
> Signed-off-by: Maximiliano Sandoval <m.sandoval@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
> 
> 
> 
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
> 
> 
> 


_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [pbs-devel] [PATCH backup v3 2/3] remove create & truncate when create_new is used
  2025-01-27 12:27   ` Fabian Grünbichler
@ 2025-01-27 12:37     ` Maximiliano Sandoval
  0 siblings, 0 replies; 7+ messages in thread
From: Maximiliano Sandoval @ 2025-01-27 12:37 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion


Fabian Grünbichler <f.gruenbichler@proxmox.com> writes:

> this one I already applied in v2?

It landed in the git repo after this email was sent.



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-01-27 12:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-27 12:10 [pbs-devel] [PATCH backup v3 1/3] use truncate whenever we create files Maximiliano Sandoval
2025-01-27 12:10 ` [pbs-devel] [PATCH backup v3 2/3] remove create & truncate when create_new is used Maximiliano Sandoval
2025-01-27 12:27   ` Fabian Grünbichler
2025-01-27 12:37     ` Maximiliano Sandoval
2025-01-27 12:10 ` [pbs-devel] [PATCH backup v3 3/3] pxar: extract: Follow overwrite_flags when opening file Maximiliano Sandoval
2025-01-27 12:27   ` [pbs-devel] applied: " Fabian Grünbichler
2025-01-27 12:27 ` [pbs-devel] applied: [PATCH backup v3 1/3] use truncate whenever we create files Fabian Grünbichler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal