Skip to content

unwatch removes the watch handles recursively but only removes the root watch item #8

@sapphi-red

Description

@sapphi-red

Need to think about how remove_watch should work.

notify/notify/src/kqueue.rs

Lines 407 to 450 in 02c3f56

fn remove_watch(&mut self, path: PathBuf) -> Result<()> {
log::trace!("removing kqueue watch: {}", path.display());
match self.watches.remove(&path) {
None => return Err(Error::watch_not_found()),
Some(recursive_mode) => {
self.remove_maybe_recursive_watch(path, recursive_mode.is_recursive())?;
self.kqueue.watch()?;
}
}
Ok(())
}
/// The caller of this function must call `self.kqueue.watch()` afterwards to register the new watch.
fn remove_maybe_recursive_watch(&mut self, path: PathBuf, is_recursive: bool) -> Result<()> {
if is_recursive {
self.remove_single_watch(path.clone())?;
for entry in WalkDir::new(&path)
.follow_links(self.follow_symlinks)
.into_iter()
{
let entry = entry.map_err(map_walkdir_error)?;
if entry.path() == path {
continue;
}
self.remove_single_watch(entry.into_path())?;
}
} else {
self.remove_single_watch(path.clone())?;
}
Ok(())
}
/// Removes a single watch from the kqueue.
///
/// The caller of this function must call `self.kqueue.watch()` afterwards to unregister the old watch.
fn remove_single_watch(&mut self, path: PathBuf) -> Result<()> {
self.kqueue
.remove_filename(&path, EventFilter::EVFILT_VNODE)
.map_err(|e| Error::io(e).add_path(path.clone()))?;
self.watch_handles.remove(&path);
Ok(())
}

Leaving it as-is for now as I don't use it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions