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 A70FE1FF15C for ; Fri, 14 Nov 2025 13:11:55 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B6AC31171A; Fri, 14 Nov 2025 13:12:51 +0100 (CET) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Date: Fri, 14 Nov 2025 13:11:15 +0100 Message-ID: <20251114121218.2479318-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251114121218.2479318-1-d.csapak@proxmox.com> References: <20251114121218.2479318-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.029 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [mod.rs, views.rs] Subject: [pdm-devel] [PATCH datacenter-manager v2 01/18] lib: pdm-config: views: add locking/saving methods X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" Signed-off-by: Dominik Csapak --- lib/pdm-config/src/views.rs | 22 +++++++++++++++++++--- server/src/views/mod.rs | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/pdm-config/src/views.rs b/lib/pdm-config/src/views.rs index 59c02a66..5f523d07 100644 --- a/lib/pdm-config/src/views.rs +++ b/lib/pdm-config/src/views.rs @@ -1,17 +1,33 @@ use anyhow::Error; +use proxmox_product_config::{open_api_lockfile, replace_config, ApiLockGuard}; use proxmox_section_config::typed::{ApiSectionDataEntry, SectionConfigData}; -use pdm_api_types::views::ViewConfigEntry; +use pdm_api_types::{views::ViewConfigEntry, ConfigDigest}; use pdm_buildcfg::configdir; const VIEW_CFG_FILENAME: &str = configdir!("/views.cfg"); +const VIEW_FILTER_CFG_LOCKFILE: &str = configdir!("/.views.lock"); /// Get the `views.cfg` config file contents. -pub fn config() -> Result, Error> { +pub fn config() -> Result<(SectionConfigData, ConfigDigest), Error> { let content = proxmox_sys::fs::file_read_optional_string(VIEW_CFG_FILENAME)?.unwrap_or_default(); - ViewConfigEntry::parse_section_config(VIEW_CFG_FILENAME, &content) + let digest = openssl::sha::sha256(content.as_bytes()); + + let data = ViewConfigEntry::parse_section_config(VIEW_CFG_FILENAME, &content)?; + Ok((data, digest.into())) +} + +/// Get exclusive lock +pub fn lock_config() -> Result { + open_api_lockfile(VIEW_FILTER_CFG_LOCKFILE, None, true) +} + +pub fn save_config(config: &SectionConfigData) -> Result<(), Error> { + let raw = ViewConfigEntry::write_section_config(VIEW_CFG_FILENAME, config)?; + replace_config(VIEW_CFG_FILENAME, raw.as_bytes())?; + Ok(()) } diff --git a/server/src/views/mod.rs b/server/src/views/mod.rs index 80f8425c..04d39620 100644 --- a/server/src/views/mod.rs +++ b/server/src/views/mod.rs @@ -13,7 +13,7 @@ mod tests; /// Returns an error if the view configuration file could not be read, or /// if the view with the provided ID does not exist. pub fn get_view(view_id: &str) -> Result { - let config = pdm_config::views::config()?; + let (config, _) = pdm_config::views::config()?; let entry = config .get(view_id) -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel