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"
-use anyhow::{bail, Error};
+use anyhow::{Error};
use lazy_static::lazy_static;
use std::collections::HashMap;
use serde::{Serialize, Deserialize};
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)?;
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);
-use anyhow::{bail, Error};
+use anyhow::{Error};
use lazy_static::lazy_static;
use std::collections::HashMap;
use serde::{Serialize, Deserialize};
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)?;
-use anyhow::{bail, Error};
+use anyhow::{Error};
use lazy_static::lazy_static;
use std::collections::HashMap;
use serde::{Serialize, Deserialize};
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)?;
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)?;