55use anyhow:: { anyhow, Result } ;
66use std:: collections:: HashMap ;
77use std:: fmt:: Display ;
8+ use uapi_version:: Version ;
89
910/// Represents a single Boot Loader Specification config file.
1011///
@@ -18,7 +19,9 @@ pub(crate) struct BLSConfig {
1819 pub ( crate ) title : Option < String > ,
1920 /// The version of the boot entry.
2021 /// See <https://uapi-group.org/specifications/specs/version_format_specification/>
21- pub ( crate ) version : String ,
22+ ///
23+ /// This is hidden and must be accessed via [`Self::version()`];
24+ version : String ,
2225 /// The path to the linux kernel to boot.
2326 pub ( crate ) linux : String ,
2427 /// The paths to the initrd images.
@@ -63,8 +66,7 @@ impl Ord for BLSConfig {
6366 }
6467
6568 // Finally, sort by version in descending order.
66- // FIXME: This should use <https://uapi-group.org/specifications/specs/version_format_specification/>
67- self . version . cmp ( & other. version ) . reverse ( )
69+ self . version ( ) . cmp ( & other. version ( ) ) . reverse ( )
6870 }
6971}
7072
@@ -97,6 +99,12 @@ impl Display for BLSConfig {
9799 }
98100}
99101
102+ impl BLSConfig {
103+ pub ( crate ) fn version ( & self ) -> Version {
104+ Version :: from ( & self . version )
105+ }
106+ }
107+
100108pub ( crate ) fn parse_bls_config ( input : & str ) -> Result < BLSConfig > {
101109 let mut title = None ;
102110 let mut version = None ;
@@ -394,4 +402,31 @@ mod tests {
394402 assert ! ( config1 > config2) ;
395403 Ok ( ( ) )
396404 }
405+
406+ #[ test]
407+ fn test_ordering_by_nontrivial_version ( ) -> Result < ( ) > {
408+ let config_final = parse_bls_config (
409+ r#"
410+ title Entry 1
411+ version 1.0
412+ linux /vmlinuz-1
413+ initrd /initrd-1
414+ "# ,
415+ ) ?;
416+
417+ let config_rc1 = parse_bls_config (
418+ r#"
419+ title Entry 2
420+ version 1.0~rc1
421+ linux /vmlinuz-2
422+ initrd /initrd-2
423+ "# ,
424+ ) ?;
425+
426+ // In a sorted list, we want 1.0 to appear before 1.0~rc1 because
427+ // versions are sorted descending. This means that in Rust's sort order,
428+ // config_final should be "less than" config_rc1.
429+ assert ! ( config_final < config_rc1) ;
430+ Ok ( ( ) )
431+ }
397432}
0 commit comments