@@ -28,8 +28,9 @@ const BOOTC_GENERATED_PREFIX: &str = "bootc-autogenerated-var";
2828struct BootcTmpfilesGeneration ( u32 ) ;
2929
3030impl 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 ( ) ;
3334 }
3435
3536 fn path ( & self ) -> Utf8PathBuf {
@@ -478,7 +479,7 @@ fn read_tmpfiles(rootfs: &Dir) -> Result<(BTreeMap<PathBuf, String>, BootcTmpfil
478479 }
479480 if let Ok ( s) = stem. as_str ( ) {
480481 if s. starts_with ( BOOTC_GENERATED_PREFIX ) {
481- generation = generation . increment ( ) ;
482+ generation. increment ( ) ;
482483 }
483484 }
484485 let r = BufReader :: new ( entry. open ( ) ?) ;
@@ -588,7 +589,7 @@ mod tests {
588589 var_to_tmpfiles ( rootfs, userdb, userdb) . unwrap ( ) ;
589590
590591 // This is the first run
591- let gen = BootcTmpfilesGeneration ( 0 ) ;
592+ let mut gen = BootcTmpfilesGeneration ( 0 ) ;
592593 let autovar_path = & gen. path ( ) ;
593594 assert ! ( rootfs. try_exists( autovar_path) . unwrap( ) ) ;
594595 let entries: Vec < String > = rootfs
@@ -615,7 +616,7 @@ mod tests {
615616 let wg = w. generated . as_ref ( ) . unwrap ( ) ;
616617 assert_eq ! ( wg. 0 , NonZeroUsize :: new( 1 ) . unwrap( ) ) ;
617618 assert_eq ! ( w. unsupported, 0 ) ;
618- let gen = gen. increment ( ) ;
619+ gen. increment ( ) ;
619620 let autovar_path = & gen. path ( ) ;
620621 assert_eq ! ( autovar_path, & wg. 1 ) ;
621622 assert ! ( rootfs. try_exists( autovar_path) . unwrap( ) ) ;
0 commit comments