Skip to content
Myr

command.rs

This file

Path

src/exec/command.rs

52 lines · 1.6 KiB · Rust

Last changed by

Address feedback for removing buffering when running on a single threadThayne McCombsbefore adoptione473060

History of this file

Take it

The walk stopped after 200 commits: lines older than a85f33c point at it.

Clean up build.rssharkdpbefore adoptiona85f33c

lines 1–9why, one step back
1use std::io;
2use std::io::Write;3use std::process::Command;4use std::sync::Mutex;56use crate::error::print_error;7use crate::exit_codes::ExitCode;89/// Executes a command.

Address feedback for removing buffering when running on a single threadThayne McCombsbefore adoptione473060

lines 10–14why, one step back
10pub fn execute_command(
11 mut cmd: Command,12 out_perm: &Mutex<()>,13 enable_output_buffering: bool,14) -> ExitCode {

Clean up build.rssharkdpbefore adoptiona85f33c

line 15why, one step back
15 // Spawn the supplied command.

Address feedback for removing buffering when running on a single threadThayne McCombsbefore adoptione473060

lines 16–17why, one step back
16 let output = if enable_output_buffering {
17 cmd.output()

No buffering cmd output when running on 1 threadMax Trianobefore adoption394e967

line 18why, one step back
18 } else {

Clarifying commentsMax Trianobefore adoption154cd6e

lines 19–20why, one step back
19 // If running on only one thread, don't buffer output
20 // Allows for viewing and interacting with intermediate command output

Address feedback for removing buffering when running on a single threadThayne McCombsbefore adoptione473060

lines 21–23why, one step back
21 cmd.spawn().and_then(|c| c.wait_with_output())
22 };23

Clean up build.rssharkdpbefore adoptiona85f33c

line 24why, one step back
24 // Then wait for the command to exit, if it was spawned.

No buffering cmd output when running on 1 threadMax Trianobefore adoption394e967

line 25why, one step back
25 match output {

Clean up build.rssharkdpbefore adoptiona85f33c

lines 26–33why, one step back
26 Ok(output) => {
27 // While this lock is active, this thread will be the only thread allowed28 // to write its outputs.29 let _lock = out_perm.lock().unwrap();3031 let stdout = io::stdout();32 let stderr = io::stderr();33

No buffering cmd output when running on 1 threadMax Trianobefore adoption394e967

lines 34–35why, one step back
34 let _ = stdout.lock().write_all(&output.stdout);
35 let _ = stderr.lock().write_all(&output.stderr);

Clean up build.rssharkdpbefore adoptiona85f33c

lines 36–50why, one step back
36
37 if output.status.code() == Some(0) {38 ExitCode::Success39 } else {40 ExitCode::GeneralError41 }42 }43 Err(ref why) if why.kind() == io::ErrorKind::NotFound => {44 print_error(format!("Command not found: {:?}", cmd));45 ExitCode::GeneralError46 }47 Err(why) => {48 print_error(format!("Problem while executing command: {}", why));49 ExitCode::GeneralError50 }

No buffering cmd output when running on 1 threadMax Trianobefore adoption394e967

line 51why, one step back
51 }

Clean up build.rssharkdpbefore adoptiona85f33c

line 52why, one step back
52}