瀏覽代碼

dpkg: Add support for per-package --audit

This allows to check for specific issues with a requested package.
Guillem Jover 12 年之前
父節點
當前提交
e6c1af78ae
共有 3 個文件被更改,包括 32 次插入12 次删除
  1. 1 0
      debian/changelog
  2. 3 2
      man/dpkg.1
  3. 28 10
      src/enquiry.c

+ 1 - 0
debian/changelog

@@ -60,6 +60,7 @@ dpkg (1.17.10) UNRELEASED; urgency=low
     or vi, if the previous commands are either unset or not found.
   * Use badusage() instead of ohshit() on dpkg --ignore-depends argument
     parsing errors.
+  * Add per package dpkg --audit support.
 
   [ Updated programs translations ]
   * Catalan (Guillem Jover).

+ 3 - 2
man/dpkg.1

@@ -246,8 +246,9 @@ uninstalled unavailable packages.
 .B \-\-clear\-avail
 Erase the existing information about what packages are available.
 .TP
-\fB \-C\fP, \fB\-\-audit\fP
-Performs database sanity and consistency checks on all packages.
+.BR \-C ", " \-\-audit " [\fIpackage-name\fP...]
+Performs database sanity and consistency checks for \fIpackage-name\fP
+or all packages if omitted.
 For example, searches for packages that have been installed only partially
 on your system or that have missing, wrong or obsolete control data or
 files. \fBdpkg\fP will suggest what to do with them to get them fixed.

+ 28 - 10
src/enquiry.c

@@ -21,8 +21,6 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-/* FIXME: per-package audit. */
-
 #include <config.h>
 #include <compat.h>
 
@@ -40,6 +38,7 @@
 #include <dpkg/dpkg.h>
 #include <dpkg/dpkg-db.h>
 #include <dpkg/arch.h>
+#include <dpkg/pkg-array.h>
 #include <dpkg/pkg-show.h>
 #include <dpkg/string.h>
 #include <dpkg/options.h>
@@ -176,24 +175,41 @@ static void describebriefly(struct pkginfo *pkg) {
   printf(" %-20s %.*s\n", pkg_name(pkg, pnaw_nonambig), l, pdesc);
 }
 
+static struct pkginfo *
+pkg_array_mapper(const char *name)
+{
+  struct pkginfo *pkg;
+
+  pkg = dpkg_options_parse_pkgname(cipaction, name);
+  if (pkg->status == stat_notinstalled)
+    notice(_("package '%s' is not installed"), pkg_name(pkg, pnaw_nonambig));
+
+  return pkg;
+}
+
 int
 audit(const char *const *argv)
 {
   const struct audit_problem *problem;
+  struct pkg_array array;
   bool head_running = false;
-
-  if (*argv)
-    badusage(_("--%s takes no arguments"), cipaction->olong);
+  int i;
 
   modstatdb_open(msdbrw_readonly);
 
+  if (!*argv)
+    pkg_array_init_from_db(&array);
+  else
+    pkg_array_init_from_names(&array, pkg_array_mapper, (const char **)argv);
+
+  pkg_array_sort(&array, pkg_sorter_by_nonambig_name_arch);
+
   for (problem = audit_problems; problem->check; problem++) {
-    struct pkgiterator *it;
-    struct pkginfo *pkg;
     bool head = false;
 
-    it = pkg_db_iter_new();
-    while ((pkg = pkg_db_iter_next_pkg(it))) {
+    for (i = 0; i < array.n_pkgs; i++) {
+      struct pkginfo *pkg = array.pkgs[i];
+
       if (!problem->check(pkg, problem))
         continue;
       if (!head_running) {
@@ -209,10 +225,12 @@ audit(const char *const *argv)
       }
       describebriefly(pkg);
     }
-    pkg_db_iter_free(it);
+
     if (head) putchar('\n');
   }
 
+  pkg_array_destroy(&array);
+
   m_output(stdout, _("<standard output>"));
 
   return 0;