Skip to content

Commit

Permalink
feature(fsevents): multliplex watchers
Browse files Browse the repository at this point in the history
Allow to create multiple watchers and run them in the same runloop

Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg committed Nov 2, 2021
1 parent ecc6f29 commit e557473
Show file tree
Hide file tree
Showing 11 changed files with 598 additions and 202 deletions.
19 changes: 14 additions & 5 deletions src/dune_engine/fs_memo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ let t_ref = ref (Initialization_state.Uninitialized [])
root is not sufficient to receive events for creation of "root/a/b/c/d".
(however, subscribing to "root/a/b/c" is sufficient for that) *)
let watch_path dune_file_watcher path =
try Dune_file_watcher.add_watch dune_file_watcher path with
| Unix.Unix_error (ENOENT, _, _) -> (
match Dune_file_watcher.add_watch dune_file_watcher path with
| Ok () -> ()
| Error `Does_not_exist -> (
(* If we're at the root of the workspace (or the unix root) then we can't
get ENOENT because dune can't start without a workspace and unix root
always exists, so this [_exn] can't raise (except if the user delets the
Expand All @@ -42,9 +43,17 @@ let watch_path dune_file_watcher path =
the parent. We still try to add a watch for the file itself after that
succeeds, in case the file was created already before we started watching
its parent. *)
Dune_file_watcher.add_watch dune_file_watcher containing_dir;
try Dune_file_watcher.add_watch dune_file_watcher path with
| Unix.Unix_error (ENOENT, _, _) -> ())
(match Dune_file_watcher.add_watch dune_file_watcher containing_dir with
| Ok () -> ()
| Error `Does_not_exist ->
Log.info
[ Pp.textf "attempted to add watch to non-existant directory %s"
(Path.to_string containing_dir)
]);
match Dune_file_watcher.add_watch dune_file_watcher path with
| Error `Does_not_exist
| Ok () ->
())

let watch_path_using_ref path =
match !t_ref with
Expand Down
Loading

0 comments on commit e557473

Please sign in to comment.