mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-14 12:52:55 +00:00
open_file_locked: add options parameter (CreateOptions)
To be able to set file permissions and ownership. This is a breaking change.
This commit is contained in:
parent
a818e74a23
commit
08c2fc4acb
@ -1,7 +1,7 @@
|
|||||||
//! File related utilities such as `replace_file`.
|
//! File related utilities such as `replace_file`.
|
||||||
|
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::File;
|
||||||
use std::io::{self, BufRead, BufReader, Write};
|
use std::io::{self, BufRead, BufReader, Write};
|
||||||
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
|
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
@ -592,12 +592,17 @@ pub fn open_file_locked<P: AsRef<Path>>(
|
|||||||
path: P,
|
path: P,
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
exclusive: bool,
|
exclusive: bool,
|
||||||
|
options: CreateOptions,
|
||||||
) -> Result<File, Error> {
|
) -> Result<File, Error> {
|
||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
let mut file = match OpenOptions::new().create(true).append(true).open(path) {
|
|
||||||
Ok(file) => file,
|
let mut file = atomic_open_or_create_file(
|
||||||
Err(err) => bail!("Unable to open lock {:?} - {}", path, err),
|
path,
|
||||||
};
|
OFlag::O_RDWR | OFlag::O_CLOEXEC | OFlag::O_APPEND,
|
||||||
|
&[],
|
||||||
|
options,
|
||||||
|
)?;
|
||||||
|
|
||||||
match lock_file(&mut file, exclusive, Some(timeout)) {
|
match lock_file(&mut file, exclusive, Some(timeout)) {
|
||||||
Ok(_) => Ok(file),
|
Ok(_) => Ok(file),
|
||||||
Err(err) => bail!("Unable to acquire lock {:?} - {}", path, err),
|
Err(err) => bail!("Unable to acquire lock {:?} - {}", path, err),
|
||||||
|
Loading…
Reference in New Issue
Block a user