all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH datacenter-manager] namespaced-cache: avoid double path construction and key verification
@ 2026-05-19 11:49 Lukas Wagner
  2026-05-19 21:33 ` applied: " Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Lukas Wagner @ 2026-05-19 11:49 UTC (permalink / raw)
  To: pdm-devel

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





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

* applied: [PATCH datacenter-manager] namespaced-cache: avoid double path construction and key verification
  2026-05-19 11:49 [PATCH datacenter-manager] namespaced-cache: avoid double path construction and key verification Lukas Wagner
@ 2026-05-19 21:33 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2026-05-19 21:33 UTC (permalink / raw)
  To: pdm-devel, Lukas Wagner

On Tue, 19 May 2026 13:49:15 +0200, Lukas Wagner wrote:
> 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.
> 
> [...]

Applied, thanks!

[1/1] namespaced-cache: avoid double path construction and key verification
      commit: fbc66cff24d252854c44f8f1c2a3ac93eec53ef1




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

end of thread, other threads:[~2026-05-19 21:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-19 11:49 [PATCH datacenter-manager] namespaced-cache: avoid double path construction and key verification Lukas Wagner
2026-05-19 21:33 ` applied: " Thomas Lamprecht

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