From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH datacenter-manager] namespaced-cache: avoid double path construction and key verification
Date: Tue, 19 May 2026 13:49:15 +0200 [thread overview]
Message-ID: <20260519114915.249323-1-l.wagner@proxmox.com> (raw)
Instead of calling set_impl from set_if_newer_impl, we now pull out
common parts into another function, set_at_path. This ensures that some
of work at the start of the set_impl and set_if_newer_impl is not done
twice (key verification, path construction).
Also, while at it, add a brief comment with regards to why the .unwrap()
is safe when accessing the parent directory of the cache file path.
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
server/src/namespaced_cache.rs | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/server/src/namespaced_cache.rs b/server/src/namespaced_cache.rs
index d7831dca..50c72da8 100644
--- a/server/src/namespaced_cache.rs
+++ b/server/src/namespaced_cache.rs
@@ -603,7 +603,7 @@ fn set_if_newer_impl<T: Serialize + DeserializeOwned>(
Err(err) => return Err(err),
}
- set_impl(inner, key, value, timestamp).map(|()| None)
+ set_at_path(inner, &path, value, timestamp).map(|()| None)
}
fn set_impl<T: Serialize + DeserializeOwned>(
@@ -615,8 +615,22 @@ fn set_impl<T: Serialize + DeserializeOwned>(
ensure_valid_key(key)?;
let path = get_path(&inner.base_path, &inner.namespace, key);
+ set_at_path(inner, &path, value, timestamp)
+}
+
+fn set_at_path<T: Serialize + DeserializeOwned>(
+ inner: &WritableInner,
+ path: &Path,
+ value: T,
+ timestamp: i64,
+) -> Result<(), CacheError> {
+ // unwrap: A namespace directory is always a subdirectory of the base directory
+ // that was passed when initializing `NamespacedCache`, so `.parent()`
+ // always returns Some(...)
+ let namespace_dir = path.parent().unwrap();
+
proxmox_sys::fs::create_path(
- path.parent().unwrap(),
+ namespace_dir,
Some(inner.dir_options),
Some(inner.dir_options),
)?;
--
2.47.3
next reply other threads:[~2026-05-19 11:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-19 11:49 Lukas Wagner [this message]
2026-05-19 21:33 ` applied: [PATCH datacenter-manager] namespaced-cache: avoid double path construction and key verification Thomas Lamprecht
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=20260519114915.249323-1-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox