From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 385131FF141 for ; Tue, 19 May 2026 13:49:22 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1391947C1; Tue, 19 May 2026 13:49:22 +0200 (CEST) From: Lukas Wagner 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 Message-ID: <20260519114915.249323-1-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1779191342954 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.054 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: OLTYSDKNDOUQ22RH6GDIIUU2PGW2NDDF X-Message-ID-Hash: OLTYSDKNDOUQ22RH6GDIIUU2PGW2NDDF X-MailFrom: l.wagner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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( 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( @@ -615,8 +615,22 @@ fn set_impl( 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( + 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