This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch master in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=12b68b3fbc9970d91bbacf49291ad3e5a9e5cced commit 12b68b3fbc9970d91bbacf49291ad3e5a9e5cced Author: Guillem Jover <[email protected]> AuthorDate: Wed Mar 20 05:21:26 2019 +0100 libdpkg: Create the dpkg database directory on demand --- debian/changelog | 1 + lib/dpkg/arch.c | 2 +- lib/dpkg/dbmodify.c | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 2b24876be..11e8df6d7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -52,6 +52,7 @@ dpkg (1.20.0) UNRELEASED; urgency=medium - Do not change the ownership of the triggers database directory. Either we are running as root:root which means the ownership should be correct already, or we are not which means we cannot change it anyway. + - Create the dpkg database directory on demand. * Perl modules: - Dpkg::Source::Package: Verify original tarball signatures at build time. - Dpkg::BuildFlags: Add new unset() method. diff --git a/lib/dpkg/arch.c b/lib/dpkg/arch.c index 96f261704..d4f638e40 100644 --- a/lib/dpkg/arch.c +++ b/lib/dpkg/arch.c @@ -317,7 +317,7 @@ dpkg_arch_save_list(void) return; archfile = dpkg_db_get_path(DPKG_DB_ARCH_FILE); - file = atomic_file_new(archfile, 0); + file = atomic_file_new(archfile, ATOMIC_FILE_MKPATH); atomic_file_open(file); for (arch = arch_head; arch; arch = arch->next) { diff --git a/lib/dpkg/dbmodify.c b/lib/dpkg/dbmodify.c index 012e06033..40340865d 100644 --- a/lib/dpkg/dbmodify.c +++ b/lib/dpkg/dbmodify.c @@ -273,6 +273,8 @@ modstatdb_unlock(void) enum modstatdb_rw modstatdb_open(enum modstatdb_rw readwritereq) { + bool db_can_access = false; + modstatdb_init(); cflags = readwritereq & msdbrw_available_mask; @@ -285,7 +287,20 @@ modstatdb_open(enum modstatdb_rw readwritereq) ohshit(_("requested operation requires superuser privilege")); /* Fall through. */ case msdbrw_write: case msdbrw_writeifposs: - if (access(dpkg_db_get_dir(), W_OK)) { + db_can_access = access(dpkg_db_get_dir(), W_OK) == 0; + if (!db_can_access && errno == ENOENT) { + if (dir_make_path(dpkg_db_get_dir(), 0755) == 0) + db_can_access = true; + else if (readwritereq >= msdbrw_write) + ohshite(_("cannot create the dpkg database directory %s"), + dpkg_db_get_dir()); + else if (errno == EROFS) + /* If we cannot create the directory on read-only modes on read-only + * filesystems, make it look like an access error to be skipped. */ + errno = EACCES; + } + + if (!db_can_access) { if (errno != EACCES) ohshite(_("unable to access the dpkg database directory %s"), dpkg_db_get_dir()); -- Dpkg.Org's dpkg

