Skip to content

Commit

Permalink
composepost: Drop rpmdb sqlite journaling files
Browse files Browse the repository at this point in the history
See rpm-software-management/rpm#2219
This is one of the things that makes builds unreproducible in
general, which is worth fixing alone.

But the thing immediately driving this now for me is that I
think we're getting some ill-defined behavior because we
may have these files hardlinked (via ostree) and depending
on the container build environment, we may or may not see
modifications "through" the hardlink:
https://docs.kernel.org/filesystems/overlayfs.html#index

If we happen to mutate the `rpmdb.sqlite-shm` file in
one path but not the other confusion could easily result.

(Actually what we want to do really is drop our other
 hardlinked copies of the rpmdb entirely, but that's
 a bigger change)

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Jan 23, 2025
1 parent 49eb3b1 commit c102334
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
61 changes: 61 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ phf = { version = "0.11", features = ["macros"] }
rand = "0.8.5"
rayon = "1.10.0"
regex = "1.10"
rusqlite = "0.32.1"
reqwest = { version = "0.12", features = ["native-tls", "blocking", "gzip"] }
rpmostree-client = { path = "rust/rpmostree-client", version = "0.1.0" }
rust-ini = "0.21.1"
Expand Down
13 changes: 13 additions & 0 deletions rust/src/composepost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,17 @@ fn postprocess_cleanup_rpmdb_impl(rootfs_dfd: &Dir) -> Result<()> {
} else {
return Ok(());
};
// https://github.com/rpm-software-management/rpm/issues/2219
const RPMDB_SQLITE: &str = "rpmdb.sqlite";
const RPMDB_SQLITE_SHM: &str = "rpmdb.sqlite-shm";
if d.try_exists(RPMDB_SQLITE_SHM)? {
tracing::debug!("Cleaning up {RPMDB_SQLITE_SHM}");
let procpath = format!("/proc/self/fd/{}/{RPMDB_SQLITE}", d.as_raw_fd());
let conn = rusqlite::Connection::open(&procpath)
.with_context(|| format!("Opening {RPMDB_SQLITE}"))?;
conn.pragma_update(None, "journal_mode", "DELETE")?;
conn.close().map_err(|r| r.1)?;
}
for ent in d.entries()? {
let ent = ent?;
let name = ent.file_name()?;
Expand Down Expand Up @@ -1184,6 +1195,8 @@ fn rewrite_rpmdb_for_target_inner(rootfs_dfd: &Dir, normalize: bool) -> Result<(
normalization::normalize_rpmdb(rootfs_dfd, RPMOSTREE_RPMDB_LOCATION)?;
}

postprocess_cleanup_rpmdb_impl(rootfs_dfd)?;

tempetc.undo()?;

Ok(())
Expand Down
1 change: 1 addition & 0 deletions tests/compose/libbasic-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ echo "ok etc/default/useradd"
for path in /usr/share/rpm /usr/lib/sysimage/rpm-ostree-base-db; do
ostree --repo=${repo} ls -R ${treeref} ${path} > db.txt
assert_file_has_content_literal db.txt rpmdb.sqlite
assert_not_file_has_content db.txt rpmdb.sqlite-shm
done
ostree --repo=${repo} ls ${treeref} /usr/lib/sysimage/rpm >/dev/null
echo "ok db"
Expand Down

0 comments on commit c102334

Please sign in to comment.