@@ -31,13 +31,13 @@ impl CmdChildren {
31
31
32
32
/// Waits for the children processes to exit completely, returning the status that they exited with.
33
33
pub fn wait ( & mut self ) -> CmdResult {
34
- // wait for the last child result
35
- let handle = self . children . pop ( ) . unwrap ( ) ;
36
- if let Err ( e ) = handle . wait ( true ) {
37
- let _ = Self :: wait_children ( & mut self . children ) ;
38
- return Err ( e ) ;
39
- }
40
- Self :: wait_children ( & mut self . children )
34
+ let last_child = self . children . pop ( ) . unwrap ( ) ;
35
+ let last_child_res = last_child . wait ( true ) ;
36
+ let other_children_res = Self :: wait_children ( & mut self . children ) ;
37
+
38
+ self . ignore_error
39
+ . then_some ( Ok ( ( ) ) )
40
+ . unwrap_or ( last_child_res . and ( other_children_res ) )
41
41
}
42
42
43
43
fn wait_children ( children : & mut Vec < CmdChild > ) -> CmdResult {
@@ -149,21 +149,23 @@ impl FunChildren {
149
149
}
150
150
151
151
fn inner_wait_with_all ( & mut self , capture_stderr : bool ) -> ( CmdResult , String , String ) {
152
- // wait for the last child result
153
- let last_handle = self . children . pop ( ) . unwrap ( ) ;
154
- let mut stdout_buf = Vec :: new ( ) ;
152
+ let mut stdout = Vec :: new ( ) ;
155
153
let mut stderr = String :: new ( ) ;
156
- let last_res = last_handle. wait_with_all ( capture_stderr, & mut stdout_buf, & mut stderr) ;
157
- let res = CmdChildren :: wait_children ( & mut self . children ) ;
158
- let mut stdout: String = String :: from_utf8_lossy ( & stdout_buf) . into ( ) ;
154
+
155
+ let last_child = self . children . pop ( ) . unwrap ( ) ;
156
+ let last_child_res = last_child. wait_with_all ( capture_stderr, & mut stdout, & mut stderr) ;
157
+ let other_children_res = CmdChildren :: wait_children ( & mut self . children ) ;
158
+ let cmd_result = self
159
+ . ignore_error
160
+ . then_some ( Ok ( ( ) ) )
161
+ . unwrap_or ( last_child_res. and ( other_children_res) ) ;
162
+
163
+ let mut stdout: String = String :: from_utf8_lossy ( & stdout) . into ( ) ;
159
164
if stdout. ends_with ( '\n' ) {
160
165
stdout. pop ( ) ;
161
166
}
162
- if res. is_err ( ) && !self . ignore_error && process:: pipefail_enabled ( ) {
163
- ( res, stdout, stderr)
164
- } else {
165
- ( last_res, stdout, stderr)
166
- }
167
+
168
+ ( cmd_result, stdout, stderr)
167
169
}
168
170
}
169
171
0 commit comments