diff options
author | David Kalnischkies <kalnischkies@gmail.com> | 2010-07-05 12:06:45 +0200 |
---|---|---|
committer | David Kalnischkies <kalnischkies@gmail.com> | 2010-07-05 12:06:45 +0200 |
commit | 7ea4af9da25a802516461434b12a61e21743f960 (patch) | |
tree | 9277fece2f8bd004ffa8f5ca558423de98afa8d8 | |
parent | 9643d533f38fa35b345755201eebfd227aa5adbb (diff) | |
parent | fd3b761e8cba6ed626639b50b1221246098c7b3a (diff) |
merge with debian-experimental-ma
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 20 | ||||
-rw-r--r-- | apt-pkg/contrib/fileutl.h | 3 | ||||
-rw-r--r-- | apt-pkg/deb/deblistparser.cc | 23 | ||||
-rw-r--r-- | apt-pkg/versionmatch.cc | 60 | ||||
-rw-r--r-- | apt-pkg/versionmatch.h | 2 | ||||
-rw-r--r-- | debian/changelog | 17 | ||||
-rw-r--r-- | debian/control | 2 | ||||
-rw-r--r-- | methods/ftp.h | 2 |
8 files changed, 107 insertions, 22 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index e95ddf562..62d42e4da 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -27,6 +27,7 @@ #include <cstdlib> #include <cstring> +#include <cstdio> #include <iostream> #include <unistd.h> @@ -658,10 +659,11 @@ bool FileFd::Open(string FileName,OpenMode Mode, unsigned long Perms) case WriteEmpty: { - struct stat Buf; - if (lstat(FileName.c_str(),&Buf) == 0 && S_ISLNK(Buf.st_mode)) - unlink(FileName.c_str()); - iFd = open(FileName.c_str(),O_RDWR | O_CREAT | O_TRUNC,Perms); + Flags |= Replace; + char *name = strdup((FileName + ".XXXXXX").c_str()); + TemporaryFileName = string(mktemp(name)); + iFd = open(TemporaryFileName.c_str(),O_RDWR | O_CREAT | O_EXCL,Perms); + free(name); break; } @@ -843,11 +845,19 @@ bool FileFd::Close() if (iFd >= 0 && close(iFd) != 0) Res &= _error->Errno("close",_("Problem closing the file")); iFd = -1; - + + if ((Flags & Replace) == Replace) { + if (rename(TemporaryFileName.c_str(), FileName.c_str()) != 0) + Res &= _error->Errno("rename",_("Problem renaming the file")); + FileName = TemporaryFileName; // for the unlink() below. + } + if ((Flags & Fail) == Fail && (Flags & DelOnFail) == DelOnFail && FileName.empty() == false) if (unlink(FileName.c_str()) != 0) Res &= _error->WarningE("unlnk",_("Problem unlinking the file")); + + return Res; } /*}}}*/ diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 003bd9b83..528725f89 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -34,9 +34,10 @@ class FileFd int iFd; enum LocalFlags {AutoClose = (1<<0),Fail = (1<<1),DelOnFail = (1<<2), - HitEof = (1<<3)}; + HitEof = (1<<3), Replace = (1<<4) }; unsigned long Flags; string FileName; + string TemporaryFileName; public: enum OpenMode {ReadOnly,WriteEmpty,WriteExists,WriteAny,WriteTemp}; diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index d1931f909..24df57a5c 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -19,6 +19,7 @@ #include <apt-pkg/md5.h> #include <apt-pkg/macros.h> +#include <fnmatch.h> #include <ctype.h> /*}}}*/ @@ -473,6 +474,20 @@ const char *debListParser::ConvertRelation(const char *I,unsigned int &Op) return I; } +/* + * CompleteArch: + * + * The complete architecture, consisting of <kernel>-<cpu>. + */ +static string CompleteArch(std::string& arch) { + if (arch == "armel") 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 /*{{{*/ // --------------------------------------------------------------------- @@ -546,6 +561,7 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop, if (ParseArchFlags == true) { string arch = _config->Find("APT::Architecture"); + string completeArch = CompleteArch(arch); // Parse an architecture if (I != Stop && *I == '[') @@ -573,8 +589,13 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop, I++; } - if (stringcmp(arch,I,End) == 0) + 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 (*End++ == ']') { I = End; diff --git a/apt-pkg/versionmatch.cc b/apt-pkg/versionmatch.cc index e5f0fafd2..093180f9b 100644 --- a/apt-pkg/versionmatch.cc +++ b/apt-pkg/versionmatch.cc @@ -18,6 +18,10 @@ #include <stdio.h> #include <ctype.h> +#include <fnmatch.h> +#include <sys/types.h> +#include <regex.h> + /*}}}*/ // VersionMatch::pkgVersionMatch - Constructor /*{{{*/ @@ -151,6 +155,8 @@ pkgCache::VerIterator pkgVersionMatch::Find(pkgCache::PkgIterator Pkg) { if (MatchVer(Ver.VerStr(),VerStr,VerPrefixMatch) == true) return Ver; + if (ExpressionMatches(VerStr, Ver.VerStr()) == true) + return Ver; continue; } @@ -162,6 +168,36 @@ pkgCache::VerIterator pkgVersionMatch::Find(pkgCache::PkgIterator Pkg) // This will be Ended by now. return Ver; } + +#ifndef FNM_CASEFOLD +#define FNM_CASEFOLD 0 +#endif + +bool pkgVersionMatch::ExpressionMatches(const char *pattern, const char *string) +{ + if (pattern[0] == '/') { + bool res = false; + size_t length = strlen(pattern); + if (pattern[length - 1] == '/') { + regex_t preg; + char *regex = strdup(pattern + 1); + regex[length - 2] = '\0'; + if (regcomp(&preg, regex, REG_EXTENDED | REG_ICASE) != 0) { + _error->Warning("Invalid regular expression: %s", regex); + } else if (regexec(&preg, string, 0, NULL, 0) == 0) { + res = true; + } + free(regex); + regfree(&preg); + return res; + } + } + return fnmatch(pattern, string, FNM_CASEFOLD) == 0; +} +bool pkgVersionMatch::ExpressionMatches(const std::string& pattern, const char *string) +{ + return ExpressionMatches(pattern.c_str(), string); +} /*}}}*/ // VersionMatch::FileMatch - Match against an index file /*{{{*/ // --------------------------------------------------------------------- @@ -185,37 +221,37 @@ bool pkgVersionMatch::FileMatch(pkgCache::PkgFileIterator File) if (RelVerStr.empty() == false) if (File->Version == 0 || - MatchVer(File.Version(),RelVerStr,RelVerPrefixMatch) == false) + (MatchVer(File.Version(),RelVerStr,RelVerPrefixMatch) == false && + ExpressionMatches(RelVerStr, File.Version()) == false)) return false; if (RelOrigin.empty() == false) - if (File->Origin == 0 || - stringcasecmp(RelOrigin,File.Origin()) != 0) + if (File->Origin == 0 || !ExpressionMatches(RelOrigin,File.Origin())) return false; if (RelArchive.empty() == false) if (File->Archive == 0 || - stringcasecmp(RelArchive,File.Archive()) != 0) + !ExpressionMatches(RelArchive,File.Archive())) return false; if (RelCodename.empty() == false) if (File->Codename == 0 || - stringcasecmp(RelCodename,File.Codename()) != 0) + !ExpressionMatches(RelCodename,File.Codename())) return false; if (RelRelease.empty() == false) if ((File->Archive == 0 || - stringcasecmp(RelRelease,File.Archive()) != 0) && + !ExpressionMatches(RelRelease,File.Archive())) && (File->Codename == 0 || - stringcasecmp(RelRelease,File.Codename()) != 0)) + !ExpressionMatches(RelRelease,File.Codename()))) return false; if (RelLabel.empty() == false) if (File->Label == 0 || - stringcasecmp(RelLabel,File.Label()) != 0) + !ExpressionMatches(RelLabel,File.Label())) return false; if (RelComponent.empty() == false) if (File->Component == 0 || - stringcasecmp(RelComponent,File.Component()) != 0) + !ExpressionMatches(RelComponent,File.Component())) return false; if (RelArchitecture.empty() == false) if (File->Architecture == 0 || - stringcasecmp(RelArchitecture,File.Architecture()) != 0) + !ExpressionMatches(RelArchitecture,File.Architecture())) return false; return true; } @@ -223,12 +259,12 @@ bool pkgVersionMatch::FileMatch(pkgCache::PkgFileIterator File) if (Type == Origin) { if (OrSite.empty() == false) { - if (File->Site == 0 || OrSite != File.Site()) + if (File->Site == 0 || !ExpressionMatches(OrSite, File.Site())) return false; } else // so we are talking about file:// or status file if (strcmp(File.Site(),"") == 0 && File->Archive != 0) // skip the status file return false; - return (OrSite == File.Site()); /* both strings match */ + return (ExpressionMatches(OrSite, File.Site())); /* both strings match */ } return false; diff --git a/apt-pkg/versionmatch.h b/apt-pkg/versionmatch.h index a8da072ae..39639a23d 100644 --- a/apt-pkg/versionmatch.h +++ b/apt-pkg/versionmatch.h @@ -67,6 +67,8 @@ class pkgVersionMatch enum MatchType {None = 0,Version,Release,Origin} Type; bool MatchVer(const char *A,string B,bool Prefix); + bool ExpressionMatches(const char *pattern, const char *string); + bool ExpressionMatches(const std::string& pattern, const char *string); bool FileMatch(pkgCache::PkgFileIterator File); pkgCache::VerIterator Find(pkgCache::PkgIterator Pkg); diff --git a/debian/changelog b/debian/changelog index 51c75dad0..878d5238a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,6 @@ apt (0.7.26~exp8) UNRELEASED; urgency=low + [ David Kalnischkies ] * cmdline/cacheset.cc: - doesn't include it in the library for now as it is too volatile - get the candidate either from an already built depcache @@ -37,7 +38,21 @@ apt (0.7.26~exp8) UNRELEASED; urgency=low - add another round of const& madness as the previous round accidentally NOT overrides the virtual GetCandidateVer() method (Closes: #587725) - -- David Kalnischkies <kalnischkies@gmail.com> Mon, 28 Jun 2010 22:12:24 +0200 + [ Julian Andres Klode ] + * methods/ftp.h: + - Handle different logins on the same server (Closes: #586904). + * apt-pkg/deb/deblistparser.cc: + - Handle architecture wildcards (Closes: #547724). + * apt-pkg/versionmatch.cc: + - Support matching pins by regular expressions or glob() like patterns, + regular expressions have to be put between to slashes; for example, + /.*/. + * apt-pkg/contrib/fileutl.cc: + - Make FileFd replace files atomically in WriteTemp mode (for cache, etc). + * debian/control: + - Set Standards-Version to 3.9.0 + + -- David Kalnischkies <kalnischkies@gmail.com> Mon, 05 Jul 2010 12:05:30 +0200 apt (0.7.26~exp7) experimental; urgency=low diff --git a/debian/control b/debian/control index 4f41c130b..d482f2d0b 100644 --- a/debian/control +++ b/debian/control @@ -5,7 +5,7 @@ Maintainer: APT Development Team <deity@lists.debian.org> Uploaders: Michael Vogt <mvo@debian.org>, Otavio Salvador <otavio@debian.org>, Christian Perrier <bubulle@debian.org>, Daniel Burrows <dburrows@debian.org>, Luca Bruno <lethalman88@gmail.com>, Julian Andres Klode <jak@debian.org> -Standards-Version: 3.8.4 +Standards-Version: 3.9.0 Build-Depends: debhelper (>= 5.0), libdb-dev, gettext (>= 0.12), libcurl4-gnutls-dev | libcurl3-gnutls-dev (>= 7.15.5), debiandoc-sgml, xsltproc, docbook-xsl, po4a (>= 0.34-2), autotools-dev, autoconf, automake, doxygen Build-Conflicts: autoconf2.13, automake1.4 diff --git a/methods/ftp.h b/methods/ftp.h index 1bcea41b6..d7f1f7fbe 100644 --- a/methods/ftp.h +++ b/methods/ftp.h @@ -40,7 +40,7 @@ class FTPConn public: - bool Comp(URI Other) {return Other.Host == ServerName.Host && Other.Port == ServerName.Port;}; + bool Comp(URI Other) {return Other.Host == ServerName.Host && Other.Port == ServerName.Port && Other.User == ServerName.User && Other.Password == ServerName.Password; }; // Raw connection IO bool ReadResp(unsigned int &Ret,string &Text); |