5
5
use anyhow:: { anyhow, Result } ;
6
6
use std:: collections:: HashMap ;
7
7
use std:: fmt:: Display ;
8
+ use uapi_version:: Version ;
8
9
9
10
/// Represents a single Boot Loader Specification config file.
10
11
///
@@ -18,7 +19,9 @@ pub(crate) struct BLSConfig {
18
19
pub ( crate ) title : Option < String > ,
19
20
/// The version of the boot entry.
20
21
/// 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 ,
22
25
/// The path to the linux kernel to boot.
23
26
pub ( crate ) linux : String ,
24
27
/// The paths to the initrd images.
@@ -63,8 +66,7 @@ impl Ord for BLSConfig {
63
66
}
64
67
65
68
// 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 ( )
68
70
}
69
71
}
70
72
@@ -97,6 +99,12 @@ impl Display for BLSConfig {
97
99
}
98
100
}
99
101
102
+ impl BLSConfig {
103
+ pub ( crate ) fn version ( & self ) -> Version {
104
+ Version :: from ( & self . version )
105
+ }
106
+ }
107
+
100
108
pub ( crate ) fn parse_bls_config ( input : & str ) -> Result < BLSConfig > {
101
109
let mut title = None ;
102
110
let mut version = None ;
@@ -394,4 +402,31 @@ mod tests {
394
402
assert ! ( config1 > config2) ;
395
403
Ok ( ( ) )
396
404
}
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
+ }
397
432
}
0 commit comments