Skip to content

Commit

Permalink
Merge pull request #25 from jplatte/jplatte/cleanup
Browse files Browse the repository at this point in the history
Fix rustc / clippy warnings, upgrade deps, check typos
  • Loading branch information
ikeycode authored Dec 12, 2024
2 parents 3c1ca74 + 43b56e3 commit db959ee
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 62 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ jobs:
clippy_flags: --workspace --no-deps
filter_mode: nofilter
github_token: ${{ secrets.GITHUB_TOKEN }}

typos:
name: Spell Check with Typos
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: crate-ci/[email protected]
26 changes: 13 additions & 13 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ members = [
blake3 = { version = "1.5.1", features = ["mmap", "rayon"] }
log = "0.4.21"
gpt = "3.1.0"
thiserror = "1"
nix = { version = "0.28.0", features = ["fs", "mount"] }
thiserror = "2.0.3"
nix = { version = "0.29.0", features = ["fs", "mount"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
uuid = { version = "1.8.0", features = ["v8"] }
Expand Down
2 changes: 1 addition & 1 deletion blsctl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fn inspect_root(config: &Configuration) -> color_eyre::Result<()> {
if let Some(json) = kernel
.extras
.iter()
.find(|e| matches!(e.kind, blsforme::AuxilliaryKind::BootJSON))
.find(|e| matches!(e.kind, blsforme::AuxiliaryKind::BootJSON))
{
let text = fs::read_to_string(&json.path)?;
let decoded = BootJSON::try_from(text.as_str())?;
Expand Down
1 change: 1 addition & 0 deletions blsforme/src/bootloader/systemd_boot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub mod interface;
#[derive(Debug)]
pub struct Loader<'a, 'b> {
/// system configuration
#[allow(dead_code)]
config: &'a Configuration,
assets: &'b [PathBuf],
mounts: &'a Mounts,
Expand Down
9 changes: 5 additions & 4 deletions blsforme/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: MPL-2.0

use crate::{AuxilliaryFile, Kernel, Schema};
use crate::{AuxiliaryFile, Kernel, Schema};

/// An entry corresponds to a single kernel, and may have a supplemental
/// cmdline
Expand All @@ -11,6 +11,7 @@ pub struct Entry<'a> {
pub(crate) kernel: &'a Kernel,

// Additional cmdline
#[allow(dead_code)]
cmdline: Option<String>,
}

Expand Down Expand Up @@ -54,10 +55,10 @@ impl<'a> Entry<'a> {

/// Generate installed asset (aux) name, used by bootloaders
/// Right now this only returns CBM style IDs
pub fn installed_asset_name(&self, schema: &Schema, asset: &AuxilliaryFile) -> Option<String> {
pub fn installed_asset_name(&self, schema: &Schema, asset: &AuxiliaryFile) -> Option<String> {
match &schema {
Schema::Legacy { .. } => match asset.kind {
crate::AuxilliaryKind::InitRD => asset
crate::AuxiliaryKind::InitRD => asset
.path
.file_name()
.map(|f| f.to_string_lossy())
Expand All @@ -67,7 +68,7 @@ impl<'a> Entry<'a> {
Schema::Blsforme { .. } => {
let filename = asset.path.file_name().map(|f| f.to_string_lossy())?;
match asset.kind {
crate::AuxilliaryKind::InitRD => Some(format!("{}/{}", &self.kernel.version, filename)),
crate::AuxiliaryKind::InitRD => Some(format!("{}/{}", &self.kernel.version, filename)),
_ => None,
}
}
Expand Down
66 changes: 33 additions & 33 deletions blsforme/src/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<'a> TryFrom<&'a str> for BootJSON<'a> {
}

/// A kernel is the primary bootable element that we care about, ie
/// the vmlinuz file. It also comes with a set of auxilliary files
/// the vmlinuz file. It also comes with a set of auxiliary files
/// that are required for a fully working system, but specifically
/// dependent on that kernel version.
#[derive(Debug, PartialEq, PartialOrd, Eq, Ord)]
Expand All @@ -63,18 +63,18 @@ pub struct Kernel {
pub image: PathBuf,

/// All of the initrds
pub initrd: Vec<AuxilliaryFile>,
pub initrd: Vec<AuxiliaryFile>,

/// Any non-initrd, auxillary files
pub extras: Vec<AuxilliaryFile>,
/// Any non-initrd, auxiliary files
pub extras: Vec<AuxiliaryFile>,

/// Recorded variant type
pub variant: Option<String>,
}

/// Denotes the kind of auxillary file
/// Denotes the kind of auxiliary file
#[derive(Debug, PartialEq, PartialOrd, Eq, Ord)]
pub enum AuxilliaryKind {
pub enum AuxiliaryKind {
/// A cmdline snippet
Cmdline,

Expand All @@ -94,12 +94,12 @@ pub enum AuxilliaryKind {
/// An additional file required to be shipped with the kernel,
/// such as initrds, system maps, etc.
#[derive(Debug, PartialEq, PartialOrd, Eq, Ord)]
pub struct AuxilliaryFile {
pub struct AuxiliaryFile {
pub path: PathBuf,
pub kind: AuxilliaryKind,
pub kind: AuxiliaryKind,
}

impl<'a> Schema<'a> {
impl Schema<'_> {
/// Given a set of kernel-like paths, yield all potential kernels within them
/// This should be a set of `/usr/lib/kernel` paths. Use glob or appropriate to discover.
pub fn discover_system_kernels(&self, paths: impl Iterator<Item = impl AsRef<Path>>) -> Result<Vec<Kernel>, Error> {
Expand Down Expand Up @@ -181,29 +181,29 @@ impl<'a> Schema<'a> {
.ok_or_else(|| Error::InvalidFilesystem)?;

let aux = match filename {
x if x == sysmap_file => Some(AuxilliaryFile {
x if x == sysmap_file => Some(AuxiliaryFile {
path: path.as_ref().into(),
kind: AuxilliaryKind::SystemMap,
kind: AuxiliaryKind::SystemMap,
}),
x if x == cmdline_file => Some(AuxilliaryFile {
x if x == cmdline_file => Some(AuxiliaryFile {
path: path.as_ref().into(),
kind: AuxilliaryKind::Cmdline,
kind: AuxiliaryKind::Cmdline,
}),
x if x == config_file => Some(AuxilliaryFile {
x if x == config_file => Some(AuxiliaryFile {
path: path.as_ref().into(),
kind: AuxilliaryKind::Config,
kind: AuxiliaryKind::Config,
}),
x if x == initrd_file => Some(AuxilliaryFile {
x if x == initrd_file => Some(AuxiliaryFile {
path: path.as_ref().into(),
kind: AuxilliaryKind::InitRD,
kind: AuxiliaryKind::InitRD,
}),
x if x.starts_with(&initrd_file) => {
// Version dependent initrd
if x != initrd_file {
if x.split_once(&initrd_file).is_some() {
Some(AuxilliaryFile {
Some(AuxiliaryFile {
path: path.as_ref().into(),
kind: AuxilliaryKind::InitRD,
kind: AuxiliaryKind::InitRD,
})
} else {
None
Expand All @@ -216,9 +216,9 @@ impl<'a> Schema<'a> {
// Version independent initrd
if let Some((_, r)) = x.split_once(&indep_initrd) {
if !r.contains('.') {
Some(AuxilliaryFile {
Some(AuxiliaryFile {
path: path.as_ref().into(),
kind: AuxilliaryKind::InitRD,
kind: AuxiliaryKind::InitRD,
})
} else {
None
Expand All @@ -231,7 +231,7 @@ impl<'a> Schema<'a> {
};

if let Some(aux_file) = aux {
if matches!(aux_file.kind, AuxilliaryKind::InitRD) {
if matches!(aux_file.kind, AuxiliaryKind::InitRD) {
kernel.initrd.push(aux_file);
} else {
kernel.extras.push(aux_file);
Expand Down Expand Up @@ -290,31 +290,31 @@ impl<'a> Schema<'a> {
.to_str()
.ok_or_else(|| Error::InvalidFilesystem)?;
let aux = match filename {
"System.map" => Some(AuxilliaryFile {
"System.map" => Some(AuxiliaryFile {
path: asset.clone(),
kind: AuxilliaryKind::SystemMap,
kind: AuxiliaryKind::SystemMap,
}),
"boot.json" => Some(AuxilliaryFile {
"boot.json" => Some(AuxiliaryFile {
path: asset.clone(),
kind: AuxilliaryKind::BootJSON,
kind: AuxiliaryKind::BootJSON,
}),
"config" => Some(AuxilliaryFile {
"config" => Some(AuxiliaryFile {
path: asset.clone(),
kind: AuxilliaryKind::Config,
kind: AuxiliaryKind::Config,
}),
_ if filename.ends_with(".initrd") => Some(AuxilliaryFile {
_ if filename.ends_with(".initrd") => Some(AuxiliaryFile {
path: asset.clone(),
kind: AuxilliaryKind::InitRD,
kind: AuxiliaryKind::InitRD,
}),
_ if filename.ends_with(".cmdline") => Some(AuxilliaryFile {
_ if filename.ends_with(".cmdline") => Some(AuxiliaryFile {
path: asset.clone(),
kind: AuxilliaryKind::Cmdline,
kind: AuxiliaryKind::Cmdline,
}),
_ => None,
};

if let Some(aux_file) = aux {
if matches!(aux_file.kind, AuxilliaryKind::InitRD) {
if matches!(aux_file.kind, AuxiliaryKind::InitRD) {
kernel.initrd.push(aux_file);
} else {
kernel.extras.push(aux_file);
Expand Down
4 changes: 2 additions & 2 deletions blsforme/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bootloader::systemd_boot;
use thiserror::Error;

mod kernel;
pub use kernel::{AuxilliaryFile, AuxilliaryKind, BootJSON, Kernel, Schema};
pub use kernel::{AuxiliaryFile, AuxiliaryKind, BootJSON, Kernel, Schema};

mod bootenv;
pub use bootenv::{BootEnvironment, Firmware};
Expand Down Expand Up @@ -57,7 +57,7 @@ pub enum Error {
#[error("no ESP mounted in image mode, but detected an ESP at {0}")]
UnmountedESP(PathBuf),

#[error("unspported usage")]
#[error("unsupported usage")]
Unsupported,
}

Expand Down
4 changes: 2 additions & 2 deletions crates/superblock/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test images)
## luks+ext4.img.zst

Password : abc
Versio : LUKS2
Version : LUKS2
LUKS UUID: be373cae-2bd1-4ad5-953f-3463b2e53e59
EXT4 UUID: e27c657e-d03c-4f89-b36d-2de6880bc2a1

Expand All @@ -31,4 +31,4 @@ test images)
Limited to 12-char volume name

UUID : 45e8a3bf-8114-400f-95b0-380d0fb7d42d
LABEL: BLSFORME
LABEL: BLSFORME
4 changes: 2 additions & 2 deletions crates/topology/src/disk/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use super::probe;
pub struct BlockDevice<'a> {
pub kind: Option<superblock::Kind>,

// Actively mounted somwhere?
// Actively mounted somewhere?
pub mountpoint: Option<PathBuf>,

// Generally easier to work with strings in client code
Expand All @@ -36,7 +36,7 @@ pub struct BlockDevice<'a> {
// GPT partition GUID
pub(super) guid: Option<String>,

// Auxillary (ignored) device
// Auxiliary (ignored) device
pub(super) aux: bool,
}

Expand Down
4 changes: 2 additions & 2 deletions crates/topology/src/disk/mounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub enum MountOption<'a> {
Option(&'a str, &'a str),
}

impl<'a> MountOption<'a> {
impl MountOption<'_> {
/// Returns true if this is a flag
pub fn is_flag(&self) -> bool {
match &self {
Expand All @@ -47,7 +47,7 @@ impl<'a> MountOption<'a> {
}
}

impl<'a> Mount<'a> {
impl Mount<'_> {
/// Convert [`Mount::opts`] into an iterator of typed options
pub fn options(&self) -> impl Iterator<Item = MountOption> {
self.opts.split(',').map(|o| {
Expand Down
2 changes: 1 addition & 1 deletion crates/topology/src/disk/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Probe {
.mounts
.iter()
.find(|m| PathBuf::from(m.mountpoint) == mountpoint)
.ok_or_else(|| super::Error::UnknownMount(mountpoint))?;
.ok_or(super::Error::UnknownMount(mountpoint))?;
// TODO: Handle `ZFS=`, and composite bcachefs mounts (dev:dev1:dev2)
Ok(matching_device.device.into())
}
Expand Down

0 comments on commit db959ee

Please sign in to comment.