-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
efi: sync bootentry label with Anaconda #685
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,17 +139,28 @@ impl Efi { | |
log::debug!("Not booted via EFI, skipping firmware update"); | ||
return Ok(()); | ||
} | ||
// Read /etc/os-release | ||
let release: OsRelease = OsRelease::new()?; | ||
let product_name: &str = &release.name; | ||
let product_name = get_product_name()?; | ||
log::debug!("Get product name: {product_name}"); | ||
assert!(product_name.len() > 0); | ||
// clear all the boot entries that match the target name | ||
clear_efi_target(product_name)?; | ||
create_efi_boot_entry(device, espdir, vendordir, product_name) | ||
clear_efi_target(&product_name)?; | ||
create_efi_boot_entry(device, espdir, vendordir, &product_name) | ||
} | ||
} | ||
|
||
#[context("Get product name")] | ||
fn get_product_name() -> Result<String> { | ||
let file_path = Path::new("/etc/system-release"); | ||
if file_path.exists() { | ||
let content = std::fs::read_to_string(file_path)?; | ||
let re = regex::Regex::new(r" *release.*").unwrap(); | ||
return Ok(re.replace_all(&content, "").to_string()); | ||
} | ||
// Read /etc/os-release | ||
let release: OsRelease = OsRelease::new()?; | ||
Ok(release.name) | ||
} | ||
|
||
/// Convert a nul-terminated UTF-16 byte array to a String. | ||
fn string_from_utf16_bytes(slice: &[u8]) -> String { | ||
// For some reason, systemd appends 3 nul bytes after the string. | ||
|
@@ -659,4 +670,10 @@ Boot0003* test"; | |
); | ||
Ok(()) | ||
} | ||
#[test] | ||
fn test_get_product_name() -> Result<()> { | ||
let name = get_product_name()?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we shouldn't read global state in a unit test. This will fail on e.g. Debian or other systems and we want to support those. We can unit test parsing from a (That said of course, we could use openat or better cap-std to load from a test root...see what we do in https://github.com/containers/bootc/blob/c866bba1e96e912ab2e36b9eec3985e93e7a0c9b/lib/src/generator.rs#L90 - but unfortunately There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I was wrong, it shouldn't because the However, it does still make sense to avoid reading global state longer term. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Yes, you are correct, will switch to |
||
assert!(name.len() > 0); | ||
Ok(()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this change to
fn get_product_name(root: &Dir)
to pass root dir as parameter?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but not a blocker, just a nice to have IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, will update in the later PR.