From 795ab1fb7eb9854a3afc9e6b5b1335622f4614fd Mon Sep 17 00:00:00 2001 From: Joining7943 <111500881+Joining7943@users.noreply.github.com> Date: Thu, 8 Sep 2022 19:17:40 +0200 Subject: [PATCH] tests/common/util: Fix #3895 broken pipe error when using pipep input in UCommand --- tests/common/util.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/common/util.rs b/tests/common/util.rs index d67c27a59..7f2c2c5a4 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -17,7 +17,7 @@ use std::env; use std::ffi::CString; use std::ffi::OsStr; use std::fs::{self, hard_link, File, OpenOptions}; -use std::io::{Read, Result, Write}; +use std::io::{BufWriter, Read, Result, Write}; #[cfg(unix)] use std::os::unix::fs::{symlink as symlink_dir, symlink as symlink_file}; #[cfg(windows)] @@ -1105,13 +1105,14 @@ impl UCommand { } if let Some(ref input) = self.bytes_into_stdin { - let write_result = child + let child_stdin = child .stdin .take() - .unwrap_or_else(|| panic!("Could not take child process stdin")) - .write_all(input); + .unwrap_or_else(|| panic!("Could not take child process stdin")); + let mut writer = BufWriter::new(child_stdin); + let result = writer.write_all(input); if !self.ignore_stdin_write_error { - if let Err(e) = write_result { + if let Err(e) = result { panic!("failed to write to stdin of child: {}", e); } }