Просмотр исходного кода

dpkg: Update commands and options to accept package specifiers

This affects --ignore-depends, --configure, --remove, --purge,
--triggers-only, --get-selections and --set-selections.

Based-on-patch-by: Raphaël Hertzog <hertzog@debian.org>
Patch-sponsored-by: Linaro Limited

Signed-off-by: Guillem Jover <guillem@debian.org>
Guillem Jover лет назад: 14
Родитель
Сommit
45e1108cea
3 измененных файлов с 32 добавлено и 11 удалено
  1. 8 5
      src/main.c
  2. 7 1
      src/packages.c
  3. 17 5
      src/select.c

+ 8 - 5
src/main.c

@@ -49,6 +49,7 @@
 #include <dpkg/arch.h>
 #include <dpkg/subproc.h>
 #include <dpkg/command.h>
+#include <dpkg/pkg-spec.h>
 #include <dpkg/options.h>
 
 #include "main.h"
@@ -341,7 +342,6 @@ static void setroot(const struct cmdinfo *cip, const char *value) {
 
 static void ignoredepends(const struct cmdinfo *cip, const char *value) {
   char *copy, *p;
-  const char *pnerr;
 
   copy= m_malloc(strlen(value)+2);
   strcpy(copy,value);
@@ -355,12 +355,15 @@ static void ignoredepends(const struct cmdinfo *cip, const char *value) {
   }
   p= copy;
   while (*p) {
-    pnerr = pkg_name_is_illegal(p);
-    if (pnerr)
+    struct dpkg_error err;
+    struct pkginfo *pkg;
+
+    pkg = pkg_spec_parse_pkg(p, &err);
+    if (pkg == NULL)
       ohshit(_("--%s needs a valid package name but '%.250s' is not: %s"),
-              cip->olong, p, pnerr);
+              cip->olong, p, err.str);
 
-    pkg_list_prepend(&ignoredependss, pkg_db_find(p));
+    pkg_list_prepend(&ignoredependss, pkg);
 
     p+= strlen(p)+1;
   }

+ 7 - 1
src/packages.c

@@ -40,6 +40,7 @@
 #include <dpkg/dpkg-db.h>
 #include <dpkg/pkg-list.h>
 #include <dpkg/pkg-queue.h>
+#include <dpkg/pkg-spec.h>
 #include <dpkg/options.h>
 
 #include "filesdb.h"
@@ -104,9 +105,14 @@ enqueue_specified(const char *const *argv)
   const char *thisarg;
 
   while ((thisarg = *argv++) != NULL) {
+    struct dpkg_error err;
     struct pkginfo *pkg;
 
-    pkg = pkg_db_find(thisarg);
+    pkg = pkg_spec_parse_pkg(thisarg, &err);
+    if (pkg == NULL)
+      badusage(_("--%s needs a valid package name but '%.250s' is not: %s"),
+               cipaction->olong, thisarg, err.str);
+
     if (pkg->status == stat_notinstalled) {
       size_t l = strlen(pkg->set->name);
       const char *extension = pkg->set->name + l - sizeof(DEBEXT) + 1;

+ 17 - 5
src/select.c

@@ -4,6 +4,8 @@
  *
  * Copyright © 1995,1996 Ian Jackson <ian@chiark.greenend.org.uk>
  * Copyright © 2006,2008-2012 Guillem Jover <guillem@debian.org>
+ * Copyright © 2011 Linaro Limited
+ * Copyright © 2011 Raphaël Hertzog <hertzog@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
@@ -33,6 +35,7 @@
 #include <dpkg/dpkg-db.h>
 #include <dpkg/pkg-array.h>
 #include <dpkg/pkg-show.h>
+#include <dpkg/pkg-spec.h>
 #include <dpkg/options.h>
 
 #include "filesdb.h"
@@ -72,15 +75,22 @@ getselections(const char *const *argv)
     }
   } else {
     while ((thisarg= *argv++)) {
+      struct pkg_spec pkgspec;
+
       found= 0;
+      pkg_spec_init(&pkgspec, psf_patterns | psf_arch_def_wildcard);
+      pkg_spec_parse(&pkgspec, thisarg);
+
       for (i = 0; i < array.n_pkgs; i++) {
         pkg = array.pkgs[i];
-        if (fnmatch(thisarg, pkg->set->name, 0))
+        if (!pkg_spec_match_pkg(&pkgspec, pkg, &pkg->installed))
           continue;
         getsel1package(pkg); found++;
       }
       if (!found)
         fprintf(stderr,_("No packages found matching %s.\n"),thisarg);
+
+      pkg_spec_destroy(&pkgspec);
     }
   }
 
@@ -97,7 +107,6 @@ setselections(const char *const *argv)
 {
   const struct namevalue *nv;
   struct pkginfo *pkg;
-  const char *e;
   int c, lno;
   struct varbuf namevb = VARBUF_INIT;
   struct varbuf selvb = VARBUF_INIT;
@@ -109,6 +118,8 @@ setselections(const char *const *argv)
 
   lno= 1;
   for (;;) {
+    struct dpkg_error err;
+
     do { c= getchar(); if (c == '\n') lno++; } while (c != EOF && isspace(c));
     if (c == EOF) break;
     if (c == '#') {
@@ -143,13 +154,14 @@ setselections(const char *const *argv)
       if (!isspace(c))
         ohshit(_("unexpected data after package and selection at line %d"),lno);
     }
-    e = pkg_name_is_illegal(namevb.buf);
-    if (e) ohshit(_("illegal package name at line %d: %.250s"),lno,e);
+    pkg = pkg_spec_parse_pkg(namevb.buf, &err);
+    if (pkg == NULL)
+      ohshit(_("illegal package name at line %d: %.250s"), lno, err.str);
 
     nv = namevalue_find_by_name(wantinfos, selvb.buf);
     if (nv == NULL)
       ohshit(_("unknown wanted status at line %d: %.250s"), lno, selvb.buf);
-    pkg = pkg_db_find(namevb.buf);
+
     pkg_set_want(pkg, nv->value);
     if (c == EOF) break;
     lno++;