* [pbs-devel] [PATCH proxmox 1/2] atomic_open_or_create_file: catch unsupported flag OFlag::O_DIRECTORY
@ 2021-09-20 6:36 Dietmar Maurer
2021-09-20 6:36 ` [pbs-devel] [PATCH proxmox 2/2] atomic_open_or_create_file: add support for OFlag::O_EXCL Dietmar Maurer
2021-09-22 5:48 ` [pbs-devel] applied: [PATCH proxmox 1/2] atomic_open_or_create_file: catch unsupported flag OFlag::O_DIRECTORY Thomas Lamprecht
0 siblings, 2 replies; 3+ messages in thread
From: Dietmar Maurer @ 2021-09-20 6:36 UTC (permalink / raw)
To: pbs-devel
---
proxmox/src/tools/fs.rs | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/proxmox/src/tools/fs.rs b/proxmox/src/tools/fs.rs
index 6ae4c8a..3283d04 100644
--- a/proxmox/src/tools/fs.rs
+++ b/proxmox/src/tools/fs.rs
@@ -205,6 +205,10 @@ pub fn atomic_open_or_create_file<P: AsRef<Path>>(
bail!("open {:?} failed - unsupported OFlag O_TMPFILE", path);
}
+ if oflag.contains(OFlag::O_DIRECTORY) {
+ bail!("open {:?} failed - unsupported OFlag O_DIRECTORY", path);
+ }
+
oflag.remove(OFlag::O_CREAT); // we want to handle CREAT ourselfes
// Note: 'mode' is ignored, because oflag does not contain O_CREAT or O_TMPFILE
--
2.30.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [pbs-devel] [PATCH proxmox 2/2] atomic_open_or_create_file: add support for OFlag::O_EXCL
2021-09-20 6:36 [pbs-devel] [PATCH proxmox 1/2] atomic_open_or_create_file: catch unsupported flag OFlag::O_DIRECTORY Dietmar Maurer
@ 2021-09-20 6:36 ` Dietmar Maurer
2021-09-22 5:48 ` [pbs-devel] applied: [PATCH proxmox 1/2] atomic_open_or_create_file: catch unsupported flag OFlag::O_DIRECTORY Thomas Lamprecht
1 sibling, 0 replies; 3+ messages in thread
From: Dietmar Maurer @ 2021-09-20 6:36 UTC (permalink / raw)
To: pbs-devel
---
proxmox/src/tools/fs.rs | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/proxmox/src/tools/fs.rs b/proxmox/src/tools/fs.rs
index 3283d04..9d01aae 100644
--- a/proxmox/src/tools/fs.rs
+++ b/proxmox/src/tools/fs.rs
@@ -209,16 +209,25 @@ pub fn atomic_open_or_create_file<P: AsRef<Path>>(
bail!("open {:?} failed - unsupported OFlag O_DIRECTORY", path);
}
+ let exclusive = if oflag.contains(OFlag::O_EXCL) {
+ oflag.remove(OFlag::O_EXCL); // we nned to handle that ourselfes
+ true
+ } else {
+ false
+ };
+
oflag.remove(OFlag::O_CREAT); // we want to handle CREAT ourselfes
- // Note: 'mode' is ignored, because oflag does not contain O_CREAT or O_TMPFILE
- match nix::fcntl::open(path, oflag, stat::Mode::empty()) {
- Ok(fd) => return Ok(unsafe { File::from_raw_fd(fd) }),
- Err(err) => {
- if err.not_found() {
- // fall thrue - try to create the file
- } else {
- bail!("open {:?} failed - {}", path, err);
+ if !exclusive {
+ // Note: 'mode' is ignored, because oflag does not contain O_CREAT or O_TMPFILE
+ match nix::fcntl::open(path, oflag, stat::Mode::empty()) {
+ Ok(fd) => return Ok(unsafe { File::from_raw_fd(fd) }),
+ Err(err) => {
+ if err.not_found() {
+ // fall thrue - try to create the file
+ } else {
+ bail!("open {:?} failed - {}", path, err);
+ }
}
}
}
@@ -266,7 +275,7 @@ pub fn atomic_open_or_create_file<P: AsRef<Path>>(
// the file, let's just open theirs instead:
let _ = nix::unistd::unlink(&temp_file_name);
- if err.already_exists() {
+ if !exclusive && err.already_exists() {
match nix::fcntl::open(path, oflag, stat::Mode::empty()) {
Ok(fd) => Ok(unsafe { File::from_raw_fd(fd) }),
Err(err) => bail!("open {:?} failed - {}", path, err),
--
2.30.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [pbs-devel] applied: [PATCH proxmox 1/2] atomic_open_or_create_file: catch unsupported flag OFlag::O_DIRECTORY
2021-09-20 6:36 [pbs-devel] [PATCH proxmox 1/2] atomic_open_or_create_file: catch unsupported flag OFlag::O_DIRECTORY Dietmar Maurer
2021-09-20 6:36 ` [pbs-devel] [PATCH proxmox 2/2] atomic_open_or_create_file: add support for OFlag::O_EXCL Dietmar Maurer
@ 2021-09-22 5:48 ` Thomas Lamprecht
1 sibling, 0 replies; 3+ messages in thread
From: Thomas Lamprecht @ 2021-09-22 5:48 UTC (permalink / raw)
To: Proxmox Backup Server development discussion, Dietmar Maurer
On 20.09.21 08:36, Dietmar Maurer wrote:
> ---
> proxmox/src/tools/fs.rs | 4 ++++
> 1 file changed, 4 insertions(+)
>
>
for the record: those two patches got already applied
https://git.proxmox.com/?p=proxmox.git;a=commit;h=b46a0720ae20931f2bdc5e0f01155d2aae2a45ce
https://git.proxmox.com/?p=proxmox.git;a=commit;h=b6b9118ce388a6dc631716d5b07c000e9e9fcd18
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-09-22 5:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-20 6:36 [pbs-devel] [PATCH proxmox 1/2] atomic_open_or_create_file: catch unsupported flag OFlag::O_DIRECTORY Dietmar Maurer
2021-09-20 6:36 ` [pbs-devel] [PATCH proxmox 2/2] atomic_open_or_create_file: add support for OFlag::O_EXCL Dietmar Maurer
2021-09-22 5:48 ` [pbs-devel] applied: [PATCH proxmox 1/2] atomic_open_or_create_file: catch unsupported flag OFlag::O_DIRECTORY Thomas Lamprecht
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox