Fix intermittent test crash (#6268)

* Fix intermittent test crash

* fix windows build
This commit is contained in:
JT
2022-08-09 14:06:46 +12:00
committed by GitHub
parent 121b801baa
commit 555d9ee763
3 changed files with 8 additions and 123 deletions

View File

@ -6,7 +6,6 @@ use nu_protocol::did_you_mean;
use nu_protocol::engine::{EngineState, Stack};
use nu_protocol::{ast::Call, engine::Command, ShellError, Signature, SyntaxShape, Value};
use nu_protocol::{Category, Example, ListStream, PipelineData, RawStream, Span, Spanned};
use nu_system::ForegroundProcess;
use pathdiff::diff_paths;
use std::collections::HashMap;
use std::io::{BufRead, BufReader, Write};
@ -121,7 +120,7 @@ impl ExternalCommand {
let ctrlc = engine_state.ctrlc.clone();
let mut fg_process = ForegroundProcess::new(self.create_process(&input, false, head)?);
let mut process = self.create_process(&input, false, head)?;
let child;
#[cfg(windows)]
@ -140,10 +139,9 @@ impl ExternalCommand {
.iter()
.any(|&cmd| command_name_upper == cmd);
match fg_process.spawn() {
match process.spawn() {
Err(_) => {
let mut fg_process =
ForegroundProcess::new(self.create_process(&input, use_cmd, head)?);
let mut fg_process = self.create_process(&input, use_cmd, head)?;
child = fg_process.spawn();
}
Ok(process) => {
@ -154,7 +152,7 @@ impl ExternalCommand {
#[cfg(not(windows))]
{
child = fg_process.spawn()
child = process.spawn()
}
match child {
@ -197,7 +195,7 @@ impl ExternalCommand {
engine_state.config.use_ansi_coloring = false;
// if there is a string or a stream, that is sent to the pipe std
if let Some(mut stdin_write) = child.as_mut().stdin.take() {
if let Some(mut stdin_write) = child.stdin.take() {
std::thread::spawn(move || {
let input = crate::Table::run(
&crate::Table,
@ -238,7 +236,7 @@ impl ExternalCommand {
// and we create a ListStream that can be consumed
if redirect_stderr {
let stderr = child.as_mut().stderr.take().ok_or_else(|| {
let stderr = child.stderr.take().ok_or_else(|| {
ShellError::ExternalCommand(
"Error taking stderr from external".to_string(),
"Redirects need access to stderr of an external command"
@ -277,7 +275,7 @@ impl ExternalCommand {
}
if redirect_stdout {
let stdout = child.as_mut().stdout.take().ok_or_else(|| {
let stdout = child.stdout.take().ok_or_else(|| {
ShellError::ExternalCommand(
"Error taking stdout from external".to_string(),
"Redirects need access to stdout of an external command"
@ -315,7 +313,7 @@ impl ExternalCommand {
}
}
match child.as_mut().wait() {
match child.wait() {
Err(err) => Err(ShellError::ExternalCommand(
"External command exited with error".into(),
err.to_string(),