]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/cacheset.cc
add missing canNotFindFnmatch/showFnmatchSelection (for the next ABI break)
[apt.git] / apt-pkg / cacheset.cc
index 1fea4f94a21710b0773ba944228a6492569bbe1d..1b1e6d5958becc26ba7ccb591c392a5ff8765c21 100644 (file)
@@ -73,6 +73,8 @@ bool PackageContainerInterface::FromTask(PackageContainerInterface * const pci,
                const char *start, *end;
                parser.GetRec(start,end);
                unsigned int const length = end - start;
+               if (unlikely(length == 0))
+                  continue;
                char buf[length];
                strncpy(buf, start, length);
                buf[length-1] = '\0';
@@ -149,6 +151,77 @@ bool PackageContainerInterface::FromRegEx(PackageContainerInterface * const pci,
                return false;
        }
 
+       if (wasEmpty == false && pci->getConstructor() != UNKNOWN)
+               pci->setConstructor(UNKNOWN);
+
+       return true;
+}
+                                                                       /*}}}*/
+// FromFnmatch - Returns the package defined  by this fnmatch          /*{{{*/
+bool 
+PackageContainerInterface::FromFnmatch(PackageContainerInterface * const pci, 
+                                       pkgCacheFile &Cache,
+                                       std::string pattern,
+                                       CacheSetHelper &helper)
+{
+       static const char * const isfnmatch = ".?*[]!";
+       if (pattern.find_first_of(isfnmatch) == std::string::npos)
+               return false;
+
+       bool const wasEmpty = pci->empty();
+       if (wasEmpty == true)
+               pci->setConstructor(FNMATCH);
+
+       size_t archfound = pattern.find_last_of(':');
+       std::string arch = "native";
+       if (archfound != std::string::npos) {
+               arch = pattern.substr(archfound+1);
+               if (arch.find_first_of(isfnmatch) == std::string::npos)
+                       pattern.erase(archfound);
+               else
+                       arch = "native";
+       }
+
+       if (unlikely(Cache.GetPkgCache() == 0))
+               return false;
+
+       APT::CacheFilter::PackageNameMatchesFnmatch filter(pattern);
+
+       bool found = false;
+       for (pkgCache::GrpIterator Grp = Cache.GetPkgCache()->GrpBegin(); Grp.end() == false; ++Grp) {
+               if (filter(Grp) == false)
+                       continue;
+               pkgCache::PkgIterator Pkg = Grp.FindPkg(arch);
+               if (Pkg.end() == true) {
+                       if (archfound == std::string::npos) {
+                               std::vector<std::string> archs = APT::Configuration::getArchitectures();
+                               for (std::vector<std::string>::const_iterator a = archs.begin();
+                                    a != archs.end() && Pkg.end() != true; ++a)
+                                       Pkg = Grp.FindPkg(*a);
+                       }
+                       if (Pkg.end() == true)
+                               continue;
+               }
+
+               pci->insert(Pkg);
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+               helper.showFnmatchSelection(Pkg, pattern);
+#else
+               helper.showRegExSelection(Pkg, pattern);
+#endif
+               found = true;
+       }
+
+       if (found == false) {
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+               helper.canNotFindFnmatch(pci, Cache, pattern);
+#else
+                helper.canNotFindRegEx(pci, Cache, pattern);
+#endif
+               pci->setConstructor(UNKNOWN);
+               return false;
+       }
+
        if (wasEmpty == false && pci->getConstructor() != UNKNOWN)
                pci->setConstructor(UNKNOWN);
 
@@ -239,6 +312,7 @@ bool PackageContainerInterface::FromString(PackageContainerInterface * const pci
 
        if (FromGroup(pci, Cache, str, helper) == false &&
                 FromTask(pci, Cache, str, helper) == false &&
+                FromFnmatch(pci, Cache, str, helper) == false &&
                 FromRegEx(pci, Cache, str, helper) == false)
        {
                helper.canNotFindPackage(pci, Cache, str);
@@ -522,7 +596,13 @@ void CacheSetHelper::canNotFindRegEx(PackageContainerInterface * const pci, pkgC
        if (ShowError == true)
                _error->Insert(ErrorType, _("Couldn't find any package by regex '%s'"), pattern.c_str());
 }
-                                                                       /*}}}*/
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+// canNotFindFnmatch - handle the case no package is found by a fnmatch        /*{{{*/
+void CacheSetHelper::canNotFindFnmatch(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string pattern) {
+       if (ShowError == true)
+               _error->Insert(ErrorType, _("Couldn't find any package by glob '%s'"), pattern.c_str());
+}
+#endif                                                                 /*}}}*/
 // canNotFindPackage - handle the case no package is found from a string/*{{{*/
 void CacheSetHelper::canNotFindPackage(PackageContainerInterface * const pci, pkgCacheFile &Cache, std::string const &str) {
 }
@@ -582,6 +662,13 @@ void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator const &pkg,
                                        std::string const &pattern) {
 }
                                                                        /*}}}*/
+#if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
+// showFnmatchSelection                                                        /*{{{*/
+void CacheSetHelper::showFnmatchSelection(pkgCache::PkgIterator const &pkg,
+                                          std::string const &pattern) {
+}
+                                                                       /*}}}*/
+#endif
 // showSelectedVersion                                                 /*{{{*/
 void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator const &Pkg,
                                         pkgCache::VerIterator const Ver,