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=a9663b000b9c96030c7062fa01c0bee038cd11f9

commit a9663b000b9c96030c7062fa01c0bee038cd11f9
Author: Guillem Jover <[email protected]>
AuthorDate: Fri May 4 05:22:32 2018 +0200

    libdpkg: Move files list information from dpkg clientdata to pkginfo
    
    This will make it possible to move the fsys database parsing and dumping
    code out from dpkg into libdpkg.
    
    This is general package information, even if some clients might not be
    interested in its contents, such as frontends that just manage metadata
    and drive dpkg itself.
---
 debian/changelog   |  1 +
 lib/dpkg/dpkg-db.h | 13 +++++++++++++
 lib/dpkg/pkg.c     |  3 +++
 src/archives.c     |  2 +-
 src/filesdb.c      | 47 +++++++++++++++++------------------------------
 src/main.h         | 13 -------------
 src/querycmd.c     |  2 +-
 src/remove.c       |  8 ++++----
 src/unpack.c       | 17 ++++++++---------
 src/verify.c       |  2 +-
 10 files changed, 49 insertions(+), 59 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index a7ed64367..bec8355b6 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -180,6 +180,7 @@ dpkg (1.19.1) UNRELEASED; urgency=medium
     - dpkg: Call ensure_package_clientdata() defensively.
     - dpkg: For read-only state functions, check that clientdata is allocated
       before using it.
+    - libdpkg: Move files list information from dpkg clientdata to pkginfo.
   * Build system:
     - Set distribution tarball format to ustar, instead of default v7 format.
     - Mark PO4A and POD2MAN as precious variables.
diff --git a/lib/dpkg/dpkg-db.h b/lib/dpkg/dpkg-db.h
index caa0cf0a2..a60da4a50 100644
--- a/lib/dpkg/dpkg-db.h
+++ b/lib/dpkg/dpkg-db.h
@@ -219,6 +219,19 @@ struct pkginfo {
   struct trigaw *othertrigaw_head;
   struct trigpend *trigpend_head;
 
+  /**
+   * files_list_valid  files  Meaning
+   * ----------------  -----  -------
+   * false             NULL   Not read yet, must do so if want them.
+   * false             !NULL  Read, but rewritten and now out of date. If want
+   *                          info must throw away old and reread file.
+   * true              !NULL  Read, all is OK.
+   * true              NULL   Read OK, but, there were no files.
+   */
+  struct fileinlist *files;
+  off_t files_list_phys_offs;
+  bool files_list_valid;
+
   /* The status has changed, it needs to be logged. */
   bool status_dirty;
 };
diff --git a/lib/dpkg/pkg.c b/lib/dpkg/pkg.c
index 711df8fd8..893d14e18 100644
--- a/lib/dpkg/pkg.c
+++ b/lib/dpkg/pkg.c
@@ -123,6 +123,9 @@ pkg_blank(struct pkginfo *pkg)
        pkg->otherpriority = NULL;
        pkg->section = NULL;
        dpkg_version_blank(&pkg->configversion);
+       pkg->files_list_valid = false;
+       pkg->files_list_phys_offs = 0;
+       pkg->files = NULL;
        pkg->archives = NULL;
        pkg->clientdata = NULL;
        pkg->trigaw.head = NULL;
diff --git a/src/archives.c b/src/archives.c
index 9b736a5d9..c80db7fcd 100644
--- a/src/archives.c
+++ b/src/archives.c
@@ -198,7 +198,7 @@ filesavespackage(struct fileinlist *file,
      * we shouldn't try to make it take over this shared directory. */
     debug(dbg_eachfiledetail,"filesavespackage ...  is 3rd package");
 
-    if (!thirdpkg->clientdata->fileslistvalid) {
+    if (!thirdpkg->files_list_valid) {
       debug(dbg_eachfiledetail, "process_archive ... already disappeared!");
       continue;
     }
diff --git a/src/filesdb.c b/src/filesdb.c
index 8ca613e24..22aad89e0 100644
--- a/src/filesdb.c
+++ b/src/filesdb.c
@@ -67,18 +67,14 @@ ensure_package_clientdata(struct pkginfo *pkg)
   pkg->clientdata->istobe = PKG_ISTOBE_NORMAL;
   pkg->clientdata->color = PKG_CYCLE_WHITE;
   pkg->clientdata->enqueued = false;
-  pkg->clientdata->fileslistvalid = false;
-  pkg->clientdata->files = NULL;
   pkg->clientdata->replacingfilesandsaid = 0;
   pkg->clientdata->cmdline_seen = 0;
-  pkg->clientdata->listfile_phys_offs = 0;
   pkg->clientdata->trigprocdeferred = NULL;
 }
 
 void note_must_reread_files_inpackage(struct pkginfo *pkg) {
   allpackagesdone = false;
-  ensure_package_clientdata(pkg);
-  pkg->clientdata->fileslistvalid = false;
+  pkg->files_list_valid = false;
 }
 
 enum pkg_filesdb_load_status {
@@ -97,11 +93,7 @@ pkg_files_blank(struct pkginfo *pkg)
 {
   struct fileinlist *current;
 
-  /* Anything to empty? */
-  if (!pkg->clientdata)
-    return;
-
-  for (current= pkg->clientdata->files;
+  for (current = pkg->files;
        current;
        current= current->next) {
     struct pkg_list *pkg_node, *pkg_prev = NULL;
@@ -125,7 +117,7 @@ pkg_files_blank(struct pkginfo *pkg)
       pkg_prev = pkg_node;
     }
   }
-  pkg->clientdata->files = NULL;
+  pkg->files = NULL;
 }
 
 static struct fileinlist **
@@ -135,10 +127,8 @@ pkg_files_add_file(struct pkginfo *pkg, struct 
filenamenode *namenode,
   struct fileinlist *newent;
   struct pkg_list *pkg_node;
 
-  ensure_package_clientdata(pkg);
-
   if (file_tail == NULL)
-    file_tail = &pkg->clientdata->files;
+    file_tail = &pkg->files;
 
   /* Make sure we're at the end. */
   while ((*file_tail) != NULL) {
@@ -175,16 +165,15 @@ ensure_packagefiles_available(struct pkginfo *pkg)
   struct stat stat_buf;
   char *loaded_list, *loaded_list_end, *thisline, *nextline, *ptr;
 
-  if (pkg->clientdata && pkg->clientdata->fileslistvalid)
+  if (pkg->files_list_valid)
     return;
-  ensure_package_clientdata(pkg);
 
   /* 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->clientdata->fileslistvalid = true;
+    pkg->files_list_valid = true;
     return;
   }
 
@@ -205,8 +194,8 @@ ensure_packagefiles_available(struct pkginfo *pkg)
                 "package has no files currently installed"),
               pkg_name(pkg, pnaw_nonambig));
     }
-    pkg->clientdata->files = NULL;
-    pkg->clientdata->fileslistvalid = true;
+    pkg->files = NULL;
+    pkg->files_list_valid = true;
     return;
   }
 
@@ -228,7 +217,7 @@ ensure_packagefiles_available(struct pkginfo *pkg)
       ohshite(_("reading files list for package '%.250s'"),
               pkg_name(pkg, pnaw_nonambig));
 
-    lendp= &pkg->clientdata->files;
+    lendp = &pkg->files;
     thisline = loaded_list;
     while (thisline < loaded_list_end) {
       struct filenamenode *namenode;
@@ -259,21 +248,21 @@ ensure_packagefiles_available(struct pkginfo *pkg)
 
   onerr_abort--;
 
-  pkg->clientdata->fileslistvalid = true;
+  pkg->files_list_valid = true;
 }
 
 #if defined(HAVE_LINUX_FIEMAP_H)
 static int
-pkg_sorter_by_listfile_phys_offs(const void *a, const void *b)
+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->clientdata->listfile_phys_offs < pb->clientdata->listfile_phys_offs)
+  if (pa->files_list_phys_offs < pb->files_list_phys_offs)
     return -1;
-  else if (pa->clientdata->listfile_phys_offs > 
pb->clientdata->listfile_phys_offs)
+  else if (pa->files_list_phys_offs > pb->files_list_phys_offs)
     return 1;
   else
     return 0;
@@ -300,13 +289,11 @@ pkg_files_optimize_load(struct pkg_array *array)
     const char *listfile;
     int fd;
 
-    ensure_package_clientdata(pkg);
-
     if (pkg->status == PKG_STAT_NOTINSTALLED ||
-        pkg->clientdata->listfile_phys_offs != 0)
+        pkg->files_list_phys_offs != 0)
       continue;
 
-    pkg->clientdata->listfile_phys_offs = -1;
+    pkg->files_list_phys_offs = -1;
 
     listfile = pkg_infodb_get_file(pkg, &pkg->installed, LISTFILE);
 
@@ -321,12 +308,12 @@ pkg_files_optimize_load(struct pkg_array *array)
     fm.fiemap.fm_extent_count = 1;
 
     if (ioctl(fd, FS_IOC_FIEMAP, (unsigned long)&fm) == 0)
-      pkg->clientdata->listfile_phys_offs = 
fm.fiemap.fm_extents[0].fe_physical;
+      pkg->files_list_phys_offs = fm.fiemap.fm_extents[0].fe_physical;
 
     close(fd);
   }
 
-  pkg_array_sort(array, pkg_sorter_by_listfile_phys_offs);
+  pkg_array_sort(array, pkg_sorter_by_files_list_phys_offs);
 }
 #elif defined(HAVE_POSIX_FADVISE)
 static void
diff --git a/src/main.h b/src/main.h
index 1600abc25..f5695aeea 100644
--- a/src/main.h
+++ b/src/main.h
@@ -56,22 +56,9 @@ struct perpackagestate {
 
   bool enqueued;
 
-  /**
-   * filelistvalid  files  Meaning
-   * -------------  -----  -------
-   * false          NULL   Not read yet, must do so if want them.
-   * false          !NULL  Read, but rewritten and now out of date. If want
-   *                         info must throw away old and reread file.
-   * true           !NULL  Read, all is OK.
-   * true           NULL   Read OK, but, there were no files.
-   */
-  bool fileslistvalid;
-  struct fileinlist *files;
   int replacingfilesandsaid;
   int cmdline_seen;
 
-  off_t listfile_phys_offs;
-
   /** Non-NULL iff in trigproc.c:deferred. */
   struct pkg_list *trigprocdeferred;
 };
diff --git a/src/querycmd.c b/src/querycmd.c
index 0c637bed7..555bccd3e 100644
--- a/src/querycmd.c
+++ b/src/querycmd.c
@@ -490,7 +490,7 @@ enqperpackage(const char *const *argv)
       default:
         ensure_packagefiles_available(pkg);
         ensure_diversions();
-        file= pkg->clientdata->files;
+        file = pkg->files;
         if (!file) {
           printf(_("Package '%s' does not contain any files (!)\n"),
                  pkg_name(pkg, pnaw_nonambig));
diff --git a/src/remove.c b/src/remove.c
index 6eb2e5d90..735c9e0f3 100644
--- a/src/remove.c
+++ b/src/remove.c
@@ -266,7 +266,7 @@ removal_bulk_remove_files(struct pkginfo *pkg)
     modstatdb_note(pkg);
     push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
 
-    reversefilelist_init(&rev_iter, pkg->clientdata->files);
+    reversefilelist_init(&rev_iter, pkg->files);
     leftover = NULL;
     while ((namenode = reversefilelist_next(&rev_iter))) {
       struct filenamenode *usenode;
@@ -389,7 +389,7 @@ static void removal_bulk_remove_leftover_dirs(struct 
pkginfo *pkg) {
   modstatdb_note(pkg);
   push_checkpoint(~ehflag_bombout, ehflag_normaltidy);
 
-  reversefilelist_init(&rev_iter, pkg->clientdata->files);
+  reversefilelist_init(&rev_iter, pkg->files);
   leftover = NULL;
   while ((namenode = reversefilelist_next(&rev_iter))) {
     struct filenamenode *usenode;
@@ -498,7 +498,7 @@ static void removal_bulk_remove_configfiles(struct pkginfo 
*pkg) {
      * are involved in diversions, except if we are the package doing the
      * diverting. */
     for (lconffp = &pkg->installed.conffiles; (conff = *lconffp) != NULL; ) {
-      for (searchfile= pkg->clientdata->files;
+      for (searchfile = pkg->files;
            searchfile && strcmp(searchfile->namenode->name,conff->name);
            searchfile= searchfile->next);
       if (!searchfile) {
@@ -605,7 +605,7 @@ static void removal_bulk_remove_configfiles(struct pkginfo 
*pkg) {
     }
 
     /* Remove the conffiles from the file list file. */
-    write_filelist_except(pkg, &pkg->installed, pkg->clientdata->files,
+    write_filelist_except(pkg, &pkg->installed, pkg->files,
                           fnnf_old_conff);
 
     pkg->installed.conffiles = NULL;
diff --git a/src/unpack.c b/src/unpack.c
index 970871a3a..2fb138691 100644
--- a/src/unpack.c
+++ b/src/unpack.c
@@ -563,7 +563,7 @@ pkg_remove_old_files(struct pkginfo *pkg,
   struct filenamenode *namenode;
   struct stat stab, oldfs;
 
-  reversefilelist_init(&rev_iter, pkg->clientdata->files);
+  reversefilelist_init(&rev_iter, pkg->files);
 
   while ((namenode = reversefilelist_next(&rev_iter))) {
     struct filenamenode *usenode;
@@ -824,7 +824,7 @@ pkg_disappear(struct pkginfo *pkg, struct pkginfo *infavour)
   dpkg_version_blank(&pkg->configversion);
   pkgbin_blank(&pkg->installed);
 
-  pkg->clientdata->fileslistvalid = false;
+  pkg->files_list_valid = false;
 
   modstatdb_note(pkg);
 }
@@ -847,7 +847,7 @@ pkg_disappear_others(struct pkginfo *pkg)
         otherpkg->status == PKG_STAT_NOTINSTALLED ||
         otherpkg->status == PKG_STAT_CONFIGFILES ||
         otherpkg->clientdata->istobe == PKG_ISTOBE_REMOVE ||
-        !otherpkg->clientdata->files)
+        !otherpkg->files)
       continue;
 
     /* Do not try to disappear other packages from the same set
@@ -866,14 +866,14 @@ pkg_disappear_others(struct pkginfo *pkg)
                 "is to be %d",
                 pkg_name(otherpkg, pnaw_always), otherpkg->clientdata->istobe);
 
-    for (cfile = otherpkg->clientdata->files;
+    for (cfile = otherpkg->files;
          cfile && strcmp(cfile->namenode->name, "/.") == 0;
          cfile = cfile->next);
     if (!cfile) {
       debug(dbg_stupidlyverbose, "process_archive no non-root, no disappear");
       continue;
     }
-    for (cfile = otherpkg->clientdata->files;
+    for (cfile = otherpkg->files;
          cfile && !filesavespackage(cfile, otherpkg, pkg);
          cfile = cfile->next);
     if (cfile)
@@ -1012,18 +1012,17 @@ pkg_remove_files_from_others(struct pkginfo *pkg, 
struct fileinlist *newfileslis
       if (cfile->namenode->flags & fnnf_new_conff)
         conffile_mark_obsolete(otherpkg, cfile->namenode);
 
-      /* If !fileslistvalid then it's one of the disappeared packages above
+      /* If !files_list_valid then it's one of the disappeared packages above
        * or we have already updated the files list file, and we don't bother
        * with it here, clearly. */
-      if (!otherpkg->clientdata->fileslistvalid)
+      if (!otherpkg->files_list_valid)
         continue;
 
       /* Found one. We delete the list entry for this file,
        * (and any others in the same package) and then mark the package
        * as requiring a reread. */
       write_filelist_except(otherpkg, &otherpkg->installed,
-                            otherpkg->clientdata->files, 
fnnf_elide_other_lists);
-      ensure_package_clientdata(otherpkg);
+                            otherpkg->files, fnnf_elide_other_lists);
       debug(dbg_veryverbose, "process_archive overwrote from %s",
             pkg_name(otherpkg, pnaw_always));
     }
diff --git a/src/verify.c b/src/verify.c
index 2698fc216..a4eb86ae7 100644
--- a/src/verify.c
+++ b/src/verify.c
@@ -102,7 +102,7 @@ verify_package(struct pkginfo *pkg)
        parse_filehash(pkg, &pkg->installed);
        pkg_conffiles_mark_old(pkg);
 
-       for (file = pkg->clientdata->files; file; file = file->next) {
+       for (file = pkg->files; file; file = file->next) {
                struct verify_checks checks;
                struct filenamenode *fnn;
                char hash[MD5HASHLEN + 1];

-- 
Dpkg.Org's dpkg

Reply via email to