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 DCEA01FF170 for ; Tue, 3 Dec 2024 11:40:20 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A371EB01; Tue, 3 Dec 2024 11:40:26 +0100 (CET) Date: Tue, 03 Dec 2024 11:40:19 +0100 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox Backup Server development discussion References: <20241202131743.417269-1-m.sandoval@proxmox.com> In-Reply-To: <20241202131743.417269-1-m.sandoval@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.16.0 (https://github.com/astroidmail/astroid) Message-Id: <1733221737.l98m8tuhwc.astroid@yuna.none> X-SPAM-LEVEL: Spam detection results: 1 AWL -0.004 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_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [sync.rs, restore.rs, proxmox.com, extract.rs, rust-lang.org, rust-lang.github.io, main.rs] URIBL_SBL_A 0.1 Contains URL's A record listed in the Spamhaus SBL blocklist [185.199.109.153, 185.199.108.153, 185.199.111.153, 185.199.110.153] Subject: Re: [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" On December 2, 2024 2:17 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 > --- > > 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) this one should honor the overwrite flag and not truncate unconditionally (see below) > .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) truncate/create and create_new don't make any sense? IMHO this should probably also honor the overwrite flag instead? if we want to overwrite, I think setting create+truncate would be correct, if we don't want to overwrite, only setting create_new would be the way to go https://doc.rust-lang.org/stable/src/std/sys/pal/unix/fs.rs.html#1144 > .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) same here > .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) this is okay, provided the tape code has locked the snapshot path this is operating in (seems to be the case after a quick glance - @Dominik?) > .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) this is in a locked context, so should be okay as well.. > .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