Skip to content

Commit

Permalink
Merge pull request #4727 from cgwalters/tmpfiles-handle-old-cache
Browse files Browse the repository at this point in the history
Tmpfiles handle old cache
  • Loading branch information
jmarrero authored Dec 14, 2023
2 parents 685978c + 6b78c7f commit 76ac2f7
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions rust/src/tmpfiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,29 @@ pub fn deduplicate_tmpfiles_entries(tmprootfs_dfd: i32) -> CxxResult<()> {

// scan all rpm-ostree auto generated entries and save
let tmpfiles_dir = tmprootfs_dfd
.open_dir(RPMOSTREE_TMPFILESD)
.context("readdir {RPMOSTREE_TMPFILESD}")?;
let mut rpmostree_tmpfiles_entries = read_tmpfiles(&tmpfiles_dir)?;
.open_dir_optional(RPMOSTREE_TMPFILESD)
.context(RPMOSTREE_TMPFILESD)?;
let mut rpmostree_tmpfiles_entries = if let Some(tmpfiles_dir) = tmpfiles_dir {
read_tmpfiles(&tmpfiles_dir)?
} else {
Default::default()
};

// remove autovar.conf first, then scan all system entries and save
let tmpfiles_dir = tmprootfs_dfd
.open_dir(TMPFILESD)
.context("readdir {TMPFILESD}")?;
let tmpfiles_dir = if let Some(d) = tmprootfs_dfd
.open_dir_optional(TMPFILESD)
.context(TMPFILESD)?
{
d
} else {
if !rpmostree_tmpfiles_entries.is_empty() {
return Err(
format!("No {TMPFILESD} directory found, but have tmpfiles to process").into(),
);
}
// Nothing to do here
return Ok(());
};

if tmpfiles_dir.try_exists(AUTOVAR_PATH)? {
tmpfiles_dir.remove_file(AUTOVAR_PATH)?;
Expand Down Expand Up @@ -166,4 +181,12 @@ q /var/tmp 1777 root root 30d
assert_eq!(entries[1], "d /var/spool/mail 0775 root mail - -");
Ok(())
}

#[test]
/// Verify that we no-op if the directories don't exist.
fn test_deduplicate_emptydir() -> Result<()> {
let root = &cap_std_ext::cap_tempfile::tempdir(cap_std::ambient_authority())?;
deduplicate_tmpfiles_entries(root.as_raw_fd())?;
Ok(())
}
}

0 comments on commit 76ac2f7

Please sign in to comment.