Skip to main content

zccache_watcher/
lib.rs

1//! File watcher for zccache.
2//!
3//! Provides cross-platform file watching with settle/coalesce buffering,
4//! directory ignore filtering, and integration with the metadata cache's
5//! clock-based change tracking.
6//!
7//! Architecture:
8//! ```text
9//! notify (OS thread) → mpsc → SettleBuffer (tokio task) → CacheSystem
10//! ```
11
12#![allow(clippy::missing_errors_doc)]
13
14pub mod ignore;
15pub mod notify_watcher;
16pub mod polling_watcher;
17#[cfg(feature = "python")]
18mod python;
19pub mod recovery;
20pub mod settle;
21
22use zccache_core::NormalizedPath;
23
24pub use ignore::IgnoreFilter;
25pub use notify_watcher::NotifyWatcher;
26pub use polling_watcher::{
27    PollWatchBatch, PollWatchObserver, PollingWatcher, PollingWatcherConfig,
28};
29pub use recovery::OverflowRecovery;
30pub use settle::{SettleBuffer, SettledEvent};
31
32/// Events produced by the file watcher.
33#[derive(Debug, Clone)]
34pub enum WatchEvent {
35    /// A file was modified.
36    Modified(NormalizedPath),
37    /// A file was created.
38    Created(NormalizedPath),
39    /// A file was removed.
40    Removed(NormalizedPath),
41    /// A file was renamed (from, to).
42    Renamed {
43        from: NormalizedPath,
44        to: NormalizedPath,
45    },
46    /// The watcher's event buffer overflowed. All watched paths
47    /// should be considered stale.
48    Overflow,
49    /// An error occurred in the watcher backend.
50    Error(String),
51}
52
53/// Configuration for the file watcher.
54#[derive(Debug, Clone)]
55pub struct WatcherConfig {
56    /// Settle window in milliseconds.
57    pub settle_window_ms: u64,
58    /// Directory patterns to ignore.
59    pub ignore_patterns: Vec<String>,
60}
61
62impl Default for WatcherConfig {
63    fn default() -> Self {
64        Self {
65            settle_window_ms: 50,
66            ignore_patterns: IgnoreFilter::default_patterns(),
67        }
68    }
69}