]> git.saurik.com Git - apt.git/commitdiff
* apt-pkg/deb/deblistparser.cc:
authorDavid Kalnischkies <kalnischkies@gmail.com>
Thu, 14 Jun 2012 16:48:23 +0000 (18:48 +0200)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Thu, 14 Jun 2012 16:48:23 +0000 (18:48 +0200)
  - use PackageArchitectureMatchesSpecification filter
* apt-pkg/cachefilter.cc:
  - add PackageArchitectureMatchesSpecification (Closes: #672603)

apt-pkg/cachefilter.cc
apt-pkg/cachefilter.h
apt-pkg/deb/deblistparser.cc
debian/changelog

index fb444208c21b6f1cebd2d9ae2fbd6cbbcbe381e6..35f95fe22fcc4d558530ed9099bfcb0277c343ea 100644 (file)
@@ -9,10 +9,12 @@
 #include <apt-pkg/cachefilter.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/pkgcache.h>
 #include <apt-pkg/cachefilter.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/pkgcache.h>
+#include <apt-pkg/strutl.h>
 
 #include <string>
 
 #include <regex.h>
 
 #include <string>
 
 #include <regex.h>
+#include <fnmatch.h>
 
 #include <apti18n.h>
                                                                        /*}}}*/
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -52,5 +54,54 @@ PackageNameMatchesRegEx::~PackageNameMatchesRegEx() {                        /*{{{*/
        delete pattern;
 }
                                                                        /*}}}*/
        delete pattern;
 }
                                                                        /*}}}*/
+
+// CompleteArch to <kernel>-<cpu> tuple                                        /*{{{*/
+//----------------------------------------------------------------------
+/* The complete architecture, consisting of <kernel>-<cpu>. */
+static std::string CompleteArch(std::string const &arch) {
+       if (arch.find('-') != std::string::npos) {
+               // ensure that only -any- is replaced and not something like company-
+               std::string complete = std::string("-").append(arch).append("-");
+               complete = SubstVar(complete, "-any-", "-*-");
+               complete = complete.substr(1, complete.size()-2);
+               return complete;
+       }
+       else if (arch == "armel")               return "linux-arm";
+       else if (arch == "armhf")               return "linux-arm";
+       else if (arch == "lpia")                return "linux-i386";
+       else if (arch == "powerpcspe")          return "linux-powerpc";
+       else if (arch == "uclibc-linux-armel")  return "linux-arm";
+       else if (arch == "uclinux-armel")       return "uclinux-arm";
+       else if (arch == "any")                 return "*-*";
+       else                                    return "linux-" + arch;
+}
+                                                                       /*}}}*/
+PackageArchitectureMatchesSpecification::PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern) :/*{{{*/
+                                       literal(pattern), isPattern(isPattern), d(NULL) {
+       complete = CompleteArch(pattern);
+}
+                                                                       /*}}}*/
+bool PackageArchitectureMatchesSpecification::operator() (char const * const &arch) {/*{{{*/
+       if (strcmp(literal.c_str(), arch) == 0 ||
+           strcmp(complete.c_str(), arch) == 0)
+               return true;
+       std::string const pkgarch = CompleteArch(arch);
+       if (isPattern == true)
+               return fnmatch(complete.c_str(), pkgarch.c_str(), 0) == 0;
+       return fnmatch(pkgarch.c_str(), complete.c_str(), 0) == 0;
+}
+                                                                       /*}}}*/
+bool PackageArchitectureMatchesSpecification::operator() (pkgCache::PkgIterator const &Pkg) {/*{{{*/
+       return (*this)(Pkg.Arch());
+}
+                                                                       /*}}}*/
+bool PackageArchitectureMatchesSpecification::operator() (pkgCache::VerIterator const &Ver) {/*{{{*/
+       return (*this)(Ver.ParentPkg());
+}
+                                                                       /*}}}*/
+PackageArchitectureMatchesSpecification::~PackageArchitectureMatchesSpecification() {  /*{{{*/
+}
+                                                                       /*}}}*/
+
 }
 }
 }
 }
index 5d426008b26288abb9f83a2f1d671fedfe8ead51..25cd43f476136dd7fd95418055e29e0b8c128031 100644 (file)
@@ -26,6 +26,36 @@ public:
        ~PackageNameMatchesRegEx();
 };
                                                                        /*}}}*/
        ~PackageNameMatchesRegEx();
 };
                                                                        /*}}}*/
+// PackageArchitectureMatchesSpecification                             /*{{{*/
+/** \class PackageArchitectureMatchesSpecification
+   \brief matching against architecture specification strings
+
+   The strings are of the format <kernel>-<cpu> where either component,
+   or the whole string, can be the wildcard "any" as defined in
+   debian-policy ยง11.1 "Architecture specification strings".
+
+   Examples: i386, mipsel, linux-any, any-amd64, any */
+class PackageArchitectureMatchesSpecification {
+       std::string literal;
+       std::string complete;
+       bool isPattern;
+       /** \brief dpointer placeholder (for later in case we need it) */
+       void *d;
+public:
+       /** \brief matching against architecture specification strings
+        *
+        * @param pattern is the architecture specification string
+        * @param isPattern defines if the given \b pattern is a
+        *        architecture specification pattern to match others against
+        *        or if it is the fixed string and matched against patterns
+        */
+       PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern = true);
+       bool operator() (char const * const &arch);
+       bool operator() (pkgCache::PkgIterator const &Pkg);
+       bool operator() (pkgCache::VerIterator const &Ver);
+       ~PackageArchitectureMatchesSpecification();
+};
+                                                                       /*}}}*/
 }
 }
 #endif
 }
 }
 #endif
index d29b28d485faf94f6308e5d7829c2d71ac839997..efb76ef54795ae0833676b43a733cc13ad869307 100644 (file)
@@ -15,6 +15,7 @@
 #include <apt-pkg/deblistparser.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/deblistparser.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/configuration.h>
+#include <apt-pkg/cachefilter.h>
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/fileutl.h>
@@ -22,7 +23,6 @@
 #include <apt-pkg/md5.h>
 #include <apt-pkg/macros.h>
 
 #include <apt-pkg/md5.h>
 #include <apt-pkg/macros.h>
 
-#include <fnmatch.h>
 #include <ctype.h>
                                                                        /*}}}*/
 
 #include <ctype.h>
                                                                        /*}}}*/
 
@@ -464,22 +464,6 @@ const char *debListParser::ConvertRelation(const char *I,unsigned int &Op)
    }
    return I;
 }
    }
    return I;
 }
-
-/*
- * CompleteArch:
- *
- * The complete architecture, consisting of <kernel>-<cpu>.
- */
-static string CompleteArch(std::string const &arch) {
-    if (arch == "armel")              return "linux-arm";
-    if (arch == "armhf")              return "linux-arm";
-    if (arch == "lpia")               return "linux-i386";
-    if (arch == "powerpcspe")         return "linux-powerpc";
-    if (arch == "uclibc-linux-armel") return "linux-arm";
-    if (arch == "uclinux-armel")      return "uclinux-arm";
-
-    return (arch.find("-") != string::npos) ? arch : "linux-" + arch;
-}
                                                                        /*}}}*/
 // ListParser::ParseDepends - Parse a dependency element               /*{{{*/
 // ---------------------------------------------------------------------
                                                                        /*}}}*/
 // ListParser::ParseDepends - Parse a dependency element               /*{{{*/
 // ---------------------------------------------------------------------
@@ -556,7 +540,7 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop,
 
    if (ParseArchFlags == true)
    {
 
    if (ParseArchFlags == true)
    {
-      string completeArch = CompleteArch(arch);
+      APT::CacheFilter::PackageArchitectureMatchesSpecification matchesArch(arch, false);
 
       // Parse an architecture
       if (I != Stop && *I == '[')
 
       // Parse an architecture
       if (I != Stop && *I == '[')
@@ -583,16 +567,10 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop,
               ++I;
            }
 
               ++I;
            }
 
-           if (stringcmp(arch,I,End) == 0) {
-              Found = true;
-           } else {
-              std::string wildcard = SubstVar(string(I, End), "any", "*");
-              if (fnmatch(wildcard.c_str(), completeArch.c_str(), 0) == 0)
-                 Found = true;
-           }
-
-           if (Found == true)
+           std::string arch(I, End);
+           if (arch.empty() == false && matchesArch(arch.c_str()) == true)
            {
            {
+              Found = true;
               if (I[-1] != '!')
                  NegArch = false;
               // we found a match, so fast-forward to the end of the wildcards
               if (I[-1] != '!')
                  NegArch = false;
               // we found a match, so fast-forward to the end of the wildcards
index 2fb1b50d4b3e3d013ae69c8e973e9da1505fa520..0f6dceb86ba1258fa938420aeb9c600e94e83452 100644 (file)
@@ -1,9 +1,12 @@
 apt (0.9.6.1) UNRELEASED; urgency=low
 
   [ David Kalnischkies ]
 apt (0.9.6.1) UNRELEASED; urgency=low
 
   [ David Kalnischkies ]
-  * deb/deblistparser.cc:
+  * apt-pkg/deb/deblistparser.cc:
     - ensure that mixed positive/negative architecture wildcards
       are handled in the same way as dpkg handles them
     - ensure that mixed positive/negative architecture wildcards
       are handled in the same way as dpkg handles them
+    - use PackageArchitectureMatchesSpecification filter
+  * apt-pkg/cachefilter.cc:
+    - add PackageArchitectureMatchesSpecification (Closes: #672603)
 
  -- David Kalnischkies <kalnischkies@gmail.com>  Thu, 14 Jun 2012 15:45:13 +0200
 
 
  -- David Kalnischkies <kalnischkies@gmail.com>  Thu, 14 Jun 2012 15:45:13 +0200