diff --git a/Cargo.toml b/Cargo.toml index aac7ec5b..b49d9243 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/config/datastore.rs b/src/config/datastore.rs index 5fe55c72..7e2ae573 100644 --- a/src/config/datastore.rs +++ b/src/config/datastore.rs @@ -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)?; diff --git a/src/config/network.rs b/src/config/network.rs index c5d32069..6527cf64 100644 --- a/src/config/network.rs +++ b/src/config/network.rs @@ -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); diff --git a/src/config/remote.rs b/src/config/remote.rs index 82ac50ec..23aee1f3 100644 --- a/src/config/remote.rs +++ b/src/config/remote.rs @@ -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)?; diff --git a/src/config/sync.rs b/src/config/sync.rs index dce82abc..db9974ff 100644 --- a/src/config/sync.rs +++ b/src/config/sync.rs @@ -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)?; diff --git a/src/config/user.rs b/src/config/user.rs index b280ecc8..2ceea314 100644 --- a/src/config/user.rs +++ b/src/config/user.rs @@ -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)?;