5
0
mirror of git://git.proxmox.com/git/proxmox-backup.git synced 2024-12-22 13:34:16 +03:00

config: remove lazy_static dependency

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
This commit is contained in:
Maximiliano Sandoval 2024-08-13 10:44:10 +02:00 committed by Wolfgang Bumiller
parent e1220b02ad
commit a480089bc9
19 changed files with 124 additions and 159 deletions

View File

@ -4,11 +4,11 @@ version = "0.1.0"
authors.workspace = true authors.workspace = true
edition.workspace = true edition.workspace = true
description = "Configuration file management for PBS" description = "Configuration file management for PBS"
rust-version.workspace = true
[dependencies] [dependencies]
anyhow.workspace = true anyhow.workspace = true
const_format.workspace = true const_format.workspace = true
lazy_static.workspace = true
libc.workspace = true libc.workspace = true
nix.workspace = true nix.workspace = true
once_cell.workspace = true once_cell.workspace = true

View File

@ -2,37 +2,36 @@ use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::io::Write; use std::io::Write;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::str::FromStr; use std::str::FromStr;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, LazyLock, RwLock};
use anyhow::{bail, Error}; use anyhow::{bail, Error};
use lazy_static::lazy_static;
use proxmox_schema::{ApiStringFormat, ApiType, Schema, StringSchema}; use proxmox_schema::{ApiStringFormat, ApiType, Schema, StringSchema};
use pbs_api_types::{Authid, Role, Userid, ROLE_NAME_NO_ACCESS}; use pbs_api_types::{Authid, Role, Userid, ROLE_NAME_NO_ACCESS};
use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard};
lazy_static! { /// Map of pre-defined [Roles](Role) to their associated [privileges](PRIVILEGES) combination
/// Map of pre-defined [Roles](Role) to their associated [privileges](PRIVILEGES) combination /// and description.
/// and description. pub static ROLE_NAMES: LazyLock<HashMap<&'static str, (u64, &'static str)>> = LazyLock::new(|| {
pub static ref ROLE_NAMES: HashMap<&'static str, (u64, &'static str)> = { let mut map = HashMap::new();
let mut map = HashMap::new();
let list = match Role::API_SCHEMA { let list = match Role::API_SCHEMA {
Schema::String(StringSchema { format: Some(ApiStringFormat::Enum(list)), .. }) => list, Schema::String(StringSchema {
_ => unreachable!(), format: Some(ApiStringFormat::Enum(list)),
}; ..
}) => list,
for entry in list.iter() { _ => unreachable!(),
let privs: u64 = Role::from_str(entry.value).unwrap() as u64;
map.insert(entry.value, (privs, entry.description));
}
map
}; };
}
for entry in list.iter() {
let privs: u64 = Role::from_str(entry.value).unwrap() as u64;
map.insert(entry.value, (privs, entry.description));
}
map
});
pub fn split_acl_path(path: &str) -> Vec<&str> { pub fn split_acl_path(path: &str) -> Vec<&str> {
let items = path.split('/'); let items = path.split('/');
@ -722,13 +721,13 @@ pub fn cached_config() -> Result<Arc<AclTree>, Error> {
last_mtime_nsec: i64, last_mtime_nsec: i64,
} }
lazy_static! { static CACHED_CONFIG: LazyLock<RwLock<ConfigCache>> = LazyLock::new(|| {
static ref CACHED_CONFIG: RwLock<ConfigCache> = RwLock::new(ConfigCache { RwLock::new(ConfigCache {
data: None, data: None,
last_mtime: 0, last_mtime: 0,
last_mtime_nsec: 0 last_mtime_nsec: 0,
}); })
} });
let stat = match nix::sys::stat::stat(ACL_CFG_FILENAME) { let stat = match nix::sys::stat::stat(ACL_CFG_FILENAME) {
Ok(stat) => Some(stat), Ok(stat) => Some(stat),

View File

@ -1,9 +1,8 @@
//! Cached user info for fast ACL permission checks //! Cached user info for fast ACL permission checks
use std::sync::{Arc, RwLock}; use std::sync::{Arc, LazyLock, RwLock};
use anyhow::{bail, Error}; use anyhow::{bail, Error};
use lazy_static::lazy_static;
use proxmox_router::UserInformation; use proxmox_router::UserInformation;
use proxmox_section_config::SectionConfigData; use proxmox_section_config::SectionConfigData;
@ -26,13 +25,13 @@ struct ConfigCache {
last_user_cache_generation: usize, last_user_cache_generation: usize,
} }
lazy_static! { static CACHED_CONFIG: LazyLock<RwLock<ConfigCache>> = LazyLock::new(|| {
static ref CACHED_CONFIG: RwLock<ConfigCache> = RwLock::new(ConfigCache { RwLock::new(ConfigCache {
data: None, data: None,
last_update: 0, last_update: 0,
last_user_cache_generation: 0 last_user_cache_generation: 0,
}); })
} });
impl CachedUserInfo { impl CachedUserInfo {
/// Returns a cached instance (up to 5 seconds old). /// Returns a cached instance (up to 5 seconds old).

View File

@ -1,6 +1,7 @@
use anyhow::Error;
use lazy_static::lazy_static;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::LazyLock;
use anyhow::Error;
use proxmox_schema::{AllOfSchema, ApiType}; use proxmox_schema::{AllOfSchema, ApiType};
use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin};
@ -9,9 +10,7 @@ use pbs_api_types::{DataStoreConfig, DATASTORE_SCHEMA};
use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard, ConfigVersionCache}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard, ConfigVersionCache};
lazy_static! { pub static CONFIG: LazyLock<SectionConfig> = LazyLock::new(init);
pub static ref CONFIG: SectionConfig = init();
}
fn init() -> SectionConfig { fn init() -> SectionConfig {
const OBJ_SCHEMA: &AllOfSchema = DataStoreConfig::API_SCHEMA.unwrap_all_of_schema(); const OBJ_SCHEMA: &AllOfSchema = DataStoreConfig::API_SCHEMA.unwrap_all_of_schema();

View File

@ -1,7 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::LazyLock;
use anyhow::Error; use anyhow::Error;
use lazy_static::lazy_static;
use pbs_buildcfg::configdir; use pbs_buildcfg::configdir;
use proxmox_schema::{ApiType, ObjectSchema}; use proxmox_schema::{ApiType, ObjectSchema};
@ -10,9 +10,7 @@ use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlug
use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard};
use pbs_api_types::{AdRealmConfig, LdapRealmConfig, OpenIdRealmConfig, REALM_ID_SCHEMA}; use pbs_api_types::{AdRealmConfig, LdapRealmConfig, OpenIdRealmConfig, REALM_ID_SCHEMA};
lazy_static! { pub static CONFIG: LazyLock<SectionConfig> = LazyLock::new(init);
pub static ref CONFIG: SectionConfig = init();
}
fn init() -> SectionConfig { fn init() -> SectionConfig {
const AD_SCHEMA: &ObjectSchema = AdRealmConfig::API_SCHEMA.unwrap_object_schema(); const AD_SCHEMA: &ObjectSchema = AdRealmConfig::API_SCHEMA.unwrap_object_schema();

View File

@ -12,9 +12,9 @@
//! [SectionConfig]: proxmox::api::section_config::SectionConfig //! [SectionConfig]: proxmox::api::section_config::SectionConfig
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::LazyLock;
use anyhow::{bail, Error}; use anyhow::{bail, Error};
use lazy_static::lazy_static;
use proxmox_schema::*; use proxmox_schema::*;
use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin};
@ -23,10 +23,8 @@ use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard};
use pbs_api_types::{LtoTapeDrive, ScsiTapeChanger, VirtualTapeDrive, DRIVE_NAME_SCHEMA}; use pbs_api_types::{LtoTapeDrive, ScsiTapeChanger, VirtualTapeDrive, DRIVE_NAME_SCHEMA};
lazy_static! { /// Static [`SectionConfig`] to access parser/writer functions.
/// Static [`SectionConfig`] to access parser/writer functions. pub static CONFIG: LazyLock<SectionConfig> = LazyLock::new(init);
pub static ref CONFIG: SectionConfig = init();
}
fn init() -> SectionConfig { fn init() -> SectionConfig {
let mut config = SectionConfig::new(&DRIVE_NAME_SCHEMA); let mut config = SectionConfig::new(&DRIVE_NAME_SCHEMA);

View File

@ -7,9 +7,9 @@
//! [SectionConfig]: proxmox_section_config::SectionConfig //! [SectionConfig]: proxmox_section_config::SectionConfig
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::LazyLock;
use anyhow::Error; use anyhow::Error;
use lazy_static::lazy_static;
use proxmox_schema::*; use proxmox_schema::*;
use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin};
@ -18,10 +18,8 @@ use pbs_api_types::{MediaPoolConfig, MEDIA_POOL_NAME_SCHEMA};
use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard};
lazy_static! { /// Static [`SectionConfig`] to access parser/writer functions.
/// Static [`SectionConfig`] to access parser/writer functions. pub static CONFIG: LazyLock<SectionConfig> = LazyLock::new(init);
pub static ref CONFIG: SectionConfig = init();
}
fn init() -> SectionConfig { fn init() -> SectionConfig {
let mut config = SectionConfig::new(&MEDIA_POOL_NAME_SCHEMA); let mut config = SectionConfig::new(&MEDIA_POOL_NAME_SCHEMA);

View File

@ -1,7 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::LazyLock;
use anyhow::Error; use anyhow::Error;
use lazy_static::lazy_static;
use proxmox_schema::*; use proxmox_schema::*;
use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin};
@ -10,9 +10,7 @@ use pbs_api_types::{InfluxDbHttp, InfluxDbUdp, METRIC_SERVER_ID_SCHEMA};
use crate::{open_backup_lockfile, BackupLockGuard}; use crate::{open_backup_lockfile, BackupLockGuard};
lazy_static! { pub static CONFIG: LazyLock<SectionConfig> = LazyLock::new(init);
pub static ref CONFIG: SectionConfig = init();
}
fn init() -> SectionConfig { fn init() -> SectionConfig {
let mut config = SectionConfig::new(&METRIC_SERVER_ID_SCHEMA); let mut config = SectionConfig::new(&METRIC_SERVER_ID_SCHEMA);

View File

@ -2,10 +2,10 @@ use std::collections::HashMap;
use std::os::unix::io::{AsRawFd, FromRawFd, OwnedFd}; use std::os::unix::io::{AsRawFd, FromRawFd, OwnedFd};
use std::path::Path; use std::path::Path;
use std::process::Command; use std::process::Command;
use std::sync::LazyLock;
use anyhow::{bail, format_err, Error}; use anyhow::{bail, format_err, Error};
use const_format::concatcp; use const_format::concatcp;
use lazy_static::lazy_static;
use nix::ioctl_read_bad; use nix::ioctl_read_bad;
use nix::sys::socket::{socket, AddressFamily, SockFlag, SockType}; use nix::sys::socket::{socket, AddressFamily, SockFlag, SockType};
use regex::Regex; use regex::Regex;
@ -48,16 +48,14 @@ pub static IPV4_REVERSE_MASK: &[&str] = &[
"255.255.255.255", "255.255.255.255",
]; ];
lazy_static! { pub static IPV4_MASK_HASH_LOCALNET: LazyLock<HashMap<&'static str, u8>> = LazyLock::new(|| {
pub static ref IPV4_MASK_HASH_LOCALNET: HashMap<&'static str, u8> = { let mut map = HashMap::new();
let mut map = HashMap::new(); #[allow(clippy::needless_range_loop)]
#[allow(clippy::needless_range_loop)] for i in 0..IPV4_REVERSE_MASK.len() {
for i in 0..IPV4_REVERSE_MASK.len() { map.insert(IPV4_REVERSE_MASK[i], i as u8);
map.insert(IPV4_REVERSE_MASK[i], i as u8); }
} map
map });
};
}
pub fn parse_cidr(cidr: &str) -> Result<(String, u8, bool), Error> { pub fn parse_cidr(cidr: &str) -> Result<(String, u8, bool), Error> {
let (address, mask, is_v6) = parse_address_or_cidr(cidr)?; let (address, mask, is_v6) = parse_address_or_cidr(cidr)?;
@ -92,12 +90,10 @@ pub fn check_netmask(mask: u8, is_v6: bool) -> Result<(), Error> {
pub fn parse_address_or_cidr(cidr: &str) -> Result<(String, Option<u8>, bool), Error> { pub fn parse_address_or_cidr(cidr: &str) -> Result<(String, Option<u8>, bool), Error> {
// NOTE: This is NOT the same regex as in proxmox-schema as this one has capture groups for // NOTE: This is NOT the same regex as in proxmox-schema as this one has capture groups for
// the addresses vs cidr portions! // the addresses vs cidr portions!
lazy_static! { pub static CIDR_V4_REGEX: LazyLock<Regex> =
pub static ref CIDR_V4_REGEX: Regex = LazyLock::new(|| Regex::new(concatcp!(r"^(", IPV4RE_STR, r")(?:/(\d{1,2}))?$")).unwrap());
Regex::new(concatcp!(r"^(", IPV4RE_STR, r")(?:/(\d{1,2}))?$")).unwrap(); pub static CIDR_V6_REGEX: LazyLock<Regex> =
pub static ref CIDR_V6_REGEX: Regex = LazyLock::new(|| Regex::new(concatcp!(r"^(", IPV6RE_STR, r")(?:/(\d{1,3}))?$")).unwrap());
Regex::new(concatcp!(r"^(", IPV6RE_STR, r")(?:/(\d{1,3}))?$")).unwrap();
}
if let Some(caps) = CIDR_V4_REGEX.captures(cidr) { if let Some(caps) = CIDR_V4_REGEX.captures(cidr) {
let address = &caps[1]; let address = &caps[1];
@ -133,9 +129,9 @@ pub fn get_network_interfaces() -> Result<HashMap<String, bool>, Error> {
ioctl_read_bad!(get_interface_flags, libc::SIOCGIFFLAGS, ifreq); ioctl_read_bad!(get_interface_flags, libc::SIOCGIFFLAGS, ifreq);
lazy_static! { static IFACE_LINE_REGEX: LazyLock<Regex> =
static ref IFACE_LINE_REGEX: Regex = Regex::new(r"^\s*([^:\s]+):").unwrap(); LazyLock::new(|| Regex::new(r"^\s*([^:\s]+):").unwrap());
}
let raw = std::fs::read_to_string(PROC_NET_DEV) let raw = std::fs::read_to_string(PROC_NET_DEV)
.map_err(|err| format_err!("unable to read {} - {}", PROC_NET_DEV, err))?; .map_err(|err| format_err!("unable to read {} - {}", PROC_NET_DEV, err))?;

View File

@ -1,8 +1,7 @@
use std::collections::{HashMap, VecDeque}; use std::collections::{HashMap, VecDeque};
use std::io::BufRead; use std::io::BufRead;
use std::iter::Iterator; use std::iter::Iterator;
use std::sync::LazyLock;
use lazy_static::lazy_static;
#[derive(Debug, Copy, Clone, Eq, PartialEq)] #[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum Token { pub enum Token {
@ -33,39 +32,37 @@ pub enum Token {
EOF, EOF,
} }
lazy_static! { static KEYWORDS: LazyLock<HashMap<&'static str, Token>> = LazyLock::new(|| {
static ref KEYWORDS: HashMap<&'static str, Token> = { let mut map = HashMap::new();
let mut map = HashMap::new(); map.insert("address", Token::Address);
map.insert("address", Token::Address); map.insert("auto", Token::Auto);
map.insert("auto", Token::Auto); map.insert("dhcp", Token::DHCP);
map.insert("dhcp", Token::DHCP); map.insert("gateway", Token::Gateway);
map.insert("gateway", Token::Gateway); map.insert("inet", Token::Inet);
map.insert("inet", Token::Inet); map.insert("inet6", Token::Inet6);
map.insert("inet6", Token::Inet6); map.insert("iface", Token::Iface);
map.insert("iface", Token::Iface); map.insert("loopback", Token::Loopback);
map.insert("loopback", Token::Loopback); map.insert("manual", Token::Manual);
map.insert("manual", Token::Manual); map.insert("netmask", Token::Netmask);
map.insert("netmask", Token::Netmask); map.insert("static", Token::Static);
map.insert("static", Token::Static); map.insert("mtu", Token::MTU);
map.insert("mtu", Token::MTU); map.insert("bridge-ports", Token::BridgePorts);
map.insert("bridge-ports", Token::BridgePorts); map.insert("bridge_ports", Token::BridgePorts);
map.insert("bridge_ports", Token::BridgePorts); map.insert("bridge-vlan-aware", Token::BridgeVlanAware);
map.insert("bridge-vlan-aware", Token::BridgeVlanAware); map.insert("bridge_vlan_aware", Token::BridgeVlanAware);
map.insert("bridge_vlan_aware", Token::BridgeVlanAware); map.insert("vlan-id", Token::VlanId);
map.insert("vlan-id", Token::VlanId); map.insert("vlan_id", Token::VlanId);
map.insert("vlan_id", Token::VlanId); map.insert("vlan-raw-device", Token::VlanRawDevice);
map.insert("vlan-raw-device", Token::VlanRawDevice); map.insert("vlan_raw_device", Token::VlanRawDevice);
map.insert("vlan_raw_device", Token::VlanRawDevice); map.insert("bond-slaves", Token::BondSlaves);
map.insert("bond-slaves", Token::BondSlaves); map.insert("bond_slaves", Token::BondSlaves);
map.insert("bond_slaves", Token::BondSlaves); map.insert("bond-mode", Token::BondMode);
map.insert("bond-mode", Token::BondMode); map.insert("bond-primary", Token::BondPrimary);
map.insert("bond-primary", Token::BondPrimary); map.insert("bond_primary", Token::BondPrimary);
map.insert("bond_primary", Token::BondPrimary); map.insert("bond_xmit_hash_policy", Token::BondXmitHashPolicy);
map.insert("bond_xmit_hash_policy", Token::BondXmitHashPolicy); map.insert("bond-xmit-hash-policy", Token::BondXmitHashPolicy);
map.insert("bond-xmit-hash-policy", Token::BondXmitHashPolicy); map
map });
};
}
pub struct Lexer<R> { pub struct Lexer<R> {
input: R, input: R,

View File

@ -1,8 +1,8 @@
use std::collections::{BTreeMap, HashMap, HashSet}; use std::collections::{BTreeMap, HashMap, HashSet};
use std::io::Write; use std::io::Write;
use std::sync::LazyLock;
use anyhow::{bail, format_err, Error}; use anyhow::{bail, format_err, Error};
use lazy_static::lazy_static;
use regex::Regex; use regex::Regex;
use serde::de::{value, Deserialize, IntoDeserializer}; use serde::de::{value, Deserialize, IntoDeserializer};
@ -23,11 +23,11 @@ use pbs_api_types::{
use crate::{open_backup_lockfile, BackupLockGuard}; use crate::{open_backup_lockfile, BackupLockGuard};
lazy_static! { static PHYSICAL_NIC_REGEX: LazyLock<Regex> =
static ref PHYSICAL_NIC_REGEX: Regex = Regex::new(r"^(?:eth\d+|en[^:.]+|ib\d+)$").unwrap(); LazyLock::new(|| Regex::new(r"^(?:eth\d+|en[^:.]+|ib\d+)$").unwrap());
static ref VLAN_INTERFACE_REGEX: Regex = static VLAN_INTERFACE_REGEX: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r"^(?P<vlan_raw_device>\S+)\.(?P<vlan_id>\d+)|vlan(?P<vlan_id2>\d+)$").unwrap(); Regex::new(r"^(?P<vlan_raw_device>\S+)\.(?P<vlan_id>\d+)|vlan(?P<vlan_id2>\d+)$").unwrap()
} });
pub fn is_physical_nic(iface: &str) -> bool { pub fn is_physical_nic(iface: &str) -> bool {
PHYSICAL_NIC_REGEX.is_match(iface) PHYSICAL_NIC_REGEX.is_match(iface)
@ -366,9 +366,8 @@ impl NetworkConfig {
/// Check if bridge ports exists /// Check if bridge ports exists
fn check_bridge_ports(&self) -> Result<(), Error> { fn check_bridge_ports(&self) -> Result<(), Error> {
lazy_static! { static VLAN_INTERFACE_REGEX: LazyLock<Regex> =
static ref VLAN_INTERFACE_REGEX: Regex = Regex::new(r"^(\S+)\.(\d+)$").unwrap(); LazyLock::new(|| Regex::new(r"^(\S+)\.(\d+)$").unwrap());
}
for (iface, interface) in self.interfaces.iter() { for (iface, interface) in self.interfaces.iter() {
if let Some(ports) = &interface.bridge_ports { if let Some(ports) = &interface.bridge_ports {

View File

@ -3,9 +3,9 @@ use crate::network::VLAN_INTERFACE_REGEX;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::io::BufRead; use std::io::BufRead;
use std::iter::{Iterator, Peekable}; use std::iter::{Iterator, Peekable};
use std::sync::LazyLock;
use anyhow::{bail, format_err, Error}; use anyhow::{bail, format_err, Error};
use lazy_static::lazy_static;
use regex::Regex; use regex::Regex;
use super::helper::*; use super::helper::*;
@ -536,9 +536,8 @@ impl<R: BufRead> NetworkParser<R> {
} }
} }
lazy_static! { static INTERFACE_ALIAS_REGEX: LazyLock<Regex> =
static ref INTERFACE_ALIAS_REGEX: Regex = Regex::new(r"^\S+:\d+$").unwrap(); LazyLock::new(|| Regex::new(r"^\S+:\d+$").unwrap());
}
if let Some(existing_interfaces) = existing_interfaces { if let Some(existing_interfaces) = existing_interfaces {
for (iface, active) in existing_interfaces.iter() { for (iface, active) in existing_interfaces.iter() {

View File

@ -1,7 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use anyhow::Error; use anyhow::Error;
use lazy_static::lazy_static; use std::sync::LazyLock;
use proxmox_schema::*; use proxmox_schema::*;
use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin};
@ -10,9 +10,7 @@ use pbs_api_types::{PruneJobConfig, JOB_ID_SCHEMA};
use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard};
lazy_static! { pub static CONFIG: LazyLock<SectionConfig> = LazyLock::new(init);
pub static ref CONFIG: SectionConfig = init();
}
fn init() -> SectionConfig { fn init() -> SectionConfig {
const OBJ_SCHEMA: &AllOfSchema = PruneJobConfig::API_SCHEMA.unwrap_all_of_schema(); const OBJ_SCHEMA: &AllOfSchema = PruneJobConfig::API_SCHEMA.unwrap_all_of_schema();

View File

@ -1,7 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::LazyLock;
use anyhow::Error; use anyhow::Error;
use lazy_static::lazy_static;
use proxmox_schema::*; use proxmox_schema::*;
use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin};
@ -10,9 +10,7 @@ use pbs_api_types::{Remote, REMOTE_ID_SCHEMA};
use crate::{open_backup_lockfile, BackupLockGuard}; use crate::{open_backup_lockfile, BackupLockGuard};
lazy_static! { pub static CONFIG: LazyLock<SectionConfig> = LazyLock::new(init);
pub static ref CONFIG: SectionConfig = init();
}
fn init() -> SectionConfig { fn init() -> SectionConfig {
let obj_schema = match Remote::API_SCHEMA { let obj_schema = match Remote::API_SCHEMA {

View File

@ -1,7 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::LazyLock;
use anyhow::Error; use anyhow::Error;
use lazy_static::lazy_static;
use proxmox_schema::{ApiType, Schema}; use proxmox_schema::{ApiType, Schema};
use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin};
@ -10,9 +10,7 @@ use pbs_api_types::{SyncJobConfig, JOB_ID_SCHEMA};
use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard};
lazy_static! { pub static CONFIG: LazyLock<SectionConfig> = LazyLock::new(init);
pub static ref CONFIG: SectionConfig = init();
}
fn init() -> SectionConfig { fn init() -> SectionConfig {
let obj_schema = match SyncJobConfig::API_SCHEMA { let obj_schema = match SyncJobConfig::API_SCHEMA {

View File

@ -1,6 +1,6 @@
use anyhow::Error; use anyhow::Error;
use lazy_static::lazy_static;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::LazyLock;
use proxmox_schema::{ApiType, Schema}; use proxmox_schema::{ApiType, Schema};
use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin};
@ -9,9 +9,7 @@ use pbs_api_types::{TapeBackupJobConfig, JOB_ID_SCHEMA};
use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard};
lazy_static! { pub static CONFIG: LazyLock<SectionConfig> = LazyLock::new(init);
pub static ref CONFIG: SectionConfig = init();
}
fn init() -> SectionConfig { fn init() -> SectionConfig {
let obj_schema = match TapeBackupJobConfig::API_SCHEMA { let obj_schema = match TapeBackupJobConfig::API_SCHEMA {

View File

@ -1,8 +1,8 @@
//! Traffic Control Settings (Network rate limits) //! Traffic Control Settings (Network rate limits)
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::LazyLock;
use anyhow::Error; use anyhow::Error;
use lazy_static::lazy_static;
use proxmox_schema::{ApiType, Schema}; use proxmox_schema::{ApiType, Schema};
@ -13,10 +13,8 @@ use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlug
use crate::ConfigVersionCache; use crate::ConfigVersionCache;
use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard};
lazy_static! { /// Static [`SectionConfig`] to access parser/writer functions.
/// Static [`SectionConfig`] to access parser/writer functions. pub static CONFIG: LazyLock<SectionConfig> = LazyLock::new(init);
pub static ref CONFIG: SectionConfig = init();
}
fn init() -> SectionConfig { fn init() -> SectionConfig {
let mut config = SectionConfig::new(&TRAFFIC_CONTROL_ID_SCHEMA); let mut config = SectionConfig::new(&TRAFFIC_CONTROL_ID_SCHEMA);

View File

@ -1,8 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::{Arc, RwLock}; use std::sync::{Arc, LazyLock, RwLock};
use anyhow::{bail, Error}; use anyhow::{bail, Error};
use lazy_static::lazy_static;
use proxmox_schema::*; use proxmox_schema::*;
use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin};
@ -13,9 +12,7 @@ use crate::ConfigVersionCache;
use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard};
lazy_static! { pub static CONFIG: LazyLock<SectionConfig> = LazyLock::new(init);
pub static ref CONFIG: SectionConfig = init();
}
fn init() -> SectionConfig { fn init() -> SectionConfig {
let mut config = SectionConfig::new(&Authid::API_SCHEMA); let mut config = SectionConfig::new(&Authid::API_SCHEMA);
@ -80,13 +77,13 @@ pub fn cached_config() -> Result<Arc<SectionConfigData>, Error> {
last_mtime_nsec: i64, last_mtime_nsec: i64,
} }
lazy_static! { static CACHED_CONFIG: LazyLock<RwLock<ConfigCache>> = LazyLock::new(|| {
static ref CACHED_CONFIG: RwLock<ConfigCache> = RwLock::new(ConfigCache { RwLock::new(ConfigCache {
data: None, data: None,
last_mtime: 0, last_mtime: 0,
last_mtime_nsec: 0 last_mtime_nsec: 0,
}); })
} });
let stat = match nix::sys::stat::stat(USER_CFG_FILENAME) { let stat = match nix::sys::stat::stat(USER_CFG_FILENAME) {
Ok(stat) => Some(stat), Ok(stat) => Some(stat),

View File

@ -1,7 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::LazyLock;
use anyhow::Error; use anyhow::Error;
use lazy_static::lazy_static;
use proxmox_schema::*; use proxmox_schema::*;
use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin};
@ -10,9 +10,7 @@ use pbs_api_types::{VerificationJobConfig, JOB_ID_SCHEMA};
use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard};
lazy_static! { pub static CONFIG: LazyLock<SectionConfig> = LazyLock::new(init);
pub static ref CONFIG: SectionConfig = init();
}
fn init() -> SectionConfig { fn init() -> SectionConfig {
let obj_schema = match VerificationJobConfig::API_SCHEMA { let obj_schema = match VerificationJobConfig::API_SCHEMA {