]> git.saurik.com Git - apt.git/commitdiff
handle :arch modifier in PackageSet::FromString correctly
authorDavid Kalnischkies <kalnischkies@gmail.com>
Sat, 5 Jun 2010 13:47:16 +0000 (15:47 +0200)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Sat, 5 Jun 2010 13:47:16 +0000 (15:47 +0200)
apt-pkg/cacheset.cc
apt-pkg/cacheset.h

index 5dbd1a4dfa4322a476d3c980139ee252c0fb052d..8fcffaf9a47690108070124d0f8c64fac852a4c5 100644 (file)
@@ -87,17 +87,31 @@ PackageSet PackageSet::FromCommandLine(pkgCacheFile &Cache, const char **cmdline
 }
                                                                        /*}}}*/
 // FromString - Return all packages matching a specific string         /*{{{*/
-PackageSet PackageSet::FromString(pkgCacheFile &Cache, const char * const str, std::ostream &out) {
-       pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(str);
-       if (Grp.end() == false) {
-               pkgCache::PkgIterator Pkg = Grp.FindPreferredPkg();
+PackageSet PackageSet::FromString(pkgCacheFile &Cache, std::string const &str, std::ostream &out) {
+       std::string pkg = str;
+       size_t archfound = pkg.find_last_of(':');
+       std::string arch;
+       if (archfound != std::string::npos) {
+               arch = pkg.substr(archfound+1);
+               pkg.erase(archfound);
+       }
+
+       pkgCache::PkgIterator Pkg;
+       if (arch.empty() == true) {
+               pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(pkg);
+               if (Grp.end() == false)
+                       Pkg = Grp.FindPreferredPkg();
+       } else
+               Pkg = Cache.GetPkgCache()->FindPkg(pkg, arch);
+
+       if (Pkg.end() == false) {
                PackageSet pkgset;
                pkgset.insert(Pkg);
                return pkgset;
        }
        PackageSet regex = FromRegEx(Cache, str, out);
        if (regex.empty() == true)
-               _error->Warning(_("Unable to locate package %s"), str);
+               _error->Warning(_("Unable to locate package %s"), str.c_str());
        return regex;
 }
                                                                        /*}}}*/
@@ -188,7 +202,7 @@ pkgCache::VerIterator VersionSet::getCandidateVer(pkgCacheFile &Cache,
                pkgCache::PkgIterator const &Pkg, bool const &AllowError) {
        if (unlikely(Cache.BuildDepCache() == false))
                return pkgCache::VerIterator(*Cache);
-       pkgCache::VerIterator Cand = Cache[Pkg].InstVerIter(Cache);
+       pkgCache::VerIterator Cand = Cache[Pkg].CandidateVerIter(Cache);
        if (AllowError == false && Cand.end() == true)
                _error->Error(_("Can't select candidate version from package %s as it has no candidate"), Pkg.FullName(true).c_str());
        return Cand;
index b65e053e69e5e881b5158ac11c5397953f1b551d..4f7be4caa4875ff2491f6685ca203f77537af03b 100644 (file)
@@ -83,8 +83,8 @@ public:                                                                       /*{{{*/
            \param Cache the packages are in
            \param string String the package name(s) should be extracted from
            \param out stream to print various notices to */
-       static APT::PackageSet FromString(pkgCacheFile &Cache, const char * const string, std::ostream &out);
-       static APT::PackageSet FromString(pkgCacheFile &Cache, const char * const string) {
+       static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string, std::ostream &out);
+       static APT::PackageSet FromString(pkgCacheFile &Cache, std::string const &string) {
                std::ostream out (std::ofstream("/dev/null").rdbuf());
                return APT::PackageSet::FromString(Cache, string, out);
        }