cleanup: factor out config::datastore::lock_config()

This commit is contained in:
Dietmar Maurer
2021-06-04 08:59:52 +02:00
parent 4708f4fc21
commit b90036dadd
4 changed files with 14 additions and 7 deletions

View File

@ -13,7 +13,11 @@ use proxmox::api::{
}
};
use proxmox::tools::{fs::replace_file, fs::CreateOptions};
use proxmox::tools::fs::{
open_file_locked,
replace_file,
CreateOptions,
};
use crate::api2::types::*;
@ -133,6 +137,11 @@ fn init() -> SectionConfig {
pub const DATASTORE_CFG_FILENAME: &str = "/etc/proxmox-backup/datastore.cfg";
pub const DATASTORE_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.datastore.lck";
/// Get exclusive lock
pub fn lock_config() -> Result<std::fs::File, Error> {
open_file_locked(DATASTORE_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)
}
pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
let content = proxmox::tools::fs::file_read_optional_string(DATASTORE_CFG_FILENAME)?