From 13ca9b9e8998949b9c6ea171825d959ba660be23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Mon, 23 Aug 2021 04:53:21 +1200 Subject: [PATCH 1/3] #353: add path information to inotify watch/unwatch errors --- src/inotify.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/inotify.rs b/src/inotify.rs index c17c2333..65031b71 100644 --- a/src/inotify.rs +++ b/src/inotify.rs @@ -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); @@ -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()); } @@ -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(); From 64dc388fb8776cf82e86dae207374f5386014528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Mon, 23 Aug 2021 05:02:47 +1200 Subject: [PATCH 2/3] #353: add path information to kqueue watch/unwatch errors --- src/kqueue.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/kqueue.rs b/src/kqueue.rs index 619df009..c16b23e6 100644 --- a/src/kqueue.rs +++ b/src/kqueue.rs @@ -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(()) @@ -286,7 +287,7 @@ 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) @@ -294,10 +295,10 @@ impl EventLoop { .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()?; From 57392ec7ddfa82ebba7c072a5bf7cfe692652710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Mon, 23 Aug 2021 05:11:02 +1200 Subject: [PATCH 3/3] #353: add path information to some more windows errors --- src/windows.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/windows.rs b/src/windows.rs index d38cb026..03ea0805 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -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) = { @@ -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) @@ -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,