mirror of
https://github.com/watchexec/watchexec.git
synced 2024-09-29 22:51:33 +02:00
[run] Always canonicalize input paths (#113)
A client may pass non-canonicalized paths into `watch`, and these are therefore not matched against the filters correctly. Thus, some events could call a Handler's `on_update` method even when an ignored file was changed.
See repro: https://github.com/SpiralP/rust-cargo-watch-test
This bug was introduced in aae5a216b0
.
This commit is contained in:
parent
867ef7bc3c
commit
dbc52e012e
11
src/cli.rs
11
src/cli.rs
@ -2,7 +2,6 @@ use clap::{App, Arg, Error};
|
|||||||
use error;
|
use error;
|
||||||
use std::{
|
use std::{
|
||||||
ffi::OsString,
|
ffi::OsString,
|
||||||
fs::canonicalize,
|
|
||||||
path::{PathBuf, MAIN_SEPARATOR},
|
path::{PathBuf, MAIN_SEPARATOR},
|
||||||
process::Command,
|
process::Command,
|
||||||
};
|
};
|
||||||
@ -146,11 +145,11 @@ where
|
|||||||
};
|
};
|
||||||
|
|
||||||
let cmd: Vec<String> = values_t!(args.values_of("command"), String)?;
|
let cmd: Vec<String> = values_t!(args.values_of("command"), String)?;
|
||||||
let str_paths = values_t!(args.values_of("path"), String).unwrap_or(vec![".".into()]);
|
let paths = values_t!(args.values_of("path"), String)
|
||||||
let mut paths = vec![];
|
.unwrap_or(vec![".".into()])
|
||||||
for path in str_paths {
|
.iter()
|
||||||
paths.push(canonicalize(&path).map_err(|e| error::Error::Canonicalization(path, e))?);
|
.map(|string_path| string_path.into())
|
||||||
}
|
.collect();
|
||||||
|
|
||||||
// Treat --kill as --signal SIGKILL (for compatibility with older syntax)
|
// Treat --kill as --signal SIGKILL (for compatibility with older syntax)
|
||||||
let signal = if args.is_present("kill") {
|
let signal = if args.is_present("kill") {
|
||||||
|
17
src/run.rs
17
src/run.rs
@ -1,6 +1,6 @@
|
|||||||
use cli::{clear_screen, Args};
|
use cli::{clear_screen, Args};
|
||||||
use env_logger;
|
use env_logger;
|
||||||
use error::Result;
|
use error::{Error, Result};
|
||||||
use gitignore;
|
use gitignore;
|
||||||
use log;
|
use log;
|
||||||
use notification_filter::NotificationFilter;
|
use notification_filter::NotificationFilter;
|
||||||
@ -11,6 +11,7 @@ use process::{self, Process};
|
|||||||
use signal::{self, Signal};
|
use signal::{self, Signal};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
|
fs::canonicalize,
|
||||||
io::Write,
|
io::Write,
|
||||||
sync::{
|
sync::{
|
||||||
mpsc::{channel, Receiver},
|
mpsc::{channel, Receiver},
|
||||||
@ -78,14 +79,22 @@ where
|
|||||||
init_logger(args.debug);
|
init_logger(args.debug);
|
||||||
let mut handler = H::new(args.clone())?;
|
let mut handler = H::new(args.clone())?;
|
||||||
|
|
||||||
let gitignore = gitignore::load(if args.no_vcs_ignore { &[] } else { &args.paths });
|
let mut paths = vec![];
|
||||||
|
for path in args.paths {
|
||||||
|
paths.push(
|
||||||
|
canonicalize(&path)
|
||||||
|
.map_err(|e| Error::Canonicalization(path.to_string_lossy().into_owned(), e))?,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let gitignore = gitignore::load(if args.no_vcs_ignore { &[] } else { &paths });
|
||||||
let filter = NotificationFilter::new(&args.filters, &args.ignores, gitignore)?;
|
let filter = NotificationFilter::new(&args.filters, &args.ignores, gitignore)?;
|
||||||
|
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
let poll = args.poll.clone();
|
let poll = args.poll.clone();
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
let poll_interval = args.poll_interval.clone();
|
let poll_interval = args.poll_interval.clone();
|
||||||
let watcher = Watcher::new(tx.clone(), &args.paths, args.poll, args.poll_interval).or_else(|err| {
|
let watcher = Watcher::new(tx.clone(), &paths, args.poll, args.poll_interval).or_else(|err| {
|
||||||
if poll {
|
if poll {
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
@ -102,7 +111,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
if fallback {
|
if fallback {
|
||||||
return Watcher::new(tx, &args.paths, true, poll_interval);
|
return Watcher::new(tx, &paths, true, poll_interval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user