mirror of
https://github.com/veeso/termscp.git
synced 2026-07-26 17:41:02 +02:00
refactor: replace lazy_static with std::sync::LazyLock
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -4640,7 +4640,6 @@ dependencies = [
|
|||||||
"hostname",
|
"hostname",
|
||||||
"keyring",
|
"keyring",
|
||||||
"lazy-regex",
|
"lazy-regex",
|
||||||
"lazy_static",
|
|
||||||
"log",
|
"log",
|
||||||
"magic-crypt",
|
"magic-crypt",
|
||||||
"notify",
|
"notify",
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ keyring = { version = "^3", features = [
|
|||||||
"vendored",
|
"vendored",
|
||||||
] }
|
] }
|
||||||
lazy-regex = "^3"
|
lazy-regex = "^3"
|
||||||
lazy_static = "^1"
|
|
||||||
log = "^0.4"
|
log = "^0.4"
|
||||||
magic-crypt = "4"
|
magic-crypt = "4"
|
||||||
notify = "8"
|
notify = "8"
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ extern crate bitflags;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_regex;
|
extern crate lazy_regex;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate log;
|
extern crate log;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate magic_crypt;
|
extern crate magic_crypt;
|
||||||
|
|||||||
@@ -4,20 +4,21 @@
|
|||||||
|
|
||||||
// Ext
|
// Ext
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
|
#[cfg(not(test))]
|
||||||
|
static CONF_DIR: LazyLock<Option<PathBuf>> = LazyLock::new(dirs::config_dir);
|
||||||
|
#[cfg(test)]
|
||||||
|
static CONF_DIR: LazyLock<Option<PathBuf>> = LazyLock::new(|| Some(std::env::temp_dir()));
|
||||||
|
|
||||||
|
#[cfg(not(test))]
|
||||||
|
static CACHE_DIR: LazyLock<Option<PathBuf>> = LazyLock::new(dirs::cache_dir);
|
||||||
|
#[cfg(test)]
|
||||||
|
static CACHE_DIR: LazyLock<Option<PathBuf>> = LazyLock::new(|| Some(std::env::temp_dir()));
|
||||||
|
|
||||||
/// Get termscp config directory path and initialize it.
|
/// Get termscp config directory path and initialize it.
|
||||||
/// Returns None if it's not possible to initialize it
|
/// Returns None if it's not possible to initialize it
|
||||||
pub fn init_config_dir() -> Result<Option<PathBuf>, String> {
|
pub fn init_config_dir() -> Result<Option<PathBuf>, String> {
|
||||||
// Get file
|
|
||||||
#[cfg(not(test))]
|
|
||||||
lazy_static! {
|
|
||||||
static ref CONF_DIR: Option<PathBuf> = dirs::config_dir();
|
|
||||||
}
|
|
||||||
#[cfg(test)]
|
|
||||||
lazy_static! {
|
|
||||||
static ref CONF_DIR: Option<PathBuf> = Some(std::env::temp_dir());
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(dir) = CONF_DIR.as_deref() {
|
if let Some(dir) = CONF_DIR.as_deref() {
|
||||||
init_dir(dir).map(Option::Some)
|
init_dir(dir).map(Option::Some)
|
||||||
} else {
|
} else {
|
||||||
@@ -28,16 +29,6 @@ pub fn init_config_dir() -> Result<Option<PathBuf>, String> {
|
|||||||
/// Get termscp cache directory path and initialize it.
|
/// Get termscp cache directory path and initialize it.
|
||||||
/// Returns None if it's not possible to initialize it
|
/// Returns None if it's not possible to initialize it
|
||||||
pub fn init_cache_dir() -> Result<Option<PathBuf>, String> {
|
pub fn init_cache_dir() -> Result<Option<PathBuf>, String> {
|
||||||
// Get file
|
|
||||||
#[cfg(not(test))]
|
|
||||||
lazy_static! {
|
|
||||||
static ref CACHE_DIR: Option<PathBuf> = dirs::cache_dir();
|
|
||||||
}
|
|
||||||
#[cfg(test)]
|
|
||||||
lazy_static! {
|
|
||||||
static ref CACHE_DIR: Option<PathBuf> = Some(std::env::temp_dir());
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(dir) = CACHE_DIR.as_deref() {
|
if let Some(dir) = CACHE_DIR.as_deref() {
|
||||||
init_dir(dir).map(Option::Some)
|
init_dir(dir).map(Option::Some)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user