diff --git a/lib/rpmlock.cc b/lib/rpmlock.cc index 6335f81e0f..498e03fcec 100644 --- a/lib/rpmlock.cc +++ b/lib/rpmlock.cc @@ -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; diff --git a/tests/data/misc/rpmdb.sqlite b/tests/data/misc/rpmdb.sqlite new file mode 100644 index 0000000000..9129728413 Binary files /dev/null and b/tests/data/misc/rpmdb.sqlite differ diff --git a/tests/rpmdb.at b/tests/rpmdb.at index c4cb947804..424a1271bd 100644 --- a/tests/rpmdb.at +++ b/tests/rpmdb.at @@ -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