summaryrefslogtreecommitdiff
path: root/lisp/filenotify.el
diff options
context:
space:
mode:
authorMichael Albinus <michael.albinus@gmx.de>2016-02-22 18:52:37 +0100
committerMichael Albinus <michael.albinus@gmx.de>2016-02-22 18:52:37 +0100
commita9c48d5c9e3cb5952aab1c6e8821677d49068a74 (patch)
tree44eb55c4a5bcfdca58e397015fde7f24989455fd /lisp/filenotify.el
parent6bd9d697fd6d81726fa684fa86ef7369a1ef93de (diff)
downloademacs-a9c48d5c9e3cb5952aab1c6e8821677d49068a74.tar.gz
Additional fixes for file notification
* lisp/filenotify.el (top): Require 'cl when compiling. (file-notify--event-watched-file): New defun. (file-notify--rm-descriptor, file-notify-callback): Handle case of several monitors running in parallel. * test/automated/file-notify-tests.el (file-notify--test-event-test): Simplify test. (file-notify--test-with-events): Get rid of outer definition. Check also results of tests performed in callbacks. (file-notify-test02-events): No wrapping when calling `file-notify-rm-watch'. No special checking for callback tests. (file-notify-test07-backup): Adapt expected events for gfilenotify. (file-notify-test08-watched-file-in-watched-dir): Improve.
Diffstat (limited to 'lisp/filenotify.el')
-rw-r--r--lisp/filenotify.el57
1 files changed, 25 insertions, 32 deletions
diff --git a/lisp/filenotify.el b/lisp/filenotify.el
index ba76baca3b4..21046a85a7a 100644
--- a/lisp/filenotify.el
+++ b/lisp/filenotify.el
@@ -27,6 +27,9 @@
;;; Code:
+(eval-when-compile
+ (require 'cl))
+
(defconst file-notify--library
(cond
((featurep 'inotify) 'inotify)
@@ -54,18 +57,15 @@ different files from the same directory are watched.")
DESCRIPTOR should be an object returned by `file-notify-add-watch'.
If it is registered in `file-notify-descriptors', a stopped event is sent."
(let* ((desc (if (consp descriptor) (car descriptor) descriptor))
- (file (if (consp descriptor) (cdr descriptor)))
(registered (gethash desc file-notify-descriptors))
+ (file (if (consp descriptor) (cdr descriptor) (caadr registered)))
(dir (car registered)))
(when (consp registered)
;; Send `stopped' event.
- (dolist (entry (cdr registered))
- (funcall (cdr entry)
- `(,descriptor stopped
- ,(or (and (stringp (car entry))
- (expand-file-name (car entry) dir))
- dir))))
+ (funcall
+ (cdr (assoc file (cdr registered)))
+ `(,descriptor stopped ,(if file (expand-file-name file dir) dir)))
;; Modify `file-notify-descriptors'.
(if (not file)
@@ -99,6 +99,15 @@ Otherwise, signal a `file-notify-error'."
"A pending file notification events for a future `renamed' action.
It is a form ((DESCRIPTOR ACTION FILE [FILE1-OR-COOKIE]) CALLBACK).")
+(defun file-notify--event-watched-file (event)
+ "Return file or directory being watched.
+Could be different from the directory watched by the backend library."
+ (let* ((desc (if (consp (car event)) (caar event) (car event)))
+ (registered (gethash desc file-notify-descriptors))
+ (file (if (consp (car event)) (cdar event) (caadr registered)))
+ (dir (car registered)))
+ (if file (expand-file-name file dir) dir)))
+
(defun file-notify--event-file-name (event)
"Return file name of file notification event, or nil."
(directory-file-name
@@ -234,26 +243,6 @@ EVENT is the cadr of the event in `file-notify-handle-event'
(funcall (cadr pending-event) (car pending-event))
(setq pending-event nil))
- ;; Check for stopped.
- (setq
- stopped
- (or
- stopped
- (and
- (memq action '(deleted renamed))
- (= (length (cdr registered)) 1)
- ;; Not, when a file is backed up.
- (not (and (stringp file1) (backup-file-name-p file1)))
- (or
- ;; Watched file or directory is concerned.
- (string-equal
- (file-name-nondirectory file)
- (file-name-nondirectory (car registered)))
- ;; File inside a watched directory is concerned.
- (string-equal
- (file-name-nondirectory file)
- (car (cadr registered)))))))
-
;; Apply callback.
(when (and action
(or
@@ -282,11 +271,15 @@ EVENT is the cadr of the event in `file-notify-handle-event'
,action ,file ,file1))
(funcall
callback
- `(,(file-notify--descriptor desc (car entry)) ,action ,file)))))
-
- ;; Modify `file-notify-descriptors'.
- (when stopped
- (file-notify-rm-watch (file-notify--descriptor desc file))))))
+ `(,(file-notify--descriptor desc (car entry)) ,action ,file))))
+
+ ;; Send `stopped' event.
+ (when (and (memq action '(deleted renamed))
+ ;; Not, when a file is backed up.
+ (not (and (stringp file1) (backup-file-name-p file1)))
+ ;; Watched file or directory is concerned.
+ (string-equal file (file-notify--event-watched-file event)))
+ (file-notify-rm-watch (file-notify--descriptor desc (car entry))))))))
;; `kqueue', `gfilenotify' and `w32notify' return a unique descriptor
;; for every `file-notify-add-watch', while `inotify' returns a unique