[run] Pass ops by reference when possible
This commit is contained in:
parent
ede5505a6b
commit
6a23f77687
|
@ -2,7 +2,7 @@ use pathop::PathOp;
|
|||
use std::collections::{HashMap, HashSet};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn spawn(cmd: &Vec<String>, updated_paths: Vec<PathOp>, no_shell: bool) -> Process {
|
||||
pub fn spawn(cmd: &Vec<String>, updated_paths: &[PathOp], no_shell: bool) -> Process {
|
||||
self::imp::Process::new(cmd, updated_paths, no_shell).expect("unable to spawn process")
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ mod imp {
|
|||
impl Process {
|
||||
pub fn new(
|
||||
cmd: &Vec<String>,
|
||||
updated_paths: Vec<PathOp>,
|
||||
updated_paths: &[PathOp],
|
||||
no_shell: bool,
|
||||
) -> Result<Process> {
|
||||
use nix::unistd::*;
|
||||
|
@ -108,7 +108,7 @@ mod imp {
|
|||
|
||||
debug!("Assembled command {:?}", command);
|
||||
|
||||
let command_envs = super::collect_path_env_vars(&updated_paths);
|
||||
let command_envs = super::collect_path_env_vars(updated_paths);
|
||||
for &(ref name, ref val) in &command_envs {
|
||||
command.env(name, val);
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ mod imp {
|
|||
impl Process {
|
||||
pub fn new(
|
||||
cmd: &Vec<String>,
|
||||
updated_paths: Vec<PathOp>,
|
||||
updated_paths: &[PathOp],
|
||||
no_shell: bool,
|
||||
) -> Result<Process> {
|
||||
use std::os::windows::io::IntoRawHandle;
|
||||
|
@ -276,7 +276,7 @@ mod imp {
|
|||
command.creation_flags(CREATE_SUSPENDED);
|
||||
debug!("Assembled command {:?}", command);
|
||||
|
||||
let command_envs = super::collect_path_env_vars(&updated_paths);
|
||||
let command_envs = super::collect_path_env_vars(updated_paths);
|
||||
for &(ref name, ref val) in &command_envs {
|
||||
command.env(name, val);
|
||||
}
|
||||
|
|
10
src/run.rs
10
src/run.rs
|
@ -64,7 +64,7 @@ pub trait Handler {
|
|||
/// - `Err`: an error has occurred while processing, quit.
|
||||
/// - `Ok(true)`: everything is fine and the loop can continue.
|
||||
/// - `Ok(false)`: everything is fine but we should gracefully stop.
|
||||
fn on_update(&mut self, ops: Vec<PathOp>) -> Result<bool>;
|
||||
fn on_update(&mut self, ops: &[PathOp]) -> Result<bool>;
|
||||
}
|
||||
|
||||
/// Starts watching, and calls a handler when something happens.
|
||||
|
@ -133,7 +133,7 @@ where
|
|||
clear_screen();
|
||||
}
|
||||
|
||||
if !handler.on_update(paths)? {
|
||||
if !handler.on_update(&paths)? {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ pub struct ExecHandler {
|
|||
}
|
||||
|
||||
impl ExecHandler {
|
||||
fn spawn(&mut self, ops: Vec<PathOp>) -> Result<()> {
|
||||
fn spawn(&mut self, ops: &[PathOp]) -> Result<()> {
|
||||
let mut guard = self.child_process.write()?;
|
||||
*guard = Some(process::spawn(
|
||||
&self.args.cmd,
|
||||
|
@ -189,11 +189,11 @@ impl Handler for ExecHandler {
|
|||
|
||||
// Only returns Err() on lock poisoning.
|
||||
fn on_manual(&mut self) -> Result<bool> {
|
||||
self.spawn(Vec::new()).and(Ok(true))
|
||||
self.spawn(&[]).and(Ok(true))
|
||||
}
|
||||
|
||||
// Only returns Err() on lock poisoning.
|
||||
fn on_update(&mut self, ops: Vec<PathOp>) -> Result<bool> {
|
||||
fn on_update(&mut self, ops: &[PathOp]) -> Result<bool> {
|
||||
// We have three scenarios here:
|
||||
//
|
||||
// 1. Make sure the previous run was ended, then run the command again
|
||||
|
|
Loading…
Reference in New Issue