forked from mirrors/jj
cli: ensure child processes are wait()ed on I/O error
This commit is contained in:
parent
c8023dbd8b
commit
2817e30fc6
2 changed files with 17 additions and 24 deletions
|
@ -94,30 +94,22 @@ fn pinentry_get_pw(url: &str) -> Option<String> {
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
.ok()?;
|
.ok()?;
|
||||||
#[rustfmt::skip]
|
let mut interact = || -> std::io::Result<_> {
|
||||||
pinentry
|
#[rustfmt::skip]
|
||||||
.stdin
|
let req = format!(
|
||||||
.take()
|
"SETTITLE jj passphrase\n\
|
||||||
.unwrap()
|
SETDESC Enter passphrase for {url}\n\
|
||||||
.write_all(
|
SETPROMPT Passphrase:\n\
|
||||||
format!(
|
GETPIN\n"
|
||||||
"SETTITLE jj passphrase\n\
|
);
|
||||||
SETDESC Enter passphrase for {url}\n\
|
pinentry.stdin.take().unwrap().write_all(req.as_bytes())?;
|
||||||
SETPROMPT Passphrase:\n\
|
let mut out = String::new();
|
||||||
GETPIN\n"
|
pinentry.stdout.take().unwrap().read_to_string(&mut out)?;
|
||||||
)
|
Ok(out)
|
||||||
.as_bytes(),
|
};
|
||||||
)
|
let maybe_out = interact();
|
||||||
.ok()?;
|
|
||||||
let mut out = String::new();
|
|
||||||
pinentry
|
|
||||||
.stdout
|
|
||||||
.take()
|
|
||||||
.unwrap()
|
|
||||||
.read_to_string(&mut out)
|
|
||||||
.ok()?;
|
|
||||||
_ = pinentry.wait();
|
_ = pinentry.wait();
|
||||||
for line in out.split('\n') {
|
for line in maybe_out.ok()?.split('\n') {
|
||||||
if !line.starts_with("D ") {
|
if !line.starts_with("D ") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -552,7 +552,7 @@ pub fn generate_diff(
|
||||||
tool_binary: tool.program.clone(),
|
tool_binary: tool.program.clone(),
|
||||||
source,
|
source,
|
||||||
})?;
|
})?;
|
||||||
io::copy(&mut child.stdout.take().unwrap(), writer).map_err(ExternalToolError::Io)?;
|
let copy_result = io::copy(&mut child.stdout.take().unwrap(), writer);
|
||||||
// Non-zero exit code isn't an error. For example, the traditional diff command
|
// Non-zero exit code isn't an error. For example, the traditional diff command
|
||||||
// will exit with 1 if inputs are different.
|
// will exit with 1 if inputs are different.
|
||||||
let exit_status = child.wait().map_err(ExternalToolError::Io)?;
|
let exit_status = child.wait().map_err(ExternalToolError::Io)?;
|
||||||
|
@ -560,6 +560,7 @@ pub fn generate_diff(
|
||||||
if !exit_status.success() {
|
if !exit_status.success() {
|
||||||
writeln!(ui.warning(), "{}", format_tool_aborted(&exit_status)).ok();
|
writeln!(ui.warning(), "{}", format_tool_aborted(&exit_status)).ok();
|
||||||
}
|
}
|
||||||
|
copy_result.map_err(ExternalToolError::Io)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue