diff --git a/src/config/models.rs b/src/config/models.rs index ba9e00c1..bbd49916 100644 --- a/src/config/models.rs +++ b/src/config/models.rs @@ -102,8 +102,11 @@ pub struct ConfigOptsWatch { #[arg(short, long, value_name = "path")] pub ignore: Option>, /// Using polling mode for detecting changes - #[arg(short, long)] + #[arg(long)] pub poll: bool, + /// Allow disabling the cooldown + #[arg(long)] + pub ignore_cooldown: bool, } /// Config options for the serve system. @@ -331,6 +334,7 @@ impl ConfigOpts { watch: cli.watch, ignore: cli.ignore, poll: cli.poll, + ignore_cooldown: cli.ignore_cooldown, }; let cfg = ConfigOpts { build: None, diff --git a/src/config/rt.rs b/src/config/rt.rs index 8ae32f0b..e379543b 100644 --- a/src/config/rt.rs +++ b/src/config/rt.rs @@ -187,8 +187,10 @@ pub struct RtcWatch { pub paths: Vec, /// Paths to ignore. pub ignored_paths: Vec, - /// Use polling mode for detecting chnages + /// Use polling mode for detecting changes pub poll: bool, + /// Allow disabling the cooldown + pub ignore_cooldown: bool, } impl RtcWatch { @@ -237,6 +239,7 @@ impl RtcWatch { paths, ignored_paths, poll: opts.poll, + ignore_cooldown: opts.ignore_cooldown, }) } } diff --git a/src/watch.rs b/src/watch.rs index 99138aab..9db0bb75 100644 --- a/src/watch.rs +++ b/src/watch.rs @@ -61,6 +61,8 @@ pub struct WatchSystem { /// build cooldown period ensures that no FS events are processed until at least a duration /// of `WATCHER_COOLDOWN` has elapsed since the last build. last_build_finished: Instant, + /// The cooldown for the watcher. [`None`] disables the cooldown. + watcher_cooldown: Option, } impl WatchSystem { @@ -88,6 +90,7 @@ impl WatchSystem { shutdown: BroadcastStream::new(shutdown.subscribe()), build_done_tx, last_build_finished: Instant::now(), + watcher_cooldown: (!cfg.ignore_cooldown).then(|| WATCHER_COOLDOWN), }) } @@ -113,17 +116,19 @@ impl WatchSystem { #[tracing::instrument(level = "trace", skip(self, event))] async fn handle_watch_event(&mut self, event: DebouncedEvent) { - // There are various OS syscalls which can trigger FS changes, even though semantically no - // changes were made. A notorious example which has plagued the trunk watcher - // implementation is `std::fs::copy`, which will trigger watcher changes indicating - // that file contents have been modified. - // - // Given the difficult nature of this issue, we opt for using a cooldown period. Any changes - // events processed within the cooldown period following a build will be ignored. - if Instant::now().duration_since(self.last_build_finished) <= WATCHER_COOLDOWN { - // Purge any other events in the queue. - while let Ok(_event) = self.watch_rx.try_recv() {} - return; + if let Some(cooldown) = self.watcher_cooldown { + // There are various OS syscalls which can trigger FS changes, even though semantically no + // changes were made. A notorious example which has plagued the trunk watcher + // implementation is `std::fs::copy`, which will trigger watcher changes indicating + // that file contents have been modified. + // + // Given the difficult nature of this issue, we opt for using a cooldown period. Any changes + // events processed within the cooldown period following a build will be ignored. + if Instant::now().duration_since(self.last_build_finished) <= cooldown { + // Purge any other events in the queue. + while let Ok(_event) = self.watch_rx.try_recv() {} + return; + } } // Check each path in the event for a match.