@@ -25,6 +25,8 @@ impl LinuxWatcher {
25
25
impl Watcher for LinuxWatcher {
26
26
fn add ( & self , path : & std:: path:: Path ) -> gpui:: Result < ( ) > {
27
27
let root_path = path. to_path_buf ( ) ;
28
+ // Canonicalize the root path to handle cases where it's a symlink or below one
29
+ let target_path = std:: fs:: canonicalize ( & path) . ok ( ) ;
28
30
29
31
let tx = self . tx . clone ( ) ;
30
32
let pending_paths = self . pending_path_events . clone ( ) ;
@@ -44,10 +46,32 @@ impl Watcher for LinuxWatcher {
44
46
. paths
45
47
. iter ( )
46
48
. filter_map ( |event_path| {
47
- event_path. starts_with ( & root_path) . then ( || PathEvent {
48
- path : event_path. clone ( ) ,
49
- kind,
50
- } )
49
+ // we canonicalize the parent and join with file name to handle cases
50
+ // where the file doesn't exist anymore
51
+ if let Some ( parent) = event_path. parent ( ) {
52
+ if let Ok ( canonical_parent) = std:: fs:: canonicalize ( & parent)
53
+ {
54
+ if event_path. clone ( ) . starts_with ( canonical_parent. clone ( ) )
55
+ || event_path. starts_with ( parent)
56
+ {
57
+ if target_path != Some ( root_path. clone ( ) ) {
58
+ // there are symlinks above workspace root
59
+ if let Some ( file_name) = event_path. file_name ( ) {
60
+ return Some ( PathEvent {
61
+ path : canonical_parent. join ( file_name) ,
62
+ kind,
63
+ } ) ;
64
+ }
65
+ } else {
66
+ return Some ( PathEvent {
67
+ path : event_path. clone ( ) ,
68
+ kind,
69
+ } ) ;
70
+ }
71
+ }
72
+ }
73
+ }
74
+ None
51
75
} )
52
76
. collect :: < Vec < _ > > ( ) ;
53
77
0 commit comments