diff options
| author | Hermes Agent <hermes@localhost> | 2026-08-12 07:48:21 +0000 |
|---|---|---|
| committer | Hermes Agent <hermes@localhost> | 2026-08-12 07:48:21 +0000 |
| commit | f967d698efd44473a9285e02d0109f3bb0641622 (patch) | |
| tree | c94975571db9426cf71b15c9e6d16346e438c7c6 /src/initramfs.rs | |
| parent | 5e6cae20331f8e7cfd551b4656f0de852a4ad44c (diff) | |
Format native builder and satisfy clippy
Diffstat (limited to 'src/initramfs.rs')
| -rw-r--r-- | src/initramfs.rs | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/src/initramfs.rs b/src/initramfs.rs index 4475aed..a108b85 100644 --- a/src/initramfs.rs +++ b/src/initramfs.rs @@ -4,7 +4,7 @@ use std::os::unix::fs::symlink; use std::path::{Path, PathBuf}; use std::process::Command; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use sha2::{Digest, Sha256}; #[derive(Debug, Clone, PartialEq, Eq)] @@ -32,7 +32,11 @@ impl KernelVersion { match kernels.as_slice() { [] => bail!("no RT kernel image found in {}", boot.display()), [version] => Ok(Self(version.clone())), - _ => bail!("multiple RT kernel images found in {}: {}", boot.display(), kernels.join(", ")), + _ => bail!( + "multiple RT kernel images found in {}: {}", + boot.display(), + kernels.join(", ") + ), } } @@ -70,7 +74,10 @@ impl InitramfsRecipe { } } -fn normalize(kind: &str, values: impl IntoIterator<Item = impl Into<String>>) -> Result<Vec<String>> { +fn normalize( + kind: &str, + values: impl IntoIterator<Item = impl Into<String>>, +) -> Result<Vec<String>> { values .into_iter() .map(Into::into) @@ -117,8 +124,14 @@ pub struct Invocation { } impl Invocation { - pub fn new(program: impl Into<OsString>, arguments: impl IntoIterator<Item = impl Into<OsString>>) -> Self { - Self { program: program.into(), arguments: arguments.into_iter().map(Into::into).collect() } + pub fn new( + program: impl Into<OsString>, + arguments: impl IntoIterator<Item = impl Into<OsString>>, + ) -> Self { + Self { + program: program.into(), + arguments: arguments.into_iter().map(Into::into).collect(), + } } } @@ -136,7 +149,10 @@ impl CommandRunner for ProcessRunner { .status() .with_context(|| format!("run {}", invocation.program.to_string_lossy()))?; if !status.success() { - bail!("{} exited with {status}", invocation.program.to_string_lossy()); + bail!( + "{} exited with {status}", + invocation.program.to_string_lossy() + ); } Ok(()) } @@ -193,11 +209,17 @@ fn write_boot_alias(rootfs: &Path, alias: &str, target: &Path) -> Result<()> { let path = rootfs.join("boot").join(alias); match fs::symlink_metadata(&path) { Ok(metadata) if metadata.file_type().is_symlink() => { - fs::remove_file(&path).with_context(|| format!("remove existing boot alias {}", path.display()))?; + fs::remove_file(&path) + .with_context(|| format!("remove existing boot alias {}", path.display()))?; } - Ok(_) => bail!("refusing to replace non-symlink boot alias: {}", path.display()), + Ok(_) => bail!( + "refusing to replace non-symlink boot alias: {}", + path.display() + ), Err(error) if error.kind() == std::io::ErrorKind::NotFound => {} - Err(error) => return Err(error).with_context(|| format!("inspect boot alias {}", path.display())), + Err(error) => { + return Err(error).with_context(|| format!("inspect boot alias {}", path.display())); + } } symlink(target, &path).with_context(|| format!("create boot alias {}", path.display())) } @@ -214,7 +236,10 @@ impl InitramfsResult { let initrd_path = PathBuf::from(format!("boot/initrd-{}.img", kernel.as_str())); let contents = fs::read(rootfs.join(&initrd_path)) .with_context(|| format!("read generated initrd {}", initrd_path.display()))?; - Ok(Self { initrd_path, sha256: format!("{:x}", Sha256::digest(contents)) }) + Ok(Self { + initrd_path, + sha256: format!("{:x}", Sha256::digest(contents)), + }) } pub fn initrd_path(&self) -> &Path { |