[pbs-devel] [PATCH backup 1/3] config: Remove lazy_static dependency
Maximiliano Sandoval
m.sandoval at proxmox.com
Tue Feb 13 10:03:13 CET 2024
Makes the eventual port to std::cell::LazyCell easier and allows rustfmt
to do its thing.
Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
---
pbs-config/Cargo.toml | 1 -
pbs-config/src/acl.rs | 48 ++++++++++++-------------
pbs-config/src/cached_user_info.rs | 12 +++----
pbs-config/src/datastore.rs | 9 +++--
pbs-config/src/domains.rs | 6 ++--
pbs-config/src/drive.rs | 8 ++---
pbs-config/src/media_pool.rs | 8 ++---
pbs-config/src/metrics.rs | 6 ++--
pbs-config/src/network/helper.rs | 35 ++++++++----------
pbs-config/src/network/lexer.rs | 58 +++++++++++++++---------------
pbs-config/src/network/mod.rs | 12 +++----
pbs-config/src/network/parser.rs | 8 ++---
pbs-config/src/prune.rs | 6 ++--
pbs-config/src/remote.rs | 6 ++--
pbs-config/src/sync.rs | 6 ++--
pbs-config/src/tape_job.rs | 6 ++--
pbs-config/src/traffic_control.rs | 8 ++---
pbs-config/src/user.rs | 16 ++++-----
pbs-config/src/verify.rs | 6 ++--
19 files changed, 115 insertions(+), 150 deletions(-)
diff --git a/pbs-config/Cargo.toml b/pbs-config/Cargo.toml
index 9daa6ef4..035af222 100644
--- a/pbs-config/Cargo.toml
+++ b/pbs-config/Cargo.toml
@@ -8,7 +8,6 @@ description = "Configuration file management for PBS"
[dependencies]
anyhow.workspace = true
hex.workspace = true
-lazy_static.workspace = true
libc.workspace = true
nix.workspace = true
once_cell.workspace = true
diff --git a/pbs-config/src/acl.rs b/pbs-config/src/acl.rs
index 20269f5d..ba526a65 100644
--- a/pbs-config/src/acl.rs
+++ b/pbs-config/src/acl.rs
@@ -5,8 +5,7 @@ use std::str::FromStr;
use std::sync::{Arc, RwLock};
use anyhow::{bail, Error};
-
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
use proxmox_schema::{ApiStringFormat, ApiType, Schema, StringSchema};
@@ -14,25 +13,26 @@ use pbs_api_types::{Authid, Role, Userid, ROLE_NAME_NO_ACCESS};
use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard};
-lazy_static! {
- /// Map of pre-defined [Roles](Role) to their associated [privileges](PRIVILEGES) combination
- /// and description.
- pub static ref ROLE_NAMES: HashMap<&'static str, (u64, &'static str)> = {
- let mut map = HashMap::new();
-
- let list = match Role::API_SCHEMA {
- Schema::String(StringSchema { format: Some(ApiStringFormat::Enum(list)), .. }) => list,
- _ => unreachable!(),
- };
+/// Map of pre-defined [Roles](Role) to their associated [privileges](PRIVILEGES) combination
+/// and description.
+pub static ROLE_NAMES: Lazy<HashMap<&'static str, (u64, &'static str)>> = Lazy::new(|| {
+ let mut map = HashMap::new();
+
+ let list = match Role::API_SCHEMA {
+ Schema::String(StringSchema {
+ format: Some(ApiStringFormat::Enum(list)),
+ ..
+ }) => list,
+ _ => unreachable!(),
+ };
- for entry in list.iter() {
- let privs: u64 = Role::from_str(entry.value).unwrap() as u64;
- map.insert(entry.value, (privs, entry.description));
- }
+ for entry in list.iter() {
+ let privs: u64 = Role::from_str(entry.value).unwrap() as u64;
+ map.insert(entry.value, (privs, entry.description));
+ }
- map
- };
-}
+ map
+});
pub fn split_acl_path(path: &str) -> Vec<&str> {
let items = path.split('/');
@@ -733,13 +733,13 @@ pub fn cached_config() -> Result<Arc<AclTree>, Error> {
last_mtime_nsec: i64,
}
- lazy_static! {
- static ref CACHED_CONFIG: RwLock<ConfigCache> = RwLock::new(ConfigCache {
+ static CACHED_CONFIG: Lazy<RwLock<ConfigCache>> = Lazy::new(|| {
+ RwLock::new(ConfigCache {
data: None,
last_mtime: 0,
- last_mtime_nsec: 0
- });
- }
+ last_mtime_nsec: 0,
+ })
+ });
let stat = match nix::sys::stat::stat(ACL_CFG_FILENAME) {
Ok(stat) => Some(stat),
diff --git a/pbs-config/src/cached_user_info.rs b/pbs-config/src/cached_user_info.rs
index b9534b80..4d97c3d1 100644
--- a/pbs-config/src/cached_user_info.rs
+++ b/pbs-config/src/cached_user_info.rs
@@ -3,7 +3,7 @@
use std::sync::{Arc, RwLock};
use anyhow::{bail, Error};
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
use proxmox_router::UserInformation;
use proxmox_section_config::SectionConfigData;
@@ -26,13 +26,13 @@ struct ConfigCache {
last_user_cache_generation: usize,
}
-lazy_static! {
- static ref CACHED_CONFIG: RwLock<ConfigCache> = RwLock::new(ConfigCache {
+static CACHED_CONFIG: Lazy<RwLock<ConfigCache>> = Lazy::new(|| {
+ RwLock::new(ConfigCache {
data: None,
last_update: 0,
- last_user_cache_generation: 0
- });
-}
+ last_user_cache_generation: 0,
+ })
+});
impl CachedUserInfo {
/// Returns a cached instance (up to 5 seconds old).
diff --git a/pbs-config/src/datastore.rs b/pbs-config/src/datastore.rs
index 5844a174..45fe84fb 100644
--- a/pbs-config/src/datastore.rs
+++ b/pbs-config/src/datastore.rs
@@ -1,7 +1,8 @@
-use anyhow::Error;
-use lazy_static::lazy_static;
use std::collections::HashMap;
+use anyhow::Error;
+use once_cell::sync::Lazy;
+
use proxmox_schema::{AllOfSchema, ApiType};
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};
-lazy_static! {
- pub static ref CONFIG: SectionConfig = init();
-}
+pub static CONFIG: Lazy<SectionConfig> = Lazy::new(init);
fn init() -> SectionConfig {
const OBJ_SCHEMA: &AllOfSchema = DataStoreConfig::API_SCHEMA.unwrap_all_of_schema();
diff --git a/pbs-config/src/domains.rs b/pbs-config/src/domains.rs
index 35aa11d5..759ea6fb 100644
--- a/pbs-config/src/domains.rs
+++ b/pbs-config/src/domains.rs
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use anyhow::Error;
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
use pbs_buildcfg::configdir;
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 pbs_api_types::{LdapRealmConfig, OpenIdRealmConfig, REALM_ID_SCHEMA};
-lazy_static! {
- pub static ref CONFIG: SectionConfig = init();
-}
+pub static CONFIG: Lazy<SectionConfig> = Lazy::new(init);
fn init() -> SectionConfig {
const LDAP_SCHEMA: &ObjectSchema = LdapRealmConfig::API_SCHEMA.unwrap_object_schema();
diff --git a/pbs-config/src/drive.rs b/pbs-config/src/drive.rs
index 67ffc554..377ba462 100644
--- a/pbs-config/src/drive.rs
+++ b/pbs-config/src/drive.rs
@@ -14,7 +14,7 @@
use std::collections::HashMap;
use anyhow::{bail, Error};
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
use proxmox_schema::*;
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};
-lazy_static! {
- /// Static [`SectionConfig`] to access parser/writer functions.
- pub static ref CONFIG: SectionConfig = init();
-}
+/// Static [`SectionConfig`] to access parser/writer functions.
+pub static CONFIG: Lazy<SectionConfig> = Lazy::new(init);
fn init() -> SectionConfig {
let mut config = SectionConfig::new(&DRIVE_NAME_SCHEMA);
diff --git a/pbs-config/src/media_pool.rs b/pbs-config/src/media_pool.rs
index 3b6448c3..c606efd6 100644
--- a/pbs-config/src/media_pool.rs
+++ b/pbs-config/src/media_pool.rs
@@ -9,7 +9,7 @@
use std::collections::HashMap;
use anyhow::Error;
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
use proxmox_schema::*;
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};
-lazy_static! {
- /// Static [`SectionConfig`] to access parser/writer functions.
- pub static ref CONFIG: SectionConfig = init();
-}
+/// Static [`SectionConfig`] to access parser/writer functions.
+pub static CONFIG: Lazy<SectionConfig> = Lazy::new(init);
fn init() -> SectionConfig {
let mut config = SectionConfig::new(&MEDIA_POOL_NAME_SCHEMA);
diff --git a/pbs-config/src/metrics.rs b/pbs-config/src/metrics.rs
index 78e683e3..0d8fa1d7 100644
--- a/pbs-config/src/metrics.rs
+++ b/pbs-config/src/metrics.rs
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use anyhow::Error;
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
use proxmox_schema::*;
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};
-lazy_static! {
- pub static ref CONFIG: SectionConfig = init();
-}
+pub static CONFIG: Lazy<SectionConfig> = Lazy::new(init);
fn init() -> SectionConfig {
let mut config = SectionConfig::new(&METRIC_SERVER_ID_SCHEMA);
diff --git a/pbs-config/src/network/helper.rs b/pbs-config/src/network/helper.rs
index 7180aaaa..e4750bad 100644
--- a/pbs-config/src/network/helper.rs
+++ b/pbs-config/src/network/helper.rs
@@ -4,9 +4,9 @@ use std::path::Path;
use std::process::Command;
use anyhow::{bail, format_err, Error};
-use lazy_static::lazy_static;
use nix::ioctl_read_bad;
use nix::sys::socket::{socket, AddressFamily, SockFlag, SockType};
+use once_cell::sync::Lazy;
use regex::Regex;
use pbs_api_types::*; // for IP macros
@@ -47,16 +47,14 @@ pub static IPV4_REVERSE_MASK: &[&str] = &[
"255.255.255.255",
];
-lazy_static! {
- pub static ref IPV4_MASK_HASH_LOCALNET: HashMap<&'static str, u8> = {
- let mut map = HashMap::new();
- #[allow(clippy::needless_range_loop)]
- for i in 0..IPV4_REVERSE_MASK.len() {
- map.insert(IPV4_REVERSE_MASK[i], i as u8);
- }
- map
- };
-}
+pub static IPV4_MASK_HASH_LOCALNET: Lazy<HashMap<&'static str, u8>> = Lazy::new(|| {
+ let mut map = HashMap::new();
+ #[allow(clippy::needless_range_loop)]
+ for i in 0..IPV4_REVERSE_MASK.len() {
+ map.insert(IPV4_REVERSE_MASK[i], i as u8);
+ }
+ map
+});
pub fn parse_cidr(cidr: &str) -> Result<(String, u8, bool), Error> {
let (address, mask, is_v6) = parse_address_or_cidr(cidr)?;
@@ -89,12 +87,10 @@ pub fn check_netmask(mask: u8, is_v6: bool) -> Result<(), Error> {
// parse ip address with optional cidr mask
pub fn parse_address_or_cidr(cidr: &str) -> Result<(String, Option<u8>, bool), Error> {
- lazy_static! {
- pub static ref CIDR_V4_REGEX: Regex =
- Regex::new(concat!(r"^(", IPV4RE!(), r")(?:/(\d{1,2}))?$")).unwrap();
- pub static ref CIDR_V6_REGEX: Regex =
- Regex::new(concat!(r"^(", IPV6RE!(), r")(?:/(\d{1,3}))?$")).unwrap();
- }
+ pub static CIDR_V4_REGEX: Lazy<Regex> =
+ Lazy::new(|| Regex::new(concat!(r"^(", IPV4RE!(), r")(?:/(\d{1,2}))?$")).unwrap());
+ pub static CIDR_V6_REGEX: Lazy<Regex> =
+ Lazy::new(|| Regex::new(concat!(r"^(", IPV6RE!(), r")(?:/(\d{1,3}))?$")).unwrap());
if let Some(caps) = CIDR_V4_REGEX.captures(cidr) {
let address = &caps[1];
@@ -130,9 +126,8 @@ pub fn get_network_interfaces() -> Result<HashMap<String, bool>, Error> {
ioctl_read_bad!(get_interface_flags, libc::SIOCGIFFLAGS, ifreq);
- lazy_static! {
- static ref IFACE_LINE_REGEX: Regex = Regex::new(r"^\s*([^:\s]+):").unwrap();
- }
+ static IFACE_LINE_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^\s*([^:\s]+):").unwrap());
+
let raw = std::fs::read_to_string(PROC_NET_DEV)
.map_err(|err| format_err!("unable to read {} - {}", PROC_NET_DEV, err))?;
diff --git a/pbs-config/src/network/lexer.rs b/pbs-config/src/network/lexer.rs
index fd23e3d8..2ab5eb5a 100644
--- a/pbs-config/src/network/lexer.rs
+++ b/pbs-config/src/network/lexer.rs
@@ -2,7 +2,7 @@ use std::collections::{HashMap, VecDeque};
use std::io::BufRead;
use std::iter::Iterator;
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum Token {
@@ -31,35 +31,33 @@ pub enum Token {
EOF,
}
-lazy_static! {
- static ref KEYWORDS: HashMap<&'static str, Token> = {
- let mut map = HashMap::new();
- map.insert("address", Token::Address);
- map.insert("auto", Token::Auto);
- map.insert("dhcp", Token::DHCP);
- map.insert("gateway", Token::Gateway);
- map.insert("inet", Token::Inet);
- map.insert("inet6", Token::Inet6);
- map.insert("iface", Token::Iface);
- map.insert("loopback", Token::Loopback);
- map.insert("manual", Token::Manual);
- map.insert("netmask", Token::Netmask);
- map.insert("static", Token::Static);
- map.insert("mtu", Token::MTU);
- 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("bond-slaves", Token::BondSlaves);
- map.insert("bond_slaves", Token::BondSlaves);
- map.insert("bond-mode", Token::BondMode);
- 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
- };
-}
+static KEYWORDS: Lazy<HashMap<&'static str, Token>> = Lazy::new(|| {
+ let mut map = HashMap::new();
+ map.insert("address", Token::Address);
+ map.insert("auto", Token::Auto);
+ map.insert("dhcp", Token::DHCP);
+ map.insert("gateway", Token::Gateway);
+ map.insert("inet", Token::Inet);
+ map.insert("inet6", Token::Inet6);
+ map.insert("iface", Token::Iface);
+ map.insert("loopback", Token::Loopback);
+ map.insert("manual", Token::Manual);
+ map.insert("netmask", Token::Netmask);
+ map.insert("static", Token::Static);
+ map.insert("mtu", Token::MTU);
+ 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("bond-slaves", Token::BondSlaves);
+ map.insert("bond_slaves", Token::BondSlaves);
+ map.insert("bond-mode", Token::BondMode);
+ 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
+});
pub struct Lexer<R> {
input: R,
diff --git a/pbs-config/src/network/mod.rs b/pbs-config/src/network/mod.rs
index e2008b7c..8e1f2c1a 100644
--- a/pbs-config/src/network/mod.rs
+++ b/pbs-config/src/network/mod.rs
@@ -2,7 +2,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
use std::io::Write;
use anyhow::{bail, format_err, Error};
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
use regex::Regex;
use serde::de::{value, Deserialize, IntoDeserializer};
@@ -23,9 +23,8 @@ use pbs_api_types::{
use crate::{open_backup_lockfile, BackupLockGuard};
-lazy_static! {
- static ref PHYSICAL_NIC_REGEX: Regex = Regex::new(r"^(?:eth\d+|en[^:.]+|ib\d+)$").unwrap();
-}
+static PHYSICAL_NIC_REGEX: Lazy<Regex> =
+ Lazy::new(|| Regex::new(r"^(?:eth\d+|en[^:.]+|ib\d+)$").unwrap());
pub fn is_physical_nic(iface: &str) -> bool {
PHYSICAL_NIC_REGEX.is_match(iface)
@@ -341,9 +340,8 @@ impl NetworkConfig {
/// Check if bridge ports exists
pub fn check_bridge_ports(&self) -> Result<(), Error> {
- lazy_static! {
- static ref VLAN_INTERFACE_REGEX: Regex = Regex::new(r"^(\S+)\.(\d+)$").unwrap();
- }
+ static VLAN_INTERFACE_REGEX: Lazy<Regex> =
+ Lazy::new(|| Regex::new(r"^(\S+)\.(\d+)$").unwrap());
for (iface, interface) in self.interfaces.iter() {
if let Some(ports) = &interface.bridge_ports {
diff --git a/pbs-config/src/network/parser.rs b/pbs-config/src/network/parser.rs
index 2cff6587..96915fb2 100644
--- a/pbs-config/src/network/parser.rs
+++ b/pbs-config/src/network/parser.rs
@@ -3,7 +3,7 @@ use std::io::BufRead;
use std::iter::{Iterator, Peekable};
use anyhow::{bail, format_err, Error};
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
use regex::Regex;
use super::helper::*;
@@ -520,10 +520,8 @@ impl<R: BufRead> NetworkParser<R> {
}
}
- lazy_static! {
- static ref INTERFACE_ALIAS_REGEX: Regex = Regex::new(r"^\S+:\d+$").unwrap();
- static ref VLAN_INTERFACE_REGEX: Regex = Regex::new(r"^\S+\.\d+$").unwrap();
- }
+ static INTERFACE_ALIAS_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^\S+:\d+$").unwrap());
+ static VLAN_INTERFACE_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^\S+\.\d+$").unwrap());
if let Some(existing_interfaces) = existing_interfaces {
for (iface, active) in existing_interfaces.iter() {
diff --git a/pbs-config/src/prune.rs b/pbs-config/src/prune.rs
index 21e52ffc..2012472f 100644
--- a/pbs-config/src/prune.rs
+++ b/pbs-config/src/prune.rs
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use anyhow::Error;
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
use proxmox_schema::*;
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};
-lazy_static! {
- pub static ref CONFIG: SectionConfig = init();
-}
+pub static CONFIG: Lazy<SectionConfig> = Lazy::new(init);
fn init() -> SectionConfig {
const OBJ_SCHEMA: &AllOfSchema = PruneJobConfig::API_SCHEMA.unwrap_all_of_schema();
diff --git a/pbs-config/src/remote.rs b/pbs-config/src/remote.rs
index 9cbd1321..907dd5f4 100644
--- a/pbs-config/src/remote.rs
+++ b/pbs-config/src/remote.rs
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use anyhow::Error;
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
use proxmox_schema::*;
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};
-lazy_static! {
- pub static ref CONFIG: SectionConfig = init();
-}
+pub static CONFIG: Lazy<SectionConfig> = Lazy::new(init);
fn init() -> SectionConfig {
let obj_schema = match Remote::API_SCHEMA {
diff --git a/pbs-config/src/sync.rs b/pbs-config/src/sync.rs
index 6d27c123..654f882b 100644
--- a/pbs-config/src/sync.rs
+++ b/pbs-config/src/sync.rs
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use anyhow::Error;
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
use proxmox_schema::{ApiType, Schema};
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};
-lazy_static! {
- pub static ref CONFIG: SectionConfig = init();
-}
+pub static CONFIG: Lazy<SectionConfig> = Lazy::new(init);
fn init() -> SectionConfig {
let obj_schema = match SyncJobConfig::API_SCHEMA {
diff --git a/pbs-config/src/tape_job.rs b/pbs-config/src/tape_job.rs
index 75ace6c7..e23dbf0e 100644
--- a/pbs-config/src/tape_job.rs
+++ b/pbs-config/src/tape_job.rs
@@ -1,5 +1,5 @@
use anyhow::Error;
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
use std::collections::HashMap;
use proxmox_schema::{ApiType, Schema};
@@ -9,9 +9,7 @@ use pbs_api_types::{TapeBackupJobConfig, JOB_ID_SCHEMA};
use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard};
-lazy_static! {
- pub static ref CONFIG: SectionConfig = init();
-}
+pub static CONFIG: Lazy<SectionConfig> = Lazy::new(init);
fn init() -> SectionConfig {
let obj_schema = match TapeBackupJobConfig::API_SCHEMA {
diff --git a/pbs-config/src/traffic_control.rs b/pbs-config/src/traffic_control.rs
index 0826be83..d5206877 100644
--- a/pbs-config/src/traffic_control.rs
+++ b/pbs-config/src/traffic_control.rs
@@ -2,7 +2,7 @@
use std::collections::HashMap;
use anyhow::Error;
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
use proxmox_schema::{ApiType, Schema};
@@ -13,10 +13,8 @@ use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlug
use crate::ConfigVersionCache;
use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard};
-lazy_static! {
- /// Static [`SectionConfig`] to access parser/writer functions.
- pub static ref CONFIG: SectionConfig = init();
-}
+/// Static [`SectionConfig`] to access parser/writer functions.
+pub static CONFIG: Lazy<SectionConfig> = Lazy::new(init);
fn init() -> SectionConfig {
let mut config = SectionConfig::new(&TRAFFIC_CONTROL_ID_SCHEMA);
diff --git a/pbs-config/src/user.rs b/pbs-config/src/user.rs
index 8e10a778..92dc0c69 100644
--- a/pbs-config/src/user.rs
+++ b/pbs-config/src/user.rs
@@ -2,7 +2,7 @@ use std::collections::HashMap;
use std::sync::{Arc, RwLock};
use anyhow::{bail, Error};
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
use proxmox_schema::*;
use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin};
@@ -13,9 +13,7 @@ use crate::ConfigVersionCache;
use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard};
-lazy_static! {
- pub static ref CONFIG: SectionConfig = init();
-}
+pub static CONFIG: Lazy<SectionConfig> = Lazy::new(init);
fn init() -> SectionConfig {
let mut config = SectionConfig::new(&Authid::API_SCHEMA);
@@ -80,13 +78,13 @@ pub fn cached_config() -> Result<Arc<SectionConfigData>, Error> {
last_mtime_nsec: i64,
}
- lazy_static! {
- static ref CACHED_CONFIG: RwLock<ConfigCache> = RwLock::new(ConfigCache {
+ static CACHED_CONFIG: Lazy<RwLock<ConfigCache>> = Lazy::new(|| {
+ RwLock::new(ConfigCache {
data: None,
last_mtime: 0,
- last_mtime_nsec: 0
- });
- }
+ last_mtime_nsec: 0,
+ })
+ });
let stat = match nix::sys::stat::stat(USER_CFG_FILENAME) {
Ok(stat) => Some(stat),
diff --git a/pbs-config/src/verify.rs b/pbs-config/src/verify.rs
index 2631eeef..05d6d259 100644
--- a/pbs-config/src/verify.rs
+++ b/pbs-config/src/verify.rs
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use anyhow::Error;
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
use proxmox_schema::*;
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};
-lazy_static! {
- pub static ref CONFIG: SectionConfig = init();
-}
+pub static CONFIG: Lazy<SectionConfig> = Lazy::new(init);
fn init() -> SectionConfig {
let obj_schema = match VerificationJobConfig::API_SCHEMA {
--
2.39.2
More information about the pbs-devel
mailing list