]> git.saurik.com Git - apt.git/blame_incremental - cmdline/apt-dump-solver.cc
tests: use SHA1 checksum only by default in tests
[apt.git] / cmdline / apt-dump-solver.cc
... / ...
CommitLineData
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3/* #####################################################################
4
5 dummy solver to get quickly a scenario file out of APT
6
7 ##################################################################### */
8 /*}}}*/
9// Include Files /*{{{*/
10#include <apt-pkg/edsp.h>
11
12#include <string.h>
13#include <unistd.h>
14#include <cstdio>
15#include <iostream>
16#include <sstream>
17
18#include <config.h>
19 /*}}}*/
20
21// ShowHelp - Show a help screen /*{{{*/
22// ---------------------------------------------------------------------
23/* */
24static bool ShowHelp() {
25 ioprintf(std::cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
26 std::cout <<
27 "Usage: apt-dump-solver\n"
28 "\n"
29 "apt-dump-solver is a dummy solver who just dumps its input to the\n"
30 "file specified in the environment variable APT_EDSP_DUMP_FILENAME and\n"
31 "exists with a proper EDSP error.\n"
32 "\n"
33 " This dump has lost Super Cow Powers.\n";
34 return true;
35}
36 /*}}}*/
37int main(int argc,const char *argv[]) /*{{{*/
38{
39 if (argc > 1 && (strcmp(argv[1], "--help") == 0 || strcmp(argv[1],"-h") == 0 ||
40 strcmp(argv[1],"-v") == 0 || strcmp(argv[1],"--version") == 0)) {
41 ShowHelp();
42 return 0;
43 }
44
45 // we really don't need anything
46 DropPrivileges();
47 char const * const filename = getenv("APT_EDSP_DUMP_FILENAME");
48 if (filename == NULL || strlen(filename) == 0)
49 {
50 EDSP::WriteError("ERR_NO_FILENAME", "You have to set the environment variable APT_EDSP_DUMP_FILENAME\n"
51 "to a valid filename to store the dump of EDSP solver input in.\n"
52 "For example with: export APT_EDSP_DUMP_FILENAME=/tmp/dump.edsp", stdout);
53 return 0;
54 }
55
56 if (strcmp(filename, "/dev/null") != 0)
57 unlink(filename);
58 FileFd input, output;
59 if (input.OpenDescriptor(STDIN_FILENO, FileFd::ReadOnly) == false ||
60 output.Open(filename, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600) == false ||
61 CopyFile(input, output) == false || input.Close() == false || output.Close() == false)
62 {
63 std::ostringstream out;
64 out << "Writing EDSP solver input to file '" << filename << "' failed!\n";
65 _error->DumpErrors(out);
66 EDSP::WriteError("ERR_WRITE_ERROR", out.str(), stdout);
67 return 0;
68 }
69
70 EDSP::WriteError("ERR_JUST_DUMPING", "I am too dumb, i can just dump!\nPlease use one of my friends instead!", stdout);
71 return 0;
72}