use std::io::Result;
use std::path::Path;
use futures::Stream;
use inotify::{EventOwned, Inotify, WatchMask};
pub(crate) struct Watcher {
ino: Inotify,
}
impl Watcher {
pub(crate) fn new(path: &Path) -> Result<Self> {
let ino = Inotify::init()?;
ino.watches().add(
path,
WatchMask::CLOSE_WRITE | WatchMask::MOVED_TO | WatchMask::ONLYDIR,
)?;
Ok(Self {
ino,
})
}
pub(crate) fn events(self) -> Result<impl Stream<Item = Result<EventOwned>>> {
let vec = Box::new([0; 1024]);
self.ino.into_event_stream(Box::leak(vec))
}
}