* cmdline/apt-get.cc:
[ntk/apt.git] / cmdline / apt-get.cc
index 1925dea..a4fd3cf 100644 (file)
@@ -254,6 +254,9 @@ bool ShowList(ostream &out,string Title,string List,string VersionsList)
  */
 void ShowBroken(ostream &out,CacheFile &Cache,bool Now)
 {
+   if (Cache->BrokenCount() == 0)
+      return;
+
    out << _("The following packages have unmet dependencies:") << endl;
    for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
    {
@@ -628,20 +631,18 @@ public:
                explicitlyNamed = true;
        }
 
-       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"),
-                                Pkg.FullName(true).c_str(), pattern.c_str());
+       virtual void showTaskSelection(pkgCache::PkgIterator const &Pkg, string const &pattern) {
+               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"),
-                                Pkg.FullName(true).c_str(), pattern.c_str());
+       virtual void showRegExSelection(pkgCache::PkgIterator const &Pkg, string const &pattern) {
+               ioprintf(out, _("Note, selecting '%s' for regex '%s'\n"),
+                               Pkg.FullName(true).c_str(), pattern.c_str());
                explicitlyNamed = false;
        }
        virtual void showSelectedVersion(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const Ver,
-                                string const &ver, bool const &verIsRel) {
+                                string const &ver, bool const verIsRel) {
                if (ver == Ver.VerStr())
                        return;
                selectedByRelease.push_back(make_pair(Ver, ver));
@@ -707,7 +708,7 @@ public:
                APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, APT::VersionSet::CANDIDATE);
                if (verset.empty() == false)
                        return *(verset.begin());
-               if (ShowError == true) {
+               else if (ShowError == true) {
                        _error->Error(_("Package '%s' has no installation candidate"),Pkg.FullName(true).c_str());
                        virtualPkgs.insert(Pkg);
                }
@@ -715,11 +716,32 @@ public:
        }
 
        virtual pkgCache::VerIterator canNotFindNewestVer(pkgCacheFile &Cache, pkgCache::PkgIterator const &Pkg) {
-               APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, APT::VersionSet::NEWEST);
-               if (verset.empty() == false)
-                       return *(verset.begin());
-               if (ShowError == true)
-                       ioprintf(out, _("Virtual packages like '%s' can't be removed\n"), Pkg.FullName(true).c_str());
+               if (Pkg->ProvidesList != 0)
+               {
+                       APT::VersionSet const verset = tryVirtualPackage(Cache, Pkg, APT::VersionSet::NEWEST);
+                       if (verset.empty() == false)
+                               return *(verset.begin());
+                       if (ShowError == true)
+                               ioprintf(out, _("Virtual packages like '%s' can't be removed\n"), Pkg.FullName(true).c_str());
+               }
+               else
+               {
+                       pkgCache::GrpIterator Grp = Pkg.Group();
+                       pkgCache::PkgIterator P = Grp.PackageList();
+                       for (; P.end() != true; P = Grp.NextPkg(P))
+                       {
+                               if (P == Pkg)
+                                       continue;
+                               if (P->CurrentVer != 0) {
+                                       // TRANSLATORS: Note, this is not an interactive question
+                                       ioprintf(c1out,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"),
+                                                Pkg.FullName(true).c_str(), P.FullName(true).c_str());
+                                       break;
+                               }
+                       }
+                       if (P.end() == true)
+                               ioprintf(c1out,_("Package '%s' is not installed, so not removed\n"),Pkg.FullName(true).c_str());
+               }
                return pkgCache::VerIterator(Cache, 0);
        }
 
@@ -744,6 +766,19 @@ public:
                                Prov = PPkg;
                                found_one = true;
                        } else if (PPkg != Prov) {
+                               // same group, so it's a foreign package
+                               if (PPkg->Group == Prov->Group) {
+                                       // do we already have the requested arch?
+                                       if (strcmp(Pkg.Arch(), Prov.Arch()) == 0 ||
+                                           strcmp(Prov.Arch(), "all") == 0 ||
+                                           unlikely(strcmp(PPkg.Arch(), Prov.Arch()) == 0)) // packages have only on candidate, but just to be sure
+                                               continue;
+                                       // see which architecture we prefer more and switch to it
+                                       std::vector<std::string> archs = APT::Configuration::getArchitectures();
+                                       if (std::find(archs.begin(), archs.end(), PPkg.Arch()) < std::find(archs.begin(), archs.end(), Prov.Arch()))
+                                               Prov = PPkg;
+                                       continue;
+                               }
                                found_one = false; // we found at least two
                                break;
                        }
@@ -769,7 +804,7 @@ struct TryToInstall {
    unsigned long AutoMarkChanged;
    APT::PackageSet doAutoInstallLater;
 
-   TryToInstall(pkgCacheFile &Cache, pkgProblemResolver *PM, bool const &FixBroken) : Cache(&Cache), Fix(PM),
+   TryToInstall(pkgCacheFile &Cache, pkgProblemResolver *PM, bool const FixBroken) : Cache(&Cache), Fix(PM),
                        FixBroken(FixBroken), AutoMarkChanged(0) {};
 
    void operator() (pkgCache::VerIterator const &Ver) {
@@ -893,7 +928,23 @@ struct TryToRemove {
       if ((Pkg->CurrentVer == 0 && PurgePkgs == false) ||
          (PurgePkgs == true && Pkg->CurrentState == pkgCache::State::NotInstalled))
       {
-        ioprintf(c1out,_("Package %s is not installed, so not removed\n"),Pkg.FullName(true).c_str());
+        pkgCache::GrpIterator Grp = Pkg.Group();
+        pkgCache::PkgIterator P = Grp.PackageList();
+        for (; P.end() != true; P = Grp.NextPkg(P))
+        {
+           if (P == Pkg)
+              continue;
+           if (P->CurrentVer != 0 || (PurgePkgs == true && P->CurrentState != pkgCache::State::NotInstalled))
+           {
+              // TRANSLATORS: Note, this is not an interactive question
+              ioprintf(c1out,_("Package '%s' is not installed, so not removed. Did you mean '%s'?\n"),
+                       Pkg.FullName(true).c_str(), P.FullName(true).c_str());
+              break;
+           }
+        }
+        if (P.end() == true)
+           ioprintf(c1out,_("Package '%s' is not installed, so not removed\n"),Pkg.FullName(true).c_str());
+
         // MarkInstall refuses to install packages on hold
         Pkg->SelectedState = pkgCache::State::Hold;
       }
@@ -1367,7 +1418,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,
        "all files have been overwritten by other packages:",
        "The following packages disappeared from your system as\n"
        "all files have been overwritten by other packages:", disappearedPkgs.size()), disappear, "");
-   c0out << _("Note: This is done automatic and on purpose by dpkg.") << std::endl;
+   c0out << _("Note: This is done automatically and on purpose by dpkg.") << std::endl;
 
    return true;
 }
@@ -1631,10 +1682,13 @@ bool DoUpdate(CommandLine &CmdL)
        ListUpdate(Stat, *List);
 
    // Rebuild the cache.
-   pkgCacheFile::RemoveCaches();
-   if (Cache.BuildCaches() == false)
-      return false;
-   
+   if (_config->FindB("pkgCacheFile::Generate", true) == true)
+   {
+      pkgCacheFile::RemoveCaches();
+      if (Cache.BuildCaches() == false)
+        return false;
+   }
+
    return true;
 }
                                                                        /*}}}*/
@@ -1663,12 +1717,13 @@ bool DoAutomaticRemove(CacheFile &Cache)
    bool smallList = (hideAutoRemove == false &&
                strcasecmp(_config->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
 
-   string autoremovelist, autoremoveversions;
    unsigned long autoRemoveCount = 0;
    APT::PackageSet tooMuch;
+   APT::PackageList autoRemoveList;
    // look over the cache to see what can be removed
-   for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); ! Pkg.end(); ++Pkg)
+   for (unsigned J = 0; J < Cache->Head().PackageCount; ++J)
    {
+      pkgCache::PkgIterator Pkg(Cache,Cache.List[J]);
       if (Cache[Pkg].Garbage)
       {
         if(Pkg.CurrentVer() != 0 || Cache[Pkg].Install())
@@ -1685,6 +1740,8 @@ bool DoAutomaticRemove(CacheFile &Cache)
         }
         else
         {
+           if (hideAutoRemove == false && Cache[Pkg].Delete() == false)
+              autoRemoveList.insert(Pkg);
            // if the package is a new install and already garbage we don't need to
            // install it in the first place, so nuke it instead of show it
            if (Cache[Pkg].Install() == true && Pkg.CurrentVer() == 0)
@@ -1694,16 +1751,8 @@ bool DoAutomaticRemove(CacheFile &Cache)
               Cache->MarkDelete(Pkg, false);
            }
            // only show stuff in the list that is not yet marked for removal
-           else if(hideAutoRemove == false && Cache[Pkg].Delete() == false) 
-           {
+           else if(hideAutoRemove == false && Cache[Pkg].Delete() == false)
               ++autoRemoveCount;
-              // we don't need to fill the strings if we don't need them
-              if (smallList == false)
-              {
-                autoremovelist += Pkg.FullName(true) + " ";
-                autoremoveversions += string(Cache[Pkg].CandVersion) + "\n";
-              }
-           }
         }
       }
    }
@@ -1719,7 +1768,7 @@ bool DoAutomaticRemove(CacheFile &Cache)
              Pkg != tooMuch.end() && Changed == false; ++Pkg)
         {
            APT::PackageSet too;
-           too.insert(Pkg);
+           too.insert(*Pkg);
            for (pkgCache::PrvIterator Prv = Cache[Pkg].CandidateVerIter(Cache).ProvidesList();
                 Prv.end() == false; ++Prv)
               too.insert(Prv.ParentPkg());
@@ -1738,14 +1787,7 @@ bool DoAutomaticRemove(CacheFile &Cache)
                    std::clog << "Save " << Pkg << " as another installed garbage package depends on it" << std::endl;
                 Cache->MarkInstall(Pkg, false);
                 if (hideAutoRemove == false)
-                {
                    ++autoRemoveCount;
-                   if (smallList == false)
-                   {
-                      autoremovelist += Pkg.FullName(true) + " ";
-                      autoremoveversions += string(Cache[Pkg].CandVersion) + "\n";
-                   }
-                }
                 tooMuch.erase(Pkg);
                 Changed = true;
                 break;
@@ -1755,6 +1797,18 @@ bool DoAutomaticRemove(CacheFile &Cache)
       } while (Changed == true);
    }
 
+   std::string autoremovelist, autoremoveversions;
+   if (smallList == false && autoRemoveCount != 0)
+   {
+      for (APT::PackageList::const_iterator Pkg = autoRemoveList.begin(); Pkg != autoRemoveList.end(); ++Pkg)
+      {
+        if (Cache[Pkg].Garbage == false)
+           continue;
+        autoremovelist += Pkg.FullName(true) + " ";
+        autoremoveversions += string(Cache[Pkg].CandVersion) + "\n";
+      }
+   }
+
    // Now see if we had destroyed anything (if we had done anything)
    if (Cache->BrokenCount() != 0)
    {
@@ -1778,7 +1832,7 @@ bool DoAutomaticRemove(CacheFile &Cache)
       else
         ioprintf(c1out, P_("%lu package was automatically installed and is no longer required.\n",
                  "%lu packages were automatically installed and are no longer required.\n", autoRemoveCount), autoRemoveCount);
-      c1out << _("Use 'apt-get autoremove' to remove them.") << std::endl;
+      c1out << P_("Use 'apt-get autoremove' to remove it.", "Use 'apt-get autoremove' to remove them.", autoRemoveCount) << std::endl;
    }
    return true;
 }
@@ -2295,8 +2349,8 @@ bool DoDownload(CommandLine &CmdL)
       return false;
    
    APT::CacheSetHelper helper(c0out);
-   APT::VersionSet verset = APT::VersionSet::FromCommandLine(Cache,
-               CmdL.FileList + 1, APT::VersionSet::CANDIDATE, helper);
+   APT::VersionList verset = APT::VersionList::FromCommandLine(Cache,
+               CmdL.FileList + 1, APT::VersionList::CANDIDATE, helper);
 
    if (verset.empty() == true)
       return false;
@@ -2308,7 +2362,7 @@ bool DoDownload(CommandLine &CmdL)
 
    pkgRecords Recs(Cache);
    pkgSourceList *SrcList = Cache.GetSourceList();
-   for (APT::VersionSet::const_iterator Ver = verset.begin(); 
+   for (APT::VersionList::const_iterator Ver = verset.begin(); 
         Ver != verset.end(); 
         ++Ver) 
    {
@@ -2445,7 +2499,7 @@ bool DoSource(CommandLine &CmdL)
                  Src.c_str(), vcs.c_str(), uri.c_str());
         if(vcs == "Bzr") 
            ioprintf(c1out,_("Please use:\n"
-                            "bzr get %s\n"
+                            "bzr branch %s\n"
                             "to retrieve the latest (possibly unreleased) "
                             "updates to the package.\n"),
                     uri.c_str());
@@ -2738,8 +2792,18 @@ bool DoBuildDep(CommandLine &CmdL)
             
       // Process the build-dependencies
       vector<pkgSrcRecords::Parser::BuildDepRec> BuildDeps;
-      if (Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch) == false)
-       return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
+      // FIXME: Can't specify architecture to use for [wildcard] matching, so switch default arch temporary
+      if (hostArch.empty() == false)
+      {
+        std::string nativeArch = _config->Find("APT::Architecture");
+        _config->Set("APT::Architecture", hostArch);
+        bool Success = Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch);
+        _config->Set("APT::Architecture", nativeArch);
+        if (Success == false)
+           return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
+      }
+      else if (Last->BuildDepends(BuildDeps, _config->FindB("APT::Get::Arch-Only", false), StripMultiArch) == false)
+           return _error->Error(_("Unable to get build-dependency information for %s"),Src.c_str());
    
       // Also ensure that build-essential packages are present
       Configuration::Item const *Opts = _config->Tree("APT::Build-Essential");
@@ -2816,7 +2880,7 @@ bool DoBuildDep(CommandLine &CmdL)
            pkgCache::PkgIterator Pkg;
 
            // Cross-Building?
-           if (StripMultiArch == false)
+           if (StripMultiArch == false && D->Type != pkgSrcRecords::Parser::BuildDependIndep)
            {
               size_t const colon = D->Package.find(":");
               if (colon != string::npos &&
@@ -2852,21 +2916,27 @@ bool DoBuildDep(CommandLine &CmdL)
               if ((BADVER(Ver)) == false)
               {
                  string forbidden;
-                 if (Ver->MultiArch == pkgCache::Version::None || Ver->MultiArch == pkgCache::Version::All);
+                 if (Ver->MultiArch == pkgCache::Version::None || Ver->MultiArch == pkgCache::Version::All)
+                 {
+                    if (colon == string::npos)
+                       Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
+                    else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
+                       forbidden = "Multi-Arch: none";
+                 }
                  else if (Ver->MultiArch == pkgCache::Version::Same)
                  {
-                    if (colon != string::npos)
+                    if (colon == string::npos)
                        Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
                     else if (strcmp(D->Package.c_str() + colon, ":any") == 0)
                        forbidden = "Multi-Arch: same";
                     // :native gets the buildArch
                  }
-                 else if (Ver->MultiArch == pkgCache::Version::Foreign || Ver->MultiArch == pkgCache::Version::AllForeign)
+                 else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign)
                  {
                     if (colon != string::npos)
                        forbidden = "Multi-Arch: foreign";
                  }
-                 else if (Ver->MultiArch == pkgCache::Version::Allowed || Ver->MultiArch == pkgCache::Version::AllAllowed)
+                 else if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed)
                  {
                     if (colon == string::npos)
                        Pkg = Ver.ParentPkg().Group().FindPkg(hostArch);
@@ -2886,13 +2956,13 @@ bool DoBuildDep(CommandLine &CmdL)
                  if (forbidden.empty() == false)
                  {
                     if (_config->FindB("Debug::BuildDeps",false) == true)
-                       cout << " :any is not allowed from M-A: same package " << (*D).Package << endl;
+                       cout << D->Package.substr(colon, string::npos) << " is not allowed from " << forbidden << " package " << (*D).Package << endl;
                     if (hasAlternatives)
                        continue;
                     return _error->Error(_("%s dependency for %s can't be satisfied "
                                            "because %s is not allowed on '%s' packages"),
                                          Last->BuildDepType(D->Type), Src.c_str(),
-                                         D->Package.c_str(), "Multi-Arch: same");
+                                         D->Package.c_str(), forbidden.c_str());
                  }
               }
               else if (_config->FindB("Debug::BuildDeps",false) == true)
@@ -3167,16 +3237,20 @@ bool DoChangelog(CommandLine &CmdL)
       return false;
    
    APT::CacheSetHelper helper(c0out);
-   APT::VersionSet verset = APT::VersionSet::FromCommandLine(Cache,
-               CmdL.FileList + 1, APT::VersionSet::CANDIDATE, helper);
+   APT::VersionList verset = APT::VersionList::FromCommandLine(Cache,
+               CmdL.FileList + 1, APT::VersionList::CANDIDATE, helper);
    if (verset.empty() == true)
       return false;
    pkgAcquire Fetcher;
 
    if (_config->FindB("APT::Get::Print-URIs", false) == true)
-      for (APT::VersionSet::const_iterator Ver = verset.begin();
+   {
+      bool Success = true;
+      for (APT::VersionList::const_iterator Ver = verset.begin();
           Ver != verset.end(); ++Ver)
-        return DownloadChangelog(Cache, Fetcher, Ver, "");
+        Success &= DownloadChangelog(Cache, Fetcher, Ver, "");
+      return Success;
+   }
 
    AcqTextStatus Stat(ScreenWidth, _config->FindI("quiet",0));
    Fetcher.Setup(&Stat);
@@ -3197,7 +3271,7 @@ bool DoChangelog(CommandLine &CmdL)
         return _error->Errno("mkdtemp", "mkdtemp failed");
    }
 
-   for (APT::VersionSet::const_iterator Ver = verset.begin(); 
+   for (APT::VersionList::const_iterator Ver = verset.begin(); 
         Ver != verset.end(); 
         ++Ver) 
    {
@@ -3241,7 +3315,7 @@ bool DoMoo(CommandLine &CmdL)
 /* */
 bool ShowHelp(CommandLine &CmdL)
 {
-   ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,VERSION,
+   ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION,
            COMMON_ARCH,__DATE__,__TIME__);
            
    if (_config->FindB("version") == true)