]>
git.saurik.com Git - apt.git/blob - cmdline/apt-internal-solver.cc
1 // -*- mode: cpp; mode: fold -*-
3 /* #####################################################################
5 cover around the internal solver to be able to run it like an external
7 ##################################################################### */
9 // Include Files /*{{{*/
10 #include <apt-pkg/error.h>
11 #include <apt-pkg/cmndline.h>
12 #include <apt-pkg/init.h>
13 #include <apt-pkg/cachefile.h>
14 #include <apt-pkg/strutl.h>
15 #include <apt-pkg/edsp.h>
16 #include <apt-pkg/algorithms.h>
17 #include <apt-pkg/fileutl.h>
26 // ShowHelp - Show a help screen /*{{{*/
27 // ---------------------------------------------------------------------
29 bool ShowHelp(CommandLine
&CmdL
) {
30 ioprintf(std::cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,VERSION
,
31 COMMON_ARCH
,__DATE__
,__TIME__
);
34 _("Usage: apt-internal-resolver\n"
36 "apt-internal-resolver is an interface to use the current internal\n"
37 "like an external resolver for the APT family for debugging or alike\n"
40 " -h This help text.\n"
41 " -q Loggable output - no progress indicator\n"
42 " -c=? Read this configuration file\n"
43 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
44 "apt.conf(5) manual pages for more information and options.\n"
45 " This APT has Super Cow Powers.\n");
49 int main(int argc
,const char *argv
[]) /*{{{*/
51 CommandLine::Args Args
[] = {
52 {'h',"help","help",0},
53 {'v',"version","version",0},
54 {'q',"quiet","quiet",CommandLine::IntLevel
},
55 {'q',"silent","quiet",CommandLine::IntLevel
},
58 CommandLine
CmdL(Args
,_config
);
59 if (pkgInitConfig(*_config
) == false ||
60 CmdL
.Parse(argc
,argv
) == false) {
65 // See if the help should be shown
66 if (_config
->FindB("help") == true ||
67 _config
->FindB("version") == true) {
72 // Deal with stdout not being a tty
73 if (!isatty(STDOUT_FILENO
) && _config
->FindI("quiet", -1) == -1)
74 _config
->Set("quiet","1");
76 if (_config
->FindI("quiet", 0) < 1)
77 _config
->Set("Debug::EDSP::WriteSolution", true);
79 _config
->Set("APT::Solver::Name", "internal");
80 _config
->Set("edsp::scenario", "stdin");
81 int input
= STDIN_FILENO
;
82 FILE* output
= stdout
;
83 SetNonBlock(input
, false);
85 if (pkgInitSystem(*_config
,_system
) == false) {
86 std::cerr
<< "System could not be initialized!" << std::endl
;
90 if (WaitFd(input
, false, 5) == false)
91 std::cerr
<< "WAIT timed out in the resolver" << std::endl
;
93 std::list
<std::string
> install
, remove
;
94 bool upgrade
, distUpgrade
, autoRemove
;
95 if (EDSP::ReadRequest(input
, install
, remove
, upgrade
, distUpgrade
, autoRemove
) == false) {
96 std::cerr
<< "Parsing the request failed!" << std::endl
;
100 pkgCacheFile CacheFile
;
101 CacheFile
.Open(NULL
, false);
103 if (EDSP::ApplyRequest(install
, remove
, CacheFile
) == false) {
104 std::cerr
<< "Failed to apply request to depcache!" << std::endl
;
108 pkgProblemResolver
Fix(CacheFile
);
109 for (std::list
<std::string
>::const_iterator i
= remove
.begin();
110 i
!= remove
.end(); ++i
) {
111 pkgCache::PkgIterator P
= CacheFile
->FindPkg(*i
);
117 for (std::list
<std::string
>::const_iterator i
= install
.begin();
118 i
!= install
.end(); ++i
) {
119 pkgCache::PkgIterator P
= CacheFile
->FindPkg(*i
);
124 for (std::list
<std::string
>::const_iterator i
= install
.begin();
125 i
!= install
.end(); ++i
)
126 CacheFile
->MarkInstall(CacheFile
->FindPkg(*i
), true);
129 if (Fix
.Resolve() == false) {
130 EDSP::WriteError("An error occured", output
);
134 if (EDSP::WriteSolution(CacheFile
, output
) == false) {
135 std::cerr
<< "Failed to output the solution!" << std::endl
;
139 bool const Errors
= _error
->PendingError();
140 if (_config
->FindI("quiet",0) > 0)
141 _error
->DumpErrors();
143 _error
->DumpErrors(GlobalError::DEBUG
);
144 return Errors
== true ? 100 : 0;