From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 1E484655DE for ; Thu, 23 Jul 2020 11:38:59 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 146FC276EA for ; Thu, 23 Jul 2020 11:38:29 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 477A1276DA for ; Thu, 23 Jul 2020 11:38:28 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 0B04F43339 for ; Thu, 23 Jul 2020 11:38:28 +0200 (CEST) From: Mira Limbeck To: pbs-devel@lists.proxmox.com Date: Thu, 23 Jul 2020 11:38:23 +0200 Message-Id: <20200723093824.20056-1-m.limbeck@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.634 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods NO_DNS_FOR_FROM 0.379 Envelope sender has no MX or A DNS records RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record SUBJ_OBFU_PUNCT_FEW 0.749 Possible punctuation-obfuscated Subject: header Subject: [pbs-devel] [PATCH 1/2] add tempfile helper without O_TMPFILE or memfd_create X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jul 2020 09:38:59 -0000 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 --- 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 { + 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