1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

Replace lazy_static with once_cell

This commit is contained in:
Jamie Quigley 2022-07-12 14:08:18 +01:00
parent 37b754f462
commit 1a270361c0
No known key found for this signature in database
GPG key ID: 8E8FF66E2AE8D970
9 changed files with 12 additions and 37 deletions

4
Cargo.lock generated
View file

@ -327,9 +327,9 @@ dependencies = [
"filetime", "filetime",
"glob", "glob",
"hex-literal", "hex-literal",
"lazy_static",
"libc", "libc",
"nix", "nix",
"once_cell",
"phf", "phf",
"phf_codegen", "phf_codegen",
"pretty_assertions", "pretty_assertions",
@ -2525,7 +2525,6 @@ dependencies = [
"chrono", "chrono",
"clap 3.1.18", "clap 3.1.18",
"glob", "glob",
"lazy_static",
"lscolors", "lscolors",
"number_prefix", "number_prefix",
"once_cell", "once_cell",
@ -3110,7 +3109,6 @@ dependencies = [
"dns-lookup", "dns-lookup",
"dunce", "dunce",
"itertools", "itertools",
"lazy_static",
"libc", "libc",
"nix", "nix",
"once_cell", "once_cell",

View file

@ -261,11 +261,11 @@ uudoc = [ "zip" ]
[dependencies] [dependencies]
clap = { version = "3.1", features = ["wrap_help", "cargo"] } clap = { version = "3.1", features = ["wrap_help", "cargo"] }
clap_complete = "3.1" clap_complete = "3.1"
once_cell = "1.13.0"
phf = "0.10.1" phf = "0.10.1"
lazy_static = { version="1.3" } selinux = { version="0.2", optional = true }
textwrap = { version="0.15", features=["terminal_size"] } textwrap = { version="0.15", features=["terminal_size"] }
uucore = { version=">=0.0.11", package="uucore", path="src/uucore" } uucore = { version=">=0.0.11", package="uucore", path="src/uucore" }
selinux = { version="0.2", optional = true }
zip = { version = "0.6.0", optional=true, default_features=false, features=["deflate"] } zip = { version = "0.6.0", optional=true, default_features=false, features=["deflate"] }
# * uutils # * uutils
uu_test = { optional=true, version="0.0.14", package="uu_test", path="src/uu/test" } uu_test = { optional=true, version="0.0.14", package="uu_test", path="src/uu/test" }

View file

@ -28,9 +28,6 @@ once_cell = "1.13.0"
atty = "0.2" atty = "0.2"
selinux = { version="0.2", optional = true } selinux = { version="0.2", optional = true }
[target.'cfg(unix)'.dependencies]
lazy_static = "1.4.0"
[[bin]] [[bin]]
name = "ls" name = "ls"
path = "src/main.rs" path = "src/main.rs"

View file

@ -9,9 +9,6 @@
#[macro_use] #[macro_use]
extern crate uucore; extern crate uucore;
#[cfg(unix)]
#[macro_use]
extern crate lazy_static;
use clap::{crate_version, Arg, Command}; use clap::{crate_version, Arg, Command};
use glob::Pattern; use glob::Pattern;
@ -2251,6 +2248,8 @@ fn get_inode(metadata: &Metadata) -> String {
// Currently getpwuid is `linux` target only. If it's broken out into // Currently getpwuid is `linux` target only. If it's broken out into
// a posix-compliant attribute this can be updated... // a posix-compliant attribute this can be updated...
#[cfg(unix)] #[cfg(unix)]
use once_cell::sync::Lazy;
#[cfg(unix)]
use std::sync::Mutex; use std::sync::Mutex;
#[cfg(unix)] #[cfg(unix)]
use uucore::entries; use uucore::entries;
@ -2258,9 +2257,7 @@ use uucore::quoting_style;
#[cfg(unix)] #[cfg(unix)]
fn cached_uid2usr(uid: u32) -> String { fn cached_uid2usr(uid: u32) -> String {
lazy_static! { static UID_CACHE: Lazy<Mutex<HashMap<u32, String>>> = Lazy::new(|| Mutex::new(HashMap::new()));
static ref UID_CACHE: Mutex<HashMap<u32, String>> = Mutex::new(HashMap::new());
}
let mut uid_cache = UID_CACHE.lock().unwrap(); let mut uid_cache = UID_CACHE.lock().unwrap();
uid_cache uid_cache
@ -2280,9 +2277,7 @@ fn display_uname(metadata: &Metadata, config: &Config) -> String {
#[cfg(all(unix, not(target_os = "redox")))] #[cfg(all(unix, not(target_os = "redox")))]
fn cached_gid2grp(gid: u32) -> String { fn cached_gid2grp(gid: u32) -> String {
lazy_static! { static GID_CACHE: Lazy<Mutex<HashMap<u32, String>>> = Lazy::new(|| Mutex::new(HashMap::new()));
static ref GID_CACHE: Mutex<HashMap<u32, String>> = Mutex::new(HashMap::new());
}
let mut gid_cache = GID_CACHE.lock().unwrap(); let mut gid_cache = GID_CACHE.lock().unwrap();
gid_cache gid_cache

View file

@ -41,7 +41,7 @@ nix = { version = "0.24.1", optional = true, default-features = false, features
[dev-dependencies] [dev-dependencies]
clap = "3.1" clap = "3.1"
lazy_static = "1.3" once_cell = "1.13"
[target.'cfg(target_os = "windows")'.dependencies] [target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3", features = ["errhandlingapi", "fileapi", "handleapi", "winerror"] } winapi = { version = "0.3", features = ["errhandlingapi", "fileapi", "handleapi", "winerror"] }

View file

@ -447,7 +447,7 @@ mod tests {
use std::env; use std::env;
// Required to instantiate mutex in shared context // Required to instantiate mutex in shared context
use clap::Command; use clap::Command;
use lazy_static::lazy_static; use once_cell::sync::Lazy;
use std::sync::Mutex; use std::sync::Mutex;
// The mutex is required here as by default all tests are run as separate // The mutex is required here as by default all tests are run as separate
@ -456,9 +456,7 @@ mod tests {
// occur if no precautions are taken. Thus we have all tests that rely on // occur if no precautions are taken. Thus we have all tests that rely on
// environment variables lock this empty mutex to ensure they don't access // environment variables lock this empty mutex to ensure they don't access
// it concurrently. // it concurrently.
lazy_static! { static TEST_MUTEX: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
static ref TEST_MUTEX: Mutex<()> = Mutex::new(());
}
// Environment variable for "VERSION_CONTROL" // Environment variable for "VERSION_CONTROL"
static ENV_VERSION_CONTROL: &str = "VERSION_CONTROL"; static ENV_VERSION_CONTROL: &str = "VERSION_CONTROL";

View file

@ -1,4 +1,5 @@
use crate::common::util::*; use crate::common::util::*;
use once_cell::sync::Lazy;
use std::fs::{metadata, set_permissions, OpenOptions, Permissions}; use std::fs::{metadata, set_permissions, OpenOptions, Permissions};
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt}; use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
use std::sync::Mutex; use std::sync::Mutex;
@ -11,9 +12,7 @@ use self::libc::umask;
static TEST_FILE: &str = "file"; static TEST_FILE: &str = "file";
static REFERENCE_FILE: &str = "reference"; static REFERENCE_FILE: &str = "reference";
static REFERENCE_PERMS: u32 = 0o247; static REFERENCE_PERMS: u32 = 0o247;
lazy_static! { static UMASK_MUTEX: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
static ref UMASK_MUTEX: Mutex<()> = Mutex::new(());
}
struct TestCase { struct TestCase {
args: Vec<&'static str>, args: Vec<&'static str>,

View file

@ -18,16 +18,9 @@ use std::os::unix::io::IntoRawFd;
use std::path::Path; use std::path::Path;
#[cfg(not(windows))] #[cfg(not(windows))]
use std::path::PathBuf; use std::path::PathBuf;
#[cfg(not(windows))]
use std::sync::Mutex;
use std::thread::sleep; use std::thread::sleep;
use std::time::Duration; use std::time::Duration;
#[cfg(not(windows))]
lazy_static! {
static ref UMASK_MUTEX: Mutex<()> = Mutex::new(());
}
const LONG_ARGS: &[&str] = &[ const LONG_ARGS: &[&str] = &[
"-l", "-l",
"--long", "--long",

View file

@ -1,11 +1,6 @@
#[macro_use] #[macro_use]
mod common; mod common;
#[allow(unused_imports)]
#[cfg(unix)]
#[macro_use]
extern crate lazy_static;
#[cfg(unix)] #[cfg(unix)]
extern crate rust_users; extern crate rust_users;