Skip to content

Commit f98d65e

Browse files
✨ Add ability to control follow_symlinks behaviour (#54)
1 parent c6859f4 commit f98d65e

4 files changed

Lines changed: 15 additions & 6 deletions

File tree

notifykit/_notifier.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ def __init__(
3737
tick_ms: int = 50,
3838
event_buffer_size: int = 1024,
3939
debug: bool = False,
40+
follow_symlinks: bool = True,
4041
filter: Optional[EventFilter] = None,
4142
) -> None:
4243
self._debounce_ms = debounce_ms
4344
self._tick_ms = tick_ms
4445
self._debug = debug
4546

46-
self._watcher = WatcherWrapper(debounce_ms, event_buffer_size, debug)
47+
self._watcher = WatcherWrapper(debounce_ms, event_buffer_size, debug, follow_symlinks)
4748

4849
# Extract filter config to pass to the Rust side
4950
if filter is not None:

notifykit/_notifykit_lib.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class WatcherWrapper:
110110
debounce_ms: int,
111111
event_buffer_size: int = 1024,
112112
debug: bool = False,
113+
follow_symlinks: bool = True,
113114
) -> None: ...
114115
async def watch(self, paths: List[str], recursive: bool = True, ignore_permission_errors: bool = False) -> None: ...
115116
async def unwatch(self, paths: List[str]) -> None: ...

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ pub struct WatcherWrapper {
3131
#[pymethods]
3232
impl WatcherWrapper {
3333
#[new]
34-
fn __init__(debounce_ms: u64, event_buffer_size: usize, debug: bool) -> PyResult<Self> {
35-
let inner =
36-
Watcher::new(debounce_ms, event_buffer_size, debug).map_err(|e| PyOSError::new_err(e.to_string()))?;
34+
fn __init__(debounce_ms: u64, event_buffer_size: usize, debug: bool, follow_symlinks: bool) -> PyResult<Self> {
35+
let inner = Watcher::new(debounce_ms, event_buffer_size, debug, follow_symlinks)
36+
.map_err(|e| PyOSError::new_err(e.to_string()))?;
3737

3838
Ok(WatcherWrapper {
3939
inner: Arc::new(Mutex::new(inner)),

src/watcher.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ pub(crate) struct Watcher {
3838
}
3939

4040
impl Watcher {
41-
pub fn new(buffering_time_ms: u64, event_buffer_size: usize, debug: bool) -> Result<Self, notify::Error> {
41+
pub fn new(
42+
buffering_time_ms: u64,
43+
event_buffer_size: usize,
44+
debug: bool,
45+
follow_symlinks: bool,
46+
) -> Result<Self, notify::Error> {
4247
// TODO: hide usage of file cache from Watcher
4348
// let file_cache = FileCache::new();
4449
// let file_cache_c = file_cache.clone();
@@ -49,6 +54,8 @@ impl Watcher {
4954

5055
let (tx, _rx) = broadcast::channel::<Vec<EventType>>(event_buffer_size);
5156

57+
let config = notify::Config::default().with_follow_symlinks(follow_symlinks);
58+
5259
let inner = RecommendedWatcher::new(
5360
move |e: Result<Event, notify::Error>| {
5461
let mut event_processor = match processor_c.lock() {
@@ -68,7 +75,7 @@ impl Watcher {
6875
Err(e) => event_processor.add_error(e),
6976
}
7077
},
71-
notify::Config::default(),
78+
config,
7279
)?;
7380

7481
Ok(Self {

0 commit comments

Comments
 (0)