use truncate whenever we create files

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>
This commit is contained in:
Maximiliano Sandoval 2025-01-27 13:10:14 +01:00 committed by Fabian Grünbichler
parent 1cf52c6bb3
commit 600ce36d57
2 changed files with 2 additions and 0 deletions

View File

@ -1711,6 +1711,7 @@ fn try_restore_snapshot_archive<R: pxar::decoder::SeqRead>(
let mut tmpfile = std::fs::OpenOptions::new() let mut tmpfile = std::fs::OpenOptions::new()
.write(true) .write(true)
.create(true) .create(true)
.truncate(true)
.read(true) .read(true)
.open(&tmp_path) .open(&tmp_path)
.map_err(|err| format_err!("restore {:?} failed - {}", tmp_path, err))?; .map_err(|err| format_err!("restore {:?} failed - {}", tmp_path, err))?;

View File

@ -159,6 +159,7 @@ impl SyncSourceReader for RemoteSourceReader {
let tmpfile = std::fs::OpenOptions::new() let tmpfile = std::fs::OpenOptions::new()
.write(true) .write(true)
.create(true) .create(true)
.truncate(true)
.read(true) .read(true)
.open(&tmp_path)?; .open(&tmp_path)?;