@@ -66,8 +66,13 @@ void uv__fsevents_cb(uv_async_t* cb, int status) {
66
66
handle = cb -> data ;
67
67
68
68
UV__FSEVENTS_WALK (handle , {
69
- if (handle -> fd != -1 )
69
+ if (handle -> fd != -1 ) {
70
+ #ifdef MAC_OS_X_VERSION_10_7
70
71
handle -> cb (handle , event -> path , event -> events , 0 );
72
+ #else
73
+ handle -> cb (handle , NULL , event -> events , 0 );
74
+ #endif /* MAC_OS_X_VERSION_10_7 */
75
+ }
71
76
})
72
77
73
78
if ((handle -> flags & (UV_CLOSING | UV_CLOSED )) == 0 && handle -> fd == -1 )
@@ -84,6 +89,8 @@ void uv__fsevents_event_cb(ConstFSEventStreamRef streamRef,
84
89
size_t i ;
85
90
int len ;
86
91
char * * paths ;
92
+ char * path ;
93
+ char * pos ;
87
94
uv_fs_event_t * handle ;
88
95
uv__fsevents_event_t * event ;
89
96
ngx_queue_t add_list ;
@@ -99,17 +106,50 @@ void uv__fsevents_event_cb(ConstFSEventStreamRef streamRef,
99
106
kFSEventStreamEventFlagEventIdsWrapped |
100
107
kFSEventStreamEventFlagHistoryDone |
101
108
kFSEventStreamEventFlagMount |
102
- kFSEventStreamEventFlagUnmount )) {
109
+ kFSEventStreamEventFlagUnmount |
110
+ kFSEventStreamEventFlagRootChanged )) {
103
111
continue ;
104
112
}
105
113
106
114
/* TODO: Report errors */
107
- len = strlen (paths [i ]);
115
+ path = paths [i ];
116
+ len = strlen (path );
117
+
118
+ /* Remove absolute path prefix */
119
+ if (strstr (path , handle -> realpath ) == path ) {
120
+ path += handle -> realpath_len ;
121
+ len -= handle -> realpath_len ;
122
+
123
+ /* Skip back slash */
124
+ if (* path != 0 ) {
125
+ path ++ ;
126
+ len -- ;
127
+ }
128
+ }
129
+
130
+ #ifdef MAC_OS_X_VERSION_10_7
131
+ /* Ignore events with path equal to directory itself */
132
+ if (len == 0 )
133
+ continue ;
134
+ #endif /* MAC_OS_X_VERSION_10_7 */
135
+
136
+ /* Do not emit events from subdirectories (without option set) */
137
+ pos = strchr (path , '/' );
138
+ if ((handle -> cf_flags & UV_FS_EVENT_RECURSIVE ) == 0 &&
139
+ pos != NULL &&
140
+ pos != path + 1 )
141
+ continue ;
142
+
143
+ #ifndef MAC_OS_X_VERSION_10_7
144
+ path = "" ;
145
+ len = 0 ;
146
+ #endif /* MAC_OS_X_VERSION_10_7 */
147
+
108
148
event = malloc (sizeof (* event ) + len );
109
149
if (event == NULL )
110
150
break ;
111
151
112
- memcpy (event -> path , paths [ i ] , len + 1 );
152
+ memcpy (event -> path , path , len + 1 );
113
153
114
154
if (eventFlags [i ] & kFSEventStreamEventFlagItemModified )
115
155
event -> events = UV_CHANGE ;
@@ -153,6 +193,11 @@ int uv__fsevents_init(uv_fs_event_t* handle) {
153
193
ctx .release = NULL ;
154
194
ctx .copyDescription = NULL ;
155
195
196
+ /* Get absolute path to file */
197
+ handle -> realpath = realpath (handle -> filename , NULL );
198
+ if (handle -> realpath != NULL )
199
+ handle -> realpath_len = strlen (handle -> realpath );
200
+
156
201
/* Initialize paths array */
157
202
path = CFStringCreateWithCString (NULL ,
158
203
handle -> filename ,
@@ -220,6 +265,9 @@ int uv__fsevents_close(uv_fs_event_t* handle) {
220
265
221
266
uv_mutex_destroy (& handle -> cf_mutex );
222
267
uv_sem_destroy (& handle -> cf_sem );
268
+ free (handle -> realpath );
269
+ handle -> realpath = NULL ;
270
+ handle -> realpath_len = 0 ;
223
271
224
272
return 0 ;
225
273
}
0 commit comments