Skip to content

Commit 736b02e

Browse files
authored
feat: make Windows path style configurable (#823)
1 parent c1ff405 commit 736b02e

4 files changed

Lines changed: 316 additions & 16 deletions

File tree

notify/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
## notify 9.0.0 (unreleased)
44

5+
- FIX: [windows] normalize emitted event paths to follow the watched path separator style and trim leading separators; add `Config::with_windows_path_separator_style` for explicit control [#375]
56
- FIX: [macOS] annotate FSEvents clone-related events with `info = "is: clone"` [#465]
67

8+
[#375]: https://github.com/notify-rs/notify/issues/375
79
[#465]: https://github.com/notify-rs/notify/issues/465
810

911
## notify 9.0.0-rc.2 (2026-02-14)

notify/src/config.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ impl RecursiveMode {
2525
}
2626
}
2727

28+
/// Controls how path separators are represented in emitted event paths on Windows.
29+
///
30+
/// This applies to [`ReadDirectoryChangesWatcher`](crate::ReadDirectoryChangesWatcher).
31+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Default)]
32+
pub enum WindowsPathSeparatorStyle {
33+
/// Infer separator style from each watched input path.
34+
///
35+
/// For example, watching `C:/tmp` yields paths with `/`, while watching `C:\tmp`
36+
/// yields paths with `\`.
37+
#[default]
38+
Auto,
39+
40+
/// Always use `/` in emitted event paths.
41+
Slash,
42+
43+
/// Always use `\` in emitted event paths.
44+
Backslash,
45+
}
46+
2847
/// Watcher Backend configuration
2948
///
3049
/// This contains multiple settings that may relate to only one specific backend,
@@ -51,6 +70,9 @@ pub struct Config {
5170

5271
/// See [Config::with_event_kinds]
5372
event_kinds: EventKindMask,
73+
74+
/// See [Config::with_windows_path_separator_style]
75+
windows_path_separator_style: WindowsPathSeparatorStyle,
5476
}
5577

5678
impl Config {
@@ -155,6 +177,24 @@ impl Config {
155177
pub fn event_kinds(&self) -> EventKindMask {
156178
self.event_kinds
157179
}
180+
181+
/// For the [`ReadDirectoryChangesWatcher`](crate::ReadDirectoryChangesWatcher) backend.
182+
///
183+
/// Controls path separator normalization for emitted event paths on Windows.
184+
///
185+
/// The default is [`WindowsPathSeparatorStyle::Auto`], which preserves the
186+
/// separator style implied by each watched input path.
187+
///
188+
/// This can't be changed during runtime.
189+
pub fn with_windows_path_separator_style(mut self, style: WindowsPathSeparatorStyle) -> Self {
190+
self.windows_path_separator_style = style;
191+
self
192+
}
193+
194+
/// Returns current setting.
195+
pub fn windows_path_separator_style(&self) -> WindowsPathSeparatorStyle {
196+
self.windows_path_separator_style
197+
}
158198
}
159199

160200
impl Default for Config {
@@ -164,6 +204,7 @@ impl Default for Config {
164204
compare_contents: false,
165205
follow_symlinks: true,
166206
event_kinds: EventKindMask::ALL,
207+
windows_path_separator_style: WindowsPathSeparatorStyle::Auto,
167208
}
168209
}
169210
}
@@ -279,4 +320,23 @@ mod tests {
279320
assert_eq!(EventKindMask::default(), Config::default().event_kinds());
280321
assert_eq!(EventKindMask::default(), EventKindMask::ALL);
281322
}
323+
324+
#[test]
325+
fn config_default_windows_separator_style_is_auto() {
326+
let config = Config::default();
327+
assert_eq!(
328+
config.windows_path_separator_style(),
329+
WindowsPathSeparatorStyle::Auto
330+
);
331+
}
332+
333+
#[test]
334+
fn config_with_windows_separator_style() {
335+
let config =
336+
Config::default().with_windows_path_separator_style(WindowsPathSeparatorStyle::Slash);
337+
assert_eq!(
338+
config.windows_path_separator_style(),
339+
WindowsPathSeparatorStyle::Slash
340+
);
341+
}
282342
}

notify/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173
174174
#![deny(missing_docs)]
175175

176-
pub use config::{Config, PathOp, RecursiveMode, WatchPathConfig};
176+
pub use config::{Config, PathOp, RecursiveMode, WatchPathConfig, WindowsPathSeparatorStyle};
177177
pub use error::{Error, ErrorKind, Result, UpdatePathsError};
178178
pub use notify_types::event::{self, Event, EventKind, EventKindMask};
179179
use std::path::Path;

0 commit comments

Comments
 (0)