瀏覽代碼

dpkg-query: Add new --control-list and --control-show commands

These replace the now deprecated --control-path command, as these do
not rely on any specific database layout.
Guillem Jover 14 年之前
父節點
當前提交
1a60e53173
共有 5 個文件被更改,包括 104 次插入4 次删除
  1. 2 0
      debian/changelog
  2. 8 0
      doc/README.feature-removal-schedule
  3. 10 4
      man/dpkg-query.1
  4. 2 0
      src/main.h
  5. 82 0
      src/querycmd.c

+ 2 - 0
debian/changelog

@@ -32,6 +32,8 @@ dpkg (1.16.5) UNRELEASED; urgency=low
   * Switch source compression to xz.
   * Switch source compression to xz.
   * Detect ar header fields truncation due to too long member names or too
   * Detect ar header fields truncation due to too long member names or too
     large member sizes. Closes: #678933
     large member sizes. Closes: #678933
+  * Add new dpkg-query --control-list and --control-show commands, which
+    replace the now deprecated --control-path.
 
 
   [ Updated dpkg translations ]
   [ Updated dpkg translations ]
   * Swedish (Peter Krefting).
   * Swedish (Peter Krefting).

+ 8 - 0
doc/README.feature-removal-schedule

@@ -54,6 +54,14 @@ Why:
  support compressing new .deb files with that format, although unpacking
  support compressing new .deb files with that format, although unpacking
  will be kept being supported to handle existing compressed files.
  will be kept being supported to handle existing compressed files.
 
 
+What: --control-path (dpkg-query option)
+Status: deprecated
+When: 1.18.x
+Warning: man page
+ This was a semi-public interface now superceded by --control-list and
+ --control-show, which are a better interface as they do not rely on any
+ specific database layout.
+
 History of feature removals
 History of feature removals
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 

+ 10 - 4
man/dpkg-query.1

@@ -107,13 +107,19 @@ by an empty line, with the same order as specified on the argument list.
 However, note that files created by package-specific installation-scripts
 However, note that files created by package-specific installation-scripts
 are not listed.
 are not listed.
 .TP
 .TP
+.BR \-\-control\-list " \fIpackage-name\fP
+List control files installed to your system from \fIpackage-name\fP.
+These can be used as input arguments to \fB\-\-control\-show\fP.
+.TP
+.BR \-\-control\-show " \fIpackage-name\fP \fIcontrol-file\fP"
+Print the \fIcontrol-file\fP installed to your system from \fIpackage-name\fP
+to the standard output.
+.TP
 .BR \-c ", " \-\-control\-path " \fIpackage-name\fP [\fIcontrol-file\fP]"
 .BR \-c ", " \-\-control\-path " \fIpackage-name\fP [\fIcontrol-file\fP]"
 List paths for control files installed to your system from \fIpackage-name\fP.
 List paths for control files installed to your system from \fIpackage-name\fP.
 If \fIcontrol-file\fP is specified then only list the path for that control
 If \fIcontrol-file\fP is specified then only list the path for that control
-file if it is present. \fBWarning\fP: this command is semi-public, it should
-be used only as a last resort solution, and if no other interface is
-available. It might get deprecated later on if better interfaces or the
-current architectural deficiencies have been solved.
+file if it is present. \fBWarning\fP: this command is deprecated, please
+switch to use \fB\-\-control\-list\fP and \fB\-\-control\-show\fP instead.
 .TP
 .TP
 .BR \-S ", " \-\-search " \fIfilename-search-pattern\fP..."
 .BR \-S ", " \-\-search " \fIfilename-search-pattern\fP..."
 Search for packages that own files corresponding to the given pattern.
 Search for packages that own files corresponding to the given pattern.

+ 2 - 0
src/main.h

@@ -75,6 +75,8 @@ enum action {
 	act_listfiles,
 	act_listfiles,
 	act_searchfiles,
 	act_searchfiles,
 	act_controlpath,
 	act_controlpath,
+	act_controllist,
+	act_controlshow,
 
 
 	act_cmpversions,
 	act_cmpversions,
 
 

+ 82 - 0
src/querycmd.c

@@ -50,6 +50,7 @@
 #include <dpkg/pkg-show.h>
 #include <dpkg/pkg-show.h>
 #include <dpkg/string.h>
 #include <dpkg/string.h>
 #include <dpkg/path.h>
 #include <dpkg/path.h>
+#include <dpkg/file.h>
 #include <dpkg/options.h>
 #include <dpkg/options.h>
 
 
 #include "filesdb.h"
 #include "filesdb.h"
@@ -600,6 +601,15 @@ pkg_infodb_print_filename(const char *filename, const char *filetype)
   printf("%s\n", filename);
   printf("%s\n", filename);
 }
 }
 
 
+static void
+pkg_infodb_print_filetype(const char *filename, const char *filetype)
+{
+  if (pkg_infodb_is_internal(filetype))
+    return;
+
+  printf("%s\n", filetype);
+}
+
 static void
 static void
 control_path_file(struct pkginfo *pkg, const char *control_file)
 control_path_file(struct pkginfo *pkg, const char *control_file)
 {
 {
@@ -656,6 +666,76 @@ control_path(const char *const *argv)
   return 0;
   return 0;
 }
 }
 
 
+static int
+control_list(const char *const *argv)
+{
+  struct dpkg_error err;
+  struct pkginfo *pkg;
+  const char *pkgname;
+
+  pkgname = *argv++;
+  if (!pkgname || *argv)
+    badusage(_("--%s takes one package name argument"), cipaction->olong);
+
+  modstatdb_open(msdbrw_readonly);
+
+  pkg = pkg_spec_parse_pkg(pkgname, &err);
+  if (pkg == NULL)
+    badusage(_("--%s needs a valid package name but '%.250s' is not: %s"),
+             cipaction->olong, pkgname, err.str);
+
+  if (pkg->status == stat_notinstalled)
+    ohshit(_("package '%s' is not installed"), pkg_name(pkg, pnaw_nonambig));
+
+  pkg_infodb_foreach(pkg, &pkg->installed, pkg_infodb_print_filetype);
+
+  modstatdb_shutdown();
+
+  return 0;
+}
+
+static int
+control_show(const char *const *argv)
+{
+  struct dpkg_error err;
+  struct pkginfo *pkg;
+  const char *pkgname;
+  const char *filename;
+  const char *control_file;
+
+  pkgname = *argv++;
+  if (!pkgname || !*argv)
+    badusage(_("--%s needs at two arguments"),
+             cipaction->olong);
+
+  control_file = *argv++;
+  if (!control_file || *argv)
+    badusage(_("--%s takes at most two arguments"), cipaction->olong);
+
+  pkg_infodb_check_filetype(control_file);
+
+  modstatdb_open(msdbrw_readonly);
+
+  pkg = pkg_spec_parse_pkg(pkgname, &err);
+  if (pkg == NULL)
+    badusage(_("--%s needs a valid package name but '%.250s' is not: %s"),
+             cipaction->olong, pkgname, err.str);
+
+  if (pkg->status == stat_notinstalled)
+    ohshit(_("package '%s' is not installed"), pkg_name(pkg, pnaw_nonambig));
+
+  if (pkg_infodb_has_file(pkg, &pkg->installed, control_file))
+    filename = pkg_infodb_get_file(pkg, &pkg->installed, control_file);
+  else
+    ohshit(_("control file '%s' does not exist"), control_file);
+
+  modstatdb_shutdown();
+
+  file_show(filename);
+
+  return 0;
+}
+
 static void DPKG_ATTR_NORET
 static void DPKG_ATTR_NORET
 printversion(const struct cmdinfo *ci, const char *value)
 printversion(const struct cmdinfo *ci, const char *value)
 {
 {
@@ -731,6 +811,8 @@ static const struct cmdinfo cmdinfos[]= {
   ACTION( "search",                         'S', act_searchfiles,   searchfiles     ),
   ACTION( "search",                         'S', act_searchfiles,   searchfiles     ),
   ACTION( "show",                           'W', act_listpackages,  showpackages    ),
   ACTION( "show",                           'W', act_listpackages,  showpackages    ),
   ACTION( "control-path",                   'c', act_controlpath,   control_path    ),
   ACTION( "control-path",                   'c', act_controlpath,   control_path    ),
+  ACTION( "control-list",                    0,  act_controllist,   control_list    ),
+  ACTION( "control-show",                    0,  act_controlshow,   control_show    ),
 
 
   { "admindir",   0,   1, NULL, &admindir,   NULL          },
   { "admindir",   0,   1, NULL, &admindir,   NULL          },
   { "load-avail", 0,   0, &opt_loadavail, NULL, NULL, 1    },
   { "load-avail", 0,   0, &opt_loadavail, NULL, NULL, 1    },