Skip to content

Commit

Permalink
rely on existing --subst call for ${pwd} replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
dae committed Nov 24, 2020
1 parent d054308 commit 81a6f27
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions util/process_wrapper/process_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<System::StrType, System::StrType>;
Expand Down Expand Up @@ -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")) {
Expand Down

0 comments on commit 81a6f27

Please sign in to comment.