From 347834df2567b55a79dfdb623ffc920907cb9774 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 15 Jan 2020 11:57:12 +0100 Subject: [PATCH] src/api2/config: correctly lock files --- src/api2/config/datastore.rs | 5 +++-- src/api2/config/remotes.rs | 5 +++-- src/config/datastore.rs | 3 ++- src/config/remotes.rs | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index 2ddf77ea..daee1c0a 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -53,7 +53,7 @@ pub fn list_datastores( /// Create new datastore config. pub fn create_datastore(name: String, param: Value) -> Result<(), Error> { - // fixme: locking ? + let _lock = crate::tools::open_file_locked(datastore::DATASTORE_CFG_LOCKFILE, std::time::Duration::new(10, 0))?; let datastore: datastore::DataStoreConfig = serde_json::from_value(param.clone())?; @@ -122,7 +122,8 @@ pub fn update_datastore( path: Option, ) -> Result<(), Error> { - // fixme: locking ? + let _lock = crate::tools::open_file_locked(datastore::DATASTORE_CFG_LOCKFILE, std::time::Duration::new(10, 0))?; + // pass/compare digest let (mut config, _digest) = datastore::config()?; diff --git a/src/api2/config/remotes.rs b/src/api2/config/remotes.rs index 15a817c6..4d073981 100644 --- a/src/api2/config/remotes.rs +++ b/src/api2/config/remotes.rs @@ -56,7 +56,7 @@ pub fn list_remotes( /// Create new remote. pub fn create_remote(name: String, param: Value) -> Result<(), Error> { - // fixme: locking ? + let _lock = crate::tools::open_file_locked(remotes::REMOTES_CFG_LOCKFILE, std::time::Duration::new(10, 0))?; let remote: remotes::Remote = serde_json::from_value(param.clone())?; @@ -130,7 +130,8 @@ pub fn update_remote( password: Option, ) -> Result<(), Error> { - // fixme: locking ? + let _lock = crate::tools::open_file_locked(remotes::REMOTES_CFG_LOCKFILE, std::time::Duration::new(10, 0))?; + // pass/compare digest let (mut config, _digest) = remotes::config()?; diff --git a/src/config/datastore.rs b/src/config/datastore.rs index 8eaeb259..db84a27c 100644 --- a/src/config/datastore.rs +++ b/src/config/datastore.rs @@ -49,7 +49,8 @@ fn init() -> SectionConfig { config } -const DATASTORE_CFG_FILENAME: &str = "/etc/proxmox-backup/datastore.cfg"; +pub const DATASTORE_CFG_FILENAME: &str = "/etc/proxmox-backup/datastore.cfg"; +pub const DATASTORE_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.datastore.lck"; pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> { let content = match std::fs::read_to_string(DATASTORE_CFG_FILENAME) { diff --git a/src/config/remotes.rs b/src/config/remotes.rs index 2b2c0305..4bba3672 100644 --- a/src/config/remotes.rs +++ b/src/config/remotes.rs @@ -60,7 +60,8 @@ fn init() -> SectionConfig { config } -const REMOTES_CFG_FILENAME: &str = "/etc/proxmox-backup/remotes.cfg"; +pub const REMOTES_CFG_FILENAME: &str = "/etc/proxmox-backup/remotes.cfg"; +pub const REMOTES_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.remotes.lck"; pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> { let content = match std::fs::read_to_string(REMOTES_CFG_FILENAME) {