Skip to content
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

Tmpfiles handle old cache #4727

Merged
merged 2 commits into from
Dec 14, 2023
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
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(())
}
}