-
Notifications
You must be signed in to change notification settings - Fork 43
package: keep the full name if not grub2 or shim
#1002
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,7 +116,12 @@ fn parse_evr(pkg: &str) -> Module { | |
| (nevra.name().to_string(), nevra.evr().to_string()) | ||
| }; | ||
|
|
||
| let (name, _) = name_str.split_once('-').unwrap_or((&name_str, "")); | ||
| // Only cut the packages name that we know | ||
| let (name, _) = if ["grub2", "shim"].iter().any(|p| name_str.starts_with(p)) { | ||
| name_str.split_once('-').unwrap_or((&name_str, "")) | ||
| } else { | ||
| (name_str.as_str(), "") | ||
| }; | ||
|
Comment on lines
+120
to
+124
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. This change correctly handles package names that are not The logic To ensure consistent and correct parsing, consider refactoring this function to apply the same corrected logic for both cases. It might be possible to unify the parsing logic for both branches. On a related note, for better performance and code style, you could define |
||
| Module { | ||
| name: name.to_string(), | ||
| rpm_evr, | ||
|
|
@@ -181,6 +186,37 @@ pub(crate) fn compare_package_versions(a: &str, b: &str) -> Ordering { | |
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_parse_evr() { | ||
| let cases = [ | ||
| // Case from this PR | ||
| ( | ||
| "test-bootupd-payload-1.0-1.x86_64", | ||
| "test-bootupd-payload", | ||
| "1.0-1", | ||
| ), | ||
| // grub2/shim cases | ||
| ( | ||
| "grub2-efi-x64-1:2.06-95.fc38.x86_64", | ||
| "grub2", | ||
| "1:2.06-95.fc38", | ||
| ), | ||
| ("shim-x64-15.6-2.x86_64", "shim", "15.6-2"), | ||
| // Case without arch suffix | ||
| ("grub2-1:2.12-28.fc42", "grub2", "1:2.12-28.fc42"), | ||
| ]; | ||
|
|
||
| for &(input, expected_name, expected_evr) in &cases { | ||
| assert_eq!( | ||
| Module { | ||
| name: expected_name.to_string(), | ||
| rpm_evr: expected_evr.to_string(), | ||
| }, | ||
| parse_evr(input) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parse_rpmout() { | ||
| let testdata = "grub2-efi-x64-1:2.06-95.fc38.x86_64,1681321788 grub2-efi-x64-1:2.06-95.fc38.x86_64,1681321788 shim-x64-15.6-2.x86_64,1657222566 shim-x64-15.6-2.x86_64,1657222566 shim-x64-15.6-2.x86_64,1657222566"; | ||
|
|
||
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.
I would do something like