From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH proxmox-datacenter-manager 2/8] test support: add NamedTempDir helper
Date: Fri, 14 Mar 2025 15:12:19 +0100 [thread overview]
Message-ID: <20250314141225.240768-3-l.wagner@proxmox.com> (raw)
In-Reply-To: <20250314141225.240768-1-l.wagner@proxmox.com>
This one is useful when writing tests, it automatically removes the
temporary directory when dropped.
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
server/src/test_support/temp.rs | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/server/src/test_support/temp.rs b/server/src/test_support/temp.rs
index a3a6d59b..a93c914d 100644
--- a/server/src/test_support/temp.rs
+++ b/server/src/test_support/temp.rs
@@ -31,3 +31,30 @@ impl Drop for NamedTempFile {
let _ = std::fs::remove_file(&self.path);
}
}
+
+/// Temporary directory that is cleaned up when dropped.
+pub struct NamedTempDir {
+ path: PathBuf,
+}
+
+impl NamedTempDir {
+ /// Create a new temporary directory.
+ ///
+ /// The directory will be created with `0o700` permissions.
+ pub fn new() -> Result<Self, Error> {
+ let path = proxmox_sys::fs::make_tmp_dir("/tmp", None)?;
+
+ Ok(Self { path })
+ }
+
+ /// Return the [`Path`] to the temporary directory.
+ pub fn path(&self) -> &Path {
+ &self.path
+ }
+}
+
+impl Drop for NamedTempDir {
+ fn drop(&mut self) {
+ let _ = std::fs::remove_dir_all(&self.path);
+ }
+}
--
2.39.5
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
next prev parent reply other threads:[~2025-03-14 14:13 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-14 14:12 [pdm-devel] [PATCH proxmox-datacenter-manager 0/8] remote task cache fetching task / better cache backend Lukas Wagner
2025-03-14 14:12 ` [pdm-devel] [PATCH proxmox-datacenter-manager 1/8] test support: add NamedTempFile helper Lukas Wagner
2025-04-09 12:50 ` [pdm-devel] applied: " Thomas Lamprecht
2025-03-14 14:12 ` Lukas Wagner [this message]
2025-04-09 12:50 ` [pdm-devel] applied: [PATCH proxmox-datacenter-manager 2/8] test support: add NamedTempDir helper Thomas Lamprecht
2025-03-14 14:12 ` [pdm-devel] [PATCH proxmox-datacenter-manager 3/8] move task_cache.rs to remote_tasks/mod.rs Lukas Wagner
2025-04-09 12:50 ` [pdm-devel] applied: " Thomas Lamprecht
2025-03-14 14:12 ` [pdm-devel] [PATCH proxmox-datacenter-manager 4/8] remote tasks: implement improved cache for remote tasks Lukas Wagner
2025-03-14 14:12 ` [pdm-devel] [PATCH proxmox-datacenter-manager 5/8] remote tasks: add background task for task polling, use new task cache Lukas Wagner
2025-03-20 17:39 ` Thomas Lamprecht
2025-03-21 13:33 ` Lukas Wagner
2025-03-21 13:39 ` Max Carrara
2025-04-11 8:03 ` Lukas Wagner
2025-03-14 14:12 ` [pdm-devel] [PATCH proxmox-datacenter-manager 6/8] pdm-api-types: remote tasks: implement From<&str> for TaskStateType Lukas Wagner
2025-03-14 14:12 ` [pdm-devel] [PATCH proxmox-datacenter-manager 7/8] fake remote: add missing fields to make the debug feature compile again Lukas Wagner
2025-04-09 12:52 ` [pdm-devel] applied: " Thomas Lamprecht
2025-03-14 14:12 ` [pdm-devel] [PATCH proxmox-datacenter-manager 8/8] fake remote: generate fake task data Lukas Wagner
2025-04-09 12:52 ` [pdm-devel] applied: " Thomas Lamprecht
2025-04-11 11:02 ` [pdm-devel] superseded: [PATCH proxmox-datacenter-manager 0/8] remote task cache fetching task / better cache backend Lukas Wagner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250314141225.240768-3-l.wagner@proxmox.com \
--to=l.wagner@proxmox.com \
--cc=pdm-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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