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 0BC9F1FF14F for ; Fri, 08 May 2026 17:04:10 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id DD8341C2BF; Fri, 8 May 2026 17:04:09 +0200 (CEST) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Subject: [PATCH datacenter-manager 4/4] remote-updates: switch over to pdm_cache Date: Fri, 8 May 2026 17:03:30 +0200 Message-ID: <20260508150330.363622-5-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260508150330.363622-1-l.wagner@proxmox.com> References: <20260508150330.363622-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1778252507343 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: AW3NF3W7MPCGS3D57U2JERP7YBRWQUGU X-Message-ID-Hash: AW3NF3W7MPCGS3D57U2JERP7YBRWQUGU 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: Signed-off-by: Lukas Wagner --- Notes: Should probably add clean-up code for the old cache-file before this is applied server/src/remote_updates.rs | 52 +++++++++++------------------------- 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/server/src/remote_updates.rs b/server/src/remote_updates.rs index 7aaacc46..e0f61da4 100644 --- a/server/src/remote_updates.rs +++ b/server/src/remote_updates.rs @@ -1,6 +1,3 @@ -use std::fs::File; -use std::io::ErrorKind; - use anyhow::{bail, Error}; use serde::{Deserialize, Serialize}; @@ -12,12 +9,11 @@ use pdm_api_types::remote_updates::{ }; use pdm_api_types::remotes::{Remote, RemoteType}; use pdm_api_types::RemoteUpid; -use pdm_buildcfg::PDM_CACHE_DIR_M; -use crate::connection; use crate::parallel_fetcher::ParallelFetcher; +use crate::{connection, pdm_cache}; -pub const UPDATE_CACHE: &str = concat!(PDM_CACHE_DIR_M!(), "/remote-updates.json"); +const UPDATE_SUMMARY_CACHE_KEY: &str = "remote-updates"; #[derive(Clone, Default, Debug, Deserialize, Serialize)] #[serde(rename_all = "kebab-case")] @@ -157,21 +153,10 @@ pub fn get_available_updates_for_remote(remote: &str) -> Result Result { - match File::open(UPDATE_CACHE) { - Ok(file) => { - let content = match serde_json::from_reader(file) { - Ok(cache_content) => cache_content, - Err(err) => { - log::error!("failed to deserialize remote update cache: {err:#}"); - Default::default() - } - }; - - Ok(content) - } - Err(err) if err.kind() == ErrorKind::NotFound => Ok(Default::default()), - Err(err) => Err(err.into()), - } + Ok(pdm_cache::instance() + .read_global()? + .get::(UPDATE_SUMMARY_CACHE_KEY)? + .unwrap_or_default()) } async fn update_cached_summary_for_node( @@ -179,10 +164,11 @@ async fn update_cached_summary_for_node( node: String, node_data: NodeUpdateSummary, ) -> Result<(), Error> { - let mut file = File::open(UPDATE_CACHE)?; - let mut cache_content: UpdateSummary = serde_json::from_reader(&mut file)?; - let remote_entry = - cache_content + let cache = pdm_cache::instance().write_global()?; + let cache_content = cache.get::(UPDATE_SUMMARY_CACHE_KEY)?; + + if let Some(mut entry) = cache_content { + let remote_entry = entry .remotes .entry(remote.id) .or_insert_with(|| RemoteUpdateSummary { @@ -191,15 +177,9 @@ async fn update_cached_summary_for_node( status: RemoteUpdateStatus::Success, }); - remote_entry.nodes.insert(node, node_data); - - let options = proxmox_product_config::default_create_options(); - proxmox_sys::fs::replace_file( - UPDATE_CACHE, - &serde_json::to_vec(&cache_content)?, - options, - true, - )?; + remote_entry.nodes.insert(node, node_data); + cache.set(UPDATE_SUMMARY_CACHE_KEY, &entry)?; + } Ok(()) } @@ -275,8 +255,8 @@ pub async fn refresh_update_summary_cache(remotes: Vec) -> Result<(), Er } } - let options = proxmox_product_config::default_create_options(); - proxmox_sys::fs::replace_file(UPDATE_CACHE, &serde_json::to_vec(&content)?, options, true)?; + let cache = pdm_cache::instance().write_global()?; + cache.set(UPDATE_SUMMARY_CACHE_KEY, &content)?; Ok(()) } -- 2.47.3