From c158ff49dacb8f6fdca98f9b43329eac44f1a827 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 19 Sep 2006 14:02:53 +0200 Subject: * tasksupport (apt-get installtask lala) added --- cmdline/apt-get.cc | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 64882e3e8..9705f84dc 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1406,6 +1406,61 @@ bool DoUpgrade(CommandLine &CmdL) return InstallPackages(Cache,true); } /*}}}*/ +// DoInstallTask - Install task from the command line /*{{{*/ +// --------------------------------------------------------------------- +/* Install named task */ +bool DoInstallTask(CommandLine &CmdL) +{ + const char *start, *end; + pkgCache::PkgIterator Pkg; + + CacheFile Cache; + if (Cache.OpenForInstall() == false || + Cache.CheckDeps(CmdL.FileSize() != 1) == false) + return false; + + // create the records parser + 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++) + { + 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); + } + } + + // Call the scored problem resolver + Fix.InstallProtect(); + if (Fix.Resolve(true) == false) + _error->Discard(); + + // prompt for install + return InstallPackages(Cache,false,true); +} + // DoInstall - Install packages from the command line /*{{{*/ // --------------------------------------------------------------------- /* Install named packages */ @@ -2546,6 +2601,7 @@ int main(int argc,const char *argv[]) CommandLine::Dispatch Cmds[] = {{"update",&DoUpdate}, {"upgrade",&DoUpgrade}, {"install",&DoInstall}, + {"installtask",&DoInstallTask}, {"remove",&DoInstall}, {"dist-upgrade",&DoDistUpgrade}, {"dselect-upgrade",&DoDSelectUpgrade}, -- cgit v1.2.3 From ab04fa68f216974b277c708ab0788ef8798f879f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 19 Sep 2006 15:41:52 +0200 Subject: * cmdline/apt-get.cc: - install with FixBroken=true --- cmdline/apt-get.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 9705f84dc..57e0e9ec7 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1434,7 +1434,7 @@ bool DoInstallTask(CommandLine &CmdL) // build regexp for the task char S[300]; - snprintf(S, sizeof(S), "^Task:.*%s.*\n", *I); + snprintf(S, sizeof(S), "^Task:.*[^a-z]%s[^a-z].*\n", *I); regcomp(&Pattern,S, REG_EXTENDED | REG_NOSUB | REG_NEWLINE); for (Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++) @@ -1448,14 +1448,13 @@ bool DoInstallTask(CommandLine &CmdL) buf[end-start] = 0x0; if (regexec(&Pattern,buf,0,0,0) != 0) continue; - TryToInstall(Pkg,Cache,Fix,false,false,ExpectedInst); + TryToInstall(Pkg,Cache,Fix,false,true,ExpectedInst); } } // Call the scored problem resolver Fix.InstallProtect(); - if (Fix.Resolve(true) == false) - _error->Discard(); + Fix.Resolve(true); // prompt for install return InstallPackages(Cache,false,true); -- cgit v1.2.3 From d6df222d8edb3e38401affcee2a4e5eba605da32 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 19 Sep 2006 16:06:06 +0200 Subject: * cmdline/apt-get.cc: - call regexp_free() --- cmdline/apt-get.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 57e0e9ec7..2062aaa16 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1423,14 +1423,12 @@ bool DoInstallTask(CommandLine &CmdL) 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++) { regex_t Pattern; - int Res; // build regexp for the task char S[300]; @@ -1450,6 +1448,8 @@ bool DoInstallTask(CommandLine &CmdL) continue; TryToInstall(Pkg,Cache,Fix,false,true,ExpectedInst); } + + regfree(&Pattern); } // Call the scored problem resolver -- cgit v1.2.3 From 39cc1bbdd0faa13dcb150b573f56cd2dd64fa460 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 19 Sep 2006 17:22:41 +0200 Subject: * cmdline/apt-get.cc: - changed syntax from "installtask" to "install taskname^" (the ^ <- makes it look for tasks) --- cmdline/apt-get.cc | 86 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 42 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 2062aaa16..09bf572a5 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1409,55 +1409,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; - 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; - - // build regexp for the task - char S[300]; - snprintf(S, sizeof(S), "^Task:.*[^a-z]%s[^a-z].*\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,true,ExpectedInst); - } - - regfree(&Pattern); + 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,BrokenFix,ExpectedInst); + found = true; } - - // Call the scored problem resolver - Fix.InstallProtect(); - Fix.Resolve(true); - // 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 /*{{{*/ @@ -1496,6 +1487,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 @@ -1512,7 +1515,7 @@ bool DoInstall(CommandLine &CmdL) S[--Length] = 0; continue; } - + char *Slash = strchr(S,'='); if (Slash != 0) { @@ -2600,7 +2603,6 @@ int main(int argc,const char *argv[]) CommandLine::Dispatch Cmds[] = {{"update",&DoUpdate}, {"upgrade",&DoUpgrade}, {"install",&DoInstall}, - {"installtask",&DoInstallTask}, {"remove",&DoInstall}, {"dist-upgrade",&DoDistUpgrade}, {"dselect-upgrade",&DoDSelectUpgrade}, -- cgit v1.2.3