Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: Drop our once_cell usage #583

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ indicatif = "0.17.8"
libc = "^0.2.154"
liboverdrop = "0.1.0"
libsystemd = "0.7"
once_cell = "1.19"
openssl = "^0.10.64"
# TODO drop this in favor of rustix
nix = { version = "0.28", features = ["ioctl", "sched"] }
Expand Down
7 changes: 4 additions & 3 deletions lib/src/blockdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use anyhow::{anyhow, Context, Result};
use camino::{Utf8Path, Utf8PathBuf};
use fn_error_context::context;
use nix::errno::Errno;
use once_cell::sync::Lazy;
use regex::Regex;
use serde::Deserialize;
use std::collections::HashMap;
Expand All @@ -13,6 +12,7 @@ use std::fs::File;
use std::os::unix::io::AsRawFd;
use std::path::Path;
use std::process::Command;
use std::sync::OnceLock;

#[derive(Debug, Deserialize)]
struct DevicesOutput {
Expand Down Expand Up @@ -185,9 +185,10 @@ pub(crate) fn reread_partition_table(file: &mut File, retry: bool) -> Result<()>
/// Parse key-value pairs from lsblk --pairs.
/// Newer versions of lsblk support JSON but the one in CentOS 7 doesn't.
fn split_lsblk_line(line: &str) -> HashMap<String, String> {
static REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r#"([A-Z-_]+)="([^"]+)""#).unwrap());
static REGEX: OnceLock<Regex> = OnceLock::new();
let regex = REGEX.get_or_init(|| Regex::new(r#"([A-Z-_]+)="([^"]+)""#).unwrap());
let mut fields: HashMap<String, String> = HashMap::new();
for cap in REGEX.captures_iter(line) {
for cap in regex.captures_iter(line) {
fields.insert(cap[1].to_string(), cap[2].to_string());
}
fields
Expand Down
Loading