[run] Further dry the ExecHandler

This commit is contained in:
Félix Saparelli 2019-01-26 17:32:48 +13:00
parent 3dd2f797ab
commit 5846b64020
2 changed files with 13 additions and 37 deletions

View File

@ -82,11 +82,7 @@ mod imp {
#[allow(unknown_lints)] #[allow(unknown_lints)]
#[allow(mutex_atomic)] #[allow(mutex_atomic)]
impl Process { impl Process {
pub fn new( pub fn new(cmd: &Vec<String>, updated_paths: &[PathOp], no_shell: bool) -> Result<Process> {
cmd: &Vec<String>,
updated_paths: &[PathOp],
no_shell: bool,
) -> Result<Process> {
use nix::unistd::*; use nix::unistd::*;
use std::os::unix::process::CommandExt; use std::os::unix::process::CommandExt;
@ -203,11 +199,7 @@ mod imp {
} }
impl Process { impl Process {
pub fn new( pub fn new(cmd: &Vec<String>, updated_paths: &[PathOp], no_shell: bool) -> Result<Process> {
cmd: &Vec<String>,
updated_paths: &[PathOp],
no_shell: bool,
) -> Result<Process> {
use std::os::windows::io::IntoRawHandle; use std::os::windows::io::IntoRawHandle;
use std::os::windows::process::CommandExt; use std::os::windows::process::CommandExt;

View File

@ -149,12 +149,13 @@ pub struct ExecHandler {
impl ExecHandler { impl ExecHandler {
fn spawn(&mut self, ops: &[PathOp]) -> Result<()> { fn spawn(&mut self, ops: &[PathOp]) -> Result<()> {
if self.args.clear_screen {
clear_screen();
}
debug!("Launching child process");
let mut guard = self.child_process.write()?; let mut guard = self.child_process.write()?;
*guard = Some(process::spawn( *guard = Some(process::spawn(&self.args.cmd, ops, self.args.no_shell)?);
&self.args.cmd,
ops,
self.args.no_shell,
)?);
Ok(()) Ok(())
} }
@ -189,7 +190,11 @@ impl Handler for ExecHandler {
// Only returns Err() on lock poisoning. // Only returns Err() on lock poisoning.
fn on_manual(&mut self) -> Result<bool> { fn on_manual(&mut self) -> Result<bool> {
self.spawn(&[]).and(Ok(true)) let cls = self.args.clear_screen;
self.args.clear_screen = false;
self.spawn(&[])?;
self.args.clear_screen = cls;
Ok(true)
} }
// Only returns Err() on lock poisoning. // Only returns Err() on lock poisoning.
@ -208,13 +213,6 @@ impl Handler for ExecHandler {
// Send specified signal to the child, wait for it to exit, then run the command again // Send specified signal to the child, wait for it to exit, then run the command again
(true, true) => { (true, true) => {
signal_process(&self.child_process, self.signal, true); signal_process(&self.child_process, self.signal, true);
// Launch child process
if self.args.clear_screen {
clear_screen();
}
debug!("Launching child process");
self.spawn(ops)?; self.spawn(ops)?;
} }
@ -223,13 +221,6 @@ impl Handler for ExecHandler {
(true, false) => { (true, false) => {
let sigterm = signal::new(Some("SIGTERM".into())); let sigterm = signal::new(Some("SIGTERM".into()));
signal_process(&self.child_process, sigterm, true); signal_process(&self.child_process, sigterm, true);
// Launch child process
if self.args.clear_screen {
clear_screen();
}
debug!("Launching child process");
self.spawn(ops)?; self.spawn(ops)?;
} }
@ -241,13 +232,6 @@ impl Handler for ExecHandler {
// Make sure the previous run was ended, then run the command again // Make sure the previous run was ended, then run the command again
(false, false) => { (false, false) => {
signal_process(&self.child_process, None, true); signal_process(&self.child_process, None, true);
// Launch child process
if self.args.clear_screen {
clear_screen();
}
debug!("Launching child process");
self.spawn(ops)?; self.spawn(ops)?;
} }
} }