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

compose: Drop rpmdb sqlite journaling files if rpmdb-normalize #5244

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
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
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
24 changes: 23 additions & 1 deletion rust/src/normalization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

use crate::bwrap::Bubblewrap;
use crate::nameservice::shadow::parse_shadow_content;
use anyhow::{anyhow, Result};
use anyhow::{anyhow, Context, Result};
use cap_std::fs::OpenOptionsExt;
use cap_std::fs::{Dir, OpenOptions};
use cap_std_ext::cap_std;
use fn_error_context::context;
use ostree_ext::gio;
use std::io::{BufReader, Read, Seek, SeekFrom, Write};
use std::os::fd::{AsFd, AsRawFd};
use std::path::Path;

pub(crate) fn source_date_epoch() -> Option<i64> {
Expand Down Expand Up @@ -129,6 +130,27 @@ pub(crate) fn rewrite_rpmdb_timestamps<F: Read + Write + Seek>(rpmdb: &mut F) ->

#[context("Rewriting rpmdb database files for build stability")]
pub(crate) fn normalize_rpmdb(rootfs: &Dir, rpmdb_path: impl AsRef<Path>) -> Result<()> {
let rpmdb_path = rpmdb_path.as_ref();
{
// Unconditionally clean up the sqlite SHM file if it exists.
// https://github.com/rpm-software-management/rpm/issues/2219
const RPMDB_SQLITE: &str = "rpmdb.sqlite";
const RPMDB_SQLITE_SHM: &str = "rpmdb.sqlite-shm";
let subdir = rootfs.open_dir(rpmdb_path)?;
if subdir.try_exists(RPMDB_SQLITE_SHM)? {
tracing::debug!("Cleaning up {RPMDB_SQLITE_SHM}");
let procpath = format!(
"/proc/self/fd/{}/{RPMDB_SQLITE}",
subdir.as_fd().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)?;
}
}

// If SOURCE_DATE_EPOCH isn't set then we don't attempt to rewrite the database.
let source_date = if let Some(source_date) = source_date_epoch() {
source_date as u32
} else {
Expand Down
2 changes: 2 additions & 0 deletions tests/compose/libbasic-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ 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
# Verify we *aren't* normalizing yet
assert_file_has_content_literal db.txt rpmdb.sqlite-shm
done
ostree --repo=${repo} ls ${treeref} /usr/lib/sysimage/rpm >/dev/null
echo "ok db"
Expand Down
7 changes: 7 additions & 0 deletions tests/compose/test-misc-tweaks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ cat > config/other.yaml <<'EOF'
recommends: true
selinux-label-version: 1
readonly-executables: true
rpmdb-normalize: true
container-cmd:
- /usr/bin/bash
opt-usrlocal: "root"
Expand Down Expand Up @@ -188,6 +189,12 @@ ostree --repo=${repo} ls ${treeref} /usr/etc > out.txt
assert_file_has_content out.txt 'etc/sharedfile'
echo "ok remove-from-packages"

# Verify rpmdb-normalize
ostree --repo=${repo} ls -R ${treeref} /usr/share/rpm > db.txt
assert_file_has_content_literal db.txt rpmdb.sqlite
assert_not_file_has_content_literal db.txt rpmdb.sqlite-shm
echo "ok db"

ostree --repo=${repo} ls ${treeref} /opt > ls.txt
assert_file_has_content ls.txt '^d0'
ostree --repo=${repo} ls ${treeref} /usr/local > ls.txt
Expand Down
Loading