Skip to content

tmpfiles: Minor PR followup nit #1257

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

Merged
merged 1 commit into from
Apr 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions tmpfiles/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ const BOOTC_GENERATED_PREFIX: &str = "bootc-autogenerated-var";
struct BootcTmpfilesGeneration(u32);

impl BootcTmpfilesGeneration {
fn increment(&self) -> Self {
Self(self.0 + 1)
fn increment(&mut self) {
// SAFETY: We shouldn't ever wrap here
self.0 = self.0.checked_add(1).unwrap();
}

fn path(&self) -> Utf8PathBuf {
Expand Down Expand Up @@ -478,7 +479,7 @@ fn read_tmpfiles(rootfs: &Dir) -> Result<(BTreeMap<PathBuf, String>, BootcTmpfil
}
if let Ok(s) = stem.as_str() {
if s.starts_with(BOOTC_GENERATED_PREFIX) {
generation = generation.increment();
generation.increment();
}
}
let r = BufReader::new(entry.open()?);
Expand Down Expand Up @@ -588,7 +589,7 @@ mod tests {
var_to_tmpfiles(rootfs, userdb, userdb).unwrap();

// This is the first run
let gen = BootcTmpfilesGeneration(0);
let mut gen = BootcTmpfilesGeneration(0);
let autovar_path = &gen.path();
assert!(rootfs.try_exists(autovar_path).unwrap());
let entries: Vec<String> = rootfs
Expand All @@ -615,7 +616,7 @@ mod tests {
let wg = w.generated.as_ref().unwrap();
assert_eq!(wg.0, NonZeroUsize::new(1).unwrap());
assert_eq!(w.unsupported, 0);
let gen = gen.increment();
gen.increment();
let autovar_path = &gen.path();
assert_eq!(autovar_path, &wg.1);
assert!(rootfs.try_exists(autovar_path).unwrap());
Expand Down