X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/b53c9cea2902572822bbbece5bac236c1bbf846e..08fcf9628806af202e555bd02b3611e4e9a3d757:/apt-private/private-cacheset.cc?ds=sidebyside

diff --git a/apt-private/private-cacheset.cc b/apt-private/private-cacheset.cc
index 8db736507..52cd22d2a 100644
--- a/apt-private/private-cacheset.cc
+++ b/apt-private/private-cacheset.cc
@@ -4,6 +4,7 @@
 #include <apt-pkg/pkgcache.h>
 #include <apt-pkg/depcache.h>
 #include <apt-pkg/cacheiterators.h>
+#include <apt-pkg/cachefilter.h>
 #include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/progress.h>
@@ -29,13 +30,18 @@ bool GetLocalitySortedVersionSet(pkgCacheFile &CacheFile,
                                  Matcher &matcher,
                                  OpProgress * const progress)
 {
-   pkgCache *Cache = CacheFile.GetPkgCache();
-   pkgDepCache *DepCache = CacheFile.GetDepCache();
+   pkgCache * const Cache = CacheFile.GetPkgCache();
+   if (unlikely(Cache == nullptr))
+      return false;
+   if (progress != nullptr)
+      progress->SubProgress(Cache->Head().PackageCount, _("Sorting"));
+
+   pkgDepCache * const DepCache = CacheFile.GetDepCache();
+   if (unlikely(DepCache == nullptr))
+      return false;
    APT::CacheSetHelper helper(false);
 
    int Done=0;
-   if (progress != NULL)
-      progress->SubProgress(Cache->Head().PackageCount, _("Sorting"));
 
    bool const insertCurrentVer = _config->FindB("APT::Cmd::Installed", false);
    bool const insertUpgradable = _config->FindB("APT::Cmd::Upgradable", false);
@@ -111,14 +117,75 @@ void CacheSetHelperVirtuals::canNotFindVersion(
       virtualPkgs.insert(Pkg);
    return CacheSetHelper::canNotFindVersion(select, vci, Cache, Pkg);
 }
+static pkgCache::PkgIterator canNotFindPkgName_impl(pkgCacheFile &Cache, std::string const &str)
+{
+   std::string pkg = str;
+   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");
+   }
+
+   // If we don't find 'foo:amd64' look for 'foo:amd64:any'.
+   // Note: we prepare for an error here as if foo:amd64 does not exist,
+   // but foo:amd64:any it means that this package is only referenced in a
+   // (architecture specific) dependency. We do not add to virtualPkgs directly
+   // as we can't decide from here which error message has to be printed.
+   // FIXME: This doesn't match 'barbarian' architectures
+   pkgCache::PkgIterator Pkg(Cache, 0);
+   std::vector<std::string> const archs = APT::Configuration::getArchitectures();
+   if (archfound == std::string::npos)
+   {
+      for (auto const &a : archs)
+      {
+	 Pkg = Cache.GetPkgCache()->FindPkg(pkg + ':' + a, "any");
+	 if (Pkg.end() == false && Pkg->ProvidesList != 0)
+	    break;
+      }
+      if (Pkg.end() == true)
+	 for (auto const &a : archs)
+	 {
+	    Pkg = Cache.GetPkgCache()->FindPkg(pkg + ':' + a, "any");
+	    if (Pkg.end() == false)
+	       break;
+	 }
+   }
+   else
+   {
+      Pkg = Cache.GetPkgCache()->FindPkg(pkg + ':' + arch, "any");
+      if (Pkg.end() == true)
+      {
+	 APT::CacheFilter::PackageArchitectureMatchesSpecification pams(arch);
+	 for (auto const &a : archs)
+	 {
+	    if (pams(a.c_str()) == false)
+	       continue;
+	    Pkg = Cache.GetPkgCache()->FindPkg(pkg + ':' + a, "any");
+	    if (Pkg.end() == false)
+	       break;
+	 }
+      }
+   }
+   return Pkg;
+}
+pkgCache::PkgIterator CacheSetHelperVirtuals::canNotFindPkgName(pkgCacheFile &Cache, std::string const &str)
+{
+   pkgCache::PkgIterator const Pkg = canNotFindPkgName_impl(Cache, str);
+   if (Pkg.end())
+      return APT::CacheSetHelper::canNotFindPkgName(Cache, str);
+   return Pkg;
+}
 CacheSetHelperVirtuals::CacheSetHelperVirtuals(bool const ShowErrors, GlobalError::MsgType const &ErrorType) :
    CacheSetHelper{ShowErrors, ErrorType}
 {}
 									/*}}}*/
 
 // CacheSetHelperAPTGet - responsible for message telling from the CacheSets/*{{{*/
-CacheSetHelperAPTGet::CacheSetHelperAPTGet(std::ostream &out) :
-   APT::CacheSetHelper{true}, out(out)
+CacheSetHelperAPTGet::CacheSetHelperAPTGet(std::ostream &pout) :
+   APT::CacheSetHelper{true}, out(pout)
 {
    explicitlyNamed = true;
 }
@@ -183,8 +250,6 @@ bool CacheSetHelperAPTGet::showVirtualPackageErrors(pkgCacheFile &Cache)
 		  "This may mean that the package is missing, has been obsoleted, or\n"
 		  "is only available from another source\n"),Pkg.FullName(true).c_str());
 
-	 std::string List;
-	 std::string VersionsList;
 	 std::vector<bool> Seen(Cache.GetPkgCache()->Head().PackageCount, false);
 	 APT::PackageList pkglist;
 	 for (pkgCache::DepIterator Dep = Pkg.RevDependsList();
@@ -291,5 +356,12 @@ APT::VersionSet CacheSetHelperAPTGet::tryVirtualPackage(pkgCacheFile &Cache, pkg
       return APT::VersionSet::FromPackage(Cache, Prov, select, *this);
    }
    return APT::VersionSet();
+}
+pkgCache::PkgIterator CacheSetHelperAPTGet::canNotFindPkgName(pkgCacheFile &Cache, std::string const &str)
+{
+   pkgCache::PkgIterator const Pkg = canNotFindPkgName_impl(Cache, str);
+   if (Pkg.end())
+      return APT::CacheSetHelper::canNotFindPkgName(Cache, str);
+   return Pkg;
 }
 									/*}}}*/