forked from mirrors/jj
signing: ensure child processes are wait()ed on I/O error
This will also provide a better error indication. If write() failed, the child process would presumably have exited with non-zero status and error message to stderr.
This commit is contained in:
parent
a09ee4b9a3
commit
fa7864edeb
2 changed files with 9 additions and 9 deletions
|
@ -68,9 +68,10 @@ fn parse_gpg_verify_output(
|
|||
|
||||
fn run_sign_command(command: &mut Command, input: &[u8]) -> Result<Vec<u8>, GpgError> {
|
||||
let process = command.stderr(Stdio::piped()).spawn()?;
|
||||
process.stdin.as_ref().unwrap().write_all(input)?;
|
||||
let write_result = process.stdin.as_ref().unwrap().write_all(input);
|
||||
let output = process.wait_with_output()?;
|
||||
if output.status.success() {
|
||||
write_result?;
|
||||
Ok(output.stdout)
|
||||
} else {
|
||||
Err(GpgError::Command {
|
||||
|
|
|
@ -60,18 +60,17 @@ fn parse_utf8_string(data: Vec<u8>) -> SshResult<String> {
|
|||
|
||||
fn run_command(command: &mut Command, stdin: &[u8]) -> SshResult<Vec<u8>> {
|
||||
let process = command.spawn()?;
|
||||
process.stdin.as_ref().unwrap().write_all(stdin)?;
|
||||
|
||||
let write_result = process.stdin.as_ref().unwrap().write_all(stdin);
|
||||
let output = process.wait_with_output()?;
|
||||
|
||||
if !output.status.success() {
|
||||
return Err(SshError::Command {
|
||||
if output.status.success() {
|
||||
write_result?;
|
||||
Ok(output.stdout)
|
||||
} else {
|
||||
Err(SshError::Command {
|
||||
exit_status: output.status,
|
||||
stderr: String::from_utf8_lossy(&output.stderr).trim_end().into(),
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
Ok(output.stdout)
|
||||
}
|
||||
|
||||
// This attempts to convert given key data into a file and return the filepath.
|
||||
|
|
Loading…
Reference in a new issue