Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #49: update inotify to v0.2 #70

Merged
merged 1 commit into from
Jun 4, 2016
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
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ filetime = "^0.1.9"
walkdir = "^0.1.5"

[target.x86_64-unknown-linux-gnu.dependencies]
inotify = "^0.1.12"
inotify = "^0.2.3"
mio = "^0.5.0"

[target.i686-unknown-linux-gnu.dependencies]
inotify = "^0.1.12"
inotify = "^0.2.3"
mio = "^0.5.0"

[target.x86_64-unknown-linux-musl.dependencies]
inotify = "^0.1.12"
inotify = "^0.2.3"
mio = "^0.5.0"

[target.i686-unknown-linux-musl.dependencies]
inotify = "^0.1.12"
inotify = "^0.2.3"
mio = "^0.5.0"

[target.i686-apple-darwin.dependencies]
Expand Down
68 changes: 40 additions & 28 deletions src/inotify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const INOTIFY: mio::Token = mio::Token(0);
pub struct INotifyWatcher(mio::Sender<EventLoopMsg>);

struct INotifyHandler {
inotify: INotify,
inotify: Option<INotify>,
tx: Sender<Event>,
watches: HashMap<PathBuf, (Watch, flags::Mask)>,
paths: Arc<RwLock<HashMap<Watch, PathBuf>>>,
Expand All @@ -44,19 +44,21 @@ impl mio::Handler for INotifyHandler {
INOTIFY => {
assert!(events.is_readable());

match self.inotify.available_events() {
Ok(events) => {
assert!(!events.is_empty());
if let Some(ref mut inotify) = self.inotify {
match inotify.available_events() {
Ok(events) => {
assert!(!events.is_empty());

for e in events {
handle_event(e.clone(), &self.tx, &self.paths)
for e in events {
handle_event(e.clone(), &self.tx, &self.paths)
}
}
Err(e) => {
let _ = self.tx.send(Event {
path: None,
op: Err(Error::Io(e)),
});
}
}
Err(e) => {
let _ = self.tx.send(Event {
path: None,
op: Err(Error::Io(e)),
});
}
}
}
Expand All @@ -76,7 +78,9 @@ impl mio::Handler for INotifyHandler {
for path in self.watches.clone().keys() {
let _ = self.remove_watch(path.to_owned());
}
let _ = self.inotify.close();
if let Some(inotify) = self.inotify.take() {
let _ = inotify.close();
}

event_loop.shutdown();
}
Expand Down Expand Up @@ -115,14 +119,18 @@ impl INotifyHandler {
watching.insert(flags::IN_MASK_ADD);
}

match self.inotify.add_watch(&path, watching.bits()) {
Err(e) => Err(Error::Io(e)),
Ok(w) => {
watching.remove(flags::IN_MASK_ADD);
self.watches.insert(path.clone(), (w, watching));
(*self.paths).write().unwrap().insert(w, path);
Ok(())
if let Some(ref inotify) = self.inotify {
match inotify.add_watch(&path, watching.bits()) {
Err(e) => Err(Error::Io(e)),
Ok(w) => {
watching.remove(flags::IN_MASK_ADD);
self.watches.insert(path.clone(), (w, watching));
(*self.paths).write().unwrap().insert(w, path);
Ok(())
}
}
} else {
Ok(())
}
}

Expand All @@ -131,14 +139,18 @@ impl INotifyHandler {
None => Err(Error::WatchNotFound),
Some(p) => {
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);
Ok(())
if let Some(ref inotify) = self.inotify {
match 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);
Ok(())
}
}
} else {
Ok(())
}
}
}
Expand Down Expand Up @@ -190,7 +202,7 @@ impl Watcher for INotifyWatcher {
let evented_inotify = mio::unix::EventedFd(&inotify_fd);

let handler = INotifyHandler {
inotify: inotify,
inotify: Some(inotify),
tx: tx,
watches: HashMap::new(),
paths: Arc::new(RwLock::new(HashMap::new())),
Expand Down