src/api2/config: correctly lock files
This commit is contained in:
parent
1c79e1017f
commit
347834df25
|
@ -53,7 +53,7 @@ pub fn list_datastores(
|
||||||
/// Create new datastore config.
|
/// Create new datastore config.
|
||||||
pub fn create_datastore(name: String, param: Value) -> Result<(), Error> {
|
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())?;
|
let datastore: datastore::DataStoreConfig = serde_json::from_value(param.clone())?;
|
||||||
|
|
||||||
|
@ -122,7 +122,8 @@ pub fn update_datastore(
|
||||||
path: Option<String>,
|
path: Option<String>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
|
||||||
// fixme: locking ?
|
let _lock = crate::tools::open_file_locked(datastore::DATASTORE_CFG_LOCKFILE, std::time::Duration::new(10, 0))?;
|
||||||
|
|
||||||
// pass/compare digest
|
// pass/compare digest
|
||||||
let (mut config, _digest) = datastore::config()?;
|
let (mut config, _digest) = datastore::config()?;
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ pub fn list_remotes(
|
||||||
/// Create new remote.
|
/// Create new remote.
|
||||||
pub fn create_remote(name: String, param: Value) -> Result<(), Error> {
|
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())?;
|
let remote: remotes::Remote = serde_json::from_value(param.clone())?;
|
||||||
|
|
||||||
|
@ -130,7 +130,8 @@ pub fn update_remote(
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
|
||||||
// fixme: locking ?
|
let _lock = crate::tools::open_file_locked(remotes::REMOTES_CFG_LOCKFILE, std::time::Duration::new(10, 0))?;
|
||||||
|
|
||||||
// pass/compare digest
|
// pass/compare digest
|
||||||
let (mut config, _digest) = remotes::config()?;
|
let (mut config, _digest) = remotes::config()?;
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,8 @@ fn init() -> SectionConfig {
|
||||||
config
|
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> {
|
pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
|
||||||
let content = match std::fs::read_to_string(DATASTORE_CFG_FILENAME) {
|
let content = match std::fs::read_to_string(DATASTORE_CFG_FILENAME) {
|
||||||
|
|
|
@ -60,7 +60,8 @@ fn init() -> SectionConfig {
|
||||||
config
|
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> {
|
pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
|
||||||
let content = match std::fs::read_to_string(REMOTES_CFG_FILENAME) {
|
let content = match std::fs::read_to_string(REMOTES_CFG_FILENAME) {
|
||||||
|
|
Loading…
Reference in New Issue