]> git.saurik.com Git - apt.git/blobdiff - cmdline/apt-get.cc
[cmdline/apt-get.cc] add APT::Get::HideAutoRemove=small to display only
[apt.git] / cmdline / apt-get.cc
index 93b3a83dc58a25515bc3a6fb868a3a2997d5be81..d3972ad81b94b2fb4acd12ac6e13f15c3042a449 100644 (file)
@@ -111,6 +111,9 @@ class CacheFile : public pkgCacheFile
         return Open(true);
    }
    CacheFile() : List(0) {};
+   ~CacheFile() {
+      delete[] List;
+   }
 };
                                                                        /*}}}*/
 
@@ -594,7 +597,6 @@ void Stats(ostream &out,pkgDepCache &Dep)
               Dep.BadCount());
 }
                                                                        /*}}}*/
-
 // CacheFile::NameComp - QSort compare by name                         /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -687,7 +689,10 @@ bool CacheFile::CheckDeps(bool AllowBroken)
       
    return true;
 }
-
+                                                                       /*}}}*/
+// CheckAuth - check if each download comes form a trusted source      /*{{{*/
+// ---------------------------------------------------------------------
+/* */
 static bool CheckAuth(pkgAcquire& Fetcher)
 {
    string UntrustedList;
@@ -728,10 +733,7 @@ static bool CheckAuth(pkgAcquire& Fetcher)
 
    return _error->Error(_("There are problems and -y was used without --force-yes"));
 }
-
-
                                                                        /*}}}*/
-
 // InstallPackages - Actually download and install the packages                /*{{{*/
 // ---------------------------------------------------------------------
 /* This displays the informative messages describing what is going to 
@@ -1260,7 +1262,8 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
    /* Lookup the version of the package we would install if we were to
       install a version and determine the source package name, then look
       in the archive for a source package of the same name. */
-   if (_config->FindB("APT::Get::Only-Source") == false)
+   bool MatchSrcOnly = _config->FindB("APT::Get::Only-Source");
+   if (MatchSrcOnly == false)
    {
       if (Pkg.end() == false)
       {
@@ -1278,7 +1281,6 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
    unsigned long Offset = 0;
    string Version;
    bool IsMatch = false;
-   bool MatchSrcOnly = false;
 
    // No source package name..
    if (Src.empty() == true)
@@ -1335,7 +1337,6 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
    return Last;
 }
                                                                        /*}}}*/
-
 // DoUpdate - Update the package lists                                 /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -1399,20 +1400,29 @@ bool DoAutomaticRemove(CacheFile &Cache)
    bool Debug = _config->FindI("Debug::pkgAutoRemove",false);
    bool doAutoRemove = _config->FindB("APT::Get::AutomaticRemove", false);
    bool hideAutoRemove = _config->FindB("APT::Get::HideAutoRemove");
-   pkgDepCache::ActionGroup group(*Cache);
 
+   pkgDepCache::ActionGroup group(*Cache);
    if(Debug)
       std::cout << "DoAutomaticRemove()" << std::endl;
 
-   if (_config->FindB("APT::Get::Remove",true) == false &&
-       doAutoRemove == true)
+   // we don't want to autoremove and we don't want to see it, so why calculating?
+   if (doAutoRemove == false && hideAutoRemove == true)
+      return true;
+
+   if (doAutoRemove == true &&
+       _config->FindB("APT::Get::Remove",true) == false)
    {
       c1out << _("We are not supposed to delete stuff, can't start "
                 "AutoRemover") << std::endl;
-      doAutoRemove = false;
+      return false;
    }
 
+   bool purgePkgs = _config->FindB("APT::Get::Purge", false);
+   bool smallList = (hideAutoRemove == false &&
+       strcasecmp(_config->Find("APT::Get::HideAutoRemove","").c_str(),"small") == 0);
+
    string autoremovelist, autoremoveversions;
+   unsigned long autoRemoveCount = 0;
    // look over the cache to see what can be removed
    for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); ! Pkg.end(); ++Pkg)
    {
@@ -1421,30 +1431,43 @@ bool DoAutomaticRemove(CacheFile &Cache)
         if(Pkg.CurrentVer() != 0 || Cache[Pkg].Install())
            if(Debug)
               std::cout << "We could delete %s" <<  Pkg.Name() << std::endl;
-         
-        // only show stuff in the list that is not yet marked for removal
-        if(Cache[Pkg].Delete() == false) 
-        {
-           autoremovelist += string(Pkg.Name()) + " ";
-           autoremoveversions += string(Cache[Pkg].CandVersion) + "\n";
-        }
+
         if (doAutoRemove)
         {
            if(Pkg.CurrentVer() != 0 && 
               Pkg->CurrentState != pkgCache::State::ConfigFiles)
-              Cache->MarkDelete(Pkg, _config->FindB("APT::Get::Purge", false));
+              Cache->MarkDelete(Pkg, purgePkgs);
            else
               Cache->MarkKeep(Pkg, false, false);
         }
+        else
+        {
+           // only show stuff in the list that is not yet marked for removal
+           if(Cache[Pkg].Delete() == false) 
+           {
+              // we don't need to fill the strings if we don't need them
+              if (smallList == true)
+                 ++autoRemoveCount;
+              else
+              {
+                autoremovelist += string(Pkg.Name()) + " ";
+                autoremoveversions += string(Cache[Pkg].CandVersion) + "\n";
+              }
+           }
+        }
       }
    }
-   if (!hideAutoRemove) 
-      ShowList(c1out, _("The following packages were automatically installed and are no longer required:"), autoremovelist, autoremoveversions);
-   if (!doAutoRemove && !hideAutoRemove && autoremovelist.size() > 0)
+   // if we don't remove them, we should show them!
+   if (doAutoRemove == false && (autoremovelist.empty() == false || autoRemoveCount != 0))
+   {
+      if (smallList == false)
+        ShowList(c1out, _("The following packages were automatically installed and are no longer required:"), autoremovelist, autoremoveversions);
+      else
+        ioprintf(c1out, _("%lu packages were automatically installed and are no longer required.\n"), autoRemoveCount);
       c1out << _("Use 'apt-get autoremove' to remove them.") << std::endl;
-
-   // Now see if we destroyed anything
-   if (Cache->BrokenCount() != 0)
+   }
+   // Now see if we had destroyed anything (if we had done anything)
+   else if (Cache->BrokenCount() != 0)
    {
       c1out << _("Hmm, seems like the AutoRemover destroyed something which really\n"
                 "shouldn't happen. Please file a bug report against apt.") << endl;
@@ -1457,7 +1480,7 @@ bool DoAutomaticRemove(CacheFile &Cache)
    }
    return true;
 }
-
+                                                                       /*}}}*/
 // DoUpgrade - Upgrade all packages                                    /*{{{*/
 // ---------------------------------------------------------------------
 /* Upgrade all packages without installing new packages or erasing old
@@ -1532,7 +1555,7 @@ bool TryInstallTask(pkgDepCache &Cache, pkgProblemResolver &Fix,
    regfree(&Pattern);
    return res;
 }
-
+                                                                       /*}}}*/
 // DoInstall - Install packages from the command line                  /*{{{*/
 // ---------------------------------------------------------------------
 /* Install named packages */
@@ -2699,8 +2722,7 @@ void SigWinch(int)
 #endif
 }
                                                                        /*}}}*/
-
-int main(int argc,const char *argv[])
+int main(int argc,const char *argv[])                                  /*{{{*/
 {
    CommandLine::Args Args[] = {
       {'h',"help","help",0},
@@ -2793,11 +2815,12 @@ int main(int argc,const char *argv[])
    // simulate user-friendly if apt-get has no root privileges
    if (getuid() != 0 && _config->FindB("APT::Get::Simulate") == true)
    {
-      cout << _("NOTE: This is only a simulation!\n"
-        "      apt-get needs root privileges for real execution.\n"
-        "      Keep also in mind that locking is deactivated,\n"
-        "      so don't depend on the relevance to the real current situation!"
-        ) << std::endl;
+      if (_config->FindB("APT::Get::Show-User-Simulation-Note",true) == true)
+        cout << _("NOTE: This is only a simulation!\n"
+           "      apt-get needs root privileges for real execution.\n"
+           "      Keep also in mind that locking is deactivated,\n"
+           "      so don't depend on the relevance to the real current situation!"
+        ) << std::endl;
       _config->Set("Debug::NoLocking",true);
    }
 
@@ -2832,3 +2855,4 @@ int main(int argc,const char *argv[])
    
    return 0;   
 }
+                                                                       /*}}}*/