From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH datacenter-manager] remote.cfg: clean up shadow entries for non-existent remotes
Date: Tue, 2 Dec 2025 08:18:34 +0100 [thread overview]
Message-ID: <20251202071856.112200-1-f.gruenbichler@proxmox.com> (raw)
this requires restructuring the code a bit, since it is now necessary to read
both configs always.
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
lib/pdm-config/src/remotes.rs | 67 ++++++++++++++++++++---------------
1 file changed, 38 insertions(+), 29 deletions(-)
diff --git a/lib/pdm-config/src/remotes.rs b/lib/pdm-config/src/remotes.rs
index 677981f..6462fde 100644
--- a/lib/pdm-config/src/remotes.rs
+++ b/lib/pdm-config/src/remotes.rs
@@ -3,7 +3,7 @@
//! Make sure to call [`init`] to inject a concrete `RemoteConfig` instance
//! before calling the [`lock_config`], [`config`] or [`save_config`] functions.
-use std::{collections::HashMap, sync::OnceLock};
+use std::{collections::HashSet, sync::OnceLock};
use anyhow::{bail, Error};
@@ -87,41 +87,50 @@ impl RemoteConfig for DefaultRemoteConfig {
}
fn save_config(&self, mut config: SectionConfigData<Remote>) -> Result<(), Error> {
- let mut new_shadow_entries = HashMap::new();
- for (id, remote) in config.iter() {
+ let shadow_content = proxmox_sys::fs::file_read_optional_string(REMOTES_SHADOW_FILENAME)?
+ .unwrap_or_default();
+
+ let mut shadow_config =
+ RemoteShadow::parse_section_config(REMOTES_SHADOW_FILENAME, &shadow_content)?;
+
+ // collect valid remotes
+ let mut remote_ids = HashSet::new();
+
+ // collect any remotes which are not yet shadowed
+ let new_shadow_entries = config.iter().fold(Vec::new(), |mut entries, (id, remote)| {
if remote.token != "-" {
- new_shadow_entries.insert(
- id.to_string(),
- RemoteShadow {
- ty: remote.ty,
- id: remote.id.clone(),
- token: remote.token.clone(),
- },
- );
+ entries.push(RemoteShadow {
+ ty: remote.ty,
+ id: remote.id.clone(),
+ token: remote.token.clone(),
+ });
+ }
+ remote_ids.insert(id.to_string());
+ entries
+ });
+
+ // remove leftover shadow entries
+ let shadow_ids = shadow_config.keys().cloned().collect::<Vec<String>>();
+ for id in shadow_ids.iter() {
+ if !remote_ids.contains(id) {
+ shadow_config.remove(id);
}
}
- // only read and modify shadow config if needed
- if !new_shadow_entries.is_empty() {
- let shadow_content =
- proxmox_sys::fs::file_read_optional_string(REMOTES_SHADOW_FILENAME)?
- .unwrap_or_default();
-
- let mut shadow_config =
- RemoteShadow::parse_section_config(REMOTES_SHADOW_FILENAME, &shadow_content)?;
-
- for (id, shadow_entry) in new_shadow_entries.into_iter() {
- if let Some(remote) = config.get_mut(&id) {
- remote.token = '-'.to_string();
- }
- shadow_config.insert(id, shadow_entry);
+ // add new shadow entries
+ for entry in new_shadow_entries.into_iter() {
+ if let Some(remote) = config.get_mut(&entry.id) {
+ remote.token = "-".to_string();
}
- let raw = RemoteShadow::write_section_config(REMOTES_SHADOW_FILENAME, &shadow_config)?;
- replace_config(REMOTES_SHADOW_FILENAME, raw.as_bytes())?;
+ shadow_config.insert(entry.id.clone(), entry);
}
- // only write out remote.cfg with potentially new shadowed entries
- // if shadow file was successfully written!
+ // write out shadow config
+ let raw_shadow =
+ RemoteShadow::write_section_config(REMOTES_SHADOW_FILENAME, &shadow_config)?;
+ replace_config(REMOTES_SHADOW_FILENAME, raw_shadow.as_bytes())?;
+
+ // write out remotes.cfg *only after shadow config has been written*
let raw = Remote::write_section_config(REMOTES_CFG_FILENAME, &config)?;
replace_config(REMOTES_CFG_FILENAME, raw.as_bytes())
}
--
2.47.3
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
next reply other threads:[~2025-12-02 7:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-02 7:18 Fabian Grünbichler [this message]
2025-12-02 9:00 ` [pdm-devel] applied: " 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=20251202071856.112200-1-f.gruenbichler@proxmox.com \
--to=f.gruenbichler@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