[pbs-devel] [PATCH backup 09/11] restore-daemon: remove lazy_static dependency

Maximiliano Sandoval m.sandoval at proxmox.com
Tue Aug 13 10:44:14 CEST 2024


Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
---
 proxmox-restore-daemon/Cargo.toml             |  2 +-
 proxmox-restore-daemon/src/main.rs            | 12 +++----
 .../src/proxmox_restore_daemon/disk.rs        | 32 +++++++++----------
 3 files changed, 20 insertions(+), 26 deletions(-)

diff --git a/proxmox-restore-daemon/Cargo.toml b/proxmox-restore-daemon/Cargo.toml
index 161b371d..beb455e5 100644
--- a/proxmox-restore-daemon/Cargo.toml
+++ b/proxmox-restore-daemon/Cargo.toml
@@ -4,6 +4,7 @@ version = "0.1.0"
 authors.workspace = true
 edition.workspace = true
 description = "Proxmox Restore Daemon"
+rust-version.workspace = true
 
 [dependencies]
 anyhow.workspace = true
@@ -12,7 +13,6 @@ env_logger.workspace = true
 futures.workspace = true
 http.workspace = true
 hyper.workspace = true
-lazy_static.workspace = true
 libc.workspace = true
 log.workspace = true
 nix.workspace = true
diff --git a/proxmox-restore-daemon/src/main.rs b/proxmox-restore-daemon/src/main.rs
index f94b6c67..0131d771 100644
--- a/proxmox-restore-daemon/src/main.rs
+++ b/proxmox-restore-daemon/src/main.rs
@@ -6,10 +6,9 @@ use std::os::unix::{
     net,
 };
 use std::path::Path;
-use std::sync::{Arc, Mutex};
+use std::sync::{Arc, LazyLock, Mutex};
 
 use anyhow::{bail, format_err, Error};
-use lazy_static::lazy_static;
 use log::{error, info};
 use tokio::sync::mpsc;
 use tokio_stream::wrappers::ReceiverStream;
@@ -29,12 +28,9 @@ pub const MAX_PENDING: usize = 32;
 /// Will be present in base initramfs
 pub const VM_DETECT_FILE: &str = "/restore-vm-marker";
 
-lazy_static! {
-    /// The current disks state. Use for accessing data on the attached snapshots.
-    pub static ref DISK_STATE: Arc<Mutex<DiskState>> = {
-        Arc::new(Mutex::new(DiskState::scan().unwrap()))
-    };
-}
+/// The current disks state. Use for accessing data on the attached snapshots.
+pub static DISK_STATE: LazyLock<Arc<Mutex<DiskState>>> =
+    LazyLock::new(|| Arc::new(Mutex::new(DiskState::scan().unwrap())));
 
 fn init_disk_state() {
     info!("scanning all disks...");
diff --git a/proxmox-restore-daemon/src/proxmox_restore_daemon/disk.rs b/proxmox-restore-daemon/src/proxmox_restore_daemon/disk.rs
index 20ddfc6b..f60dbbfa 100644
--- a/proxmox-restore-daemon/src/proxmox_restore_daemon/disk.rs
+++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/disk.rs
@@ -4,9 +4,9 @@ use std::fs::{create_dir_all, File};
 use std::io::{BufRead, BufReader};
 use std::path::{Component, Path, PathBuf};
 use std::process::Command;
+use std::sync::LazyLock;
 
 use anyhow::{bail, format_err, Error};
-use lazy_static::lazy_static;
 use log::{info, warn};
 
 use proxmox_schema::const_regex;
@@ -21,27 +21,25 @@ const_regex! {
     ZPOOL_IMPORT_DISK_REGEX = r"^\t {2,4}(vd[a-z]+(?:\d+)?)\s+ONLINE$";
 }
 
-lazy_static! {
-    static ref FS_OPT_MAP: HashMap<&'static str, &'static str> = {
-        let mut m = HashMap::new();
+static FS_OPT_MAP: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(|| {
+    let mut m = HashMap::new();
 
-        // otherwise ext complains about mounting read-only
-        m.insert("ext2", "noload");
-        m.insert("ext3", "noload");
-        m.insert("ext4", "noload");
+    // otherwise ext complains about mounting read-only
+    m.insert("ext2", "noload");
+    m.insert("ext3", "noload");
+    m.insert("ext4", "noload");
 
-        m.insert("xfs", "norecovery");
+    m.insert("xfs", "norecovery");
 
-        // ufs2 is used as default since FreeBSD 5.0 released in 2003, so let's assume that
-        // whatever the user is trying to restore is not using anything older...
-        m.insert("ufs", "ufstype=ufs2");
+    // ufs2 is used as default since FreeBSD 5.0 released in 2003, so let's assume that
+    // whatever the user is trying to restore is not using anything older...
+    m.insert("ufs", "ufstype=ufs2");
 
-        m.insert("ntfs", "utf8");
-        m.insert("ntfs3", "iocharset=utf8");
+    m.insert("ntfs", "utf8");
+    m.insert("ntfs3", "iocharset=utf8");
 
-        m
-    };
-}
+    m
+});
 
 pub enum ResolveResult {
     Path(PathBuf),
-- 
2.39.2





More information about the pbs-devel mailing list