Skip to content

Commit

Permalink
Fix rpmdb --exportdb from database on read-only media
Browse files Browse the repository at this point in the history
Read-only media doesn't need any locking by definition. But if the
file we're trying to open doesn't exist there, we can't very well open
it for even reading, causing the unnecessary locking to fail
unnecessarily. Feed it a dup of our STDIN_FILENO to keep the beast happy.

Couldn't figure how to get a read-only mount inside the test-root
so we need to add a pre-generated rpmdb and then run it without
having the test-image read-write mounted. The rpmdb file is ridiculously
big just for testing this corner-case purpose, but maybe it could be
used to speed up some other tests later on.

Fixes: rpm-software-management#3371 rpm-software-management#1266
  • Loading branch information
pmatilai committed Oct 11, 2024
1 parent 0413c3b commit 791a6d4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rpmlock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ static rpmlock rpmlock_new(const char *lock_path, const char *descr)
if (lock->fd == -1) {
if (errno == EACCES)
lock->fd = open(lock_path, O_RDONLY);
else if (errno == EROFS) {
/* read-only media doesn't need locks, just feed it something */
lock->fd = dup(STDIN_FILENO);
}
if (lock->fd == -1) {
delete lock;
lock = NULL;
Expand Down
Binary file added tests/data/misc/rpmdb.sqlite
Binary file not shown.
9 changes: 9 additions & 0 deletions tests/rpmdb.at
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ RPMTEST_CLEANUP
AT_SETUP([rpmdb --export and --import])
AT_KEYWORDS([rpmdb])

# This needs to run *without* RPMDB_INIT to test behavior on read-only mount
RPMTEST_CHECK([
run rpmdb --exportdb --dbpath ${RPMTEST}/data/misc/ > rdonly.list
test -s rdonly.list
],
[0],
[],
[])

RPMTEST_CHECK([
RPMDB_INIT
runroot rpm -U /data/RPMS/hlinktest-1.0-1.noarch.rpm
Expand Down

0 comments on commit 791a6d4

Please sign in to comment.