remove unneeded cwd option from cpp-subprocess

This commit is contained in:
Sebastian Falbesoner 2024-04-16 14:13:08 +02:00
parent 03ffb09c31
commit 2088777ba0
1 changed files with 2 additions and 26 deletions

View File

@ -656,18 +656,6 @@ struct executable: string_arg
executable(T&& arg): string_arg(std::forward<T>(arg)) {} executable(T&& arg): string_arg(std::forward<T>(arg)) {}
}; };
/*!
* Option to set the current working directory
* of the spawned process.
*
* Eg: cwd{"/some/path/x"}
*/
struct cwd: string_arg
{
template <typename T>
cwd(T&& arg): string_arg(std::forward<T>(arg)) {}
};
/*! /*!
* Option to specify environment variables required by * Option to specify environment variables required by
* the spawned process. * the spawned process.
@ -899,7 +887,6 @@ struct ArgumentDeducer
ArgumentDeducer(Popen* p): popen_(p) {} ArgumentDeducer(Popen* p): popen_(p) {}
void set_option(executable&& exe); void set_option(executable&& exe);
void set_option(cwd&& cwdir);
void set_option(environment&& env); void set_option(environment&& env);
void set_option(input&& inp); void set_option(input&& inp);
void set_option(output&& out); void set_option(output&& out);
@ -1083,9 +1070,9 @@ private:
* interface to the client. * interface to the client.
* *
* API's provided by the class: * API's provided by the class:
* 1. Popen({"cmd"}, output{..}, error{..}, cwd{..}, ....) * 1. Popen({"cmd"}, output{..}, error{..}, ....)
* Command provided as a sequence. * Command provided as a sequence.
* 2. Popen("cmd arg1"m output{..}, error{..}, cwd{..}, ....) * 2. Popen("cmd arg1"m output{..}, error{..}, ....)
* Command provided in a single string. * Command provided in a single string.
* 3. wait() - Wait for the child to exit. * 3. wait() - Wait for the child to exit.
* 4. retcode() - The return code of the exited child. * 4. retcode() - The return code of the exited child.
@ -1227,7 +1214,6 @@ private:
#endif #endif
std::string exe_name_; std::string exe_name_;
std::string cwd_;
env_map_t env_; env_map_t env_;
// Command in string format // Command in string format
@ -1507,10 +1493,6 @@ namespace detail {
popen_->exe_name_ = std::move(exe.arg_value); popen_->exe_name_ = std::move(exe.arg_value);
} }
inline void ArgumentDeducer::set_option(cwd&& cwdir) {
popen_->cwd_ = std::move(cwdir.arg_value);
}
inline void ArgumentDeducer::set_option(environment&& env) { inline void ArgumentDeducer::set_option(environment&& env) {
popen_->env_ = std::move(env.env_); popen_->env_ = std::move(env.env_);
} }
@ -1583,12 +1565,6 @@ namespace detail {
if (stream.err_write_ != -1 && stream.err_write_ > 2) if (stream.err_write_ != -1 && stream.err_write_ > 2)
close(stream.err_write_); close(stream.err_write_);
// Change the working directory if provided
if (parent_->cwd_.length()) {
sys_ret = chdir(parent_->cwd_.c_str());
if (sys_ret == -1) throw OSError("chdir failed", errno);
}
// Replace the current image with the executable // Replace the current image with the executable
if (parent_->env_.size()) { if (parent_->env_.size()) {
for (auto& kv : parent_->env_) { for (auto& kv : parent_->env_) {