From 385d9f2f23057bc5808b5e013e77ba16d1c94da4 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 7 Jun 2016 17:01:33 +0200 Subject: edsp: optionally store a compressed copy of the last scenario For bugreports and co it could be handy to have the scenario and all the settings used in it around later for inspection for EDSP like protocols. EDSP might not be the most interesting as the user can still interrupt the process before the solution is applied and users tend to have an opinion on the "rightness" of a solution, so it is disabled by default. --- apt-pkg/edsp.cc | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) (limited to 'apt-pkg/edsp.cc') diff --git a/apt-pkg/edsp.cc b/apt-pkg/edsp.cc index 94cac4eb1..58d2769f9 100644 --- a/apt-pkg/edsp.cc +++ b/apt-pkg/edsp.cc @@ -597,10 +597,12 @@ bool EDSP::WriteRequest(pkgDepCache &Cache, FileFd &output, WriteOkay(Okay, output, "Forbid-New-Install: yes\n"); if (flags & Request::FORBID_REMOVE) WriteOkay(Okay, output, "Forbid-Remove: yes\n"); + auto const solver = _config->Find("APT::Solver", "internal"); + WriteOkay(Okay, output, "Solver: ", solver, "\n"); if (_config->FindB("APT::Solver::Strict-Pinning", true) == false) WriteOkay(Okay, output, "Strict-Pinning: no\n"); string solverpref("APT::Solver::"); - solverpref.append(_config->Find("APT::Solver", "internal")).append("::Preferences"); + solverpref.append(solver).append("::Preferences"); if (_config->Exists(solverpref) == true) WriteOkay(Okay, output, "Preferences: ", _config->Find(solverpref,""), "\n"); return WriteOkay(Okay, output, "\n"); @@ -926,15 +928,23 @@ bool EDSP::WriteError(char const * const uuid, std::string const &message, FileF "\n\n"); } /*}}}*/ +static std::string findExecutable(std::vector const &dirs, char const * const binary) {/*{{{*/ + for (auto && dir : dirs) { + std::string const file = flCombine(dir, binary); + if (RealFileExists(file) == true) + return file; + } + return ""; +} + /*}}}*/ static pid_t ExecuteExternal(char const* const type, char const * const binary, char const * const configdir, int * const solver_in, int * const solver_out) {/*{{{*/ - std::vector const solverDirs = _config->FindVector(configdir); - std::string file; - for (std::vector::const_iterator dir = solverDirs.begin(); - dir != solverDirs.end(); ++dir) { - file = flCombine(*dir, binary); - if (RealFileExists(file.c_str()) == true) - break; - file.clear(); + auto const solverDirs = _config->FindVector(configdir); + auto const file = findExecutable(solverDirs, binary); + std::string dumper; + { + dumper = findExecutable(solverDirs, "apt-dump-solver"); + if (dumper.empty()) + dumper = findExecutable(solverDirs, "dump"); } if (file.empty() == true) @@ -955,8 +965,18 @@ static pid_t ExecuteExternal(char const* const type, char const * const binary, if (Solver == 0) { dup2(external[0], STDIN_FILENO); dup2(external[3], STDOUT_FILENO); - const char* calling[2] = { file.c_str(), 0 }; - execv(calling[0], (char**) calling); + auto const dumpfile = _config->FindFile((std::string("Dir::Log::") + type).c_str()); + auto const dumpdir = flNotFile(dumpfile); + if (dumper.empty() || dumpfile.empty() || dumper == file || CreateAPTDirectoryIfNeeded(dumpdir, dumpdir) == false) + { + char const * const calling[] = { file.c_str(), nullptr }; + execv(calling[0], const_cast(calling)); + } + else + { + char const * const calling[] = { dumper.c_str(), dumpfile.c_str(), file.c_str(), nullptr }; + execv(calling[0], const_cast(calling)); + } std::cerr << "Failed to execute " << type << " '" << binary << "'!" << std::endl; _exit(100); } -- cgit v1.2.3