]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/versionmatch.cc
add volatile sources support in libapt-pkg
[apt.git] / apt-pkg / versionmatch.cc
index c40b1fdbc859b0875192ac79ca55a3d461fc6e43..2376ca8fd80de21596b866fd42b5626da1447102 100644 (file)
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
-#include <apt-pkg/versionmatch.h>
+#include<config.h>
 
 
+#include <apt-pkg/versionmatch.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/strutl.h>
 #include <apt-pkg/error.h>
+#include <apt-pkg/pkgcache.h>
+#include <apt-pkg/cacheiterators.h>
 
 
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <string>
 #include <stdio.h>
 #include <ctype.h>
 #include <fnmatch.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <fnmatch.h>
-#include <sys/types.h>
 #include <regex.h>
 #include <regex.h>
-
                                                                        /*}}}*/
 
                                                                        /*}}}*/
 
+using std::string;
+
 // VersionMatch::pkgVersionMatch - Constructor                         /*{{{*/
 // ---------------------------------------------------------------------
 /* Break up the data string according to the selected type */
 // VersionMatch::pkgVersionMatch - Constructor                         /*{{{*/
 // ---------------------------------------------------------------------
 /* Break up the data string according to the selected type */
@@ -60,7 +67,7 @@ pkgVersionMatch::pkgVersionMatch(string Data,MatchType Type) : Type(Type)
       
       // Are we a simple specification?
       string::const_iterator I = Data.begin();
       
       // Are we a simple specification?
       string::const_iterator I = Data.begin();
-      for (; I != Data.end() && *I != '='; I++);
+      for (; I != Data.end() && *I != '='; ++I);
       if (I == Data.end())
       {
         // Temporary
       if (I == Data.end())
       {
         // Temporary
@@ -130,7 +137,10 @@ pkgVersionMatch::pkgVersionMatch(string Data,MatchType Type) : Type(Type)
 // ---------------------------------------------------------------------
 /* */
 bool pkgVersionMatch::MatchVer(const char *A,string B,bool Prefix)
 // ---------------------------------------------------------------------
 /* */
 bool pkgVersionMatch::MatchVer(const char *A,string B,bool Prefix)
-{   
+{
+   if (A == NULL)
+      return false;
+
    const char *Ab = A;
    const char *Ae = Ab + strlen(A);
    
    const char *Ab = A;
    const char *Ae = Ab + strlen(A);
    
@@ -152,36 +162,51 @@ bool pkgVersionMatch::MatchVer(const char *A,string B,bool Prefix)
 pkgCache::VerIterator pkgVersionMatch::Find(pkgCache::PkgIterator Pkg)
 {
    pkgCache::VerIterator Ver = Pkg.VersionList();
 pkgCache::VerIterator pkgVersionMatch::Find(pkgCache::PkgIterator Pkg)
 {
    pkgCache::VerIterator Ver = Pkg.VersionList();
-   for (; Ver.end() == false; Ver++)
+   for (; Ver.end() == false; ++Ver)
    {
    {
-      if (Type == Version)
-      {
-        if (MatchVer(Ver.VerStr(),VerStr,VerPrefixMatch) == true)
-           return Ver;
-        if (ExpressionMatches(VerStr, Ver.VerStr()) == true)
-           return Ver;
-        continue;
-      }
-      
-      for (pkgCache::VerFileIterator VF = Ver.FileList(); VF.end() == false; VF++)
-        if (FileMatch(VF.File()) == true)
-           return Ver;
+      if (VersionMatches(Ver))
+        return Ver;
    }
    }
-      
+
    // This will be Ended by now.
    return Ver;
 }
    // This will be Ended by now.
    return Ver;
 }
+                                                                       /*}}}*/
+
+// VersionMatch::Find - Locate the best match for the select type      /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool pkgVersionMatch::VersionMatches(pkgCache::VerIterator Ver)
+{
+   if (Type == Version)
+   {
+      if (MatchVer(Ver.VerStr(),VerStr,VerPrefixMatch) == true)
+        return true;
+      if (ExpressionMatches(VerStr, Ver.VerStr()) == true)
+        return true;
+      return false;
+   }
+
+   for (pkgCache::VerFileIterator VF = Ver.FileList(); VF.end() == false; ++VF)
+      if (FileMatch(VF.File()) == true)
+        return true;
+
+   return false;
+}
+                                                                       /*}}}*/
 
 #ifndef FNM_CASEFOLD
 #define FNM_CASEFOLD 0
 #endif
 
 
 #ifndef FNM_CASEFOLD
 #define FNM_CASEFOLD 0
 #endif
 
-bool pkgVersionMatch::ExpressionMatches(const char *pattern, const char *string)
+bool pkgVersionMatch::ExpressionMatches(const char *pattern, const char *string)/*{{{*/
 {
 {
+   if (pattern == NULL || string == NULL)
+      return false;
    if (pattern[0] == '/') {
    if (pattern[0] == '/') {
-      bool res = false;
       size_t length = strlen(pattern);
       if (pattern[length - 1] == '/') {
       size_t length = strlen(pattern);
       if (pattern[length - 1] == '/') {
+        bool res = false;
         regex_t preg;
         char *regex = strdup(pattern + 1);
         regex[length - 2] = '\0';
         regex_t preg;
         char *regex = strdup(pattern + 1);
         regex[length - 2] = '\0';
@@ -223,38 +248,30 @@ bool pkgVersionMatch::FileMatch(pkgCache::PkgFileIterator File)
         return false;
 
       if (RelVerStr.empty() == false)
         return false;
 
       if (RelVerStr.empty() == false)
-        if (File->Version == 0 ||
-            (MatchVer(File.Version(),RelVerStr,RelVerPrefixMatch) == false &&
-             ExpressionMatches(RelVerStr, File.Version()) == false))
+        if (MatchVer(File.Version(),RelVerStr,RelVerPrefixMatch) == false &&
+              ExpressionMatches(RelVerStr, File.Version()) == false)
            return false;
       if (RelOrigin.empty() == false)
            return false;
       if (RelOrigin.empty() == false)
-        if (File->Origin == 0 || !ExpressionMatches(RelOrigin,File.Origin()))
+        if (!ExpressionMatches(RelOrigin,File.Origin()))
            return false;
       if (RelArchive.empty() == false)
            return false;
       if (RelArchive.empty() == false)
-        if (File->Archive == 0 ||
-            !ExpressionMatches(RelArchive,File.Archive()))
+        if (!ExpressionMatches(RelArchive,File.Archive()))
             return false;
       if (RelCodename.empty() == false)
             return false;
       if (RelCodename.empty() == false)
-        if (File->Codename == 0 ||
-            !ExpressionMatches(RelCodename,File.Codename()))
+        if (!ExpressionMatches(RelCodename,File.Codename()))
             return false;
       if (RelRelease.empty() == false)
             return false;
       if (RelRelease.empty() == false)
-        if ((File->Archive == 0 ||
-            !ExpressionMatches(RelRelease,File.Archive())) &&
-             (File->Codename == 0 ||
-             !ExpressionMatches(RelRelease,File.Codename())))
+        if (!ExpressionMatches(RelRelease,File.Archive()) &&
+             !ExpressionMatches(RelRelease,File.Codename()))
               return false;
       if (RelLabel.empty() == false)
               return false;
       if (RelLabel.empty() == false)
-        if (File->Label == 0 ||
-            !ExpressionMatches(RelLabel,File.Label()))
+        if (!ExpressionMatches(RelLabel,File.Label()))
            return false;
       if (RelComponent.empty() == false)
            return false;
       if (RelComponent.empty() == false)
-        if (File->Component == 0 ||
-            !ExpressionMatches(RelComponent,File.Component()))
+        if (!ExpressionMatches(RelComponent,File.Component()))
            return false;
       if (RelArchitecture.empty() == false)
            return false;
       if (RelArchitecture.empty() == false)
-        if (File->Architecture == 0 ||
-            !ExpressionMatches(RelArchitecture,File.Architecture()))
+        if (!ExpressionMatches(RelArchitecture,File.Architecture()))
            return false;
       return true;
    }
            return false;
       return true;
    }
@@ -262,11 +279,11 @@ bool pkgVersionMatch::FileMatch(pkgCache::PkgFileIterator File)
    if (Type == Origin)
    {
       if (OrSite.empty() == false) {
    if (Type == Origin)
    {
       if (OrSite.empty() == false) {
-        if (File->Site == 0)
-           return false;
-      } else // so we are talking about file:// or status file
-        if (strcmp(File.Site(),"") == 0 && File->Archive != 0 && strcmp(File.Archive(),"now") == 0) // skip the status file
+        if (File.Site() == NULL)
            return false;
            return false;
+      }
+      else if (File->Release == 0)// only 'bad' files like dpkg.status file has no release file
+        return false;
       return (ExpressionMatches(OrSite, File.Site())); /* both strings match */
    }
 
       return (ExpressionMatches(OrSite, File.Site())); /* both strings match */
    }