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 84FE6767AB for ; Fri, 16 Jul 2021 10:28:43 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7B767DA73 for ; Fri, 16 Jul 2021 10:28:43 +0200 (CEST) Received: from elsa.proxmox.com (unknown [94.136.29.99]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3A68ADA50 for ; Fri, 16 Jul 2021 10:28:42 +0200 (CEST) Received: by elsa.proxmox.com (Postfix, from userid 0) id E8808AE1D4D; Fri, 16 Jul 2021 10:28:35 +0200 (CEST) From: Dietmar Maurer To: pbs-devel@lists.proxmox.com Date: Fri, 16 Jul 2021 10:28:34 +0200 Message-Id: <20210716082834.2354163-4-dietmar@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210716082834.2354163-1-dietmar@proxmox.com> References: <20210716082834.2354163-1-dietmar@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.490 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 Subject: [pbs-devel] [PATCH proxmox 2/2] 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: Fri, 16 Jul 2021 08:28:43 -0000 To be able to set file permissions and ownership. --- 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 2a93b30..5c269a6 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}; @@ -584,12 +584,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