mirror of
https://git.proxmox.com/git/proxmox-backup
synced 2025-04-28 20:44:53 +00:00
backup: remove lazy_static dependency
Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
This commit is contained in:
parent
8dc1b5abf7
commit
17c82d4a73
@ -128,7 +128,6 @@ handlebars = "3.0"
|
|||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
http = "0.2"
|
http = "0.2"
|
||||||
hyper = { version = "0.14", features = [ "full" ] }
|
hyper = { version = "0.14", features = [ "full" ] }
|
||||||
lazy_static = "1.4"
|
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
nix = "0.26.1"
|
nix = "0.26.1"
|
||||||
@ -180,7 +179,6 @@ handlebars.workspace = true
|
|||||||
hex.workspace = true
|
hex.workspace = true
|
||||||
http.workspace = true
|
http.workspace = true
|
||||||
hyper.workspace = true
|
hyper.workspace = true
|
||||||
lazy_static.workspace = true
|
|
||||||
libc.workspace = true
|
libc.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
nix.workspace = true
|
nix.workspace = true
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::ops::ControlFlow;
|
use std::ops::ControlFlow;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, LazyLock, Mutex};
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
use anyhow::{bail, format_err, Error};
|
use anyhow::{bail, format_err, Error};
|
||||||
use hex::FromHex;
|
use hex::FromHex;
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
@ -430,10 +429,8 @@ impl Serialize for ChallengeSchemaWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_cached_challenge_schemas() -> Result<ChallengeSchemaWrapper, Error> {
|
fn get_cached_challenge_schemas() -> Result<ChallengeSchemaWrapper, Error> {
|
||||||
lazy_static! {
|
static CACHE: LazyLock<Mutex<Option<(Arc<Vec<AcmeChallengeSchema>>, SystemTime)>>> =
|
||||||
static ref CACHE: Mutex<Option<(Arc<Vec<AcmeChallengeSchema>>, SystemTime)>> =
|
LazyLock::new(|| Mutex::new(None));
|
||||||
Mutex::new(None);
|
|
||||||
}
|
|
||||||
|
|
||||||
// the actual loading code
|
// the actual loading code
|
||||||
let mut last = CACHE.lock().unwrap();
|
let mut last = CACHE.lock().unwrap();
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use ::serde::{Deserialize, Serialize};
|
use ::serde::{Deserialize, Serialize};
|
||||||
use anyhow::{bail, Error};
|
use anyhow::{bail, Error};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
@ -71,9 +73,8 @@ pub struct DatastoreMountInfo {
|
|||||||
)]
|
)]
|
||||||
/// List systemd datastore mount units.
|
/// List systemd datastore mount units.
|
||||||
pub fn list_datastore_mounts() -> Result<Vec<DatastoreMountInfo>, Error> {
|
pub fn list_datastore_mounts() -> Result<Vec<DatastoreMountInfo>, Error> {
|
||||||
lazy_static::lazy_static! {
|
static MOUNT_NAME_REGEX: LazyLock<regex::Regex> =
|
||||||
static ref MOUNT_NAME_REGEX: regex::Regex = regex::Regex::new(r"^mnt-datastore-(.+)\.mount$").unwrap();
|
LazyLock::new(|| regex::Regex::new(r"^mnt-datastore-(.+)\.mount$").unwrap());
|
||||||
}
|
|
||||||
|
|
||||||
let mut list = Vec::new();
|
let mut list = Vec::new();
|
||||||
|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, LazyLock, Mutex};
|
||||||
|
|
||||||
use ::serde::{Deserialize, Serialize};
|
use ::serde::{Deserialize, Serialize};
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
use const_format::concatcp;
|
use const_format::concatcp;
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use openssl::sha;
|
use openssl::sha;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
@ -46,11 +45,10 @@ pub fn read_etc_resolv_conf() -> Result<Value, Error> {
|
|||||||
|
|
||||||
let data = String::from_utf8(raw)?;
|
let data = String::from_utf8(raw)?;
|
||||||
|
|
||||||
lazy_static! {
|
static DOMAIN_REGEX: LazyLock<Regex> =
|
||||||
static ref DOMAIN_REGEX: Regex = Regex::new(r"^\s*(?:search|domain)\s+(\S+)\s*").unwrap();
|
LazyLock::new(|| Regex::new(r"^\s*(?:search|domain)\s+(\S+)\s*").unwrap());
|
||||||
static ref SERVER_REGEX: Regex =
|
static SERVER_REGEX: LazyLock<Regex> =
|
||||||
Regex::new(concatcp!(r"^\s*nameserver\s+(", IPRE_STR, r")\s*")).unwrap();
|
LazyLock::new(|| Regex::new(concatcp!(r"^\s*nameserver\s+(", IPRE_STR, r")\s*")).unwrap());
|
||||||
}
|
|
||||||
|
|
||||||
let mut options = String::new();
|
let mut options = String::new();
|
||||||
|
|
||||||
@ -131,9 +129,7 @@ pub fn update_dns(
|
|||||||
delete: Option<Vec<DeletableProperty>>,
|
delete: Option<Vec<DeletableProperty>>,
|
||||||
digest: Option<String>,
|
digest: Option<String>,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
lazy_static! {
|
static MUTEX: LazyLock<Arc<Mutex<()>>> = LazyLock::new(|| Arc::new(Mutex::new(())));
|
||||||
static ref MUTEX: Arc<Mutex<()>> = Arc::new(Mutex::new(()));
|
|
||||||
}
|
|
||||||
|
|
||||||
let _guard = MUTEX.lock();
|
let _guard = MUTEX.lock();
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
@ -15,9 +16,7 @@ pub const PLUGIN_ID_SCHEMA: Schema = StringSchema::new("ACME Challenge Plugin ID
|
|||||||
.max_length(32)
|
.max_length(32)
|
||||||
.schema();
|
.schema();
|
||||||
|
|
||||||
lazy_static! {
|
pub static CONFIG: LazyLock<SectionConfig> = LazyLock::new(init);
|
||||||
pub static ref CONFIG: SectionConfig = init();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[api(
|
#[api(
|
||||||
properties: {
|
properties: {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
//! tapes
|
//! tapes
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use endian_trait::Endian;
|
use endian_trait::Endian;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@ -56,22 +57,48 @@ pub const PROXMOX_BACKUP_CATALOG_ARCHIVE_MAGIC_1_0: [u8; 8] =
|
|||||||
// openssl::sha::sha256(b"Proxmox Backup Catalog Archive v1.1")[0..8];
|
// openssl::sha::sha256(b"Proxmox Backup Catalog Archive v1.1")[0..8];
|
||||||
pub const PROXMOX_BACKUP_CATALOG_ARCHIVE_MAGIC_1_1: [u8; 8] = [179, 236, 113, 240, 173, 236, 2, 96];
|
pub const PROXMOX_BACKUP_CATALOG_ARCHIVE_MAGIC_1_1: [u8; 8] = [179, 236, 113, 240, 173, 236, 2, 96];
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
// Map content magic numbers to human readable names.
|
||||||
// Map content magic numbers to human readable names.
|
static PROXMOX_TAPE_CONTENT_NAME: LazyLock<HashMap<&'static [u8; 8], &'static str>> =
|
||||||
static ref PROXMOX_TAPE_CONTENT_NAME: HashMap<&'static [u8;8], &'static str> = {
|
LazyLock::new(|| {
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
map.insert(&PROXMOX_BACKUP_MEDIA_LABEL_MAGIC_1_0, "Proxmox Backup Tape Label v1.0");
|
map.insert(
|
||||||
map.insert(&PROXMOX_BACKUP_MEDIA_SET_LABEL_MAGIC_1_0, "Proxmox Backup MediaSet Label v1.0");
|
&PROXMOX_BACKUP_MEDIA_LABEL_MAGIC_1_0,
|
||||||
map.insert(&PROXMOX_BACKUP_CHUNK_ARCHIVE_MAGIC_1_0, "Proxmox Backup Chunk Archive v1.0");
|
"Proxmox Backup Tape Label v1.0",
|
||||||
map.insert(&PROXMOX_BACKUP_CHUNK_ARCHIVE_MAGIC_1_1, "Proxmox Backup Chunk Archive v1.1");
|
);
|
||||||
map.insert(&PROXMOX_BACKUP_SNAPSHOT_ARCHIVE_MAGIC_1_0, "Proxmox Backup Snapshot Archive v1.0");
|
map.insert(
|
||||||
map.insert(&PROXMOX_BACKUP_SNAPSHOT_ARCHIVE_MAGIC_1_1, "Proxmox Backup Snapshot Archive v1.1");
|
&PROXMOX_BACKUP_MEDIA_SET_LABEL_MAGIC_1_0,
|
||||||
map.insert(&PROXMOX_BACKUP_SNAPSHOT_ARCHIVE_MAGIC_1_2, "Proxmox Backup Snapshot Archive v1.2");
|
"Proxmox Backup MediaSet Label v1.0",
|
||||||
map.insert(&PROXMOX_BACKUP_CATALOG_ARCHIVE_MAGIC_1_0, "Proxmox Backup Catalog Archive v1.0");
|
);
|
||||||
map.insert(&PROXMOX_BACKUP_CATALOG_ARCHIVE_MAGIC_1_1, "Proxmox Backup Catalog Archive v1.1");
|
map.insert(
|
||||||
|
&PROXMOX_BACKUP_CHUNK_ARCHIVE_MAGIC_1_0,
|
||||||
|
"Proxmox Backup Chunk Archive v1.0",
|
||||||
|
);
|
||||||
|
map.insert(
|
||||||
|
&PROXMOX_BACKUP_CHUNK_ARCHIVE_MAGIC_1_1,
|
||||||
|
"Proxmox Backup Chunk Archive v1.1",
|
||||||
|
);
|
||||||
|
map.insert(
|
||||||
|
&PROXMOX_BACKUP_SNAPSHOT_ARCHIVE_MAGIC_1_0,
|
||||||
|
"Proxmox Backup Snapshot Archive v1.0",
|
||||||
|
);
|
||||||
|
map.insert(
|
||||||
|
&PROXMOX_BACKUP_SNAPSHOT_ARCHIVE_MAGIC_1_1,
|
||||||
|
"Proxmox Backup Snapshot Archive v1.1",
|
||||||
|
);
|
||||||
|
map.insert(
|
||||||
|
&PROXMOX_BACKUP_SNAPSHOT_ARCHIVE_MAGIC_1_2,
|
||||||
|
"Proxmox Backup Snapshot Archive v1.2",
|
||||||
|
);
|
||||||
|
map.insert(
|
||||||
|
&PROXMOX_BACKUP_CATALOG_ARCHIVE_MAGIC_1_0,
|
||||||
|
"Proxmox Backup Catalog Archive v1.0",
|
||||||
|
);
|
||||||
|
map.insert(
|
||||||
|
&PROXMOX_BACKUP_CATALOG_ARCHIVE_MAGIC_1_1,
|
||||||
|
"Proxmox Backup Catalog Archive v1.1",
|
||||||
|
);
|
||||||
map
|
map
|
||||||
};
|
});
|
||||||
}
|
|
||||||
|
|
||||||
/// Map content magic numbers to human readable names.
|
/// Map content magic numbers to human readable names.
|
||||||
pub fn proxmox_tape_magic_to_text(magic: &[u8; 8]) -> Option<String> {
|
pub fn proxmox_tape_magic_to_text(magic: &[u8; 8]) -> Option<String> {
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
use super::LsblkInfo;
|
use super::LsblkInfo;
|
||||||
|
|
||||||
lazy_static! {
|
static LVM_UUIDS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
|
||||||
static ref LVM_UUIDS: HashSet<&'static str> = {
|
let mut set = HashSet::new();
|
||||||
let mut set = HashSet::new();
|
set.insert("e6d6d379-f507-44c2-a23c-238f2a3df928");
|
||||||
set.insert("e6d6d379-f507-44c2-a23c-238f2a3df928");
|
set
|
||||||
set
|
});
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get set of devices used by LVM (pvs).
|
/// Get set of devices used by LVM (pvs).
|
||||||
///
|
///
|
||||||
|
@ -6,7 +6,7 @@ use std::io;
|
|||||||
use std::os::unix::ffi::{OsStrExt, OsStringExt};
|
use std::os::unix::ffi::{OsStrExt, OsStringExt};
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::Arc;
|
use std::sync::{Arc, LazyLock};
|
||||||
|
|
||||||
use anyhow::{bail, format_err, Error};
|
use anyhow::{bail, format_err, Error};
|
||||||
use libc::dev_t;
|
use libc::dev_t;
|
||||||
@ -32,10 +32,8 @@ pub use lvm::*;
|
|||||||
mod smart;
|
mod smart;
|
||||||
pub use smart::*;
|
pub use smart::*;
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
static ISCSI_PATH_REGEX: LazyLock<regex::Regex> =
|
||||||
static ref ISCSI_PATH_REGEX: regex::Regex =
|
LazyLock::new(|| regex::Regex::new(r"host[^/]*/session[^/]*").unwrap());
|
||||||
regex::Regex::new(r"host[^/]*/session[^/]*").unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Disk management context.
|
/// Disk management context.
|
||||||
///
|
///
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use ::serde::{Deserialize, Serialize};
|
use ::serde::{Deserialize, Serialize};
|
||||||
use anyhow::{bail, Error};
|
use anyhow::{bail, Error};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
|
|
||||||
use proxmox_schema::api;
|
use proxmox_schema::api;
|
||||||
|
|
||||||
@ -224,7 +224,5 @@ static WEAROUT_FIELD_ORDER: &[&str] = &[
|
|||||||
"Perc_Rated_Life_Used",
|
"Perc_Rated_Life_Used",
|
||||||
];
|
];
|
||||||
|
|
||||||
lazy_static! {
|
static WEAROUT_FIELD_NAMES: LazyLock<HashSet<&'static str>> =
|
||||||
static ref WEAROUT_FIELD_NAMES: HashSet<&'static str> =
|
LazyLock::new(|| WEAROUT_FIELD_ORDER.iter().cloned().collect());
|
||||||
WEAROUT_FIELD_ORDER.iter().cloned().collect();
|
|
||||||
}
|
|
||||||
|
@ -1,23 +1,20 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, LazyLock, Mutex};
|
||||||
|
|
||||||
use anyhow::{bail, Error};
|
use anyhow::{bail, Error};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
|
|
||||||
use proxmox_schema::const_regex;
|
use proxmox_schema::const_regex;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
lazy_static! {
|
static ZFS_UUIDS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
|
||||||
static ref ZFS_UUIDS: HashSet<&'static str> = {
|
let mut set = HashSet::new();
|
||||||
let mut set = HashSet::new();
|
set.insert("6a898cc3-1dd2-11b2-99a6-080020736631"); // apple
|
||||||
set.insert("6a898cc3-1dd2-11b2-99a6-080020736631"); // apple
|
set.insert("516e7cba-6ecf-11d6-8ff8-00022d09712b"); // bsd
|
||||||
set.insert("516e7cba-6ecf-11d6-8ff8-00022d09712b"); // bsd
|
set
|
||||||
set
|
});
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_pool_from_dataset(dataset: &str) -> &str {
|
fn get_pool_from_dataset(dataset: &str) -> &str {
|
||||||
if let Some(idx) = dataset.find('/') {
|
if let Some(idx) = dataset.find('/') {
|
||||||
@ -100,10 +97,8 @@ const_regex! {
|
|||||||
OBJSET_REGEX = r"^objset-0x[a-fA-F0-9]+$";
|
OBJSET_REGEX = r"^objset-0x[a-fA-F0-9]+$";
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
pub static ZFS_DATASET_OBJSET_MAP: LazyLock<Arc<Mutex<HashMap<String, (String, String)>>>> =
|
||||||
pub static ref ZFS_DATASET_OBJSET_MAP: Arc<Mutex<HashMap<String, (String, String)>>> =
|
LazyLock::new(|| Arc::new(Mutex::new(HashMap::new())));
|
||||||
Arc::new(Mutex::new(HashMap::new()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// parses /proc/spl/kstat/zfs/POOL/objset-ID files
|
// parses /proc/spl/kstat/zfs/POOL/objset-ID files
|
||||||
// they have the following format:
|
// they have the following format:
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
use lazy_static::lazy_static;
|
|
||||||
|
|
||||||
use super::types::*;
|
use super::types::*;
|
||||||
|
|
||||||
@ -8,11 +9,9 @@ use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlug
|
|||||||
|
|
||||||
use proxmox_sys::{fs::replace_file, fs::CreateOptions};
|
use proxmox_sys::{fs::replace_file, fs::CreateOptions};
|
||||||
|
|
||||||
lazy_static! {
|
pub static SERVICE_CONFIG: LazyLock<SectionConfig> = LazyLock::new(init_service);
|
||||||
pub static ref SERVICE_CONFIG: SectionConfig = init_service();
|
pub static TIMER_CONFIG: LazyLock<SectionConfig> = LazyLock::new(init_timer);
|
||||||
pub static ref TIMER_CONFIG: SectionConfig = init_timer();
|
pub static MOUNT_CONFIG: LazyLock<SectionConfig> = LazyLock::new(init_mount);
|
||||||
pub static ref MOUNT_CONFIG: SectionConfig = init_mount();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn init_service() -> SectionConfig {
|
fn init_service() -> SectionConfig {
|
||||||
let mut config = SectionConfig::with_systemd_syntax(&SYSTEMD_SECTION_NAME_SCHEMA);
|
let mut config = SectionConfig::with_systemd_syntax(&SYSTEMD_SECTION_NAME_SCHEMA);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, LazyLock, Mutex};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
@ -21,11 +21,9 @@ use crate::tools::SharedRateLimiter;
|
|||||||
|
|
||||||
pub type SharedRateLimit = Arc<dyn ShareableRateLimit>;
|
pub type SharedRateLimit = Arc<dyn ShareableRateLimit>;
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
/// Shared traffic control cache singleton.
|
||||||
/// Shared traffic control cache singleton.
|
pub static TRAFFIC_CONTROL_CACHE: LazyLock<Arc<Mutex<TrafficControlCache>>> =
|
||||||
pub static ref TRAFFIC_CONTROL_CACHE: Arc<Mutex<TrafficControlCache>> =
|
LazyLock::new(|| Arc::new(Mutex::new(TrafficControlCache::new())));
|
||||||
Arc::new(Mutex::new(TrafficControlCache::new()));
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ParsedTcRule {
|
struct ParsedTcRule {
|
||||||
config: TrafficControlRule, // original rule config
|
config: TrafficControlRule, // original rule config
|
||||||
|
Loading…
Reference in New Issue
Block a user