feat(autoconfigure): generate names using a unique hash

This commit is contained in:
2025-10-27 18:21:28 -04:00
parent 3bbe6561ef
commit e7f5be30dd
6 changed files with 151 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ use crate::config::RootConfiguration;
use crate::entries::EntryDeclaration;
use crate::generators::GeneratorDeclaration;
use crate::generators::bls::BlsConfiguration;
use crate::utils;
use anyhow::{Context, Result};
use uefi::cstr16;
use uefi::fs::{FileSystem, Path};
@@ -33,6 +34,9 @@ pub fn scan(
// Add a trailing slash to the root to ensure the path is valid.
root.push('/');
// Generate a unique hash of the root path.
let root_unique_hash = utils::unique_hash(&root);
// Whether we have a loader.conf file.
let has_loader_conf = filesystem
.try_exists(bls_loader_conf_path)
@@ -54,7 +58,7 @@ pub fn scan(
}
// Generate a unique name for the BLS chainload action.
let chainload_action_name = format!("{}{}", BLS_CHAINLOAD_ACTION_PREFIX, root);
let chainload_action_name = format!("{}{}", BLS_CHAINLOAD_ACTION_PREFIX, root_unique_hash,);
// BLS is now detected, generate a configuration for it.
let generator = BlsConfiguration {
@@ -68,7 +72,7 @@ pub fn scan(
// Generate a unique name for the BLS generator and insert the generator into the configuration.
config.generators.insert(
format!("autoconfigure-bls-{}", root),
format!("autoconfigure-bls-{}", root_unique_hash),
GeneratorDeclaration {
bls: Some(generator),
..Default::default()

View File

@@ -4,6 +4,7 @@ use crate::config::RootConfiguration;
use crate::entries::EntryDeclaration;
use crate::generators::GeneratorDeclaration;
use crate::generators::list::ListConfiguration;
use crate::utils;
use anyhow::{Context, Result};
use std::collections::BTreeMap;
use uefi::CString16;
@@ -136,6 +137,9 @@ pub fn scan(
// Add a trailing slash to the root to ensure the path is valid.
root.push('/');
// Generate a unique hash of the root path.
let root_unique_hash = utils::unique_hash(&root);
// Scan all locations for kernel pairs, adding them to the list.
for location in SCAN_LOCATIONS {
let scanned = scan_directory(filesystem, location)
@@ -149,7 +153,7 @@ pub fn scan(
}
// Generate a unique name for the linux chainload action.
let chainload_action_name = format!("{}{}", LINUX_CHAINLOAD_ACTION_PREFIX, root);
let chainload_action_name = format!("{}{}", LINUX_CHAINLOAD_ACTION_PREFIX, root_unique_hash,);
// Kernel pairs are detected, generate a list configuration for it.
let generator = ListConfiguration {
@@ -171,7 +175,7 @@ pub fn scan(
// Generate a unique name for the Linux generator and insert the generator into the configuration.
config.generators.insert(
format!("autoconfigure-linux-{}", root),
format!("autoconfigure-linux-{}", root_unique_hash),
GeneratorDeclaration {
list: Some(generator),
..Default::default()

View File

@@ -102,7 +102,7 @@ fn select_with_input<'a>(
info!("Boot Menu:");
for (index, entry) in entries.iter().enumerate() {
let title = entry.context().stamp(&entry.declaration().title);
info!(" [{}] {}", index, title);
info!(" [{}] {} ({})", index, title, entry.name());
}
}

View File

@@ -175,3 +175,9 @@ pub fn combine_options<T: AsRef<str>>(options: impl Iterator<Item = T>) -> Strin
.collect::<Vec<_>>()
.join(" ")
}
/// Produce a unique hash for the input.
/// This uses SHA-256, which is unique enough but relatively short.
pub fn unique_hash(input: &str) -> String {
sha256::digest(input.as_bytes())
}