]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/cacheset.cc
releasing version 0.9.7.8~exp2
[apt.git] / apt-pkg / cacheset.cc
index b892ab4bfd9a69964c3c0762d63c4e187347f7d2..1fea4f94a21710b0773ba944228a6492569bbe1d 100644 (file)
@@ -182,15 +182,63 @@ pkgCache::PkgIterator PackageContainerInterface::FromName(pkgCacheFile &Cache,
        return Pkg;
 }
                                                                        /*}}}*/
+// FromGroup - Returns the package defined  by this string             /*{{{*/
+bool PackageContainerInterface::FromGroup(PackageContainerInterface * const pci, pkgCacheFile &Cache,
+                       std::string pkg, CacheSetHelper &helper) {
+       if (unlikely(Cache.GetPkgCache() == 0))
+               return false;
+
+       size_t const archfound = pkg.find_last_of(':');
+       std::string arch;
+       if (archfound != std::string::npos) {
+               arch = pkg.substr(archfound+1);
+               pkg.erase(archfound);
+               if (arch == "all" || arch == "native")
+                       arch = _config->Find("APT::Architecture");
+       }
+
+       pkgCache::GrpIterator Grp = Cache.GetPkgCache()->FindGrp(pkg);
+       if (Grp.end() == false) {
+               if (arch.empty() == true) {
+                       pkgCache::PkgIterator Pkg = Grp.FindPreferredPkg();
+                       if (Pkg.end() == false)
+                       {
+                          pci->insert(Pkg);
+                          return true;
+                       }
+               } else {
+                       bool found = false;
+                       // for 'linux-any' return the first package matching, for 'linux-*' return all matches
+                       bool const isGlobal = arch.find('*') != std::string::npos;
+                       APT::CacheFilter::PackageArchitectureMatchesSpecification pams(arch);
+                       for (pkgCache::PkgIterator Pkg = Grp.PackageList(); Pkg.end() == false; Pkg = Grp.NextPkg(Pkg)) {
+                               if (pams(Pkg) == false)
+                                       continue;
+                               pci->insert(Pkg);
+                               found = true;
+                               if (isGlobal == false)
+                                       break;
+                       }
+                       if (found == true)
+                               return true;
+               }
+       }
+
+       pkgCache::PkgIterator Pkg = helper.canNotFindPkgName(Cache, pkg);
+       if (Pkg.end() == true)
+          return false;
+
+       pci->insert(Pkg);
+       return true;
+}
+                                                                       /*}}}*/
 // FromString - Return all packages matching a specific string         /*{{{*/
 bool PackageContainerInterface::FromString(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str, CacheSetHelper &helper) {
        bool found = true;
        _error->PushToStack();
 
-       pkgCache::PkgIterator Pkg = FromName(Cache, str, helper);
-       if (Pkg.end() == false)
-               pci->insert(Pkg);
-       else if (FromTask(pci, Cache, str, helper) == false &&
+       if (FromGroup(pci, Cache, str, helper) == false &&
+                FromTask(pci, Cache, str, helper) == false &&
                 FromRegEx(pci, Cache, str, helper) == false)
        {
                helper.canNotFindPackage(pci, Cache, str);
@@ -217,6 +265,7 @@ bool PackageContainerInterface::FromModifierCommandLine(unsigned short &modID, P
                                                        pkgCacheFile &Cache, const char * cmdline,
                                                        std::list<Modifier> const &mods, CacheSetHelper &helper) {
        std::string str = cmdline;
+       unsigned short fallback = modID;
        bool modifierPresent = false;
        for (std::list<Modifier>::const_iterator mod = mods.begin();
             mod != mods.end(); ++mod) {
@@ -243,6 +292,7 @@ bool PackageContainerInterface::FromModifierCommandLine(unsigned short &modID, P
                helper.showErrors(errors);
                if (Pkg.end() == false) {
                        pci->insert(Pkg);
+                       modID = fallback;
                        return true;
                }
        }
@@ -281,13 +331,14 @@ bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID,
                modifierPresent = true;
                break;
        }
-
        if (modifierPresent == true) {
                bool const errors = helper.showErrors(false);
                bool const found = VersionContainerInterface::FromString(vci, Cache, cmdline, select, helper, true);
                helper.showErrors(errors);
-               if (found == true)
+               if (found == true) {
+                       modID = fallback;
                        return true;
+               }
        }
        return FromString(vci, Cache, str, select, helper);
 }