aboutsummaryrefslogtreecommitdiff
path: root/paludis/util/process.cc
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-19 18:45:40 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-21 14:58:16 +0100
commit1bb84c09850dcf2136bc9134ead3409a3ccaf547 (patch)
treec740028982d8655ab4fa337dc34509f8b8328999 /paludis/util/process.cc
parent625454e26c1ea5fa5640135d34f043adeec54527 (diff)
downloadpaludis-1bb84c09850dcf2136bc9134ead3409a3ccaf547.tar.gz
paludis-1bb84c09850dcf2136bc9134ead3409a3ccaf547.tar.xz
Process::chdir
Diffstat (limited to 'paludis/util/process.cc')
-rw-r--r--paludis/util/process.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/paludis/util/process.cc b/paludis/util/process.cc
index 1458124..0da85b0 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 <>