mirror of
https://github.com/watchexec/watchexec.git
synced 2024-09-29 22:51:33 +02:00
Merge pull request #9 from 4tm4j33tk4ur/clippy
some clippy-suggested improvements
This commit is contained in:
commit
2ceefe44db
@ -64,7 +64,7 @@ impl PatternSet {
|
|||||||
let mut excluded = false;
|
let mut excluded = false;
|
||||||
let has_whitelistings = self.patterns.iter().any(|p| p.whitelist);
|
let has_whitelistings = self.patterns.iter().any(|p| p.whitelist);
|
||||||
|
|
||||||
for pattern in self.patterns.iter() {
|
for pattern in &self.patterns {
|
||||||
let matched = pattern.matches(path);
|
let matched = pattern.matches(path);
|
||||||
|
|
||||||
if matched {
|
if matched {
|
||||||
@ -90,23 +90,20 @@ impl Pattern {
|
|||||||
fn new(pattern: &str, root: &Path) -> Result<Pattern, Error> {
|
fn new(pattern: &str, root: &Path) -> Result<Pattern, Error> {
|
||||||
let mut normalized = String::from(pattern);
|
let mut normalized = String::from(pattern);
|
||||||
|
|
||||||
let mut whitelisted = false;
|
let whitelisted = if normalized.starts_with('!') {
|
||||||
if normalized.starts_with("!") {
|
|
||||||
normalized.remove(0);
|
normalized.remove(0);
|
||||||
whitelisted = true;
|
true
|
||||||
}
|
} else { false };
|
||||||
|
|
||||||
let mut anchored = false;
|
let anchored = if normalized.starts_with('/') {
|
||||||
if normalized.starts_with("/") {
|
|
||||||
normalized.remove(0);
|
normalized.remove(0);
|
||||||
anchored = true;
|
true
|
||||||
}
|
} else { false };
|
||||||
|
|
||||||
let mut directory = false;
|
let directory = if normalized.ends_with('/') {
|
||||||
if normalized.ends_with("/") {
|
|
||||||
normalized.pop();
|
normalized.pop();
|
||||||
directory = true;
|
true
|
||||||
}
|
} else { false };
|
||||||
|
|
||||||
if normalized.starts_with("\\#") || normalized.starts_with("\\!") {
|
if normalized.starts_with("\\#") || normalized.starts_with("\\!") {
|
||||||
normalized.remove(0);
|
normalized.remove(0);
|
||||||
@ -145,15 +142,13 @@ impl Pattern {
|
|||||||
None => false
|
None => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if !self.str.contains("/") {
|
else if !self.str.contains('/') {
|
||||||
result = stripped_path.iter().any(|c| {
|
result = stripped_path.iter().any(|c| {
|
||||||
self.pattern.matches_path_with(Path::new(c), &options)
|
self.pattern.matches_path_with(Path::new(c), &options)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else if self.pattern.matches_path_with(stripped_path, &options) {
|
||||||
if self.pattern.matches_path_with(stripped_path, &options) {
|
result = true;
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result
|
result
|
||||||
|
18
src/main.rs
18
src/main.rs
@ -76,10 +76,11 @@ fn get_args<'a>() -> ArgMatches<'a> {
|
|||||||
|
|
||||||
fn init_logger(debug: bool) {
|
fn init_logger(debug: bool) {
|
||||||
let mut log_builder = env_logger::LogBuilder::new();
|
let mut log_builder = env_logger::LogBuilder::new();
|
||||||
let mut level = log::LogLevelFilter::Warn;
|
let level = if debug {
|
||||||
if debug {
|
log::LogLevelFilter::Debug
|
||||||
level = log::LogLevelFilter::Debug;
|
} else {
|
||||||
}
|
log::LogLevelFilter::Warn
|
||||||
|
};
|
||||||
|
|
||||||
log_builder
|
log_builder
|
||||||
.format(|r| format!("*** {}", r.args()))
|
.format(|r| format!("*** {}", r.args()))
|
||||||
@ -166,7 +167,7 @@ fn wait(rx: &Receiver<Event>, filter: &NotificationFilter) -> Result<Event, Recv
|
|||||||
// Block on initial notification
|
// Block on initial notification
|
||||||
let e = try!(rx.recv());
|
let e = try!(rx.recv());
|
||||||
if let Some(ref path) = e.path {
|
if let Some(ref path) = e.path {
|
||||||
if filter.is_excluded(&path) {
|
if filter.is_excluded(path) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -175,11 +176,8 @@ fn wait(rx: &Receiver<Event>, filter: &NotificationFilter) -> Result<Event, Recv
|
|||||||
thread::sleep(time::Duration::from_millis(250));
|
thread::sleep(time::Duration::from_millis(250));
|
||||||
|
|
||||||
// Drain rx buffer and drop them
|
// Drain rx buffer and drop them
|
||||||
loop {
|
while let Ok(_) = rx.try_recv() {
|
||||||
match rx.try_recv() {
|
// nothing to do here
|
||||||
Ok(_) => continue,
|
|
||||||
Err(_) => break,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(e);
|
return Ok(e);
|
||||||
|
@ -33,7 +33,7 @@ impl NotificationFilter {
|
|||||||
|
|
||||||
pub fn add_extension(&mut self, extensions: &str) -> Result<(), NotificationError> {
|
pub fn add_extension(&mut self, extensions: &str) -> Result<(), NotificationError> {
|
||||||
let patterns: Vec<String> = extensions
|
let patterns: Vec<String> = extensions
|
||||||
.split(",")
|
.split(',')
|
||||||
.filter(|ext| !ext.is_empty())
|
.filter(|ext| !ext.is_empty())
|
||||||
.map(|ext| format!("*.{}", ext.replace(".", "")))
|
.map(|ext| format!("*.{}", ext.replace(".", "")))
|
||||||
.collect();
|
.collect();
|
||||||
@ -108,11 +108,11 @@ impl NotificationFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.filters.len() > 0 {
|
if !self.filters.is_empty() {
|
||||||
debug!("Ignoring {:?}: did not match any given filters", path);
|
debug!("Ignoring {:?}: did not match any given filters", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.filters.len() > 0
|
!self.filters.is_empty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user