Skip to content

Refactoring helpers.Exec io handling (again). - #445

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_406186726
Oct 29, 2021
Merged

Refactoring helpers.Exec io handling (again).#445
copybara-service[bot] merged 1 commit into
masterfrom
test_406186726

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Oct 28, 2021

Copy link
Copy Markdown

Refactoring helpers.Exec io handling (again).

Do away with unique handling depending on the type of input to stderr/stdout writers as this greatly complicated the other features of Exec like validation. Instead:

  • Always allocate our own buffer to receive a copy of stderr/stdout. This avoids a problem where interacting with the buffer inside the helper potentially consumes or modifies it before it gets returned.
  • Use a Multiwriter to copy all stderr/stdout to any user supplied writers; this allows the caller's own writers to receive output as its written, while keeping a copy for the helper to use at the end.
  • cmd.Stdout and cmd.Stderr are always supplied a writer (either multi or single)
  • result.Stdout and result.Stderr always get copies of the outputs

@google-cla google-cla Bot added the cla: yes label Oct 28, 2021
@copybara-service
copybara-service Bot force-pushed the test_406186726 branch 2 times, most recently from 52587cd to 335312a Compare October 28, 2021 18:55
@copybara-service copybara-service Bot changed the title Refactoring helpers.Exec error handling (again). Refactoring helpers.Exec io handling (again). Oct 28, 2021
@copybara-service
copybara-service Bot force-pushed the test_406186726 branch 2 times, most recently from f41628b to 02b369f Compare October 29, 2021 14:54
Do away with unique handling depending on the type of input to stderr/stdout writers as this greatly complicated the other features of Exec like validation. Instead:

* Always allocate our own buffer to receive a copy of stderr/stdout. This avoids a problem where interacting with the buffer inside the helper potentially consumes or modifies it before it gets returned.
* Use a Multiwriter to copy all stderr/stdout to any user supplied writers; this allows the caller's own writers to receive output as its written, while keeping a copy for the helper to use at the end.
* cmd.Stdout and cmd.Stderr are always supplied a writer (either multi or single)
* result.Stdout and result.Stderr always get copies of the outputs

PiperOrigin-RevId: 406359841
@copybara-service
copybara-service Bot merged commit 5992d81 into master Oct 29, 2021
@copybara-service
copybara-service Bot deleted the test_406186726 branch October 29, 2021 15:02
@github-pages
github-pages Bot temporarily deployed to github-pages October 29, 2021 15:03 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants