You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
773 B
Rust

use std::{
path::Path,
sync::mpsc,
time::Duration,
};
use notify::{
DebouncedEvent,
RecommendedWatcher,
RecursiveMode,
Watcher,
watcher,
};
use tracing::info;
use crate::Error;
pub(crate) fn start_watching(
tx: mpsc::Sender<DebouncedEvent>,
watch_path: &Path
) -> Result<RecommendedWatcher, Error>
{
let mut watcher = watcher(tx, Duration::from_secs(2))
.map_err(Error::CreateWatcher)?;
// Watch the path in non-recursive mode, so events are not generated for nodes in
// sub-directories.
watcher.watch(watch_path, RecursiveMode::NonRecursive)
.map_err(|err| Error::WatchDir(watch_path.to_owned(), err))?;
info!(path = %watch_path.to_string_lossy(), "Watching directory");
Ok(watcher)
}