]> git.saurik.com Git - apt.git/blobdiff - cmdline/apt-get.cc
* merged the install-recommends branch
[apt.git] / cmdline / apt-get.cc
index 31148a80754b6811ea2437ea7b1ac8a36e230ae3..4dfb3325c07009141bec0989bf6782946874a730 100644 (file)
@@ -38,6 +38,7 @@
 #include <apt-pkg/version.h>
 #include <apt-pkg/cachefile.h>
 #include <apt-pkg/sptr.h>
+#include <apt-pkg/md5.h>
 #include <apt-pkg/versionmatch.h>
     
 #include <config.h>
@@ -45,6 +46,7 @@
 
 #include "acqprogress.h"
 
+#include <set>
 #include <locale.h>
 #include <langinfo.h>
 #include <fstream>
@@ -67,7 +69,7 @@ ostream c0out(0);
 ostream c1out(0);
 ostream c2out(0);
 ofstream devnull("/dev/null");
-unsigned int ScreenWidth = 80;
+unsigned int ScreenWidth = 80 - 1; /* - 1 for the cursor */
 
 // class CacheFile - Cover class for some dependency cache functions   /*{{{*/
 // ---------------------------------------------------------------------
@@ -542,7 +544,7 @@ bool ShowEssential(ostream &out,CacheFile &Cache)
    }
    
    delete [] Added;
-   return ShowList(out,_("WARNING: The following essential packages will be removed\n"
+   return ShowList(out,_("WARNING: The following essential packages will be removed.\n"
                         "This should NOT be done unless you know exactly what you are doing!"),List,VersionsList);
 }
 
@@ -627,6 +629,8 @@ void CacheFile::Sort()
    and verifies that the system is OK. */
 bool CacheFile::CheckDeps(bool AllowBroken)
 {
+   bool FixBroken = _config->FindB("APT::Get::Fix-Broken",false);
+
    if (_error->PendingError() == true)
       return false;
 
@@ -638,12 +642,24 @@ bool CacheFile::CheckDeps(bool AllowBroken)
    if (pkgApplyStatus(*DCache) == false)
       return false;
    
+   if (_config->FindB("APT::Get::Fix-Policy-Broken",false) == true)
+   {
+      FixBroken = true;
+      if ((DCache->PolicyBrokenCount() > 0))
+      {
+        // upgrade all policy-broken packages with ForceImportantDeps=True
+        for (pkgCache::PkgIterator I = Cache->PkgBegin(); !I.end(); I++)
+           if ((*DCache)[I].NowPolicyBroken() == true) 
+              DCache->MarkInstall(I,true,0, false, true);
+      }
+   }
+
    // Nothing is broken
    if (DCache->BrokenCount() == 0 || AllowBroken == true)
       return true;
 
    // Attempt to fix broken things
-   if (_config->FindB("APT::Get::Fix-Broken",false) == true)
+   if (FixBroken == true)
    {
       c1out << _("Correcting dependencies...") << flush;
       if (pkgFixBroken(*DCache) == false || DCache->BrokenCount() != 0)
@@ -689,7 +705,7 @@ static bool CheckAuth(pkgAcquire& Fetcher)
 
    if (_config->FindB("APT::Get::AllowUnauthenticated",false) == true)
    {
-      c2out << "Authentication warning overridden.\n";
+      c2out << _("Authentication warning overridden.\n");
       return true;
    }
 
@@ -751,7 +767,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,
    if (Cache->BrokenCount() != 0)
    {
       ShowBroken(c1out,Cache,false);
-      return _error->Error("Internal error, InstallPackages was called with broken packages!");
+      return _error->Error(_("Internal error, InstallPackages was called with broken packages!"));
    }
 
    if (Cache->DelCount() == 0 && Cache->InstCount() == 0 &&
@@ -766,11 +782,12 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,
    if (_config->FindB("APT::Get::Simulate") == true)
    {
       pkgSimulate PM(Cache);
-      pkgPackageManager::OrderResult Res = PM.DoInstall();
+      int status_fd = _config->FindI("APT::Status-Fd",-1);
+      pkgPackageManager::OrderResult Res = PM.DoInstall(status_fd);
       if (Res == pkgPackageManager::Failed)
         return false;
       if (Res != pkgPackageManager::Completed)
-        return _error->Error("Internal error, Ordering didn't finish");
+        return _error->Error(_("Internal error, Ordering didn't finish"));
       return true;
    }
    
@@ -811,7 +828,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,
    if (DebBytes != Cache->DebSize())
    {
       c0out << DebBytes << ',' << Cache->DebSize() << endl;
-      c0out << "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl;
+      c0out << _("How odd.. The sizes didn't match, email apt@packages.debian.org") << endl;
    }
    
    // Number of bytes
@@ -841,7 +858,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,
       struct statvfs Buf;
       string OutputDir = _config->FindDir("Dir::Cache::Archives");
       if (statvfs(OutputDir.c_str(),&Buf) != 0)
-        return _error->Errno("statvfs","Couldn't determine free space in %s",
+        return _error->Errno("statvfs",_("Couldn't determine free space in %s"),
                              OutputDir.c_str());
       if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize)
         return _error->Error(_("You don't have enough free space in %s."),
@@ -863,7 +880,7 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,
       
       const char *Prompt = _("Yes, do as I say!");
       ioprintf(c2out,
-              _("You are about to do something potentially harmful\n"
+              _("You are about to do something potentially harmful.\n"
                 "To continue type in the phrase '%s'\n"
                 " ?] "),Prompt);
       c2out << flush;
@@ -994,28 +1011,9 @@ bool InstallPackages(CacheFile &Cache,bool ShwKept,bool Ask = true,
         return _error->Error(_("Aborting install."));
       }
 
-      // write the auto-mark list ----------------------------------
-      // -- we do it here because there is no libapt::Commit() :/
-      FileFd state_file;
-      string state = _config->FindDir("Dir::State") + "pkgstates";
-
-
-      state_file.Open(state, FileFd::WriteEmpty);
-      std::ostringstream ostr;
-      for(pkgCache::PkgIterator p=Cache->PkgBegin(); !p.end();p++) {
-        if(Cache[p].AutomaticRemove != pkgCache::State::RemoveUnknown) {
-           ostr.str(string(""));
-           ostr << "Package: " << p.Name()
-                << "\nRemove-Reason: "
-                << (int)(Cache[p].AutomaticRemove) << "\n\n";
-           state_file.Write(ostr.str().c_str(), ostr.str().size());
-           //std::cout << "Writing auto-mark: " << ostr.str() << endl;
-        }
-      }
-      // ----------------------------------------------------------
-                
       _system->UnLock();
-      pkgPackageManager::OrderResult Res = PM->DoInstall();
+      int status_fd = _config->FindI("APT::Status-Fd",-1);
+      pkgPackageManager::OrderResult Res = PM->DoInstall(status_fd);
       if (Res == pkgPackageManager::Failed || _error->PendingError() == true)
         return false;
       if (Res == pkgPackageManager::Completed)
@@ -1162,9 +1160,11 @@ bool TryToInstall(pkgCache::PkgIterator Pkg,pkgDepCache &Cache,
    else
       ExpectedInst++;
    
-   // Install it with autoinstalling enabled.
-   if (State.InstBroken() == true && BrokenFix == false)
+   // Install it with autoinstalling enabled (if we not respect the minial
+   // required deps or the policy)
+   if ((State.InstBroken() == true || State.InstPolicyBroken() == true) && BrokenFix == false)
       Cache.MarkInstall(Pkg,true);
+
    return true;
 }
                                                                        /*}}}*/
@@ -1209,24 +1209,54 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
    string VerTag;
    string TmpSrc = Name;
    string::size_type Slash = TmpSrc.rfind('=');
+
+   // honor default release
+   string DefRel = _config->Find("APT::Default-Release");
+   pkgCache::PkgIterator Pkg = Cache.FindPkg(TmpSrc);
+
    if (Slash != string::npos)
    {
       VerTag = string(TmpSrc.begin() + Slash + 1,TmpSrc.end());
       TmpSrc = string(TmpSrc.begin(),TmpSrc.begin() + Slash);
+   } 
+   else  if(!Pkg.end() && DefRel.empty() == false)
+   {
+      // we have a default release, try to locate the pkg. we do it like
+      // this because GetCandidateVer() will not "downgrade", that means
+      // "apt-get source -t stable apt" won't work on a unstable system
+      for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false; 
+          Ver++)
+      {
+        for (pkgCache::VerFileIterator VF = Ver.FileList(); VF.end() == false;
+             VF++)
+        {
+           /* If this is the status file, and the current version is not the
+              version in the status file (ie it is not installed, or somesuch)
+              then it is not a candidate for installation, ever. This weeds
+              out bogus entries that may be due to config-file states, or
+              other. */
+           if ((VF.File()->Flags & pkgCache::Flag::NotSource) == 
+               pkgCache::Flag::NotSource && Pkg.CurrentVer() != Ver)
+           continue;
+           
+           //std::cout << VF.File().Archive() << std::endl;
+           if(VF.File().Archive() && (VF.File().Archive() == DefRel)) 
+           {
+              VerTag = Ver.VerStr();
+              break;
+           }
+        }
+      }
    }
-   
+
    /* 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. In theory
-      we could stash the version string as well and match that too but
-      today there aren't multi source versions in the archive. */
-   if (_config->FindB("APT::Get::Only-Source") == false && 
-       VerTag.empty() == true)
+      in the archive for a source package of the same name. */
+   if (_config->FindB("APT::Get::Only-Source") == false)
    {
-      pkgCache::PkgIterator Pkg = Cache.FindPkg(TmpSrc);
       if (Pkg.end() == false)
       {
-        pkgCache::VerIterator Ver = Cache.GetCandidateVer(Pkg);      
+        pkgCache::VerIterator Ver = Cache.GetCandidateVer(Pkg);
         if (Ver.end() == false)
         {
            pkgRecords::Parser &Parse = Recs.Lookup(Ver.FileList());
@@ -1284,10 +1314,7 @@ pkgSrcRecords::Parser *FindSrc(const char *Name,pkgRecords &Recs,
       }      
    }
    
-   if (Last == 0)
-      return 0;
-   
-   if (Last->Jump(Offset) == false)
+   if (Last == 0 || Last->Jump(Offset) == false)
       return 0;
    
    return Last;
@@ -1358,7 +1385,7 @@ bool DoUpdate(CommandLine &CmdL)
    }
    
    // Clean out any old list files
-   if (_config->FindB("APT::Get::List-Cleanup",true) == true)
+   if (!Failed && _config->FindB("APT::Get::List-Cleanup",true) == true)
    {
       if (Fetcher.Clean(_config->FindDir("Dir::State::lists")) == false ||
          Fetcher.Clean(_config->FindDir("Dir::State::lists") + "partial/") == false)
@@ -1374,106 +1401,6 @@ bool DoUpdate(CommandLine &CmdL)
       return _error->Error(_("Some index files failed to download, they have been ignored, or old ones used instead."));
    
    return true;
-}
-                                                                       /*}}}*/
-// DoUpgrade - Upgrade all packages                                    /*{{{*/
-// ---------------------------------------------------------------------
-/* Upgrade all packages without installing new packages or erasing old
-   packages */
-bool DoUpgrade(CommandLine &CmdL)
-{
-   CacheFile Cache;
-   if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
-      return false;
-
-   // Do the upgrade
-   if (pkgAllUpgrade(Cache) == false)
-   {
-      ShowBroken(c1out,Cache,false);
-      return _error->Error(_("Internal error, AllUpgrade broke stuff"));
-   }
-   
-   return InstallPackages(Cache,true);
-}
-                                                                       /*}}}*/
-// RecurseDirty - Mark used packages as dirty                          /*{{{*/
-// ---------------------------------------------------------------------
-/* Mark all reachable packages as dirty. */
-void RecurseDirty (CacheFile &Cache, pkgCache::PkgIterator Pkg, pkgCache::State::PkgRemoveState DirtLevel)
-{
-   // If it is not installed, and we are in manual mode, ignore it
-   if ((Pkg->CurrentVer == 0 && Cache[Pkg].Install() == false || Cache[Pkg].Delete() == true) &&
-       DirtLevel == pkgCache::State::RemoveManual) 
-   {
-//      fprintf(stdout,"This one is not installed/virtual %s %d %d\n", Pkg.Name(), Pkg->AutomaticRemove, DirtLevel);
-      return;
-   }
-
-   // If it is not installed, and it is not virtual, ignore it
-   if ((Pkg->CurrentVer == 0 && Cache[Pkg].Install() == false || Cache[Pkg].Delete() == true) &&
-       Pkg->VersionList != 0)
-   {
-//      fprintf(stdout,"This one is not installed %s %d %d\n", Pkg.Name(), Pkg->AutomaticRemove, DirtLevel);
-      return;
-   }
-
-   // If it is similar or more dirty than we are ;-), because we've been here already, don't mark it
-   // This is necessary because virtual packages just relay the current level,
-   // so it may be possible e.g. that this was already seen with ::RemoveSuggested, but
-   // we are ::RemoveRequired
-   if (Cache[Pkg].Dirty() >= DirtLevel) 
-   {
-      //fprintf(stdout,"Seen already %s %d %d\n", Pkg.Name(), Pkg->AutomaticRemove, DirtLevel);
-      return;
-   }
-   
-   // If it is less important than the current DirtLevel, don't mark it
-   if (Cache[Pkg].AutomaticRemove != pkgCache::State::RemoveManual && 
-      Cache[Pkg].AutomaticRemove > DirtLevel) 
-   {
-//       fprintf(stdout,"We don't need %s %d %d %d\n", Pkg.Name(), Pkg->AutomaticRemove, DirtLevel, Cache[Pkg].Dirty());
-       return;
-   }
-
-   // Mark it as used
-   Cache->SetDirty(Pkg, DirtLevel);
-       
-   //fprintf(stdout,"We keep %s %d %d\n", Pkg.Name(), Pkg->AutomaticRemove, DirtLevel);
-
-   // We are a virtual package
-   if (Pkg->VersionList == 0)
-   {
-//      fprintf(stdout,"We are virtual %s %d %d\n", Pkg.Name(), Pkg->AutomaticRemove, DirtLevel);
-      for (pkgCache::PrvIterator Prv = Pkg.ProvidesList(); ! Prv.end(); ++Prv)
-        RecurseDirty (Cache, Prv.OwnerPkg(), DirtLevel);
-      return;
-   }
-
-   // Depending on the type of dependency, follow it
-   for (pkgCache::DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); ! D.end(); ++D) 
-   {
-//      fprintf(stdout,"We depend on %s %s\n", D.TargetPkg().Name(), D.DepType());
-
-      switch(D->Type) 
-      {
-        case pkgCache::Dep::Depends:
-        case pkgCache::Dep::PreDepends:
-           RecurseDirty (Cache, D.TargetPkg(), pkgCache::State::RemoveRequired);
-           break;
-        case pkgCache::Dep::Recommends:
-            RecurseDirty (Cache, D.TargetPkg(), pkgCache::State::RemoveRecommended);
-           break;
-         case pkgCache::Dep::Suggests:
-            RecurseDirty (Cache, D.TargetPkg(), pkgCache::State::RemoveSuggested);
-           break;
-        case pkgCache::Dep::Conflicts:
-        case pkgCache::Dep::Replaces:
-        case pkgCache::Dep::Obsoletes:
-           // We don't handle these here
-           break;
-      }
-   }
-//   fprintf(stdout,"We keep %s %d %d <END>\n", Pkg.Name(), Pkg->AutomaticRemove, DirtLevel);
 }
                                                                        /*}}}*/
 // DoAutomaticRemove - Remove all automatic unused packages            /*{{{*/
@@ -1481,33 +1408,30 @@ void RecurseDirty (CacheFile &Cache, pkgCache::PkgIterator Pkg, pkgCache::State:
 /* Remove unused automatic packages */
 bool DoAutomaticRemove(CacheFile &Cache)
 {
-   std::cout << "DoAutomaticRemove()" << std::endl;
-   for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); ! Pkg.end(); ++Pkg)
-      if(!Cache[Pkg].Dirty() && Cache[Pkg].AutomaticRemove > 0)
-        std::cout << "has auto-remove information: " << Pkg.Name() 
-                  << " " << (int)Cache[Pkg].AutomaticRemove 
-                  << std::endl;
-
+   if(_config->FindI("Debug::pkgAutoRemove",false))
+      std::cout << "DoAutomaticRemove()" << std::endl;
 
    if (_config->FindB("APT::Get::Remove",true) == false)
-      return _error->Error(_("We are not supposed to delete stuff, can't start AutoRemover"));
-
-   for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); ! Pkg.end(); ++Pkg)
-      Cache->SetDirty(Pkg, pkgCache::State::RemoveUnknown);
+      return _error->Error(_("We are not supposed to delete stuff, can't "
+                            "start AutoRemover"));
 
-   for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); ! Pkg.end(); ++Pkg) 
-      RecurseDirty (Cache, Pkg, pkgCache::State::RemoveManual);
-   
+   {
+     pkgDepCache::ActionGroup group(*Cache);
 
+     // look over the cache to see what can be removed
+     for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); ! Pkg.end(); ++Pkg)
+       {
+        if (Cache[Pkg].Garbage)
+          {
+            if(Pkg.CurrentVer() != 0 || Cache[Pkg].Install())
+              fprintf(stdout,"We could delete %s\n", Pkg.Name());
 
-   for (pkgCache::PkgIterator Pkg = Cache->PkgBegin(); ! Pkg.end(); ++Pkg)
-   {
-      if (! Cache[Pkg].Dirty() &&
-          (Pkg->CurrentVer != 0 && Cache[Pkg].Install() == false && Cache[Pkg].Delete() == false))
-      {
-         fprintf(stdout,"We could delete %s %d\n", Pkg.Name(), Cache[Pkg].AutomaticRemove);
-         Cache->MarkDelete(Pkg,_config->FindB("APT::Get::Purge",false));
-      }
+            if(Pkg.CurrentVer() != 0 && Pkg->CurrentState != pkgCache::State::ConfigFiles)
+              Cache->MarkDelete(Pkg, _config->FindB("APT::Get::Purge", false));
+            else
+              Cache->MarkKeep(Pkg, false, false);
+          }
+       }
    }
 
    // Now see if we destroyed anything
@@ -1524,6 +1448,26 @@ bool DoAutomaticRemove(CacheFile &Cache)
    }
    return true;
 }
+
+// DoUpgrade - Upgrade all packages                                    /*{{{*/
+// ---------------------------------------------------------------------
+/* Upgrade all packages without installing new packages or erasing old
+   packages */
+bool DoUpgrade(CommandLine &CmdL)
+{
+   CacheFile Cache;
+   if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
+      return false;
+
+   // Do the upgrade
+   if (pkgAllUpgrade(Cache) == false)
+   {
+      ShowBroken(c1out,Cache,false);
+      return _error->Error(_("Internal error, AllUpgrade broke stuff"));
+   }
+   
+   return InstallPackages(Cache,true);
+}
                                                                        /*}}}*/
 // DoInstall - Install packages from the command line                  /*{{{*/
 // ---------------------------------------------------------------------
@@ -1547,6 +1491,11 @@ bool DoInstall(CommandLine &CmdL)
    bool DefRemove = false;
    if (strcasecmp(CmdL.FileList[0],"remove") == 0)
       DefRemove = true;
+   else if (strcasecmp(CmdL.FileList[0], "autoremove") == 0)
+     {
+       _config->Set("APT::Get::AutomaticRemove", "true");
+       DefRemove = true;
+     }
 
    for (const char **I = CmdL.FileList + 1; *I != 0; I++)
    {
@@ -1696,10 +1645,10 @@ bool DoInstall(CommandLine &CmdL)
       return _error->Error(_("Broken packages"));
    }   
    
-   //if (_config->FindB("APT::Get::AutomaticRemove")) {
+   if (_config->FindB("APT::Get::AutomaticRemove")) {
       if (!DoAutomaticRemove(Cache)) 
         return false;
-   //}
+   }
 
    /* Print out a list of packages that are going to be installed extra
       to what the user asked */
@@ -1720,10 +1669,8 @@ bool DoInstall(CommandLine &CmdL)
         
         if (*J == 0) {
            List += string(I.Name()) + " ";
-           //if (_config->FindB("APT::Get::AutomaticRemove"))
-              Cache[I].AutomaticRemove = pkgCache::State::RemoveRequired;
-        VersionsList += string(Cache[I].CandVersion) + "\n";
-     }
+           VersionsList += string(Cache[I].CandVersion) + "\n";
+        }
       }
       
       ShowList(c1out,_("The following extra packages will be installed:"),List,VersionsList);
@@ -1735,68 +1682,86 @@ bool DoInstall(CommandLine &CmdL)
       string SuggestsVersions, RecommendsVersions;
       for (unsigned J = 0; J < Cache->Head().PackageCount; J++)
       {
-        pkgCache::PkgIterator I(Cache,Cache.List[J]);
+        pkgCache::PkgIterator Pkg(Cache,Cache.List[J]);
 
         /* Just look at the ones we want to install */
-        if ((*Cache)[I].Install() == false)
+        if ((*Cache)[Pkg].Install() == false)
           continue;
 
-        for (pkgCache::VerIterator V = I.VersionList(); V.end() == false; V++)
-         {
-            for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; )
-             {
-                pkgCache::DepIterator Start;
-                pkgCache::DepIterator End;
-                D.GlobOr(Start,End); // advances D
-
-                /* 
-                 * If this is a virtual package, we need to check the list of
-                 * packages that provide it and see if any of those are
-                 * installed
-                 */
-                
-                bool providedBySomething = false;
-                for (pkgCache::PrvIterator Prv = Start.TargetPkg().ProvidesList();
-                      Prv.end() != true;
-                      Prv++)
-                   if ((*Cache)[Prv.OwnerPkg()].InstVerIter(*Cache).end() == false)
-                    {
-                      providedBySomething = true;
-                      break;
-                   }
-
-                if (providedBySomething) continue;
-            
-                 for(;;)
-                 {
-                     /* Skip if package is  installed already, or is about to be */
-                     string target = string(Start.TargetPkg().Name()) + " ";
-
-                     if ((*Start.TargetPkg()).SelectedState == pkgCache::State::Install
-                         || Cache[Start.TargetPkg()].Install())
-                       break;
-
-                     /* Skip if we already saw it */
-                     if (int(SuggestsList.find(target)) != -1 || int(RecommendsList.find(target)) != -1)
-                       break; 
-
-                    if (Start->Type == pkgCache::Dep::Suggests) {
-                      SuggestsList += target;
-                      SuggestsVersions += string(Cache[Start.TargetPkg()].CandVersion) + "\n";
-                    }
-                    
-                    if (Start->Type == pkgCache::Dep::Recommends) {
-                      RecommendsList += target;
-                      RecommendsVersions += string(Cache[Start.TargetPkg()].CandVersion) + "\n";
-                    }
-
-                     if (Start >= End)
-                        break;
-                     Start++;
-                 }
-             }
-         }
+        // get the recommends/suggests for the candidate ver
+        pkgCache::VerIterator CV = (*Cache)[Pkg].CandidateVerIter(*Cache);
+        for (pkgCache::DepIterator D = CV.DependsList(); D.end() == false; )
+        {
+           pkgCache::DepIterator Start;
+           pkgCache::DepIterator End;
+           D.GlobOr(Start,End); // advances D
+
+           // FIXME: we really should display a or-group as a or-group to the user
+           //        the problem is that ShowList is incapable of doing this
+           string RecommendsOrList,RecommendsOrVersions;
+           string SuggestsOrList,SuggestsOrVersions;
+           bool foundInstalledInOrGroup = false;
+           for(;;)
+           {
+              /* Skip if package is  installed already, or is about to be */
+              string target = string(Start.TargetPkg().Name()) + " ";
+              
+              if ((*Start.TargetPkg()).SelectedState == pkgCache::State::Install
+                  || Cache[Start.TargetPkg()].Install())
+              {
+                 foundInstalledInOrGroup=true;
+                 break;
+              }
+
+              /* Skip if we already saw it */
+              if (int(SuggestsList.find(target)) != -1 || int(RecommendsList.find(target)) != -1)
+              {
+                 foundInstalledInOrGroup=true;
+                 break; 
+              }
+
+              // this is a dep on a virtual pkg, check if any package that provides it
+              // should be installed
+              if(Start.TargetPkg().ProvidesList() != 0)
+              {
+                 pkgCache::PrvIterator I = Start.TargetPkg().ProvidesList();
+                 for (; I.end() == false; I++)
+                 {
+                    pkgCache::PkgIterator Pkg = I.OwnerPkg();
+                    if (Cache[Pkg].CandidateVerIter(Cache) == I.OwnerVer() && 
+                        Pkg.CurrentVer() != 0)
+                       foundInstalledInOrGroup=true;
+                 }
+              }
+
+              if (Start->Type == pkgCache::Dep::Suggests) 
+              {
+                 SuggestsOrList += target;
+                 SuggestsOrVersions += string(Cache[Start.TargetPkg()].CandVersion) + "\n";
+              }
+              
+              if (Start->Type == pkgCache::Dep::Recommends) 
+              {
+                 RecommendsOrList += target;
+                 RecommendsOrVersions += string(Cache[Start.TargetPkg()].CandVersion) + "\n";
+              }
+
+              if (Start >= End)
+                 break;
+              Start++;
+           }
+           
+           if(foundInstalledInOrGroup == false)
+           {
+              RecommendsList += RecommendsOrList;
+              RecommendsVersions += RecommendsOrVersions;
+              SuggestsList += SuggestsOrList;
+              SuggestsVersions += SuggestsOrVersions;
+           }
+              
+        }
       }
+
       ShowList(c1out,_("Suggested packages:"),SuggestsList,SuggestsVersions);
       ShowList(c1out,_("Recommended packages:"),RecommendsList,RecommendsVersions);
 
@@ -1805,7 +1770,7 @@ bool DoInstall(CommandLine &CmdL)
    // See if we need to prompt
    if (Cache->InstCount() == ExpectedInst && Cache->DelCount() == 0)
       return InstallPackages(Cache,false,false);
-   
+
    return InstallPackages(Cache,false);   
 }
                                                                        /*}}}*/
@@ -1840,6 +1805,8 @@ bool DoDSelectUpgrade(CommandLine &CmdL)
    if (Cache.OpenForInstall() == false || Cache.CheckDeps() == false)
       return false;
    
+   pkgDepCache::ActionGroup group(Cache);
+
    // Install everything with the install flag set
    pkgCache::PkgIterator I = Cache->PkgBegin();
    for (;I.end() != true; I++)
@@ -1891,7 +1858,7 @@ bool DoDSelectUpgrade(CommandLine &CmdL)
       if (Fix.Resolve() == false)
       {
         ShowBroken(c1out,Cache,false);
-        return _error->Error("Internal error, problem resolver broke stuff");
+        return _error->Error(_("Internal error, problem resolver broke stuff"));
       }
    }
 
@@ -1899,7 +1866,7 @@ bool DoDSelectUpgrade(CommandLine &CmdL)
    if (pkgAllUpgrade(Cache) == false)
    {
       ShowBroken(c1out,Cache,false);
-      return _error->Error("Internal error, problem resolver broke stuff");
+      return _error->Error(_("Internal error, problem resolver broke stuff"));
    }
    
    return InstallPackages(Cache,false);
@@ -2018,6 +1985,9 @@ bool DoSource(CommandLine &CmdL)
 
    DscFile *Dsc = new DscFile[CmdL.FileSize()];
    
+   // insert all downloaded uris into this set to avoid downloading them
+   // twice
+   set<string> queued;
    // Load the requestd sources into the fetcher
    unsigned J = 0;
    for (const char **I = CmdL.FileList + 1; *I != 0; I++, J++)
@@ -2054,7 +2024,28 @@ bool DoSource(CommandLine &CmdL)
         if (_config->FindB("APT::Get::Tar-Only",false) == true &&
             I->Type != "tar")
            continue;
-        
+
+        // don't download the same uri twice (should this be moved to
+        // the fetcher interface itself?)
+        if(queued.find(Last->Index().ArchiveURI(I->Path)) != queued.end())
+           continue;
+        queued.insert(Last->Index().ArchiveURI(I->Path));
+           
+        // check if we have a file with that md5 sum already localy
+        if(!I->MD5Hash.empty() && FileExists(flNotDir(I->Path)))  
+        {
+           FileFd Fd(flNotDir(I->Path), FileFd::ReadOnly);
+           MD5Summation sum;
+           sum.AddFD(Fd.Fd(), Fd.Size());
+           Fd.Close();
+           if((string)sum.Result() == I->MD5Hash) 
+           {
+              ioprintf(c1out,_("Skipping already downloaded file '%s'\n"),
+                       flNotDir(I->Path).c_str());
+              continue;
+           }
+        }
+
         new pkgAcqFile(&Fetcher,Last->Index().ArchiveURI(I->Path),
                        I->MD5Hash,I->Size,
                        Last->Index().SourceInfo(*Last,*I),Src);
@@ -2070,7 +2061,7 @@ bool DoSource(CommandLine &CmdL)
    struct statvfs Buf;
    string OutputDir = ".";
    if (statvfs(OutputDir.c_str(),&Buf) != 0)
-      return _error->Errno("statvfs","Couldn't determine free space in %s",
+      return _error->Errno("statvfs",_("Couldn't determine free space in %s"),
                           OutputDir.c_str());
    if (unsigned(Buf.f_bfree) < (FetchBytes - FetchPBytes)/Buf.f_bsize)
       return _error->Error(_("You don't have enough free space in %s"),
@@ -2159,6 +2150,7 @@ bool DoSource(CommandLine &CmdL)
            if (system(S) != 0)
            {
               fprintf(stderr,_("Unpack command '%s' failed.\n"),S);
+              fprintf(stderr,_("Check if the 'dpkg-dev' package is installed.\n"));
               _exit(1);
            }       
         }
@@ -2623,8 +2615,10 @@ int main(int argc,const char *argv[])
       {0,"remove","APT::Get::Remove",0},
       {0,"only-source","APT::Get::Only-Source",0},
       {0,"arch-only","APT::Get::Arch-Only",0},
-      {0,"experimental-automatic-remove","APT::Get::AutomaticRemove",0},
+      {0,"auto-remove","APT::Get::AutomaticRemove",0},
       {0,"allow-unauthenticated","APT::Get::AllowUnauthenticated",0},
+      {0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean},
+      {0,"fix-policy","APT::Get::Fix-Policy-Broken",0},
       {'c',"config-file",0,CommandLine::ConfigFile},
       {'o',"option",0,CommandLine::ArbItem},
       {0,0,0,0}};
@@ -2632,6 +2626,7 @@ int main(int argc,const char *argv[])
                                    {"upgrade",&DoUpgrade},
                                    {"install",&DoInstall},
                                    {"remove",&DoInstall},
+                                  {"autoremove",&DoInstall},
                                    {"dist-upgrade",&DoDistUpgrade},
                                    {"dselect-upgrade",&DoDSelectUpgrade},
                                   {"build-dep",&DoBuildDep},