Skip to content

Commit 76b9e5e

Browse files
authored
Merge pull request #1283 from cgwalters/drop-once-cell
Port from once_cell to std
2 parents 50f088b + 3cb7e09 commit 76b9e5e

File tree

6 files changed

+16
-20
lines changed

6 files changed

+16
-20
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ostree-ext/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ gvariant = "0.5.0"
3434
hex = { workspace = true }
3535
io-lifetimes = "2"
3636
indicatif = { workspace = true }
37-
once_cell = "1.9"
3837
libc = { workspace = true }
3938
libsystemd = "0.7.0"
4039
openssl = { workspace = true }

ostree-ext/src/fixture.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use gvariant::{Marker, Structure};
2424
use io_lifetimes::AsFd;
2525
use ocidir::cap_std::fs::{DirBuilder, DirBuilderExt as _};
2626
use ocidir::oci_spec::image::ImageConfigurationBuilder;
27-
use once_cell::sync::Lazy;
2827
use regex::Regex;
2928
use std::borrow::Cow;
3029
use std::ffi::CString;
@@ -33,7 +32,7 @@ use std::io::{self, Write};
3332
use std::ops::Add;
3433
use std::process::{Command, Stdio};
3534
use std::rc::Rc;
36-
use std::sync::Arc;
35+
use std::sync::{Arc, LazyLock};
3736
use tempfile::TempDir;
3837

3938
const OSTREE_GPG_HOME: &[u8] = include_bytes!("fixtures/ostree-gpg-test-home.tar.gz");
@@ -183,7 +182,7 @@ impl FileDef {
183182
}
184183

185184
/// This is like a package database, mapping our test fixture files to package names
186-
static OWNERS: Lazy<Vec<(Regex, &str)>> = Lazy::new(|| {
185+
static OWNERS: LazyLock<Vec<(Regex, &str)>> = LazyLock::new(|| {
187186
[
188187
("usr/lib/modules/.*/initramfs", "initramfs"),
189188
("usr/lib/modules", "kernel"),

ostree-ext/src/globals.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use super::Result;
44
use camino::{Utf8Path, Utf8PathBuf};
55
use cap_std_ext::cap_std::fs::Dir;
66
use cap_std_ext::RootDir;
7-
use once_cell::sync::OnceCell;
87
use ostree::glib;
98
use std::fs::File;
9+
use std::sync::OnceLock;
1010

1111
struct ConfigPaths {
1212
persistent: Utf8PathBuf,
@@ -19,10 +19,10 @@ struct ConfigPaths {
1919
/// user(nonroot) case: /run/user/$uid/ostree ~/.config/ostree <none>
2020
fn get_config_paths(root: bool) -> &'static ConfigPaths {
2121
if root {
22-
static PATHS_ROOT: OnceCell<ConfigPaths> = OnceCell::new();
22+
static PATHS_ROOT: OnceLock<ConfigPaths> = OnceLock::new();
2323
PATHS_ROOT.get_or_init(|| ConfigPaths::new("etc", "run", Some("usr/lib")))
2424
} else {
25-
static PATHS_USER: OnceCell<ConfigPaths> = OnceCell::new();
25+
static PATHS_USER: OnceLock<ConfigPaths> = OnceLock::new();
2626
PATHS_USER.get_or_init(|| {
2727
ConfigPaths::new(
2828
Utf8PathBuf::try_from(glib::user_config_dir()).unwrap(),

ostree-ext/src/isolation.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
use std::process::Command;
2-
3-
use once_cell::sync::Lazy;
2+
use std::sync::OnceLock;
43

54
pub(crate) const DEFAULT_UNPRIVILEGED_USER: &str = "nobody";
65

76
/// Checks if the current process is (apparently at least)
87
/// running under systemd. We use this in various places
98
/// to e.g. log to the journal instead of printing to stdout.
109
pub(crate) fn running_in_systemd() -> bool {
11-
static RUNNING_IN_SYSTEMD: Lazy<bool> = Lazy::new(|| {
10+
static RUNNING_IN_SYSTEMD: OnceLock<bool> = OnceLock::new();
11+
*RUNNING_IN_SYSTEMD.get_or_init(|| {
1212
// See https://www.freedesktop.org/software/systemd/man/systemd.exec.html#%24INVOCATION_ID
1313
std::env::var_os("INVOCATION_ID")
1414
.filter(|s| !s.is_empty())
1515
.is_some()
16-
});
17-
18-
*RUNNING_IN_SYSTEMD
16+
})
1917
}
2018

2119
/// Return a prepared subprocess configuration that will run as an unprivileged user if possible.

ostree-ext/tests/it/main.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use gvariant::{Marker, Structure};
1010
use oci_image::ImageManifest;
1111
use oci_spec::image as oci_image;
1212
use ocidir::oci_spec::image::{Arch, DigestAlgorithm};
13-
use once_cell::sync::{Lazy, OnceCell};
1413
use ostree_ext::chunking::ObjectMetaSized;
1514
use ostree_ext::container::{store, ManifestDiff};
1615
use ostree_ext::container::{
@@ -24,6 +23,7 @@ use std::borrow::Cow;
2423
use std::collections::{HashMap, HashSet};
2524
use std::io::{BufReader, BufWriter};
2625
use std::process::{Command, Stdio};
26+
use std::sync::{LazyLock, OnceLock};
2727
use std::time::SystemTime;
2828
use xshell::cmd;
2929

@@ -36,7 +36,7 @@ const TEST_REGISTRY_DEFAULT: &str = "localhost:5000";
3636

3737
/// Check if we have skopeo
3838
fn check_skopeo() -> bool {
39-
static HAVE_SKOPEO: OnceCell<bool> = OnceCell::new();
39+
static HAVE_SKOPEO: OnceLock<bool> = OnceLock::new();
4040
*HAVE_SKOPEO.get_or_init(|| {
4141
Command::new("skopeo")
4242
.arg("--help")
@@ -56,10 +56,11 @@ fn assert_err_contains<T>(r: Result<T>, s: impl AsRef<str>) {
5656
}
5757
}
5858

59-
static TEST_REGISTRY: Lazy<String> = Lazy::new(|| match std::env::var_os("TEST_REGISTRY") {
60-
Some(t) => t.to_str().unwrap().to_owned(),
61-
None => TEST_REGISTRY_DEFAULT.to_string(),
62-
});
59+
static TEST_REGISTRY: LazyLock<String> =
60+
LazyLock::new(|| match std::env::var_os("TEST_REGISTRY") {
61+
Some(t) => t.to_str().unwrap().to_owned(),
62+
None => TEST_REGISTRY_DEFAULT.to_string(),
63+
});
6364

6465
// This is mostly just sanity checking these functions are publicly accessible
6566
#[test]

0 commit comments

Comments
 (0)