]> git.saurik.com Git - apt.git/blobdiff - cmdline/apt-get.cc
add a ConstructedBy member to the PackageSet which can be used by the
[apt.git] / cmdline / apt-get.cc
index e3477b6db501eb15d7774ed307a9a7d49a898233..d3ddcbfe8e1a1346da53166e02f889a7c71c9edb 100644 (file)
@@ -1081,41 +1081,6 @@ bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache,
                  pkgProblemResolver &Fix,bool Remove,bool BrokenFix,
                  bool AllowFail = true)
 {
-   /* This is a pure virtual package and there is a single available
-      candidate providing it. */
-   if (Cache[Pkg].CandidateVer == 0 && Pkg->ProvidesList != 0)
-   {
-      pkgCache::PkgIterator Prov;
-      bool found_one = false;
-
-      for (pkgCache::PrvIterator P = Pkg.ProvidesList(); P; P++)
-      {
-        pkgCache::VerIterator const PVer = P.OwnerVer();
-        pkgCache::PkgIterator const PPkg = PVer.ParentPkg();
-
-        /* Ignore versions that are not a candidate. */
-        if (Cache[PPkg].CandidateVer != PVer)
-            continue;
-
-        if (found_one == false)
-        {
-           Prov = PPkg;
-           found_one = true;
-        }
-        else if (PPkg != Prov)
-        {
-           found_one = false; // we found at least two
-           break;
-        }
-      }
-
-      if (found_one == true)
-      {
-        ioprintf(c1out,_("Note, selecting %s instead of %s\n"),
-                 Prov.FullName(true).c_str(),Pkg.FullName(true).c_str());
-        Pkg = Prov;
-      }
-   }
 
    // Handle the no-upgrade case
    if (_config->FindB("APT::Get::upgrade",true) == false &&
@@ -1601,13 +1566,13 @@ public:
 
        virtual void showTaskSelection(APT::PackageSet const &pkgset, string const &pattern) {
                for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg)
-                       ioprintf(out, _("Note, selecting %s for task '%s'\n"),
+                       ioprintf(out, _("Note, selecting '%s' for task '%s'\n"),
                                 Pkg.FullName(true).c_str(), pattern.c_str());
                explicitlyNamed = false;
        }
        virtual void showRegExSelection(APT::PackageSet const &pkgset, string const &pattern) {
                for (APT::PackageSet::const_iterator Pkg = pkgset.begin(); Pkg != pkgset.end(); ++Pkg)
-                       ioprintf(out, _("Note, selecting %s for regex '%s'\n"),
+                       ioprintf(out, _("Note, selecting '%s' for regex '%s'\n"),
                                 Pkg.FullName(true).c_str(), pattern.c_str());
                explicitlyNamed = false;
        }
@@ -1618,6 +1583,53 @@ public:
                                 Ver.VerStr(), Ver.RelStr().c_str(), Pkg.FullName(true).c_str());
        }
 
+       virtual APT::VersionSet canNotFindCandInstVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) {
+               return tryVirtualPackage(Cache, Pkg, APT::VersionSet::CANDINST);
+       }
+
+       virtual APT::VersionSet canNotFindInstCandVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) {
+               return tryVirtualPackage(Cache, Pkg, APT::VersionSet::INSTCAND);
+       }
+
+       APT::VersionSet tryVirtualPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg,
+                                               APT::VersionSet::Version const &select) {
+               /* This is a pure virtual package and there is a single available
+                  candidate providing it. */
+               if (unlikely(Cache[Pkg].CandidateVer != 0) || Pkg->ProvidesList == 0) {
+                       if (select == APT::VersionSet::CANDINST)
+                               return APT::CacheSetHelper::canNotFindCandInstVer(Cache, Pkg);
+                       return APT::CacheSetHelper::canNotFindInstCandVer(Cache, Pkg);
+               }
+
+               pkgCache::PkgIterator Prov;
+               bool found_one = false;
+               for (pkgCache::PrvIterator P = Pkg.ProvidesList(); P; ++P) {
+                       pkgCache::VerIterator const PVer = P.OwnerVer();
+                       pkgCache::PkgIterator const PPkg = PVer.ParentPkg();
+
+                       /* Ignore versions that are not a candidate. */
+                       if (Cache[PPkg].CandidateVer != PVer)
+                               continue;
+
+                       if (found_one == false) {
+                               Prov = PPkg;
+                               found_one = true;
+                       } else if (PPkg != Prov) {
+                               found_one = false; // we found at least two
+                               break;
+                       }
+               }
+
+               if (found_one == true) {
+                       ioprintf(out, _("Note, selecting '%s' instead of '%s'\n"),
+                                Prov.FullName(true).c_str(), Pkg.FullName(true).c_str());
+                       return APT::VersionSet::FromPackage(Cache, Prov, select, *this);
+               }
+               if (select == APT::VersionSet::CANDINST)
+                       return APT::CacheSetHelper::canNotFindCandInstVer(Cache, Pkg);
+               return APT::CacheSetHelper::canNotFindInstCandVer(Cache, Pkg);
+       }
+
        inline bool allPkgNamedExplicitly() const { return explicitlyNamed; }
 
 };
@@ -1640,24 +1652,27 @@ bool DoInstall(CommandLine &CmdL)
    unsigned int AutoMarkChanged = 0;
    pkgProblemResolver Fix(Cache);
 
-   unsigned short fallback = 0;
+   static const unsigned short MOD_REMOVE = 1;
+   static const unsigned short MOD_INSTALL = 2;
+
+   unsigned short fallback = MOD_INSTALL;
    if (strcasecmp(CmdL.FileList[0],"remove") == 0)
-      fallback = 1;
+      fallback = MOD_REMOVE;
    else if (strcasecmp(CmdL.FileList[0], "purge") == 0)
    {
       _config->Set("APT::Get::Purge", true);
-      fallback = 1;
+      fallback = MOD_REMOVE;
    }
    else if (strcasecmp(CmdL.FileList[0], "autoremove") == 0)
    {
       _config->Set("APT::Get::AutomaticRemove", "true");
-      fallback = 1;
+      fallback = MOD_REMOVE;
    }
 
    std::list<APT::VersionSet::Modifier> mods;
-   mods.push_back(APT::VersionSet::Modifier(0, "+",
+   mods.push_back(APT::VersionSet::Modifier(MOD_INSTALL, "+",
                APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::CANDINST));
-   mods.push_back(APT::VersionSet::Modifier(1, "-",
+   mods.push_back(APT::VersionSet::Modifier(MOD_REMOVE, "-",
                APT::VersionSet::Modifier::POSTFIX, APT::VersionSet::INSTCAND));
    CacheSetHelperAPTGet helper(c0out);
    std::map<unsigned short, APT::VersionSet> verset = APT::VersionSet::GroupedFromCommandLine(Cache,
@@ -1666,41 +1681,54 @@ bool DoInstall(CommandLine &CmdL)
    if (_error->PendingError() == true)
       return false;
 
+   unsigned short order[] = { 0, 0, 0 };
+   if (fallback == MOD_INSTALL) {
+      order[0] = MOD_INSTALL;
+      order[1] = MOD_REMOVE;
+   } else {
+      order[0] = MOD_REMOVE;
+      order[1] = MOD_INSTALL;
+   }
+
    // new scope for the ActionGroup
    {
       pkgDepCache::ActionGroup group(Cache);
-      for (APT::VersionSet::const_iterator Ver = verset[0].begin();
-          Ver != verset[0].end(); ++Ver)
+      for (unsigned short i = 0; order[i] != 0; ++i)
       {
-        pkgCache::PkgIterator Pkg = Ver.ParentPkg();
-        Cache->SetCandidateVersion(Ver);
-
-        if (TryToInstall(Pkg, Cache, Fix, false, BrokenFix) == false)
-           return false;
-
-        // see if we need to fix the auto-mark flag
-        // e.g. apt-get install foo
-        // where foo is marked automatic
-        if (Cache[Pkg].Install() == false &&
-            (Cache[Pkg].Flags & pkgCache::Flag::Auto) &&
-            _config->FindB("APT::Get::ReInstall",false) == false &&
-            _config->FindB("APT::Get::Only-Upgrade",false) == false &&
-            _config->FindB("APT::Get::Download-Only",false) == false)
-        {
-           ioprintf(c1out,_("%s set to manually installed.\n"),
-                       Pkg.FullName(true).c_str());
-           Cache->MarkAuto(Pkg,false);
-           AutoMarkChanged++;
-        }
-      }
-
-      for (APT::VersionSet::const_iterator Ver = verset[1].begin();
-          Ver != verset[1].end(); ++Ver)
-      {
-        pkgCache::PkgIterator Pkg = Ver.ParentPkg();
+        if (order[i] == MOD_INSTALL)
+           for (APT::VersionSet::const_iterator Ver = verset[MOD_INSTALL].begin();
+                Ver != verset[MOD_INSTALL].end(); ++Ver)
+           {
+              pkgCache::PkgIterator Pkg = Ver.ParentPkg();
+              Cache->SetCandidateVersion(Ver);
+
+              if (TryToInstall(Pkg, Cache, Fix, false, BrokenFix) == false)
+                 return false;
+
+              // see if we need to fix the auto-mark flag
+              // e.g. apt-get install foo
+              // where foo is marked automatic
+              if (Cache[Pkg].Install() == false &&
+                  (Cache[Pkg].Flags & pkgCache::Flag::Auto) &&
+                  _config->FindB("APT::Get::ReInstall",false) == false &&
+                  _config->FindB("APT::Get::Only-Upgrade",false) == false &&
+                  _config->FindB("APT::Get::Download-Only",false) == false)
+              {
+                 ioprintf(c1out,_("%s set to manually installed.\n"),
+                               Pkg.FullName(true).c_str());
+                 Cache->MarkAuto(Pkg,false);
+                 AutoMarkChanged++;
+              }
+           }
+        else if (order[i] == MOD_REMOVE)
+           for (APT::VersionSet::const_iterator Ver = verset[MOD_REMOVE].begin();
+                Ver != verset[MOD_REMOVE].end(); ++Ver)
+           {
+              pkgCache::PkgIterator Pkg = Ver.ParentPkg();
 
-        if (TryToInstall(Pkg, Cache, Fix, true, BrokenFix) == false)
-           return false;
+              if (TryToInstall(Pkg, Cache, Fix, true, BrokenFix) == false)
+                 return false;
+           }
       }
 
       if (_error->PendingError() == true)
@@ -1752,7 +1780,7 @@ bool DoInstall(CommandLine &CmdL)
 
    /* Print out a list of packages that are going to be installed extra
       to what the user asked */
-   if (Cache->InstCount() != verset[0].size())
+   if (Cache->InstCount() != verset[MOD_INSTALL].size())
    {
       string List;
       string VersionsList;
@@ -1879,7 +1907,7 @@ bool DoInstall(CommandLine &CmdL)
 
    // See if we need to prompt
    // FIXME: check if really the packages in the set are going to be installed
-   if (Cache->InstCount() == verset[0].size() && Cache->DelCount() == 0)
+   if (Cache->InstCount() == verset[MOD_INSTALL].size() && Cache->DelCount() == 0)
       return InstallPackages(Cache,false,false);
 
    return InstallPackages(Cache,false);