X-Git-Url: https://git.hcoop.net/ntk/apt.git/blobdiff_plain/05002864535069dbc35fd1c713ab072a5b6df65f..220cf74e3c33fefb9f90853a22a5f828a15ff521:/apt-pkg/versionmatch.cc diff --git a/apt-pkg/versionmatch.cc b/apt-pkg/versionmatch.cc index 2abb73e8..284098bd 100644 --- a/apt-pkg/versionmatch.cc +++ b/apt-pkg/versionmatch.cc @@ -11,19 +11,26 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ -#include +#include +#include #include #include +#include +#include +#include +#include +#include +#include #include #include #include -#include #include - /*}}}*/ +using std::string; + // 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(); - for (; I != Data.end() && *I != '='; I++); + for (; I != Data.end() && *I != '='; ++I); if (I == Data.end()) { // Temporary @@ -118,7 +125,10 @@ pkgVersionMatch::pkgVersionMatch(string Data,MatchType Type) : Type(Type) if (Type == Origin) { - OrSite = Data; + if (Data[0] == '"' && Data.length() >= 2 && Data.end()[-1] == '"') + OrSite = Data.substr(1, Data.length() - 2); + else + OrSite = Data; return; } } @@ -149,7 +159,7 @@ bool pkgVersionMatch::MatchVer(const char *A,string B,bool Prefix) 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) { @@ -160,7 +170,7 @@ pkgCache::VerIterator pkgVersionMatch::Find(pkgCache::PkgIterator Pkg) continue; } - for (pkgCache::VerFileIterator VF = Ver.FileList(); VF.end() == false; VF++) + for (pkgCache::VerFileIterator VF = Ver.FileList(); VF.end() == false; ++VF) if (FileMatch(VF.File()) == true) return Ver; } @@ -175,20 +185,20 @@ pkgCache::VerIterator pkgVersionMatch::Find(pkgCache::PkgIterator Pkg) bool pkgVersionMatch::ExpressionMatches(const char *pattern, const char *string) { - std::cerr << "MATCH " << pattern; if (pattern[0] == '/') { - bool res = false; size_t length = strlen(pattern); if (pattern[length - 1] == '/') { + bool res = false; regex_t preg; char *regex = strdup(pattern + 1); regex[length - 2] = '\0'; if (regcomp(&preg, regex, REG_EXTENDED | REG_ICASE) != 0) { - std::cerr << "E: Invalid regular expression: " << regex << "\n"; + _error->Warning("Invalid regular expression: %s", regex); } else if (regexec(&preg, string, 0, NULL, 0) == 0) { res = true; } free(regex); + regfree(&preg); return res; } } @@ -259,10 +269,10 @@ bool pkgVersionMatch::FileMatch(pkgCache::PkgFileIterator File) if (Type == Origin) { if (OrSite.empty() == false) { - if (File->Site == 0 || !ExpressionMatches(OrSite, File.Site())) + if (File->Site == 0) return false; } else // so we are talking about file:// or status file - if (strcmp(File.Site(),"") == 0 && File->Archive != 0) // skip the status file + if (strcmp(File.Site(),"") == 0 && File->Archive != 0 && strcmp(File.Archive(),"now") == 0) // skip the status file return false; return (ExpressionMatches(OrSite, File.Site())); /* both strings match */ }