Skip to content

Commit

Permalink
Merge pull request #74 from vandenoever/only-watch-dirs
Browse files Browse the repository at this point in the history
Only register directories for watching
  • Loading branch information
passcod committed Jun 8, 2016
2 parents 11856a7 + 13c3d04 commit 00375e8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/inotify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ impl mio::Handler for INotifyHandler {
}
}

/// return DirEntry when it is a directory
fn filter_dir(e: walkdir::Result<walkdir::DirEntry>) -> Option<walkdir::DirEntry> {
if let Ok(e) = e {
if let Ok(metadata) = e.metadata() {
if metadata.is_dir() {
return Some(e);
}
}
}
None
}

impl INotifyHandler {
fn add_watch_recursively(&mut self, path: PathBuf) -> Result<()> {
match metadata(&path) {
Expand All @@ -109,7 +121,7 @@ impl INotifyHandler {
for entry in WalkDir::new(path)
.follow_links(true)
.into_iter()
.filter_map(|e| e.ok()) {
.filter_map(|e| filter_dir(e)) {
try!(self.add_watch(entry.path().to_path_buf()));
}

Expand Down

0 comments on commit 00375e8

Please sign in to comment.