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=99c9cdbf1b9650ef5025c3c06ea918ef3007888e commit 99c9cdbf1b9650ef5025c3c06ea918ef3007888e Author: Guillem Jover <[email protected]> AuthorDate: Fri Mar 15 03:25:16 2019 +0100 libdpkg: Allow missing status and available databases This makes it possible to bootstrap an installation w/o requiring external knowledge of the dpkg internals, as the databases will be created on write when necessary. We can then remove the code setting them up from the dpkg postinst. Closes: #647911 --- Makefile.am | 1 - debian/changelog | 3 +++ debian/dpkg.postinst | 32 -------------------------------- lib/dpkg/dpkg-db.h | 7 +++++-- lib/dpkg/parse.c | 14 ++++++++++++-- t/shellcheck.t | 1 - 6 files changed, 20 insertions(+), 38 deletions(-) diff --git a/Makefile.am b/Makefile.am index 86bc59184..ad5a361bd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -73,7 +73,6 @@ EXTRA_DIST = \ debian/dpkg.docs \ debian/dpkg.install \ debian/dpkg.manpages \ - debian/dpkg.postinst \ debian/dpkg.postrm \ debian/dpkg.logrotate \ debian/dpkg.lintian-overrides \ diff --git a/debian/changelog b/debian/changelog index b7524055d..73fbfafc1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -46,6 +46,9 @@ dpkg (1.20.0) UNRELEASED; urgency=medium * libdpkg: Add support for bootstrapping the installation of dpkg: - Create the logfile with correct permissions, and remove the code setting up the logfile from the dpkg postinst. + - Allow missing status and available databases, so that they get created + on write, and remove the code setting them up from the dpkg postinst. + Closes: #647911 * Perl modules: - Dpkg::Source::Package: Verify original tarball signatures at build time. - Dpkg::BuildFlags: Add new unset() method. diff --git a/debian/dpkg.postinst b/debian/dpkg.postinst deleted file mode 100755 index 78b0e3362..000000000 --- a/debian/dpkg.postinst +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh -# See deb-postinst(5). - -set -e - -# Create the database files if they don't already exist -create_database() { - admindir=${DPKG_ADMINDIR:-/var/lib/dpkg} - - for file in diversions statoverride status; do - if [ ! -f "$admindir/$file" ]; then - touch "$admindir/$file" - fi - done -} - -case "$1" in - configure) - create_database - ;; - - abort-upgrade|abort-deconfigure|abort-remove) - ;; - - *) - echo "$0 called with unknown argument '$1'" 1>&2 - exit 1 - ;; -esac - -#DEBHELPER# -exit 0 diff --git a/lib/dpkg/dpkg-db.h b/lib/dpkg/dpkg-db.h index 6c818ba47..1ed116bd4 100644 --- a/lib/dpkg/dpkg-db.h +++ b/lib/dpkg/dpkg-db.h @@ -350,13 +350,16 @@ enum parsedbflags { pdb_close_fd = DPKG_BIT(7), /** Interpret filename ‘-’ as stdin. */ pdb_dash_is_stdin = DPKG_BIT(8), + /** Allow empty/missing files. */ + pdb_allow_empty = DPKG_BIT(9), /* Standard operations. */ - pdb_parse_status = pdb_lax_parser | pdb_weakclassification, + pdb_parse_status = pdb_lax_parser | pdb_weakclassification | + pdb_allow_empty, pdb_parse_update = pdb_parse_status | pdb_single_stanza, pdb_parse_available = pdb_recordavailable | pdb_rejectstatus | - pdb_lax_parser, + pdb_lax_parser | pdb_allow_empty, pdb_parse_binary = pdb_recordavailable | pdb_rejectstatus | pdb_single_stanza, }; diff --git a/lib/dpkg/parse.c b/lib/dpkg/parse.c index f7979b8e5..5fbdd8ffa 100644 --- a/lib/dpkg/parse.c +++ b/lib/dpkg/parse.c @@ -28,6 +28,7 @@ #include <sys/mman.h> #endif +#include <errno.h> #include <fcntl.h> #include <string.h> #include <unistd.h> @@ -531,6 +532,9 @@ parsedb_new(const char *filename, int fd, enum parsedbflags flags) ps->flags = flags; ps->fd = fd; ps->lno = 0; + ps->data = NULL; + ps->dataptr = NULL; + ps->endptr = NULL; ps->pkg = NULL; ps->pkgbin = NULL; @@ -551,7 +555,7 @@ parsedb_open(const char *filename, enum parsedbflags flags) return parsedb_new(filename, STDIN_FILENO, flags); fd = open(filename, O_RDONLY); - if (fd == -1) + if (fd == -1 && !(errno == ENOENT && (flags & pdb_allow_empty))) ohshite(_("failed to open package info file '%.255s' for reading"), filename); @@ -570,6 +574,9 @@ parsedb_load(struct parsedb_state *ps) { struct stat st; + if (ps->fd < 0 && (ps->flags & pdb_allow_empty)) + return; + if (fstat(ps->fd, &st) == -1) ohshite(_("can't stat package info file '%.255s'"), ps->filename); @@ -735,7 +742,7 @@ parsedb_close(struct parsedb_state *ps) if (ps->flags & pdb_close_fd) { pop_cleanup(ehflag_normaltidy); - if (close(ps->fd)) + if (ps->fd >= 0 && close(ps->fd) < 0) ohshite(_("failed to close after read: '%.255s'"), ps->filename); } @@ -766,6 +773,9 @@ parsedb_parse(struct parsedb_state *ps, struct pkginfo **donep) int pdone; struct field_state fs; + if (ps->data == NULL && (ps->flags & pdb_allow_empty)) + return 0; + memset(&fs, 0, sizeof(fs)); fs.fieldencountered = fieldencountered; diff --git a/t/shellcheck.t b/t/shellcheck.t index 0eb64bd05..a27b678fe 100644 --- a/t/shellcheck.t +++ b/t/shellcheck.t @@ -36,7 +36,6 @@ my @files = qw( get-version run-script debian/dpkg.cron.daily - debian/dpkg.postinst debian/dpkg.postrm scripts/dpkg-maintscript-helper.sh ); -- Dpkg.Org's dpkg

