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

Add path information to inotify and kqueue watch/unwatch errors #354

Merged
merged 3 commits into from Aug 22, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/inotify.rs
Expand Up @@ -485,12 +485,12 @@ impl EventLoop {
if let Some(ref mut inotify) = self.inotify {
match inotify.add_watch(&path, watchmask) {
Err(e) => {
// do not report inotify limits as "no more space" on linux #266
if e.raw_os_error() == Some(libc::ENOSPC) {
Err(Error::new(ErrorKind::MaxFilesWatch))
Err(if e.raw_os_error() == Some(libc::ENOSPC) {
// do not report inotify limits as "no more space" on linux #266
Error::new(ErrorKind::MaxFilesWatch)
} else {
Err(Error::io(e))
}
Error::io(e)
}.add_path(path))
}
Ok(w) => {
watchmask.remove(WatchMask::MASK_ADD);
Expand All @@ -507,17 +507,17 @@ impl EventLoop {

fn remove_watch(&mut self, path: PathBuf, remove_recursive: bool) -> Result<()> {
match self.watches.remove(&path) {
None => return Err(Error::watch_not_found()),
None => return Err(Error::watch_not_found().add_path(path)),
Some((w, _, is_recursive)) => {
if let Some(ref mut inotify) = self.inotify {
inotify.rm_watch(w.clone()).map_err(Error::io)?;
inotify.rm_watch(w.clone()).map_err(|e| Error::io(e).add_path(path.clone()))?;
self.paths.remove(&w);

if is_recursive || remove_recursive {
let mut remove_list = Vec::new();
for (w, p) in &self.paths {
if p.starts_with(&path) {
inotify.rm_watch(w.clone()).map_err(Error::io)?;
inotify.rm_watch(w.clone()).map_err(|e| Error::io(e).add_path(p.into()))?;
self.watches.remove(p);
remove_list.push(w.clone());
}
Expand All @@ -534,8 +534,8 @@ impl EventLoop {

fn remove_all_watches(&mut self) -> Result<()> {
if let Some(ref mut inotify) = self.inotify {
for w in self.paths.keys() {
inotify.rm_watch(w.clone()).map_err(Error::io)?;
for (w, p) in &self.paths {
inotify.rm_watch(w.clone()).map_err(|e| Error::io(e).add_path(p.into()))?;
}
self.watches.clear();
self.paths.clear();
Expand Down
13 changes: 7 additions & 6 deletions src/kqueue.rs
Expand Up @@ -274,7 +274,8 @@ impl EventLoop {
| FilterFlag::NOTE_REVOKE;

self.kqueue
.add_filename(&path, event_filter, filter_flags)?;
.add_filename(&path, event_filter, filter_flags)
.map_err(|e| Error::io(e).add_path(path.clone()))?;
self.watches.insert(path, is_recursive);
self.kqueue.watch()?;
Ok(())
Expand All @@ -286,18 +287,18 @@ impl EventLoop {
Some(is_recursive) => {
self.kqueue
.remove_filename(&path, EventFilter::EVFILT_VNODE)
.map_err(|e| Error::io(e))?;
.map_err(|e| Error::io(e).add_path(path.clone()))?;

if is_recursive || remove_recursive {
for entry in WalkDir::new(path)
.follow_links(true)
.into_iter()
.filter_map(filter_dir)
{
self.kqueue.remove_filename(
entry.path().to_path_buf(),
EventFilter::EVFILT_VNODE,
)?;
let p = entry.path().to_path_buf();
self.kqueue
.remove_filename(&p, EventFilter::EVFILT_VNODE)
.map_err(|e| Error::io(e).add_path(p))?;
}
}
self.kqueue.watch()?;
Expand Down
6 changes: 3 additions & 3 deletions src/windows.rs
Expand Up @@ -147,7 +147,7 @@ impl ReadDirectoryChangesServer {
if !path.is_dir() && !path.is_file() {
return Err(Error::generic(
"Input watch path is neither a file nor a directory.",
));
).add_path(path));
}

let (watching_file, dir_target) = {
Expand Down Expand Up @@ -181,7 +181,7 @@ impl ReadDirectoryChangesServer {
Error::generic(
"You attempted to watch a single file, but parent \
directory could not be opened.",
)
).add_path(path)
} else {
// TODO: Call GetLastError for better error info?
Error::path_not_found().add_path(path)
Expand All @@ -200,7 +200,7 @@ impl ReadDirectoryChangesServer {
unsafe {
handleapi::CloseHandle(handle);
}
return Err(Error::generic("Failed to create semaphore for watch."));
return Err(Error::generic("Failed to create semaphore for watch.").add_path(path));
}
let rd = ReadData {
dir: dir_target,
Expand Down