aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/filenotify.el36
1 files changed, 23 insertions, 13 deletions
diff --git a/lisp/filenotify.el b/lisp/filenotify.el
index 0d7a2b914c6..b6c1f686fe1 100644
--- a/lisp/filenotify.el
+++ b/lisp/filenotify.el
@@ -49,17 +49,16 @@ handler. The value in the hash table is a list
49Several values for a given DIR happen only for `inotify', when 49Several values for a given DIR happen only for `inotify', when
50different files from the same directory are watched.") 50different files from the same directory are watched.")
51 51
52(defun file-notify--rm-descriptor (descriptor &optional what) 52(defun file-notify--rm-descriptor (descriptor)
53 "Remove DESCRIPTOR from `file-notify-descriptors'. 53 "Remove DESCRIPTOR from `file-notify-descriptors'.
54DESCRIPTOR should be an object returned by `file-notify-add-watch'. 54DESCRIPTOR should be an object returned by `file-notify-add-watch'.
55If it is registered in `file-notify-descriptors', a stopped event is sent. 55If it is registered in `file-notify-descriptors', a stopped event is sent."
56WHAT is a file or directory name to be removed, needed just for `inotify'."
57 (let* ((desc (if (consp descriptor) (car descriptor) descriptor)) 56 (let* ((desc (if (consp descriptor) (car descriptor) descriptor))
58 (file (if (consp descriptor) (cdr descriptor))) 57 (file (if (consp descriptor) (cdr descriptor)))
59 (registered (gethash desc file-notify-descriptors)) 58 (registered (gethash desc file-notify-descriptors))
60 (dir (car registered))) 59 (dir (car registered)))
61 60
62 (when (and (consp registered) (or (null what) (string-equal dir what))) 61 (when (consp registered)
63 ;; Send `stopped' event. 62 ;; Send `stopped' event.
64 (dolist (entry (cdr registered)) 63 (dolist (entry (cdr registered))
65 (funcall (cdr entry) 64 (funcall (cdr entry)
@@ -236,7 +235,6 @@ EVENT is the cadr of the event in `file-notify-handle-event'
236 (setq pending-event nil)) 235 (setq pending-event nil))
237 236
238 ;; Check for stopped. 237 ;; Check for stopped.
239 ;;(message "file-notify-callback %S %S %S" file file1 registered)
240 (setq 238 (setq
241 stopped 239 stopped
242 (or 240 (or
@@ -244,10 +242,13 @@ EVENT is the cadr of the event in `file-notify-handle-event'
244 (and 242 (and
245 (memq action '(deleted renamed)) 243 (memq action '(deleted renamed))
246 (= (length (cdr registered)) 1) 244 (= (length (cdr registered)) 1)
247 (string-equal 245 (or
248 (file-name-nondirectory file) 246 (string-equal
249 (or (file-name-nondirectory (car registered)) 247 (file-name-nondirectory file)
250 (car (cadr registered))))))) 248 (file-name-nondirectory (car registered)))
249 (string-equal
250 (file-name-nondirectory file)
251 (car (cadr registered)))))))
251 252
252 ;; Apply callback. 253 ;; Apply callback.
253 (when (and action 254 (when (and action
@@ -266,6 +267,9 @@ EVENT is the cadr of the event in `file-notify-handle-event'
266 (and (stringp file1) 267 (and (stringp file1)
267 (string-equal 268 (string-equal
268 (nth 0 entry) (file-name-nondirectory file1))))) 269 (nth 0 entry) (file-name-nondirectory file1)))))
270 ;;(message
271 ;;"file-notify-callback %S %S %S %S %S"
272 ;;(file-notify--descriptor desc file) action file file1 registered)
269 (if file1 273 (if file1
270 (funcall 274 (funcall
271 callback 275 callback
@@ -276,8 +280,7 @@ EVENT is the cadr of the event in `file-notify-handle-event'
276 280
277 ;; Modify `file-notify-descriptors'. 281 ;; Modify `file-notify-descriptors'.
278 (when stopped 282 (when stopped
279 (file-notify--rm-descriptor 283 (file-notify-rm-watch (file-notify--descriptor desc file))))))
280 (file-notify--descriptor desc file) file)))))
281 284
282;; `kqueue', `gfilenotify' and `w32notify' return a unique descriptor 285;; `kqueue', `gfilenotify' and `w32notify' return a unique descriptor
283;; for every `file-notify-add-watch', while `inotify' returns a unique 286;; for every `file-notify-add-watch', while `inotify' returns a unique
@@ -342,7 +345,12 @@ FILE is the name of the file whose event is being reported."
342 ;; A file name handler could exist even if there is no local 345 ;; A file name handler could exist even if there is no local
343 ;; file notification support. 346 ;; file notification support.
344 (setq desc (funcall 347 (setq desc (funcall
345 handler 'file-notify-add-watch file flags callback)) 348 handler 'file-notify-add-watch
349 ;; kqueue does not report file changes in
350 ;; directory monitor. So we must watch the file
351 ;; itself.
352 (if (eq file-notify--library 'kqueue) file dir)
353 flags callback))
346 354
347 ;; Check, whether Emacs has been compiled with file notification 355 ;; Check, whether Emacs has been compiled with file notification
348 ;; support. 356 ;; support.
@@ -379,7 +387,9 @@ FILE is the name of the file whose event is being reported."
379 l-flags))) 387 l-flags)))
380 388
381 ;; Call low-level function. 389 ;; Call low-level function.
382 (setq desc (funcall func file l-flags 'file-notify-callback))) 390 (setq desc (funcall
391 func (if (eq file-notify--library 'kqueue) file dir)
392 l-flags 'file-notify-callback)))
383 393
384 ;; Modify `file-notify-descriptors'. 394 ;; Modify `file-notify-descriptors'.
385 (setq file (unless (file-directory-p file) (file-name-nondirectory file)) 395 (setq file (unless (file-directory-p file) (file-name-nondirectory file))