Skip to content

Commit

Permalink
Ensure any partial ReadFile response is passed through.
Browse files Browse the repository at this point in the history
This makes sure any partial buffer is consumed, in particular the last write that gives us ERROR_BROKEN_PIPE, and ensures we get any debugging output from msiexec by replacing nulls with ? instead.
  • Loading branch information
BillyONeal committed Mar 3, 2022
1 parent b5eb40c commit a1e5ac5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
7 changes: 2 additions & 5 deletions src/vcpkg/base/downloads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,8 @@ namespace vcpkg
}
}).value_or_exit(VCPKG_LINE_INFO);

auto res = cmd_execute_and_capture_output(Command{}.raw_arg(cmd),
default_working_directory,
get_clean_environment(),
Encoding::Utf8,
EchoInDebug::Show);
auto res = cmd_execute_and_capture_output(
Command{}.raw_arg(cmd), default_working_directory, get_clean_environment(), EchoInDebug::Show);
if (res.exit_code == 0)
{
auto maybe_error =
Expand Down
19 changes: 16 additions & 3 deletions src/vcpkg/base/system.process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,15 +594,28 @@ namespace vcpkg
{
CloseHandle(child_stdin);

DWORD bytes_read = 0;
static constexpr DWORD buffer_size = 1024 * 32;
char buf[buffer_size];
while (ReadFile(child_stdout, static_cast<void*>(buf), buffer_size, &bytes_read, nullptr))
DWORD bytes_read;
BOOL read_file_result;
do
{
bytes_read = 0; // in case ReadFile doesn't update this on failure
Debug::print("wait_and_stream_output() attempt\n");
read_file_result = ReadFile(child_stdout, static_cast<void*>(buf), buffer_size, &bytes_read, nullptr);
std::replace(buf, buf + bytes_read, '\0', '?');
f(StringView{buf, static_cast<size_t>(bytes_read)});
} while (read_file_result);

const auto last_error = GetLastError();
switch (last_error)
{
case ERROR_BROKEN_PIPE:
Debug::print("ReadFile() finished with ERROR_BROKEN_PIPE (probably normal exit)\n");
break;
default: Debug::print("ReadFile() finished with GetLastError(): ", GetLastError(), '\n'); break;
}

Debug::print("ReadFile() finished with GetLastError(): ", GetLastError(), '\n');
CloseHandle(child_stdout);
return proc_info.wait();
}
Expand Down

0 comments on commit a1e5ac5

Please sign in to comment.