From 99f443c6ae8dda2af668bcbbe04e2b5419217634 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Fri, 22 May 2020 14:51:42 +0200 Subject: [PATCH] api2/config/remote: lock and use digest for removal Signed-off-by: Dominik Csapak --- src/api2/config/remote.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/api2/config/remote.rs b/src/api2/config/remote.rs index 1bc00fed..731c4df6 100644 --- a/src/api2/config/remote.rs +++ b/src/api2/config/remote.rs @@ -251,6 +251,10 @@ pub fn update_remote( name: { schema: REMOTE_ID_SCHEMA, }, + digest: { + optional: true, + schema: PROXMOX_CONFIG_DIGEST_SCHEMA, + }, }, }, access: { @@ -258,12 +262,16 @@ pub fn update_remote( }, )] /// Remove a remote from the configuration file. -pub fn delete_remote(name: String) -> Result<(), Error> { +pub fn delete_remote(name: String, digest: Option) -> Result<(), Error> { - // fixme: locking ? - // fixme: check digest ? + let _lock = crate::tools::open_file_locked(remote::REMOTE_CFG_LOCKFILE, std::time::Duration::new(10, 0))?; - let (mut config, _digest) = remote::config()?; + let (mut config, expected_digest) = remote::config()?; + + if let Some(ref digest) = digest { + let digest = proxmox::tools::hex_to_digest(digest)?; + crate::tools::detect_modified_configuration_file(&digest, &expected_digest)?; + } match config.sections.get(&name) { Some(_) => { config.sections.remove(&name); },