(repo_root: PathBuf, indexer: Arc<Mutex<Indexer>>)
| 11 | |
| 12 | impl RepoWatcher { |
| 13 | pub fn start(repo_root: PathBuf, indexer: Arc<Mutex<Indexer>>) -> Result<Self> { |
| 14 | let root_for_cb = repo_root.clone(); |
| 15 | let mut watcher = RecommendedWatcher::new( |
| 16 | move |res: notify::Result<notify::Event>| { |
| 17 | let event = match res { |
| 18 | Ok(ev) => ev, |
| 19 | Err(_) => return, |
| 20 | }; |
| 21 | |
| 22 | for path in &event.paths { |
| 23 | if let Some(relative) = to_relative(&root_for_cb, path) { |
| 24 | let mut idx = indexer.lock(); |
| 25 | match event.kind { |
| 26 | EventKind::Remove(_) => { |
| 27 | let _ = idx.delete_file(&relative); |
| 28 | } |
| 29 | EventKind::Modify(_) | EventKind::Create(_) => { |
| 30 | let _ = idx.index_file(&root_for_cb, &relative); |
| 31 | } |
| 32 | _ => {} |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | }, |
| 37 | Config::default(), |
| 38 | )?; |
| 39 | |
| 40 | watcher.watch(&repo_root, RecursiveMode::Recursive)?; |
| 41 | Ok(Self { _watcher: watcher }) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | fn to_relative(root: &Path, path: &Path) -> Option<String> { |
nothing calls this directly
no test coverage detected