- support task removal too: apt-get remove taskname^
[ntk/apt.git] / cmdline / apt-get.cc
index aa6a70f..df04140 100644 (file)
@@ -1507,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;
@@ -1519,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;
@@ -1535,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;
    }
    
@@ -1569,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);
@@ -1591,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
@@ -1739,10 +1757,8 @@ bool DoInstall(CommandLine &CmdL)
         return _error->Error(_("Broken packages"));
       }   
    }
-   if (_config->FindB("APT::Get::AutomaticRemove")) {
-      if (!DoAutomaticRemove(Cache)) 
-        return false;
-   }
+   if (!DoAutomaticRemove(Cache)) 
+      return false;
 
    /* Print out a list of packages that are going to be installed extra
       to what the user asked */
@@ -2127,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())
@@ -2620,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"
@@ -2709,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},