From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id A31171FF15F for ; Mon, 2 Dec 2024 14:17:41 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D658418466; Mon, 2 Dec 2024 14:17:46 +0100 (CET) From: Maximiliano Sandoval To: pbs-devel@lists.proxmox.com Date: Mon, 2 Dec 2024 14:17:43 +0100 Message-Id: <20241202131743.417269-1-m.sandoval@proxmox.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 1 AWL 0.057 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy FSL_BULK_SIG 0.001 Bulk signature with no Unsubscribe KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RAZOR2_CF_RANGE_51_100 1.886 Razor2 gives confidence level above 50% RAZOR2_CHECK 0.922 Listed in Razor2 (http://razor.sf.net/) RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_SBL_A 0.1 Contains URL's A record listed in the Spamhaus SBL blocklist [185.199.110.153, 185.199.108.153, 185.199.109.153, 185.199.111.153] Subject: [pbs-devel] [PATCH backup] use truncate whenever we create files X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "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 --- Some of these are quite obvious (tmp files) but I am not 100% about all of them, a few extra eyes on it would ne appreciated. pbs-client/src/pxar/extract.rs | 1 + proxmox-backup-client/src/main.rs | 2 ++ src/api2/tape/restore.rs | 1 + src/server/sync.rs | 1 + 4 files changed, 5 insertions(+) diff --git a/pbs-client/src/pxar/extract.rs b/pbs-client/src/pxar/extract.rs index cfbd8d51..b3e7d535 100644 --- a/pbs-client/src/pxar/extract.rs +++ b/pbs-client/src/pxar/extract.rs @@ -134,6 +134,7 @@ where if let Some(entry) = prelude { let mut prelude_file = OpenOptions::new() .create(true) + .truncate(true) .write(true) .open(path) .with_context(|| format!("error creating prelude file '{path:?}'"))?; diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs index b0d45f89..9fcf35d7 100644 --- a/proxmox-backup-client/src/main.rs +++ b/proxmox-backup-client/src/main.rs @@ -1597,6 +1597,7 @@ async fn restore( let mut writer = std::fs::OpenOptions::new() .write(true) .create(true) + .truncate(true) .create_new(true) .open(target) .map_err(|err| { @@ -1723,6 +1724,7 @@ async fn restore( std::fs::OpenOptions::new() .write(true) .create(true) + .truncate(true) .create_new(true) .open(target) .map_err(|err| format_err!("unable to create target file {:?} - {}", target, err))? 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( 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 0bd7a7a8..04654c28 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