From 81a6f272c7d2739f07cc01b27cc672778486a25e Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 24 Nov 2020 16:09:23 +1000 Subject: [PATCH] rely on existing --subst call for ${pwd} replacement --- util/process_wrapper/process_wrapper.cc | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/util/process_wrapper/process_wrapper.cc b/util/process_wrapper/process_wrapper.cc index dd86d48e7a..2100ac640d 100644 --- a/util/process_wrapper/process_wrapper.cc +++ b/util/process_wrapper/process_wrapper.cc @@ -28,20 +28,11 @@ using CharType = process_wrapper::System::StrType::value_type; int PW_MAIN(int argc, const CharType* argv[], const CharType* envp[]) { using namespace process_wrapper; - System::StrType current_dir = System::GetWorkingDirectory(); - System::EnvironmentBlock environment_block; // Taking all environment variables from the current process - // and sending them down to the child process, replacing - // ${pwd} with the current folder. + // and sending them down to the child process for (int i = 0; envp[i] != nullptr; ++i) { - System::StrType replaced = envp[i]; - std::size_t location; - while ((location = replaced.find("${pwd}")) != System::StrType::npos) { - replaced = replaced.replace(location, 6, current_dir); - } - - environment_block.push_back(replaced); + environment_block.push_back(envp[i]); } using Subst = std::pair; @@ -81,7 +72,7 @@ int PW_MAIN(int argc, const CharType* argv[], const CharType* envp[]) { } System::StrType value = subst.substr(equal_pos + 1, subst.size()); if (value == PW_SYS_STR("${pwd}")) { - value = current_dir; + value = System::GetWorkingDirectory(); } subst_mappings.push_back({std::move(key), std::move(value)}); } else if (arg == PW_SYS_STR("--env-file")) {