]> git.proxmox.com Git - proxmox-backup.git/commitdiff
depend on proxmox 0.1.38, use new fs helper functions
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 28 May 2020 08:06:44 +0000 (10:06 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 28 May 2020 08:06:44 +0000 (10:06 +0200)
Cargo.toml
src/config/datastore.rs
src/config/network.rs
src/config/remote.rs
src/config/sync.rs
src/config/user.rs

index aac7ec5b1150e5cf3b587198b18341f0bcdcc004..b49d92432871f1e9fa267fa9f2136a4444bc5131 100644 (file)
@@ -36,7 +36,7 @@ pam = "0.7"
 pam-sys = "0.5"
 percent-encoding = "2.1"
 pin-utils = "0.1.0"
-proxmox = { version = "0.1.37", features = [ "sortable-macro", "api-macro" ] }
+proxmox = { version = "0.1.38", features = [ "sortable-macro", "api-macro" ] }
 #proxmox = { git = "ssh://gitolite3@proxdev.maurer-it.com/rust/proxmox", version = "0.1.2", features = [ "sortable-macro", "api-macro" ] }
 #proxmox = { path = "../proxmox/proxmox", features = [ "sortable-macro", "api-macro" ] }
 regex = "1.2"
index 5fe55c72aaf4b944f21b9e746a20f712ac6a599f..7e2ae5730346fd553f4dfa7b26a994822f97d199 100644 (file)
@@ -1,4 +1,4 @@
-use anyhow::{bail, Error};
+use anyhow::{Error};
 use lazy_static::lazy_static;
 use std::collections::HashMap;
 use serde::{Serialize, Deserialize};
@@ -113,16 +113,9 @@ 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) {
-        Ok(c) => c,
-        Err(err) => {
-            if err.kind() == std::io::ErrorKind::NotFound {
-                String::from("")
-            } else {
-                bail!("unable to read '{}' - {}", DATASTORE_CFG_FILENAME, err);
-            }
-        }
-    };
+
+    let content = proxmox::tools::fs::file_read_optional_string(DATASTORE_CFG_FILENAME)?;
+    let content = content.unwrap_or(String::from(""));
 
     let digest = openssl::sha::sha256(content.as_bytes());
     let data = CONFIG.parse(DATASTORE_CFG_FILENAME, &content)?;
index c5d3206996527fe540b9e008f1c96d1ad52854db..6527cf64970635a80cca4424a29c76740fd20abc 100644 (file)
@@ -477,24 +477,15 @@ pub const NETWORK_INTERFACES_FILENAME: &str = "/etc/network/interfaces";
 pub const NETWORK_INTERFACES_NEW_FILENAME: &str = "/etc/network/interfaces.new";
 pub const NETWORK_LOCKFILE: &str = "/var/lock/pve-network.lck";
 
-
 pub fn config() -> Result<(NetworkConfig, [u8;32]), Error> {
-    let content = std::fs::read(NETWORK_INTERFACES_NEW_FILENAME)
-        .or_else(|err| {
-            if err.kind() == std::io::ErrorKind::NotFound {
-                std::fs::read(NETWORK_INTERFACES_FILENAME)
-                    .or_else(|err| {
-                        if err.kind() == std::io::ErrorKind::NotFound {
-                            Ok(Vec::new())
-                        } else {
-                            bail!("unable to read '{}' - {}", NETWORK_INTERFACES_FILENAME, err);
-                         }
-                    })
-            } else {
-                bail!("unable to read '{}' - {}", NETWORK_INTERFACES_NEW_FILENAME, err);
-            }
-        })?;
 
+    let content = match proxmox::tools::fs::file_get_optional_contents(NETWORK_INTERFACES_NEW_FILENAME)? {
+        Some(content) => content,
+        None => {
+            let content = proxmox::tools::fs::file_get_optional_contents(NETWORK_INTERFACES_FILENAME)?;
+            content.unwrap_or(Vec::new())
+        }
+    };
 
     let digest = openssl::sha::sha256(&content);
 
index 82ac50ecf5522fcc1b845e4fe9f99b4721e65feb..23aee1f305d5fd1d1f12e2408264f6e164b8c330 100644 (file)
@@ -1,4 +1,4 @@
-use anyhow::{bail, Error};
+use anyhow::{Error};
 use lazy_static::lazy_static;
 use std::collections::HashMap;
 use serde::{Serialize, Deserialize};
@@ -83,16 +83,9 @@ pub const REMOTE_CFG_FILENAME: &str = "/etc/proxmox-backup/remote.cfg";
 pub const REMOTE_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.remote.lck";
 
 pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
-    let content = match std::fs::read_to_string(REMOTE_CFG_FILENAME) {
-        Ok(c) => c,
-        Err(err) => {
-            if err.kind() == std::io::ErrorKind::NotFound {
-                String::from("")
-            } else {
-                bail!("unable to read '{}' - {}", REMOTE_CFG_FILENAME, err);
-            }
-        }
-    };
+
+    let content = proxmox::tools::fs::file_read_optional_string(REMOTE_CFG_FILENAME)?;
+    let content = content.unwrap_or(String::from(""));
 
     let digest = openssl::sha::sha256(content.as_bytes());
     let data = CONFIG.parse(REMOTE_CFG_FILENAME, &content)?;
index dce82abc9186155a12512461a7f2a76e8f81ba44..db9974ff4e5822324e688ef825baaf85abcf4686 100644 (file)
@@ -1,4 +1,4 @@
-use anyhow::{bail, Error};
+use anyhow::{Error};
 use lazy_static::lazy_static;
 use std::collections::HashMap;
 use serde::{Serialize, Deserialize};
@@ -83,16 +83,9 @@ pub const SYNC_CFG_FILENAME: &str = "/etc/proxmox-backup/sync.cfg";
 pub const SYNC_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.sync.lck";
 
 pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
-    let content = match std::fs::read_to_string(SYNC_CFG_FILENAME) {
-        Ok(c) => c,
-        Err(err) => {
-            if err.kind() == std::io::ErrorKind::NotFound {
-                String::from("")
-            } else {
-                bail!("unable to read '{}' - {}", SYNC_CFG_FILENAME, err);
-            }
-        }
-    };
+
+    let content = proxmox::tools::fs::file_read_optional_string(SYNC_CFG_FILENAME)?;
+    let content = content.unwrap_or(String::from(""));
 
     let digest = openssl::sha::sha256(content.as_bytes());
     let data = CONFIG.parse(SYNC_CFG_FILENAME, &content)?;
index b280ecc8b7526a4093e2a416438ed5cbf05f69cd..2ceea314ef0f9b7cf20e1eff956b43322ba2f9dc 100644 (file)
@@ -120,16 +120,9 @@ pub const USER_CFG_FILENAME: &str = "/etc/proxmox-backup/user.cfg";
 pub const USER_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.user.lck";
 
 pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
-    let content = match std::fs::read_to_string(USER_CFG_FILENAME) {
-        Ok(c) => c,
-        Err(err) => {
-            if err.kind() == std::io::ErrorKind::NotFound {
-                String::from("")
-            } else {
-                bail!("unable to read '{}' - {}", USER_CFG_FILENAME, err);
-            }
-        }
-    };
+
+    let content = proxmox::tools::fs::file_read_optional_string(USER_CFG_FILENAME)?;
+    let content = content.unwrap_or(String::from(""));
 
     let digest = openssl::sha::sha256(content.as_bytes());
     let mut data = CONFIG.parse(USER_CFG_FILENAME, &content)?;