- support task removal too: apt-get remove taskname^
[ntk/apt.git] / cmdline / apt-get.cc
index 6949dc6..df04140 100644 (file)
@@ -1372,20 +1372,29 @@ bool DoUpdate(CommandLine &CmdL)
       return false;
 
    bool Failed = false;
+   bool TransientNetworkFailure = false;
    for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++)
    {
       if ((*I)->Status == pkgAcquire::Item::StatDone)
         continue;
 
       (*I)->Finished();
-      
+
       fprintf(stderr,_("Failed to fetch %s  %s\n"),(*I)->DescURI().c_str(),
              (*I)->ErrorText.c_str());
+
+      if ((*I)->Status == pkgAcquire::Item::StatTransientNetworkError) 
+      {
+        TransientNetworkFailure = true;
+        continue;
+      }
+
       Failed = true;
    }
    
    // Clean out any old list files
-   if (!Failed && _config->FindB("APT::Get::List-Cleanup",true) == true)
+   if (!TransientNetworkFailure &&
+       _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)
@@ -1397,9 +1406,11 @@ bool DoUpdate(CommandLine &CmdL)
    if (Cache.BuildCaches() == false)
       return false;
    
-   if (Failed == true)
+   if (TransientNetworkFailure == true)
+      _error->Warning(_("Some index files failed to download, they have been ignored, or old ones used instead."));
+   else if (Failed == true)
       return _error->Error(_("Some index files failed to download, they have been ignored, or old ones used instead."));
-   
+
    return true;
 }
                                                                        /*}}}*/
@@ -1410,8 +1421,8 @@ 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);
-   
 
    if(Debug)
       std::cout << "DoAutomaticRemove()" << std::endl;
@@ -1433,9 +1444,13 @@ bool DoAutomaticRemove(CacheFile &Cache)
         if(Pkg.CurrentVer() != 0 || Cache[Pkg].Install())
            if(Debug)
               std::cout << "We could delete %s" <<  Pkg.Name() << std::endl;
-          
-        autoremovelist += string(Pkg.Name()) + " ";
-        autoremoveversions += string(Cache[Pkg].CandVersion) + " ";
+         
+        // 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 && 
@@ -1446,8 +1461,9 @@ bool DoAutomaticRemove(CacheFile &Cache)
         }
       }
    }
-   ShowList(c1out, _("The following packages were automatically installed and are no longer required:"), autoremovelist, autoremoveversions);
-   if (!doAutoRemove && autoremovelist.size() > 0)
+   if (!hideAutoRemove) 
+      ShowList(c1out, _("The following packages were automatically installed and are no longer required:"), autoremovelist, autoremoveversions);
+   if (!doAutoRemove && !hideAutoRemove && autoremovelist.size() > 0)
       c1out << _("Use 'apt-get autoremove' to remove them.") << std::endl;
 
    // Now see if we destroyed anything
@@ -1491,7 +1507,8 @@ bool DoUpgrade(CommandLine &CmdL)
 bool TryInstallTask(pkgDepCache &Cache, pkgProblemResolver &Fix, 
                    bool BrokenFix,
                    unsigned int& ExpectedInst, 
-                   const char *taskname)
+                   const char *taskname,
+                   bool Remove)
 {
    const char *start, *end;
    pkgCache::PkgIterator Pkg;
@@ -1503,8 +1520,9 @@ bool TryInstallTask(pkgDepCache &Cache, pkgProblemResolver &Fix,
 
    // build regexp for the task
    char S[300];
-   snprintf(S, sizeof(S), "^Task:.*[^a-z]%s[^a-z].*\n", taskname);
-   regcomp(&Pattern,S, REG_EXTENDED | REG_NOSUB | REG_NEWLINE);
+   snprintf(S, sizeof(S), "^Task:.*[, ]%s([, ]|$)", taskname);
+   if(regcomp(&Pattern,S, REG_EXTENDED | REG_NOSUB | REG_NEWLINE) != 0)
+      return _error->Error("Failed to compile task regexp");
    
    bool found = false;
    bool res = true;
@@ -1519,7 +1537,7 @@ bool TryInstallTask(pkgDepCache &Cache, pkgProblemResolver &Fix,
       buf[end-start] = 0x0;
       if (regexec(&Pattern,buf,0,0,0) != 0)
         continue;
-      res &= TryToInstall(Pkg,Cache,Fix,false,BrokenFix,ExpectedInst);
+      res &= TryToInstall(Pkg,Cache,Fix,Remove,true,ExpectedInst);
       found = true;
    }
    
@@ -1545,6 +1563,7 @@ bool DoInstall(CommandLine &CmdL)
    if (Cache->BrokenCount() != 0)
       BrokenFix = true;
    
+   unsigned int AutoMarkChanged = 0;
    unsigned int ExpectedInst = 0;
    unsigned int Packages = 0;
    pkgProblemResolver Fix(Cache);
@@ -1552,12 +1571,16 @@ bool DoInstall(CommandLine &CmdL)
    bool DefRemove = false;
    if (strcasecmp(CmdL.FileList[0],"remove") == 0)
       DefRemove = true;
+   else if (strcasecmp(CmdL.FileList[0], "purge") == 0)
+   {
+      _config->Set("APT::Get::Purge", true);
+      DefRemove = true;
+   }
    else if (strcasecmp(CmdL.FileList[0], "autoremove") == 0)
    {
       _config->Set("APT::Get::AutomaticRemove", "true");
       DefRemove = true;
    }
-
    // new scope for the ActionGroup
    {
       pkgDepCache::ActionGroup group(Cache);
@@ -1574,6 +1597,18 @@ bool DoInstall(CommandLine &CmdL)
         bool Remove = DefRemove;
         char *VerTag = 0;
         bool VerIsRel = false;
+
+         // this is a task!
+         if (Length >= 1 && S[Length - 1] == '^')
+         {
+            S[--Length] = 0;
+            // tasks must always be confirmed
+            ExpectedInst += 1000;
+            // see if we can install it
+            TryInstallTask(Cache, Fix, BrokenFix, ExpectedInst, S, Remove);
+            continue;
+         }
+
         while (Cache->FindPkg(S).end() == true)
         {
            // Handle an optional end tag indicating what to do
@@ -1667,6 +1702,19 @@ bool DoInstall(CommandLine &CmdL)
                  return false;
            if (TryToInstall(Pkg,Cache,Fix,Remove,BrokenFix,ExpectedInst) == 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(!Remove && 
+              Cache[Pkg].Install() == false && 
+              (Cache[Pkg].Flags & pkgCache::Flag::Auto))
+           {
+              ioprintf(c1out,_("%s set to manual installed.\n"),
+                       Pkg.Name());
+              Cache->MarkAuto(Pkg,false);
+              AutoMarkChanged++;
+           }
         }      
       }
 
@@ -1710,7 +1758,7 @@ bool DoInstall(CommandLine &CmdL)
       }   
    }
    if (!DoAutomaticRemove(Cache)) 
-        return false;
+      return false;
 
    /* Print out a list of packages that are going to be installed extra
       to what the user asked */
@@ -1829,6 +1877,14 @@ bool DoInstall(CommandLine &CmdL)
 
    }
 
+   // if nothing changed in the cache, but only the automark information
+   // we write the StateFile here, otherwise it will be written in 
+   // cache.commit()
+   if (AutoMarkChanged > 0 &&
+       Cache->DelCount() == 0 && Cache->InstCount() == 0 &&
+       Cache->BadCount() == 0)
+      Cache->writeStateFile(NULL);
+
    // See if we need to prompt
    if (Cache->InstCount() == ExpectedInst && Cache->DelCount() == 0)
       return InstallPackages(Cache,false,false);
@@ -2087,6 +2143,11 @@ bool DoSource(CommandLine &CmdL)
             I->Type != "tar")
            continue;
 
+        // Dsc only mode only fetches .dsc files
+        if (_config->FindB("APT::Get::Dsc-Only",false) == true &&
+            I->Type != "dsc")
+           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())
@@ -2580,6 +2641,7 @@ bool ShowHelp(CommandLine &CmdL)
       "   upgrade - Perform an upgrade\n"
       "   install - Install new packages (pkg is libc6 not libc6.deb)\n"
       "   remove - Remove packages\n"
+      "   purge - Remove and purge packages\n"
       "   source - Download source archives\n"
       "   build-dep - Configure build-dependencies for source packages\n"
       "   dist-upgrade - Distribution upgrade, see apt-get(8)\n"
@@ -2621,6 +2683,7 @@ void GetInitialize()
    _config->Set("APT::Get::Fix-Broken",false);
    _config->Set("APT::Get::Force-Yes",false);
    _config->Set("APT::Get::List-Cleanup",true);
+   _config->Set("APT::Get::AutomaticRemove",false);
 }
                                                                        /*}}}*/
 // SigWinch - Window size change signal handler                                /*{{{*/
@@ -2668,7 +2731,8 @@ int main(int argc,const char *argv[])
       {0,"force-yes","APT::Get::force-yes",0},
       {0,"print-uris","APT::Get::Print-URIs",0},
       {0,"diff-only","APT::Get::Diff-Only",0},
-      {0,"tar-only","APT::Get::tar-Only",0},
+      {0,"tar-only","APT::Get::Tar-Only",0},
+      {0,"dsc-only","APT::Get::Dsc-Only",0},
       {0,"purge","APT::Get::Purge",0},
       {0,"list-cleanup","APT::Get::List-Cleanup",0},
       {0,"reinstall","APT::Get::ReInstall",0},