diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 14 | ||||
-rw-r--r-- | src/archives.c | 2 | ||||
-rw-r--r-- | src/cleanup.c | 2 | ||||
-rw-r--r-- | src/configure.c | 2 | ||||
-rw-r--r-- | src/depcon.c | 2 | ||||
-rw-r--r-- | src/divertcmd.c | 3 | ||||
-rw-r--r-- | src/divertdb.c | 133 | ||||
-rw-r--r-- | src/enquiry.c | 2 | ||||
-rw-r--r-- | src/filesdb-hash.c | 175 | ||||
-rw-r--r-- | src/filesdb.c | 410 | ||||
-rw-r--r-- | src/filesdb.h | 75 | ||||
-rw-r--r-- | src/filters.c | 2 | ||||
-rw-r--r-- | src/help.c | 2 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/main.h | 2 | ||||
-rw-r--r-- | src/packages.c | 2 | ||||
-rw-r--r-- | src/querycmd.c | 2 | ||||
-rw-r--r-- | src/remove.c | 2 | ||||
-rw-r--r-- | src/script.c | 2 | ||||
-rw-r--r-- | src/select.c | 2 | ||||
-rw-r--r-- | src/statcmd.c | 2 | ||||
-rw-r--r-- | src/statdb.c | 267 | ||||
-rw-r--r-- | src/trigproc.c | 2 | ||||
-rw-r--r-- | src/unpack.c | 2 | ||||
-rw-r--r-- | src/verify.c | 2 |
25 files changed, 19 insertions, 1094 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 38b725169..e6c957062 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -25,10 +25,6 @@ bin_PROGRAMS = \ dpkg-statoverride \ dpkg-trigger -noinst_HEADERS = \ - filesdb.h \ - $(nil) - dpkg_SOURCES = \ archives.c archives.h \ cleanup.c \ @@ -36,12 +32,8 @@ dpkg_SOURCES = \ depcon.c \ enquiry.c \ errors.c \ - filesdb.c \ - filesdb-hash.c \ file-match.c file-match.h \ filters.c filters.h \ - divertdb.c \ - statdb.c \ help.c \ main.c main.h \ packages.c \ @@ -61,19 +53,13 @@ dpkg_LDADD = \ $(SELINUX_LIBS) dpkg_divert_SOURCES = \ - filesdb.c \ - divertdb.c \ divertcmd.c dpkg_query_SOURCES = \ - filesdb.c \ - divertdb.c \ querycmd.c dpkg_statoverride_SOURCES = \ - filesdb.c \ selinux.c \ - statdb.c \ statcmd.c dpkg_statoverride_LDADD = \ diff --git a/src/archives.c b/src/archives.c index c80db7fcd..4c5fb8897 100644 --- a/src/archives.c +++ b/src/archives.c @@ -56,8 +56,8 @@ #include <dpkg/options.h> #include <dpkg/triglib.h> #include <dpkg/db-ctrl.h> +#include <dpkg/db-fsys.h> -#include "filesdb.h" #include "main.h" #include "archives.h" #include "filters.h" diff --git a/src/cleanup.c b/src/cleanup.c index ded8219c0..cbc690de9 100644 --- a/src/cleanup.c +++ b/src/cleanup.c @@ -40,8 +40,8 @@ #include <dpkg/pkg.h> #include <dpkg/path.h> #include <dpkg/options.h> +#include <dpkg/db-fsys.h> -#include "filesdb.h" #include "main.h" #include "archives.h" diff --git a/src/configure.c b/src/configure.c index 720812b38..2d9173eba 100644 --- a/src/configure.c +++ b/src/configure.c @@ -53,8 +53,8 @@ #include <dpkg/subproc.h> #include <dpkg/command.h> #include <dpkg/triglib.h> +#include <dpkg/db-fsys.h> -#include "filesdb.h" #include "main.h" enum conffopt { diff --git a/src/depcon.c b/src/depcon.c index 55f08ef08..a34384da7 100644 --- a/src/depcon.c +++ b/src/depcon.c @@ -35,8 +35,8 @@ #include <dpkg/dpkg.h> #include <dpkg/dpkg-db.h> #include <dpkg/db-ctrl.h> +#include <dpkg/db-fsys.h> -#include "filesdb.h" #include "main.h" struct deppossi_pkg_iterator { diff --git a/src/divertcmd.c b/src/divertcmd.c index 170c9e93e..d50409d02 100644 --- a/src/divertcmd.c +++ b/src/divertcmd.c @@ -45,8 +45,7 @@ #include <dpkg/glob.h> #include <dpkg/buffer.h> #include <dpkg/options.h> - -#include "filesdb.h" +#include <dpkg/db-fsys.h> static const char printforhelp[] = N_( diff --git a/src/divertdb.c b/src/divertdb.c deleted file mode 100644 index a056e8296..000000000 --- a/src/divertdb.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * dpkg - main program for package management - * divertdb.c - management of database of diverted files - * - * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk> - * Copyright © 2000, 2001 Wichert Akkerman <wakkerma@debian.org> - * - * This is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include <compat.h> - -#include <sys/types.h> -#include <sys/stat.h> - -#include <errno.h> -#include <string.h> -#include <pwd.h> -#include <grp.h> -#include <fcntl.h> -#include <unistd.h> -#include <stdlib.h> - -#include <dpkg/i18n.h> -#include <dpkg/dpkg.h> -#include <dpkg/dpkg-db.h> -#include <dpkg/debug.h> - -#include "filesdb.h" - -static struct diversion *diversions = NULL; -static char *diversionsname; - -void -ensure_diversions(void) -{ - static struct stat sb_prev; - struct stat sb_next; - char linebuf[MAXDIVERTFILENAME]; - static FILE *file_prev; - FILE *file; - struct diversion *ov, *oicontest, *oialtname; - - if (diversionsname == NULL) - diversionsname = dpkg_db_get_path(DIVERSIONSFILE); - - onerr_abort++; - - file = fopen(diversionsname, "r"); - if (!file) { - if (errno != ENOENT) - ohshite(_("failed to open diversions file")); - } else { - setcloexec(fileno(file), diversionsname); - - if (fstat(fileno(file), &sb_next)) - ohshite(_("failed to fstat diversions file")); - - /* - * We need to keep the database file open so that the - * filesystem cannot reuse the inode number (f.ex. during - * multiple dpkg-divert invocations in a maintainer script), - * otherwise the following check might turn true, and we - * would skip reloading a modified database. - */ - if (file_prev && - sb_prev.st_dev == sb_next.st_dev && - sb_prev.st_ino == sb_next.st_ino) { - fclose(file); - onerr_abort--; - debug(dbg_general, "%s: same, skipping", __func__); - return; - } - sb_prev = sb_next; - } - if (file_prev) - fclose(file_prev); - file_prev = file; - - for (ov = diversions; ov; ov = ov->next) { - ov->useinstead->divert->camefrom->divert = NULL; - ov->useinstead->divert = NULL; - } - diversions = NULL; - if (!file) { - onerr_abort--; - debug(dbg_general, "%s: none, resetting", __func__); - return; - } - debug(dbg_general, "%s: new, (re)loading", __func__); - - while (fgets_checked(linebuf, sizeof(linebuf), file, diversionsname) >= 0) { - oicontest = nfmalloc(sizeof(struct diversion)); - oialtname = nfmalloc(sizeof(struct diversion)); - - oialtname->camefrom = findnamenode(linebuf, 0); - oialtname->useinstead = NULL; - - fgets_must(linebuf, sizeof(linebuf), file, diversionsname); - oicontest->useinstead = findnamenode(linebuf, 0); - oicontest->camefrom = NULL; - - fgets_must(linebuf, sizeof(linebuf), file, diversionsname); - oicontest->pkgset = strcmp(linebuf, ":") ? - pkg_db_find_set(linebuf) : NULL; - oialtname->pkgset = oicontest->pkgset; - - if (oialtname->camefrom->divert || - oicontest->useinstead->divert) - ohshit(_("conflicting diversions involving '%.250s' or '%.250s'"), - oialtname->camefrom->name, oicontest->useinstead->name); - - oialtname->camefrom->divert = oicontest; - oicontest->useinstead->divert = oialtname; - - oicontest->next = diversions; - diversions = oicontest; - } - - onerr_abort--; -} diff --git a/src/enquiry.c b/src/enquiry.c index 9da4160d5..baf26daab 100644 --- a/src/enquiry.c +++ b/src/enquiry.c @@ -43,8 +43,8 @@ #include <dpkg/string.h> #include <dpkg/options.h> #include <dpkg/db-ctrl.h> +#include <dpkg/db-fsys.h> -#include "filesdb.h" #include "main.h" struct audit_problem { diff --git a/src/filesdb-hash.c b/src/filesdb-hash.c deleted file mode 100644 index c04d7a8e6..000000000 --- a/src/filesdb-hash.c +++ /dev/null @@ -1,175 +0,0 @@ -/* - * dpkg - main program for package management - * filesdb-hash.c - management of database of files installed on system - * - * Copyright © 2012-2014 Guillem Jover <guillem@debian.org> - * - * This is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include <compat.h> - -#include <sys/stat.h> - -#include <errno.h> -#include <string.h> -#include <stdio.h> -#include <fcntl.h> -#include <unistd.h> - -#include <dpkg/i18n.h> -#include <dpkg/dpkg.h> -#include <dpkg/dpkg-db.h> -#include <dpkg/debug.h> -#include <dpkg/fdio.h> -#include <dpkg/dir.h> -#include <dpkg/db-ctrl.h> - -#include "filesdb.h" - -/* - * If mask is nonzero, will not write any file whose filenamenode - * has any flag bits set in mask. - */ -void -write_filehash_except(struct pkginfo *pkg, struct pkgbin *pkgbin, - struct fileinlist *list, enum filenamenode_flags mask) -{ - struct atomic_file *file; - const char *hashfile; - - debug(dbg_general, "generating infodb hashfile"); - - if (pkg_infodb_has_file(pkg, &pkg->available, HASHFILE)) - return; - - hashfile = pkg_infodb_get_file(pkg, pkgbin, HASHFILE); - - file = atomic_file_new(hashfile, 0); - atomic_file_open(file); - - for (; list; list = list->next) { - struct filenamenode *namenode = list->namenode; - - if (mask && (namenode->flags & mask)) - continue; - if (strcmp(namenode->newhash, EMPTYHASHFLAG) == 0) - continue; - - fprintf(file->fp, "%s %s\n", - namenode->newhash, namenode->name + 1); - } - - atomic_file_sync(file); - atomic_file_close(file); - atomic_file_commit(file); - atomic_file_free(file); - - dir_sync_path(pkg_infodb_get_dir()); -} - -static void -parse_filehash_buffer(char *buf, char *buf_end, - struct pkginfo *pkg, struct pkgbin *pkgbin) -{ - char *thisline, *nextline; - const char *pkgname = pkg_name(pkg, pnaw_nonambig); - - for (thisline = buf; thisline < buf_end; thisline = nextline) { - struct filenamenode *namenode; - char *endline, *hash_end, *filename; - - endline = memchr(thisline, '\n', buf_end - thisline); - if (endline == NULL) - ohshit(_("control file '%s' for package '%s' is " - "missing final newline"), HASHFILE, pkgname); - - /* The md5sum hash has a constant length. */ - hash_end = thisline + MD5HASHLEN; - - filename = hash_end + 2; - if (filename + 1 > endline) - ohshit(_("control file '%s' for package '%s' is " - "missing value"), HASHFILE, pkgname); - - if (hash_end[0] != ' ' || hash_end[1] != ' ') - ohshit(_("control file '%s' for package '%s' is " - "missing value separator"), HASHFILE, pkgname); - hash_end[0] = '\0'; - - /* Where to start next time around. */ - nextline = endline + 1; - - /* Strip trailing ‘/’. */ - if (endline > thisline && endline[-1] == '/') - endline--; - *endline = '\0'; - - if (endline == thisline) - ohshit(_("control file '%s' for package '%s' " - "contains empty filename"), HASHFILE, pkgname); - - debug(dbg_eachfiledetail, "load hash '%s' for filename '%s'", - thisline, filename); - - /* Add the file to the list. */ - namenode = findnamenode(filename, fnn_nocopy); - namenode->newhash = thisline; - } -} - -void -parse_filehash(struct pkginfo *pkg, struct pkgbin *pkgbin) -{ - static int fd; - const char *hashfile; - struct stat st; - - hashfile = pkg_infodb_get_file(pkg, pkgbin, HASHFILE); - - fd = open(hashfile, O_RDONLY); - if (fd < 0) { - if (errno == ENOENT) - return; - - ohshite(_("cannot open control file '%s' for package '%s'"), - HASHFILE, pkg_name(pkg, pnaw_nonambig)); - } - - if (fstat(fd, &st) < 0) - ohshite(_("cannot stat control file '%s' for package '%s'"), - HASHFILE, pkg_name(pkg, pnaw_nonambig)); - - if (!S_ISREG(st.st_mode)) - ohshit(_("control file '%s' for package '%s' is not a regular file"), - HASHFILE, pkg_name(pkg, pnaw_nonambig)); - - if (st.st_size > 0) { - char *buf, *buf_end; - - buf = nfmalloc(st.st_size); - buf_end = buf + st.st_size; - - if (fd_read(fd, buf, st.st_size) < 0) - ohshite(_("cannot read control file '%s' for package '%s'"), - HASHFILE, pkg_name(pkg, pnaw_nonambig)); - - parse_filehash_buffer(buf, buf_end, pkg, pkgbin); - } - - if (close(fd)) - ohshite(_("cannot close control file '%s' for package '%s'"), - HASHFILE, pkg_name(pkg, pnaw_nonambig)); -} diff --git a/src/filesdb.c b/src/filesdb.c deleted file mode 100644 index 8421d327e..000000000 --- a/src/filesdb.c +++ /dev/null @@ -1,410 +0,0 @@ -/* - * dpkg - main program for package management - * filesdb.c - management of database of files installed on system - * - * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk> - * Copyright © 2000,2001 Wichert Akkerman <wakkerma@debian.org> - * Copyright © 2008-2014 Guillem Jover <guillem@debian.org> - * - * This is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include <compat.h> - -#ifdef HAVE_LINUX_FIEMAP_H -#include <linux/fiemap.h> -#include <linux/fs.h> -#include <sys/ioctl.h> -#include <sys/vfs.h> -#endif -#include <sys/types.h> -#include <sys/stat.h> - -#include <errno.h> -#include <string.h> -#include <pwd.h> -#include <grp.h> -#include <fcntl.h> -#include <unistd.h> -#include <stdlib.h> - -#include <dpkg/i18n.h> -#include <dpkg/dpkg.h> -#include <dpkg/dpkg-db.h> -#include <dpkg/string.h> -#include <dpkg/path.h> -#include <dpkg/dir.h> -#include <dpkg/fdio.h> -#include <dpkg/pkg-array.h> -#include <dpkg/progress.h> -#include <dpkg/db-ctrl.h> - -#include "filesdb.h" -#include "main.h" - -/*** Generic data structures and routines. ***/ - -static bool allpackagesdone = false; - -void note_must_reread_files_inpackage(struct pkginfo *pkg) { - allpackagesdone = false; - pkg->files_list_valid = false; -} - -enum pkg_filesdb_load_status { - PKG_FILESDB_LOAD_NONE = 0, - PKG_FILESDB_LOAD_INPROGRESS = 1, - PKG_FILESDB_LOAD_DONE = 2, -}; - -static enum pkg_filesdb_load_status saidread = PKG_FILESDB_LOAD_NONE; - -/** - * Erase the files saved in pkg. - */ -static void -pkg_files_blank(struct pkginfo *pkg) -{ - struct fileinlist *current; - - for (current = pkg->files; - current; - current= current->next) { - struct pkg_list *pkg_node, *pkg_prev = NULL; - - /* For each file that used to be in the package, - * go through looking for this package's entry in the list - * of packages containing this file, and blank it out. */ - for (pkg_node = current->namenode->packages; - pkg_node; - pkg_node = pkg_node->next) { - if (pkg_node->pkg == pkg) { - if (pkg_prev) - pkg_prev->next = pkg_node->next; - else - current->namenode->packages = pkg_node->next; - - /* The actual filelist links were allocated using nfmalloc, so - * we shouldn't free them. */ - break; - } - pkg_prev = pkg_node; - } - } - pkg->files = NULL; -} - -static struct fileinlist ** -pkg_files_add_file(struct pkginfo *pkg, struct filenamenode *namenode, - struct fileinlist **file_tail) -{ - struct fileinlist *newent; - struct pkg_list *pkg_node; - - if (file_tail == NULL) - file_tail = &pkg->files; - - /* Make sure we're at the end. */ - while ((*file_tail) != NULL) { - file_tail = &((*file_tail)->next); - } - - /* Create a new node. */ - newent = nfmalloc(sizeof(struct fileinlist)); - newent->namenode = namenode; - newent->next = NULL; - *file_tail = newent; - file_tail = &newent->next; - - /* Add pkg to newent's package list. */ - pkg_node = nfmalloc(sizeof(*pkg_node)); - pkg_node->pkg = pkg; - pkg_node->next = newent->namenode->packages; - newent->namenode->packages = pkg_node; - - /* Return the position for the next guy. */ - return file_tail; -} - -/** - * Load the list of files in this package into memory, or update the - * list if it is there but stale. - */ -void -ensure_packagefiles_available(struct pkginfo *pkg) -{ - static int fd; - const char *filelistfile; - struct fileinlist **lendp; - struct stat stat_buf; - char *loaded_list, *loaded_list_end, *thisline, *nextline, *ptr; - - if (pkg->files_list_valid) - return; - - /* Throw away any stale data, if there was any. */ - pkg_files_blank(pkg); - - /* Packages which aren't installed don't have a files list. */ - if (pkg->status == PKG_STAT_NOTINSTALLED) { - pkg->files_list_valid = true; - return; - } - - filelistfile = pkg_infodb_get_file(pkg, &pkg->installed, LISTFILE); - - onerr_abort++; - - fd= open(filelistfile,O_RDONLY); - - if (fd==-1) { - if (errno != ENOENT) - ohshite(_("unable to open files list file for package '%.250s'"), - pkg_name(pkg, pnaw_nonambig)); - onerr_abort--; - if (pkg->status != PKG_STAT_CONFIGFILES && - dpkg_version_is_informative(&pkg->configversion)) { - warning(_("files list file for package '%.250s' missing; assuming " - "package has no files currently installed"), - pkg_name(pkg, pnaw_nonambig)); - } - pkg->files = NULL; - pkg->files_list_valid = true; - return; - } - - push_cleanup(cu_closefd, ehflag_bombout, NULL, 0, 1, &fd); - - if (fstat(fd, &stat_buf)) - ohshite(_("unable to stat files list file for package '%.250s'"), - pkg_name(pkg, pnaw_nonambig)); - - if (!S_ISREG(stat_buf.st_mode)) - ohshit(_("files list for package '%.250s' is not a regular file"), - pkg_name(pkg, pnaw_nonambig)); - - if (stat_buf.st_size) { - loaded_list = nfmalloc(stat_buf.st_size); - loaded_list_end = loaded_list + stat_buf.st_size; - - if (fd_read(fd, loaded_list, stat_buf.st_size) < 0) - ohshite(_("reading files list for package '%.250s'"), - pkg_name(pkg, pnaw_nonambig)); - - lendp = &pkg->files; - thisline = loaded_list; - while (thisline < loaded_list_end) { - struct filenamenode *namenode; - - ptr = memchr(thisline, '\n', loaded_list_end - thisline); - if (ptr == NULL) - ohshit(_("files list file for package '%.250s' is missing final newline"), - pkg_name(pkg, pnaw_nonambig)); - /* Where to start next time around. */ - nextline = ptr + 1; - /* Strip trailing ‘/’. */ - if (ptr > thisline && ptr[-1] == '/') ptr--; - /* Add the file to the list. */ - if (ptr == thisline) - ohshit(_("files list file for package '%.250s' contains empty filename"), - pkg_name(pkg, pnaw_nonambig)); - *ptr = '\0'; - - namenode = findnamenode(thisline, fnn_nocopy); - lendp = pkg_files_add_file(pkg, namenode, lendp); - thisline = nextline; - } - } - pop_cleanup(ehflag_normaltidy); /* fd = open() */ - if (close(fd)) - ohshite(_("error closing files list file for package '%.250s'"), - pkg_name(pkg, pnaw_nonambig)); - - onerr_abort--; - - pkg->files_list_valid = true; -} - -#if defined(HAVE_LINUX_FIEMAP_H) -static int -pkg_sorter_by_files_list_phys_offs(const void *a, const void *b) -{ - const struct pkginfo *pa = *(const struct pkginfo **)a; - const struct pkginfo *pb = *(const struct pkginfo **)b; - - /* We can't simply subtract, because the difference may be greater than - * INT_MAX. */ - if (pa->files_list_phys_offs < pb->files_list_phys_offs) - return -1; - else if (pa->files_list_phys_offs > pb->files_list_phys_offs) - return 1; - else - return 0; -} - -static void -pkg_files_optimize_load(struct pkg_array *array) -{ - struct statfs fs; - int i; - - /* Get the filesystem block size. */ - if (statfs(pkg_infodb_get_dir(), &fs) < 0) - return; - - /* Sort packages by the physical location of their list files, so that - * scanning them later will minimize disk drive head movements. */ - for (i = 0; i < array->n_pkgs; i++) { - struct pkginfo *pkg = array->pkgs[i]; - struct { - struct fiemap fiemap; - struct fiemap_extent extent; - } fm; - const char *listfile; - int fd; - - if (pkg->status == PKG_STAT_NOTINSTALLED || - pkg->files_list_phys_offs != 0) - continue; - - pkg->files_list_phys_offs = -1; - - listfile = pkg_infodb_get_file(pkg, &pkg->installed, LISTFILE); - - fd = open(listfile, O_RDONLY); - if (fd < 0) - continue; - - memset(&fm, 0, sizeof(fm)); - fm.fiemap.fm_start = 0; - fm.fiemap.fm_length = fs.f_bsize; - fm.fiemap.fm_flags = 0; - fm.fiemap.fm_extent_count = 1; - - if (ioctl(fd, FS_IOC_FIEMAP, (unsigned long)&fm) == 0) - pkg->files_list_phys_offs = fm.fiemap.fm_extents[0].fe_physical; - - close(fd); - } - - pkg_array_sort(array, pkg_sorter_by_files_list_phys_offs); -} -#elif defined(HAVE_POSIX_FADVISE) -static void -pkg_files_optimize_load(struct pkg_array *array) -{ - int i; - - /* Ask the kernel to start preloading the list files, so as to get a - * boost when later we actually load them. */ - for (i = 0; i < array->n_pkgs; i++) { - struct pkginfo *pkg = array->pkgs[i]; - const char *listfile; - int fd; - - listfile = pkg_infodb_get_file(pkg, &pkg->installed, LISTFILE); - - fd = open(listfile, O_RDONLY | O_NONBLOCK); - if (fd != -1) { - posix_fadvise(fd, 0, 0, POSIX_FADV_WILLNEED); - close(fd); - } - } -} -#else -static void -pkg_files_optimize_load(struct pkg_array *array) -{ -} -#endif - -void ensure_allinstfiles_available(void) { - struct pkg_array array; - struct pkginfo *pkg; - struct progress progress; - int i; - - if (allpackagesdone) return; - if (saidread < PKG_FILESDB_LOAD_DONE) { - int max = pkg_db_count_pkg(); - - saidread = PKG_FILESDB_LOAD_INPROGRESS; - progress_init(&progress, _("(Reading database ... "), max); - } - - pkg_array_init_from_db(&array); - - pkg_files_optimize_load(&array); - - for (i = 0; i < array.n_pkgs; i++) { - pkg = array.pkgs[i]; - ensure_packagefiles_available(pkg); - - if (saidread == PKG_FILESDB_LOAD_INPROGRESS) - progress_step(&progress); - } - - pkg_array_destroy(&array); - - allpackagesdone = true; - - if (saidread == PKG_FILESDB_LOAD_INPROGRESS) { - progress_done(&progress); - printf(P_("%d file or directory currently installed.)\n", - "%d files and directories currently installed.)\n", - fsys_hash_entries()), - fsys_hash_entries()); - saidread = PKG_FILESDB_LOAD_DONE; - } -} - -void ensure_allinstfiles_available_quiet(void) { - saidread = PKG_FILESDB_LOAD_DONE; - ensure_allinstfiles_available(); -} - -/* - * If mask is nonzero, will not write any file whose filenamenode - * has any flag bits set in mask. - */ -void -write_filelist_except(struct pkginfo *pkg, struct pkgbin *pkgbin, - struct fileinlist *list, enum filenamenode_flags mask) -{ - struct atomic_file *file; - struct fileinlist *node; - const char *listfile; - - listfile = pkg_infodb_get_file(pkg, pkgbin, LISTFILE); - - file = atomic_file_new(listfile, 0); - atomic_file_open(file); - - for (node = list; node; node = node->next) { - if (!(mask && (node->namenode->flags & mask))) { - fputs(node->namenode->name, file->fp); - putc('\n', file->fp); - } - } - - atomic_file_sync(file); - atomic_file_close(file); - atomic_file_commit(file); - atomic_file_free(file); - - dir_sync_path(pkg_infodb_get_dir()); - - note_must_reread_files_inpackage(pkg); -} diff --git a/src/filesdb.h b/src/filesdb.h deleted file mode 100644 index f38fdd245..000000000 --- a/src/filesdb.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * dpkg - main program for package management - * filesdb.h - management of database of files installed on system - * - * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk> - * Copyright © 2008-2014 Guillem Jover <guillem@debian.org> - * - * This is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - */ - -#ifndef FILESDB_H -#define FILESDB_H - -#include <dpkg/file.h> -#include <dpkg/fsys.h> - -/* - * Data structure here is as follows: - * - * For each package we have a ‘struct fileinlist *’, the head of a list of - * files in that package. They are in ‘forwards’ order. Each entry has a - * pointer to the ‘struct filenamenode’. - * - * The struct filenamenodes are in a hash table, indexed by name. - * (This hash table is not visible to callers.) - * - * Each filenamenode has a (possibly empty) list of ‘struct filepackage’, - * giving a list of the packages listing that filename. - * - * When we read files contained info about a particular package we set the - * ‘files’ member of the clientdata struct to the appropriate thing. When - * not yet set the files pointer is made to point to ‘fileslist_uninited’ - * (this is available only internally, within filesdb.c - the published - * interface is ensure_*_available). - */ - -struct pkginfo; - -void ensure_diversions(void); - -enum statdb_parse_flags { - STATDB_PARSE_NORMAL = 0, - STATDB_PARSE_LAX = 1, -}; - -uid_t statdb_parse_uid(const char *str); -gid_t statdb_parse_gid(const char *str); -mode_t statdb_parse_mode(const char *str); -void ensure_statoverrides(enum statdb_parse_flags flags); - -#define LISTFILE "list" -#define HASHFILE "md5sums" - -void ensure_packagefiles_available(struct pkginfo *pkg); -void ensure_allinstfiles_available(void); -void ensure_allinstfiles_available_quiet(void); -void note_must_reread_files_inpackage(struct pkginfo *pkg); -void parse_filehash(struct pkginfo *pkg, struct pkgbin *pkgbin); -void write_filelist_except(struct pkginfo *pkg, struct pkgbin *pkgbin, - struct fileinlist *list, enum filenamenode_flags mask); -void write_filehash_except(struct pkginfo *pkg, struct pkgbin *pkgbin, - struct fileinlist *list, enum filenamenode_flags mask); - -#endif /* FILESDB_H */ diff --git a/src/filters.c b/src/filters.c index 2b8b43263..f770fb74c 100644 --- a/src/filters.c +++ b/src/filters.c @@ -29,9 +29,9 @@ #include <dpkg/i18n.h> #include <dpkg/dpkg.h> #include <dpkg/dpkg-db.h> +#include <dpkg/db-fsys.h> #include "main.h" -#include "filesdb.h" #include "filters.h" struct filter_node { diff --git a/src/help.c b/src/help.c index c5b06b4b6..cfcdd8ebf 100644 --- a/src/help.c +++ b/src/help.c @@ -34,8 +34,8 @@ #include <dpkg/dpkg.h> #include <dpkg/dpkg-db.h> #include <dpkg/path.h> +#include <dpkg/db-fsys.h> -#include "filesdb.h" #include "main.h" const char *const statusstrings[]= { diff --git a/src/main.c b/src/main.c index 9710f08dd..0a45f812e 100644 --- a/src/main.c +++ b/src/main.c @@ -50,9 +50,9 @@ #include <dpkg/subproc.h> #include <dpkg/command.h> #include <dpkg/options.h> +#include <dpkg/db-fsys.h> #include "main.h" -#include "filesdb.h" #include "filters.h" static void DPKG_ATTR_NORET diff --git a/src/main.h b/src/main.h index bc3f07a65..319d8afd0 100644 --- a/src/main.h +++ b/src/main.h @@ -25,7 +25,7 @@ #include <dpkg/debug.h> #include <dpkg/pkg-list.h> -/* These two are defined in filesdb.h. */ +/* These two are defined in <dpkg/fsys.h>. */ struct fileinlist; struct filenamenode; diff --git a/src/packages.c b/src/packages.c index b78d6ffe9..f735ec3e1 100644 --- a/src/packages.c +++ b/src/packages.c @@ -42,8 +42,8 @@ #include <dpkg/string.h> #include <dpkg/options.h> #include <dpkg/db-ctrl.h> +#include <dpkg/db-fsys.h> -#include "filesdb.h" #include "main.h" static struct pkginfo *progress_bytrigproc; diff --git a/src/querycmd.c b/src/querycmd.c index 555bccd3e..76ab99e66 100644 --- a/src/querycmd.c +++ b/src/querycmd.c @@ -55,8 +55,8 @@ #include <dpkg/file.h> #include <dpkg/options.h> #include <dpkg/db-ctrl.h> +#include <dpkg/db-fsys.h> -#include "filesdb.h" #include "main.h" static const char *showformat = "${binary:Package}\t${Version}\n"; diff --git a/src/remove.c b/src/remove.c index 735c9e0f3..18d470aea 100644 --- a/src/remove.c +++ b/src/remove.c @@ -43,8 +43,8 @@ #include <dpkg/options.h> #include <dpkg/triglib.h> #include <dpkg/db-ctrl.h> +#include <dpkg/db-fsys.h> -#include "filesdb.h" #include "main.h" /* diff --git a/src/script.c b/src/script.c index bb5f9825c..fc6f6117e 100644 --- a/src/script.c +++ b/src/script.c @@ -43,8 +43,8 @@ #include <dpkg/command.h> #include <dpkg/triglib.h> #include <dpkg/db-ctrl.h> +#include <dpkg/db-fsys.h> -#include "filesdb.h" #include "main.h" void diff --git a/src/select.c b/src/select.c index ebdb13b7f..3eae4cbcf 100644 --- a/src/select.c +++ b/src/select.c @@ -38,8 +38,8 @@ #include <dpkg/pkg-spec.h> #include <dpkg/options.h> #include <dpkg/db-ctrl.h> +#include <dpkg/db-fsys.h> -#include "filesdb.h" #include "main.h" static void getsel1package(struct pkginfo *pkg) { diff --git a/src/statcmd.c b/src/statcmd.c index af8a2f756..b7ca09eeb 100644 --- a/src/statcmd.c +++ b/src/statcmd.c @@ -43,10 +43,10 @@ #include <dpkg/path.h> #include <dpkg/dir.h> #include <dpkg/glob.h> +#include <dpkg/db-fsys.h> #include <dpkg/options.h> #include "main.h" -#include "filesdb.h" static const char printforhelp[] = N_( "Use --help for help about overriding file stat information."); diff --git a/src/statdb.c b/src/statdb.c deleted file mode 100644 index 042f1bb1e..000000000 --- a/src/statdb.c +++ /dev/null @@ -1,267 +0,0 @@ -/* - * dpkg - main program for package management - * statdb.c - management of database of ownership and mode of files - * - * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk> - * Copyright © 2000, 2001 Wichert Akkerman <wakkerma@debian.org> - * Copyright © 2008-2012 Guillem Jover <guillem@debian.org> - * - * This is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include <compat.h> - -#include <sys/types.h> -#include <sys/stat.h> - -#include <errno.h> -#include <string.h> -#include <pwd.h> -#include <grp.h> -#include <fcntl.h> -#include <unistd.h> -#include <stdlib.h> - -#include <dpkg/i18n.h> -#include <dpkg/dpkg.h> -#include <dpkg/dpkg-db.h> -#include <dpkg/fdio.h> -#include <dpkg/debug.h> - -#include "filesdb.h" - -static char *statoverridename; - -uid_t -statdb_parse_uid(const char *str) -{ - char *endptr; - uid_t uid; - - if (str[0] == '#') { - long int value; - - errno = 0; - value = strtol(str + 1, &endptr, 10); - if (str + 1 == endptr || *endptr || value < 0 || errno != 0) - ohshit(_("invalid statoverride uid %s"), str); - uid = (uid_t)value; - } else { - struct passwd *pw = getpwnam(str); - - if (pw == NULL) - uid = (uid_t)-1; - else - uid = pw->pw_uid; - } - - return uid; -} - -gid_t -statdb_parse_gid(const char *str) -{ - char *endptr; - gid_t gid; - - if (str[0] == '#') { - long int value; - - errno = 0; - value = strtol(str + 1, &endptr, 10); - if (str + 1 == endptr || *endptr || value < 0 || errno != 0) - ohshit(_("invalid statoverride gid %s"), str); - gid = (gid_t)value; - } else { - struct group *gr = getgrnam(str); - - if (gr == NULL) - gid = (gid_t)-1; - else - gid = gr->gr_gid; - } - - return gid; -} - -mode_t -statdb_parse_mode(const char *str) -{ - char *endptr; - long int mode; - - mode = strtol(str, &endptr, 8); - if (str == endptr || *endptr || mode < 0 || mode > 07777) - ohshit(_("invalid statoverride mode %s"), str); - - return (mode_t)mode; -} - -void -ensure_statoverrides(enum statdb_parse_flags flags) -{ - static struct stat sb_prev; - struct stat sb_next; - static FILE *file_prev; - FILE *file; - char *loaded_list, *loaded_list_end, *thisline, *nextline, *ptr; - struct file_stat *fso; - struct filenamenode *fnn; - struct fileiterator *iter; - - if (statoverridename == NULL) - statoverridename = dpkg_db_get_path(STATOVERRIDEFILE); - - onerr_abort++; - - file = fopen(statoverridename, "r"); - if (!file) { - if (errno != ENOENT) - ohshite(_("failed to open statoverride file")); - } else { - setcloexec(fileno(file), statoverridename); - - if (fstat(fileno(file), &sb_next)) - ohshite(_("failed to fstat statoverride file")); - - /* - * We need to keep the database file open so that the - * filesystem cannot reuse the inode number (f.ex. during - * multiple dpkg-statoverride invocations in a maintainer - * script), otherwise the following check might turn true, - * and we would skip reloading a modified database. - */ - if (file_prev && - sb_prev.st_dev == sb_next.st_dev && - sb_prev.st_ino == sb_next.st_ino) { - fclose(file); - onerr_abort--; - debug(dbg_general, "%s: same, skipping", __func__); - return; - } - sb_prev = sb_next; - } - if (file_prev) - fclose(file_prev); - file_prev = file; - - /* Reset statoverride information. */ - iter = files_db_iter_new(); - while ((fnn = files_db_iter_next(iter))) - fnn->statoverride = NULL; - files_db_iter_free(iter); - - if (!file) { - onerr_abort--; - debug(dbg_general, "%s: none, resetting", __func__); - return; - } - debug(dbg_general, "%s: new, (re)loading", __func__); - - /* If the statoverride list is empty we don't need to bother - * reading it. */ - if (!sb_next.st_size) { - onerr_abort--; - return; - } - - loaded_list = m_malloc(sb_next.st_size); - loaded_list_end = loaded_list + sb_next.st_size; - - if (fd_read(fileno(file), loaded_list, sb_next.st_size) < 0) - ohshite(_("reading statoverride file '%.250s'"), statoverridename); - - thisline = loaded_list; - while (thisline < loaded_list_end) { - fso = nfmalloc(sizeof(struct file_stat)); - - ptr = memchr(thisline, '\n', loaded_list_end - thisline); - if (ptr == NULL) - ohshit(_("statoverride file is missing final newline")); - /* Where to start next time around. */ - nextline = ptr + 1; - if (ptr == thisline) - ohshit(_("statoverride file contains empty line")); - *ptr = '\0'; - - /* Extract the uid. */ - ptr = memchr(thisline, ' ', nextline - thisline); - if (ptr == NULL) - ohshit(_("syntax error in statoverride file")); - *ptr = '\0'; - - fso->uid = statdb_parse_uid(thisline); - if (fso->uid == (uid_t)-1) - fso->uname = nfstrsave(thisline); - else - fso->uname = NULL; - - if (fso->uid == (uid_t)-1 && !(flags & STATDB_PARSE_LAX)) - ohshit(_("unknown user '%s' in statoverride file"), - thisline); - - /* Move to the next bit */ - thisline = ptr + 1; - if (thisline >= loaded_list_end) - ohshit(_("unexpected end of line in statoverride file")); - - /* Extract the gid */ - ptr = memchr(thisline, ' ', nextline - thisline); - if (ptr == NULL) - ohshit(_("syntax error in statoverride file")); - *ptr = '\0'; - - fso->gid = statdb_parse_gid(thisline); - if (fso->gid == (gid_t)-1) - fso->gname = nfstrsave(thisline); - else - fso->gname = NULL; - - if (fso->gid == (gid_t)-1 && !(flags & STATDB_PARSE_LAX)) - ohshit(_("unknown group '%s' in statoverride file"), - thisline); - - /* Move to the next bit */ - thisline = ptr + 1; - if (thisline >= loaded_list_end) - ohshit(_("unexpected end of line in statoverride file")); - - /* Extract the mode */ - ptr = memchr(thisline, ' ', nextline - thisline); - if (ptr == NULL) - ohshit(_("syntax error in statoverride file")); - *ptr = '\0'; - - fso->mode = statdb_parse_mode(thisline); - - /* Move to the next bit */ - thisline = ptr + 1; - if (thisline >= loaded_list_end) - ohshit(_("unexpected end of line in statoverride file")); - - fnn = findnamenode(thisline, 0); - if (fnn->statoverride) - ohshit(_("multiple statoverrides present for file '%.250s'"), - thisline); - fnn->statoverride = fso; - - /* Moving on... */ - thisline = nextline; - } - - free(loaded_list); - - onerr_abort--; -} diff --git a/src/trigproc.c b/src/trigproc.c index ef59455e3..4aee33a80 100644 --- a/src/trigproc.c +++ b/src/trigproc.c @@ -34,10 +34,10 @@ #include <dpkg/pkg.h> #include <dpkg/pkg-queue.h> #include <dpkg/db-ctrl.h> +#include <dpkg/db-fsys.h> #include <dpkg/triglib.h> #include "main.h" -#include "filesdb.h" /* * Trigger processing algorithms: diff --git a/src/unpack.c b/src/unpack.c index 2fb138691..827211d63 100644 --- a/src/unpack.c +++ b/src/unpack.c @@ -52,9 +52,9 @@ #include <dpkg/tarfn.h> #include <dpkg/options.h> #include <dpkg/db-ctrl.h> +#include <dpkg/db-fsys.h> #include <dpkg/triglib.h> -#include "filesdb.h" #include "file-match.h" #include "main.h" #include "archives.h" diff --git a/src/verify.c b/src/verify.c index a4eb86ae7..6067fb1ac 100644 --- a/src/verify.c +++ b/src/verify.c @@ -30,8 +30,8 @@ #include <dpkg/dpkg-db.h> #include <dpkg/options.h> #include <dpkg/db-ctrl.h> +#include <dpkg/db-fsys.h> -#include "filesdb.h" #include "main.h" |