@@ -28,8 +28,9 @@ const BOOTC_GENERATED_PREFIX: &str = "bootc-autogenerated-var";
28
28
struct BootcTmpfilesGeneration ( u32 ) ;
29
29
30
30
impl BootcTmpfilesGeneration {
31
- fn increment ( & self ) -> Self {
32
- Self ( self . 0 + 1 )
31
+ fn increment ( & mut self ) {
32
+ // SAFETY: We shouldn't ever wrap here
33
+ self . 0 = self . 0 . checked_add ( 1 ) . unwrap ( ) ;
33
34
}
34
35
35
36
fn path ( & self ) -> Utf8PathBuf {
@@ -478,7 +479,7 @@ fn read_tmpfiles(rootfs: &Dir) -> Result<(BTreeMap<PathBuf, String>, BootcTmpfil
478
479
}
479
480
if let Ok ( s) = stem. as_str ( ) {
480
481
if s. starts_with ( BOOTC_GENERATED_PREFIX ) {
481
- generation = generation . increment ( ) ;
482
+ generation. increment ( ) ;
482
483
}
483
484
}
484
485
let r = BufReader :: new ( entry. open ( ) ?) ;
@@ -588,7 +589,7 @@ mod tests {
588
589
var_to_tmpfiles ( rootfs, userdb, userdb) . unwrap ( ) ;
589
590
590
591
// This is the first run
591
- let gen = BootcTmpfilesGeneration ( 0 ) ;
592
+ let mut gen = BootcTmpfilesGeneration ( 0 ) ;
592
593
let autovar_path = & gen. path ( ) ;
593
594
assert ! ( rootfs. try_exists( autovar_path) . unwrap( ) ) ;
594
595
let entries: Vec < String > = rootfs
@@ -615,7 +616,7 @@ mod tests {
615
616
let wg = w. generated . as_ref ( ) . unwrap ( ) ;
616
617
assert_eq ! ( wg. 0 , NonZeroUsize :: new( 1 ) . unwrap( ) ) ;
617
618
assert_eq ! ( w. unsupported, 0 ) ;
618
- let gen = gen. increment ( ) ;
619
+ gen. increment ( ) ;
619
620
let autovar_path = & gen. path ( ) ;
620
621
assert_eq ! ( autovar_path, & wg. 1 ) ;
621
622
assert ! ( rootfs. try_exists( autovar_path) . unwrap( ) ) ;
0 commit comments