all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH 1/2] add tempfile helper without O_TMPFILE or memfd_create
@ 2020-07-23  9:38 Mira Limbeck
  2020-07-23  9:38 ` [pbs-devel] [PATCH 2/2] replace O_TMPFILE file creation with tempfile() Mira Limbeck
  2020-07-23 10:58 ` [pbs-devel] [PATCH 1/2] add tempfile helper without O_TMPFILE or memfd_create Fabian Grünbichler
  0 siblings, 2 replies; 3+ messages in thread
From: Mira Limbeck @ 2020-07-23  9:38 UTC (permalink / raw)
  To: pbs-devel

As WSL does not support O_TMPFILE nor memfd_create, we need a different
way to create tempfiles if we want to support windows host backups
through WSL (without ADS).
The workaround is to use mkstemp in /tmp and unlinking the file
right after creation.

Add FIXME comment to change it back to O_TMPFILE once we no longer require
the mkstemp workaround for windows support.

Signed-off-by: Mira Limbeck <m.limbeck@proxmox.com>
---
 src/tools.rs          |  1 +
 src/tools/tempfile.rs | 13 +++++++++++++
 2 files changed, 14 insertions(+)
 create mode 100644 src/tools/tempfile.rs

diff --git a/src/tools.rs b/src/tools.rs
index 44db796d..5e892d41 100644
--- a/src/tools.rs
+++ b/src/tools.rs
@@ -30,6 +30,7 @@ pub mod fs;
 pub mod format;
 pub mod lru_cache;
 pub mod runtime;
+pub mod tempfile;
 pub mod ticket;
 pub mod timer;
 pub mod statistics;
diff --git a/src/tools/tempfile.rs b/src/tools/tempfile.rs
new file mode 100644
index 00000000..a91ce806
--- /dev/null
+++ b/src/tools/tempfile.rs
@@ -0,0 +1,13 @@
+use nix::unistd::{mkstemp, unlink};
+use std::fs::File;
+use std::os::unix::io::FromRawFd;
+use anyhow;
+
+// FIXME change to O_TMPFILE once a native windows backup client exists
+pub fn tempfile() -> anyhow::Result<File> {
+    let (fd, path) = mkstemp("/tmp/proxmox-backup-client_XXXXXX")?;
+    unlink(path.as_path())?;
+    let file = unsafe { File::from_raw_fd(fd) };
+
+    Ok(file)
+}
-- 
2.20.1





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-23 10:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-23  9:38 [pbs-devel] [PATCH 1/2] add tempfile helper without O_TMPFILE or memfd_create Mira Limbeck
2020-07-23  9:38 ` [pbs-devel] [PATCH 2/2] replace O_TMPFILE file creation with tempfile() Mira Limbeck
2020-07-23 10:58 ` [pbs-devel] [PATCH 1/2] add tempfile helper without O_TMPFILE or memfd_create Fabian Grünbichler

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal