summaryrefslogtreecommitdiff
path: root/cmdline
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2011-06-29 12:45:30 +0100
committerMichael Vogt <michael.vogt@ubuntu.com>2011-06-29 12:45:30 +0100
commit9abccf4a63b6c887b213678d940fe912233f04c3 (patch)
tree8a22c910a0c8258f29784614aca9c0ebd2cc32d6 /cmdline
parentc56c4b82dd77258da5640bf9f63a8db10424b59a (diff)
parent627e99b0328e05b13600134655253d36575f314d (diff)
merge lp:~mvo/apt/abi-break
Diffstat (limited to 'cmdline')
-rw-r--r--cmdline/apt-dump-solver.cc50
-rw-r--r--cmdline/apt-get.cc13
-rw-r--r--cmdline/apt-internal-solver.cc190
-rw-r--r--cmdline/makefile14
4 files changed, 263 insertions, 4 deletions
diff --git a/cmdline/apt-dump-solver.cc b/cmdline/apt-dump-solver.cc
new file mode 100644
index 000000000..dab0cc6fd
--- /dev/null
+++ b/cmdline/apt-dump-solver.cc
@@ -0,0 +1,50 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+/* #####################################################################
+
+ dummy solver to get quickly a scenario file out of APT
+
+ ##################################################################### */
+ /*}}}*/
+// Include Files /*{{{*/
+#include <apt-pkg/edsp.h>
+
+#include <config.h>
+
+#include <cstdio>
+ /*}}}*/
+
+// ShowHelp - Show a help screen /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool ShowHelp() {
+
+ std::cout <<
+ PACKAGE " " VERSION " for " COMMON_ARCH " compiled on " __DATE__ " " __TIME__ << std::endl <<
+ "Usage: apt-dump-resolver\n"
+ "\n"
+ "apt-dump-resolver is a dummy solver who just dumps its input to the\n"
+ "file /tmp/dump.edsp and exists with a proper EDSP error.\n"
+ "\n"
+ " This dump has lost Super Cow Powers.\n";
+ return true;
+}
+ /*}}}*/
+int main(int argc,const char *argv[]) /*{{{*/
+{
+ if (argc > 1 && (strcmp(argv[1], "--help") == 0 || strcmp(argv[1],"-h") == 0 ||
+ strcmp(argv[1],"-v") == 0 || strcmp(argv[1],"--version") == 0)) {
+ ShowHelp();
+ return 0;
+ }
+
+ FILE* input = fdopen(STDIN_FILENO, "r");
+ FILE* output = fopen("/tmp/dump.edsp", "w");
+ char buffer[400];
+ while (fgets(buffer, sizeof(buffer), input) != NULL)
+ fputs(buffer, output);
+ fclose(output);
+ fclose(input);
+
+ EDSP::WriteError("ERR_JUST_DUMPING", "I am too dumb, i can just dump!\nPlease use one of my friends instead!", stdout);
+}
diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc
index 845c92026..66ebd30b8 100644
--- a/cmdline/apt-get.cc
+++ b/cmdline/apt-get.cc
@@ -1886,8 +1886,7 @@ bool DoInstall(CommandLine &CmdL)
{
// Call the scored problem resolver
Fix->InstallProtect();
- if (Fix->Resolve(true) == false)
- _error->Discard();
+ Fix->Resolve(true);
delete Fix;
}
@@ -1913,8 +1912,11 @@ bool DoInstall(CommandLine &CmdL)
c1out << _("The following information may help to resolve the situation:") << endl;
c1out << endl;
ShowBroken(c1out,Cache,false);
- return _error->Error(_("Broken packages"));
- }
+ if (_error->PendingError() == true)
+ return false;
+ else
+ return _error->Error(_("Broken packages"));
+ }
}
if (!DoAutomaticRemove(Cache))
return false;
@@ -2297,6 +2299,8 @@ bool DoDownload(CommandLine &CmdL)
strprintf(descr, _("Downloading %s %s"), Pkg.Name(), Ver.VerStr());
// get the most appropriate hash
HashString hash;
+ if (rec.SHA512Hash() != "")
+ hash = HashString("sha512", rec.SHA512Hash());
if (rec.SHA256Hash() != "")
hash = HashString("sha256", rec.SHA256Hash());
else if (rec.SHA1Hash() != "")
@@ -3270,6 +3274,7 @@ int main(int argc,const char *argv[]) /*{{{*/
{0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean},
{0,"install-suggests","APT::Install-Suggests",CommandLine::Boolean},
{0,"fix-policy","APT::Get::Fix-Policy-Broken",0},
+ {0,"solver","APT::Solver",CommandLine::HasArg},
{'c',"config-file",0,CommandLine::ConfigFile},
{'o',"option",0,CommandLine::ArbItem},
{0,0,0,0}};
diff --git a/cmdline/apt-internal-solver.cc b/cmdline/apt-internal-solver.cc
new file mode 100644
index 000000000..ef6c688fe
--- /dev/null
+++ b/cmdline/apt-internal-solver.cc
@@ -0,0 +1,190 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+/* #####################################################################
+
+ cover around the internal solver to be able to run it like an external
+
+ ##################################################################### */
+ /*}}}*/
+// Include Files /*{{{*/
+#include <apt-pkg/error.h>
+#include <apt-pkg/cmndline.h>
+#include <apt-pkg/init.h>
+#include <apt-pkg/cachefile.h>
+#include <apt-pkg/strutl.h>
+#include <apt-pkg/edsp.h>
+#include <apt-pkg/algorithms.h>
+#include <apt-pkg/fileutl.h>
+
+#include <config.h>
+#include <apti18n.h>
+
+#include <unistd.h>
+#include <cstdio>
+ /*}}}*/
+
+// ShowHelp - Show a help screen /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool ShowHelp(CommandLine &CmdL) {
+ ioprintf(std::cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,VERSION,
+ COMMON_ARCH,__DATE__,__TIME__);
+
+ std::cout <<
+ _("Usage: apt-internal-resolver\n"
+ "\n"
+ "apt-internal-resolver is an interface to use the current internal\n"
+ "like an external resolver for the APT family for debugging or alike\n"
+ "\n"
+ "Options:\n"
+ " -h This help text.\n"
+ " -q Loggable output - no progress indicator\n"
+ " -c=? Read this configuration file\n"
+ " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
+ "apt.conf(5) manual pages for more information and options.\n"
+ " This APT has Super Cow Powers.\n");
+ return true;
+}
+ /*}}}*/
+int main(int argc,const char *argv[]) /*{{{*/
+{
+ CommandLine::Args Args[] = {
+ {'h',"help","help",0},
+ {'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);
+ if (pkgInitConfig(*_config) == false ||
+ CmdL.Parse(argc,argv) == false) {
+ _error->DumpErrors();
+ return 2;
+ }
+
+ // See if the help should be shown
+ if (_config->FindB("help") == true ||
+ _config->FindB("version") == true) {
+ ShowHelp(CmdL);
+ 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");
+
+ if (_config->FindI("quiet", 0) < 1)
+ _config->Set("Debug::EDSP::WriteSolution", true);
+
+ _config->Set("APT::Solver", "internal");
+ _config->Set("edsp::scenario", "stdin");
+ int input = STDIN_FILENO;
+ 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;
+
+ std::list<std::string> install, remove;
+ bool upgrade, distUpgrade, autoRemove;
+ if (EDSP::ReadRequest(input, install, remove, upgrade, distUpgrade, autoRemove) == false) {
+ std::cerr << "Parsing the request failed!" << std::endl;
+ 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);
+
+ 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(std::cerr);
+ else
+ _error->DumpErrors(std::cerr, GlobalError::DEBUG);
+ return Errors == true ? 100 : 0;
+}
+ /*}}}*/
diff --git a/cmdline/makefile b/cmdline/makefile
index e867dae73..6d988a8f5 100644
--- a/cmdline/makefile
+++ b/cmdline/makefile
@@ -65,3 +65,17 @@ include $(PROGRAM_H)
#TO=$(BIN)
#TARGET=program
#include $(COPY_H)
+
+# The internal solver acting as an external
+PROGRAM=apt-internal-solver
+SLIBS = -lapt-pkg $(INTLLIBS)
+LIB_MAKES = apt-pkg/makefile
+SOURCE = apt-internal-solver.cc
+include $(PROGRAM_H)
+
+# The internal solver acting as an external
+PROGRAM=apt-dump-solver
+SLIBS = -lapt-pkg $(INTLLIBS)
+LIB_MAKES = apt-pkg/makefile
+SOURCE = apt-dump-solver.cc
+include $(PROGRAM_H)