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