Explorar o código

dpkg-query: Trim trailing slash and slash dot from arguments

Do this when the arguments are path names, but not on patterns, to avoid
unexpected behaviour. Closes: #129577
Guillem Jover %!s(int64=18) %!d(string=hai) anos
pai
achega
af9e264518
Modificáronse 3 ficheiros con 27 adicións e 0 borrados
  1. 6 0
      ChangeLog
  2. 2 0
      debian/changelog
  3. 19 0
      src/query.c

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+2008-06-01  Guillem Jover  <guillem@debian.org>
+
+	* src/query.c: Include <dpkg-priv.h>.
+	(searchfiles): Trim trailing '/' and '/.' from file searches only
+	on path names, but not patterns.
+
 2008-06-01  Guillem Jover  <guillem@debian.org>
 
 	* lib/dpkg-priv.h (rtrim_slash_slashdot): Return the string size.

+ 2 - 0
debian/changelog

@@ -10,6 +10,8 @@ dpkg (1.15.0) UNRELEASED; urgency=low
   * Fix link order when using libcompat.a and libintl.a by placing them after
     libdpkg.a. Based on a patch by Martin Koeppe. Closes: #481805
   * Remove duplicate program name from dpkg-trigger badusage output.
+  * Trim trailing slash and slash dot from 'dpkg -S' arguments when those
+    are path names, but not on patterns. Closes: #129577
 
   [ Raphael Hertzog ]
   * Enhance dpkg-shlibdeps's error message when a library can't be found to

+ 19 - 0
src/query.c

@@ -38,6 +38,7 @@
 
 #include <dpkg.h>
 #include <dpkg-db.h>
+#include <dpkg-priv.h>
 #include <myopt.h>
 
 #include "filesdb.h"
@@ -244,17 +245,33 @@ void searchfiles(const char *const *argv) {
   struct fileiterator *it;
   const char *thisarg;
   int found;
+  struct varbuf path;
   static struct varbuf vb;
   
   if (!*argv)
     badusage(_("--search needs at least one file name pattern argument"));
 
+  varbufinit(&path);
+
   modstatdb_init(admindir,msdbrw_readonly|msdbrw_noavail);
   ensure_allinstfiles_available_quiet();
   ensure_diversions();
 
   while ((thisarg= *argv++) != 0) {
     found= 0;
+
+    /* Trim trailing slash and slash dot from the argument if it's
+     * not a pattern, just a path.
+     */
+    if (!strpbrk(thisarg, "*[?\\")) {
+      varbufreset(&path);
+      varbufaddstr(&path, thisarg);
+      varbufaddc(&path, '\0');
+
+      path.used = rtrim_slash_slashdot(path.buf);
+      thisarg = path.buf;
+    }
+
     if (!strchr("*[?/",*thisarg)) {
       varbufreset(&vb);
       varbufaddc(&vb,'*');
@@ -283,6 +300,8 @@ void searchfiles(const char *const *argv) {
     }
   }
   modstatdb_shutdown();
+
+  varbuffree(&path);
 }
 
 void enqperpackage(const char *const *argv) {