From: Dietmar Maurer <dietmar@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 2/4] open_file_locked: add options parameter (CreateOptions)
Date: Tue, 20 Jul 2021 13:51:56 +0200 [thread overview]
Message-ID: <20210720115158.376164-6-dietmar@proxmox.com> (raw)
In-Reply-To: <20210720115158.376164-1-dietmar@proxmox.com>
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<P: AsRef<Path>>(
path: P,
timeout: Duration,
exclusive: bool,
+ options: CreateOptions,
) -> Result<File, Error> {
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
next prev parent reply other threads:[~2021-07-20 11:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-20 11:51 [pbs-devel] [PATCH proxmox-apt] depend on proxmox 0.12.0, bump version to 0.5.1-1 Dietmar Maurer
2021-07-20 11:51 ` [pbs-devel] [PATCH proxmox-openid-rs] depend on proxmox 0.12.0, bump version to 0.6.1 Dietmar Maurer
2021-07-20 11:51 ` [pbs-devel] [PATCH proxmox 1/4] new helper atomic_open_or_create_file() Dietmar Maurer
2021-07-20 11:51 ` [pbs-devel] [PATCH proxmox-backup 1/2] use new atomic_open_or_create_file Dietmar Maurer
2021-07-20 11:51 ` [pbs-devel] [PATCH proxmox-backup 2/2] add helpers to write configuration files Dietmar Maurer
2021-07-20 11:51 ` Dietmar Maurer [this message]
2021-07-20 11:51 ` [pbs-devel] [PATCH proxmox 3/4] bump proxmox version to 0.12.0-1 Dietmar Maurer
2021-07-20 11:51 ` [pbs-devel] [PATCH proxmox 4/4] update versions in generated control files Dietmar Maurer
2021-07-20 17:25 ` [pbs-devel] applied-series: [PATCH proxmox-apt] depend on proxmox 0.12.0, bump version to 0.5.1-1 Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210720115158.376164-6-dietmar@proxmox.com \
--to=dietmar@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox