[pbs-devel] [PATCH 1/2] add tempfile helper without O_TMPFILE or memfd_create

Mira Limbeck m.limbeck at proxmox.com
Thu Jul 23 11:38:23 CEST 2020


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 at 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






More information about the pbs-devel mailing list