Skip to content

Commit

Permalink
Fix issue 105 (notify-rs#108)
Browse files Browse the repository at this point in the history
* Check if path exists

In order to inform watch if a path exists, append_path now returns a Result<()>
  • Loading branch information
Noe Thalheim authored and dfaust committed Jan 12, 2017
1 parent 1085421 commit 850ff40
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/fsevent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ impl FsEventWatcher {
}

// https://github.com/thibaudgg/rb-fsevent/blob/master/ext/fsevent_watch/main.c
fn append_path<P: AsRef<Path>>(&mut self, path: P, recursive_mode: RecursiveMode) {
fn append_path<P: AsRef<Path>>(&mut self, path: P, recursive_mode: RecursiveMode) -> Result<()> {
if !path.as_ref().exists() {
return Err(Error::PathNotFound);
}
let str_path = path.as_ref().to_str().unwrap();
unsafe {
let cf_path = cf::str_path_to_cfstring_ref(str_path);
Expand All @@ -149,6 +152,7 @@ impl FsEventWatcher {
}
self.recursive_info.insert(path.as_ref().to_path_buf().canonicalize().unwrap(),
recursive_mode.is_recursive());
Ok(())
}

fn run(&mut self) -> Result<()> {
Expand Down Expand Up @@ -350,7 +354,7 @@ impl Watcher for FsEventWatcher {

fn watch<P: AsRef<Path>>(&mut self, path: P, recursive_mode: RecursiveMode) -> Result<()> {
self.stop();
self.append_path(path, recursive_mode);
try!(self.append_path(path, recursive_mode));
self.run()
}

Expand Down

0 comments on commit 850ff40

Please sign in to comment.