Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 18 additions & 23 deletions src/inotify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ impl INotifyHandler {
fn add_watch_recursively(&mut self, path: PathBuf) -> Result<(), Error> {
match metadata(&path) {
Err(e) => return Err(Error::Io(e)),
Ok(m) => match m.is_dir() {
false => return self.add_watch(path),
true => {}
Ok(m) => if !m.is_dir() {
return self.add_watch(path);
}
}

Expand All @@ -108,20 +107,17 @@ impl INotifyHandler {
| flags::IN_MOVED_FROM
| flags::IN_MOVED_TO
| flags::IN_MOVE_SELF;
match self.watches.get(&path) {
None => {},
Some(p) => {
watching.insert((&p.1).clone());
watching.insert(flags::IN_MASK_ADD);
}
if let Some(p) = self.watches.get(&path) {
watching.insert(p.1);
watching.insert(flags::IN_MASK_ADD);
}

match self.inotify.add_watch(&path, watching.bits()) {
Err(e) => return Err(Error::Io(e)),
Err(e) => Err(Error::Io(e)),
Ok(w) => {
watching.remove(flags::IN_MASK_ADD);
self.watches.insert(path.clone(), (w.clone(), watching));
(*self.paths).write().unwrap().insert(w.clone(), path);
self.watches.insert(path.clone(), (w, watching));
(*self.paths).write().unwrap().insert(w, path);
Ok(())
}
}
Expand All @@ -131,13 +127,13 @@ impl INotifyHandler {
match self.watches.remove(&path) {
None => Err(Error::WatchNotFound),
Some(p) => {
let w = &p.0;
match self.inotify.rm_watch(w.clone()) {
let w = p.0;
match self.inotify.rm_watch(w) {
Err(e) => Err(Error::Io(e)),
Ok(_) => {
// Nothing depends on the value being gone
// from here now that inotify isn't watching.
(*self.paths).write().unwrap().remove(w);
(*self.paths).write().unwrap().remove(&w);
Ok(())
}
}
Expand Down Expand Up @@ -165,14 +161,13 @@ fn handle_event(event: wrapper::Event, tx: &Sender<Event>, paths: &Arc<RwLock<Ha
o.insert(op::CHMOD);
}

let path = match event.name.is_empty() {
true => {
match (*paths).read().unwrap().get(&event.wd) {
Some(p) => Some(p.clone()),
None => None
}
},
false => paths.read().unwrap().get(&event.wd).map(|root| root.join(&event.name)),
let path = if event.name.is_empty() {
match (*paths).read().unwrap().get(&event.wd) {
Some(p) => Some(p.clone()),
None => None
}
} else {
paths.read().unwrap().get(&event.wd).map(|root| root.join(&event.name))
};

let _ = tx.send(Event {
Expand Down
5 changes: 3 additions & 2 deletions src/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::fs;
use std::thread;
use super::{Error, Event, op, Watcher};
use std::path::{Path, PathBuf};
use std::time::Duration;
use self::walkdir::WalkDir;

use filetime::FileTime;
Expand Down Expand Up @@ -42,7 +43,7 @@ impl PollWatcher {
let mut mtimes: HashMap<PathBuf, u64> = HashMap::new();
loop {
if delay != 0 {
thread::sleep_ms(delay);
thread::sleep(Duration::from_millis(delay as u64));
}
if !(*open.read().unwrap()) {
break
Expand Down Expand Up @@ -104,7 +105,7 @@ impl PollWatcher {
},
Ok(stat) => {
let modified = FileTime::from_last_modification_time(&stat).seconds();
match mtimes.insert(path.clone().to_path_buf(), modified) {
match mtimes.insert(path.to_path_buf(), modified) {
None => continue, // First run
Some(old) => {
if modified > old {
Expand Down