X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/36afd8495a5646ccdec0153c93945a5a27606fce..6a30946d00371ff1fb7f94791364706a4bac0ea2:/cmdline/apt-get.cc diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index cd43e17c7..765591b14 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1420,7 +1420,7 @@ bool DoUpdate(CommandLine &CmdL) bool DoAutomaticRemove(CacheFile &Cache) { bool Debug = _config->FindI("Debug::pkgAutoRemove",false); - bool doAutoRemove = _config->FindB("APT::Get::AutomaticRemove"); + bool doAutoRemove = _config->FindB("APT::Get::AutomaticRemove", false); pkgDepCache::ActionGroup group(*Cache); @@ -1499,56 +1499,46 @@ bool DoUpgrade(CommandLine &CmdL) // DoInstallTask - Install task from the command line /*{{{*/ // --------------------------------------------------------------------- /* Install named task */ -bool DoInstallTask(CommandLine &CmdL) +bool TryInstallTask(pkgDepCache &Cache, pkgProblemResolver &Fix, + bool BrokenFix, + unsigned int& ExpectedInst, + const char *taskname) { const char *start, *end; pkgCache::PkgIterator Pkg; + char buf[64*1024]; + regex_t Pattern; - CacheFile Cache; - if (Cache.OpenForInstall() == false || - Cache.CheckDeps(CmdL.FileSize() != 1) == false) - return false; - - // create the records parser + // get the records pkgRecords Recs(Cache); - - unsigned int ExpectedInst = 0; - unsigned int Packages = 0; - pkgProblemResolver Fix(Cache); - char buf[64*1024]; - for (const char **I = CmdL.FileList + 1; *I != 0; I++) + // 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); + + bool found = false; + bool res = true; + for (Pkg = Cache.PkgBegin(); Pkg.end() == false; Pkg++) { - regex_t Pattern; - int Res; - - // build regexp for the task - char S[300]; - snprintf(S, sizeof(S), "^Task:.*%s.*\n", *I); - regcomp(&Pattern,S, REG_EXTENDED | REG_NOSUB | REG_NEWLINE); - - for (Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) - { - pkgCache::VerIterator ver = (*Cache)[Pkg].CandidateVerIter(*Cache); - if(ver.end()) - continue; - pkgRecords::Parser &parser = Recs.Lookup(ver.FileList()); - parser.GetRec(start,end); - strncpy(buf, start, end-start); - buf[end-start] = 0x0; - if (regexec(&Pattern,buf,0,0,0) != 0) - continue; - TryToInstall(Pkg,Cache,Fix,false,false,ExpectedInst); - } + pkgCache::VerIterator ver = Cache[Pkg].CandidateVerIter(Cache); + if(ver.end()) + continue; + pkgRecords::Parser &parser = Recs.Lookup(ver.FileList()); + parser.GetRec(start,end); + strncpy(buf, start, end-start); + buf[end-start] = 0x0; + if (regexec(&Pattern,buf,0,0,0) != 0) + continue; + res &= TryToInstall(Pkg,Cache,Fix,false,true,ExpectedInst); + found = true; } - - // Call the scored problem resolver - Fix.InstallProtect(); - if (Fix.Resolve(true) == false) - _error->Discard(); - // prompt for install - return InstallPackages(Cache,false,true); + if(!found) + _error->Error(_("Couldn't find task %s"),taskname); + + regfree(&Pattern); + return res; } // DoInstall - Install packages from the command line /*{{{*/ @@ -1573,6 +1563,7 @@ 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"); @@ -1595,6 +1586,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); + continue; + } + while (Cache->FindPkg(S).end() == true) { // Handle an optional end tag indicating what to do @@ -1683,6 +1686,7 @@ bool DoInstall(CommandLine &CmdL) } else { + if (VerTag != 0) if (TryToChangeVer(Pkg,Cache,VerTag,VerIsRel) == false) return false; @@ -2642,7 +2646,6 @@ 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 /*{{{*/ @@ -2708,7 +2711,6 @@ int main(int argc,const char *argv[]) CommandLine::Dispatch Cmds[] = {{"update",&DoUpdate}, {"upgrade",&DoUpgrade}, {"install",&DoInstall}, - {"installtask",&DoInstallTask}, {"remove",&DoInstall}, {"autoremove",&DoInstall}, {"dist-upgrade",&DoDistUpgrade},