diff options
Diffstat (limited to 'cmdline/apt-internal-solver.cc')
-rw-r--r-- | cmdline/apt-internal-solver.cc | 71 |
1 files changed, 66 insertions, 5 deletions
diff --git a/cmdline/apt-internal-solver.cc b/cmdline/apt-internal-solver.cc index 83d79e42a..ad00a0e23 100644 --- a/cmdline/apt-internal-solver.cc +++ b/cmdline/apt-internal-solver.cc @@ -53,6 +53,8 @@ int main(int argc,const char *argv[]) /*{{{*/ {'v',"version","version",0}, {'q',"quiet","quiet",CommandLine::IntLevel}, {'q',"silent","quiet",CommandLine::IntLevel}, + {'c',"config-file",0,CommandLine::ConfigFile}, + {'o',"option",0,CommandLine::ArbItem}, {0,0,0,0}}; CommandLine CmdL(Args,_config); @@ -69,6 +71,25 @@ int main(int argc,const char *argv[]) /*{{{*/ return 1; } + if (CmdL.FileList[0] != 0 && strcmp(CmdL.FileList[0], "scenario") == 0) + { + if (pkgInitSystem(*_config,_system) == false) { + std::cerr << "System could not be initialized!" << std::endl; + return 1; + } + pkgCacheFile CacheFile; + CacheFile.Open(NULL, false); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); + FILE* output = stdout; + if (pkgset.empty() == true) + EDSP::WriteScenario(CacheFile, output); + else + EDSP::WriteLimitedScenario(CacheFile, output, pkgset); + fclose(output); + _error->DumpErrors(std::cerr); + return 0; + } + // Deal with stdout not being a tty if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1) _config->Set("quiet","1"); @@ -82,11 +103,15 @@ int main(int argc,const char *argv[]) /*{{{*/ FILE* output = stdout; SetNonBlock(input, false); + EDSP::WriteProgress(0, "Start up solver…", output); + if (pkgInitSystem(*_config,_system) == false) { std::cerr << "System could not be initialized!" << std::endl; return 1; } + EDSP::WriteProgress(1, "Read request…", output); + if (WaitFd(input, false, 5) == false) std::cerr << "WAIT timed out in the resolver" << std::endl; @@ -97,33 +122,69 @@ int main(int argc,const char *argv[]) /*{{{*/ return 2; } + EDSP::WriteProgress(5, "Read scenario…", output); + pkgCacheFile CacheFile; CacheFile.Open(NULL, false); + EDSP::WriteProgress(50, "Apply request on scenario…", output); + if (EDSP::ApplyRequest(install, remove, CacheFile) == false) { std::cerr << "Failed to apply request to depcache!" << std::endl; return 3; } + + pkgProblemResolver Fix(CacheFile); + for (std::list<std::string>::const_iterator i = remove.begin(); + i != remove.end(); ++i) { + pkgCache::PkgIterator P = CacheFile->FindPkg(*i); + Fix.Clear(P); + Fix.Protect(P); + Fix.Remove(P); + } + + for (std::list<std::string>::const_iterator i = install.begin(); + i != install.end(); ++i) { + pkgCache::PkgIterator P = CacheFile->FindPkg(*i); + Fix.Clear(P); + Fix.Protect(P); + } + for (std::list<std::string>::const_iterator i = install.begin(); i != install.end(); ++i) CacheFile->MarkInstall(CacheFile->FindPkg(*i), true); - pkgProblemResolver Fix(CacheFile); - if (Fix.Resolve() == false) { - EDSP::WriteError("An error occured", output); + EDSP::WriteProgress(60, "Call problemresolver on current scenario…", output); + + if (upgrade == true) { + if (pkgAllUpgrade(CacheFile) == false) { + EDSP::WriteError("ERR_UNSOLVABLE_UPGRADE", "An upgrade error occured", output); + return 0; + } + } else if (distUpgrade == true) { + if (pkgDistUpgrade(CacheFile) == false) { + EDSP::WriteError("ERR_UNSOLVABLE_DIST_UPGRADE", "An dist-upgrade error occured", output); + return 0; + } + } else if (Fix.Resolve() == false) { + EDSP::WriteError("ERR_UNSOLVABLE", "An error occured", output); return 0; } + EDSP::WriteProgress(95, "Write solution…", output); + if (EDSP::WriteSolution(CacheFile, output) == false) { std::cerr << "Failed to output the solution!" << std::endl; return 4; } + EDSP::WriteProgress(100, "Done", output); + bool const Errors = _error->PendingError(); if (_config->FindI("quiet",0) > 0) - _error->DumpErrors(); + _error->DumpErrors(std::cerr); else - _error->DumpErrors(GlobalError::DEBUG); + _error->DumpErrors(std::cerr, GlobalError::DEBUG); return Errors == true ? 100 : 0; } /*}}}*/ |