Skip to content

Commit 7d39437

Browse files
Cache systemd version in OnceLock
Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 94cc06c commit 7d39437

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

crates/lib/src/bootloader.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::fs::create_dir_all;
22
use std::process::Command;
3+
use std::sync::OnceLock;
34

45
use anyhow::{Context, Result, anyhow, bail};
56
use bootc_utils::{ChrootCmd, CommandRunExt};
@@ -327,8 +328,18 @@ pub(crate) fn install_systemd_boot(
327328

328329
#[context("Querying bootctl version")]
329330
pub(crate) fn bootctl_systemd_version() -> Result<u32> {
331+
static VERSION: OnceLock<u32> = OnceLock::new();
332+
333+
if let Some(v) = VERSION.get() {
334+
return Ok(*v);
335+
};
336+
330337
let out = Command::new("bootctl").arg("--version").run_get_string()?;
331-
parse_systemd_version(&out)
338+
let v = parse_systemd_version(&out).context("Failed to parse version to integer")?;
339+
340+
let version = VERSION.get_or_init(|| v);
341+
342+
Ok(*version)
332343
}
333344

334345
/// Parse the systemd major version from `bootctl --version` output, whose first

0 commit comments

Comments
 (0)