]> git.proxmox.com Git - proxmox-backup.git/commitdiff
src/api2/config: correctly lock files
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 15 Jan 2020 10:57:12 +0000 (11:57 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 15 Jan 2020 10:57:12 +0000 (11:57 +0100)
src/api2/config/datastore.rs
src/api2/config/remotes.rs
src/config/datastore.rs
src/config/remotes.rs

index 2ddf77ea9a75c17a6d1b8b79418c139bea20a3e7..daee1c0a4ef96c8b6fe1acf5860ea930de506286 100644 (file)
@@ -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<String>,
 ) -> 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()?;
 
index 15a817c65798e67048a4d126bd4e1957d8b529b8..4d0739810656f265d6387e0ce12aed6a0a377f18 100644 (file)
@@ -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<String>,
 ) -> 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()?;
 
index 8eaeb259c3f105584dbd3969ca2c166d1620f1c4..db84a27c0afe54548349037939202ae972666474 100644 (file)
@@ -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) {
index 2b2c0305121fbbb4af4a72fd0ff87d6f18548a60..4bba36728458af298b46a5f55ffc357473bc2174 100644 (file)
@@ -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) {