diff options
Diffstat (limited to 'paludis/util/process.cc')
-rw-r--r-- | paludis/util/process.cc | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/paludis/util/process.cc b/paludis/util/process.cc index 145812497..0da85b05e 100644 --- a/paludis/util/process.cc +++ b/paludis/util/process.cc @@ -21,6 +21,8 @@ #include <paludis/util/pimp-impl.hh> #include <paludis/util/thread.hh> #include <paludis/util/pipe.hh> +#include <paludis/util/fs_entry.hh> +#include <paludis/util/stringify.hh> #include <iostream> #include <functional> @@ -206,6 +208,7 @@ namespace paludis std::ostream * capture_stderr; std::map<std::string, std::string> setenvs; + std::string chdir; Imp(ProcessCommand && c) : command(std::move(c)), @@ -270,6 +273,10 @@ Process::run() m != m_end ; ++m) ::setenv(m->first.c_str(), m->second.c_str(), 1); + if (! _imp->chdir.empty()) + if (-1 == ::chdir(_imp->chdir.c_str())) + throw ProcessError("chdir() failed"); + _imp->command.exec(); } catch (const ProcessError & e) @@ -309,6 +316,13 @@ Process::setenv(const std::string & a, const std::string & b) return *this; } +Process & +Process::chdir(const FSEntry & f) +{ + _imp->chdir = stringify(f.realpath_if_exists()); + return *this; +} + namespace paludis { template <> |