From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 5204E773E6 for ; Tue, 20 Jul 2021 13:52:08 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4D8618435 for ; Tue, 20 Jul 2021 13:52:08 +0200 (CEST) Received: from elsa.proxmox.com (unknown [94.136.29.99]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3675A841E for ; Tue, 20 Jul 2021 13:52:07 +0200 (CEST) Received: by elsa.proxmox.com (Postfix, from userid 0) id 07F67AE1DE9; Tue, 20 Jul 2021 13:52:03 +0200 (CEST) From: Dietmar Maurer To: pbs-devel@lists.proxmox.com Date: Tue, 20 Jul 2021 13:51:56 +0200 Message-Id: <20210720115158.376164-6-dietmar@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210720115158.376164-1-dietmar@proxmox.com> References: <20210720115158.376164-1-dietmar@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.470 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS 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. [fs.rs] Subject: [pbs-devel] [PATCH proxmox 2/4] open_file_locked: add options parameter (CreateOptions) 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: , X-List-Received-Date: Tue, 20 Jul 2021 11:52:08 -0000 To be able to set file permissions and ownership. This is a breaking change. --- proxmox/src/tools/fs.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/proxmox/src/tools/fs.rs b/proxmox/src/tools/fs.rs index 013fb27..8087cc8 100644 --- a/proxmox/src/tools/fs.rs +++ b/proxmox/src/tools/fs.rs @@ -1,7 +1,7 @@ //! File related utilities such as `replace_file`. use std::ffi::CStr; -use std::fs::{File, OpenOptions}; +use std::fs::File; use std::io::{self, BufRead, BufReader, Write}; use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; use std::path::{Path, PathBuf}; @@ -592,12 +592,17 @@ pub fn open_file_locked>( path: P, timeout: Duration, exclusive: bool, + options: CreateOptions, ) -> Result { let path = path.as_ref(); - let mut file = match OpenOptions::new().create(true).append(true).open(path) { - Ok(file) => file, - Err(err) => bail!("Unable to open lock {:?} - {}", path, err), - }; + + let mut file = atomic_open_or_create_file( + path, + OFlag::O_RDWR | OFlag::O_CLOEXEC | OFlag::O_APPEND, + &[], + options, + )?; + match lock_file(&mut file, exclusive, Some(timeout)) { Ok(_) => Ok(file), Err(err) => bail!("Unable to acquire lock {:?} - {}", path, err), -- 2.30.2