aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/filenotify.el14
-rw-r--r--test/lisp/filenotify-tests.el192
2 files changed, 118 insertions, 88 deletions
diff --git a/lisp/filenotify.el b/lisp/filenotify.el
index f66c8ed429a..3f9bb960a9b 100644
--- a/lisp/filenotify.el
+++ b/lisp/filenotify.el
@@ -114,7 +114,7 @@ Could be different from the directory watched by the backend library."
114 (when-let* ((watch (gethash (car event) file-notify-descriptors))) 114 (when-let* ((watch (gethash (car event) file-notify-descriptors)))
115 (directory-file-name 115 (directory-file-name
116 (expand-file-name 116 (expand-file-name
117 (or (and (stringp (nth 2 event)) (nth 2 event)) "") 117 (or (and (stringp (nth 2 event)) (nth 2 event)) "")
118 (file-notify--watch-directory watch))))) 118 (file-notify--watch-directory watch)))))
119 119
120;; Only `gfilenotify' could return two file names. 120;; Only `gfilenotify' could return two file names.
@@ -240,8 +240,10 @@ EVENT is the cadr of the event in `file-notify-handle-event'
240 (file-notify--watch-filename watch) 240 (file-notify--watch-filename watch)
241 (file-name-nondirectory file1))))) 241 (file-name-nondirectory file1)))))
242 ;;(message 242 ;;(message
243 ;;"file-notify-callback %S %S %S %S %S" 243 ;;"file-notify-callback %S %S %S %S %S %S %S"
244 ;;desc action file file1 watch) 244 ;;desc action file file1 watch
245 ;;(file-notify--event-watched-file event)
246 ;;(file-notify--watch-directory watch))
245 (funcall (file-notify--watch-callback watch) 247 (funcall (file-notify--watch-callback watch)
246 (if file1 248 (if file1
247 `(,desc ,action ,file ,file1) 249 `(,desc ,action ,file ,file1)
@@ -419,11 +421,9 @@ DESCRIPTOR should be an object returned by `file-notify-add-watch'."
419 descriptor)) 421 descriptor))
420 t)))) 422 t))))
421 423
422
423;; TODO: 424;; TODO:
424;; * Watching a /dir/file may receive events for dir. 425
425;; (This may be the desired behavior.) 426;; * Watching a file in an already watched directory.
426;; * Watching a file in an already watched directory
427;; If the file is created and *then* a watch is added to that file, the 427;; If the file is created and *then* a watch is added to that file, the
428;; watch might receive events which occurred prior to it being created, 428;; watch might receive events which occurred prior to it being created,
429;; due to the way events are propagated during idle time. Note: This 429;; due to the way events are propagated during idle time. Note: This
diff --git a/test/lisp/filenotify-tests.el b/test/lisp/filenotify-tests.el
index d4e65af4186..4be51afb47f 100644
--- a/test/lisp/filenotify-tests.el
+++ b/test/lisp/filenotify-tests.el
@@ -588,7 +588,6 @@ delivered."
588 588
589(ert-deftest file-notify-test03-events () 589(ert-deftest file-notify-test03-events ()
590 "Check file creation/change/removal notifications." 590 "Check file creation/change/removal notifications."
591 :tags (if (getenv "EMACS_EMBA_CI") '(:unstable))
592 (skip-unless (file-notify--test-local-enabled)) 591 (skip-unless (file-notify--test-local-enabled))
593 592
594 (unwind-protect 593 (unwind-protect
@@ -689,6 +688,11 @@ delivered."
689 '(created deleted stopped)) 688 '(created deleted stopped))
690 ((string-equal (file-notify--test-library) "kqueue") 689 ((string-equal (file-notify--test-library) "kqueue")
691 '(created changed deleted stopped)) 690 '(created changed deleted stopped))
691 ;; inotify on emba does not detect `deleted' and
692 ;; `stopped' events of the directory.
693 ((and (string-equal (file-notify--test-library) "inotify")
694 (getenv "EMACS_EMBA_CI"))
695 '(created changed deleted))
692 (t '(created changed deleted deleted stopped))) 696 (t '(created changed deleted deleted stopped)))
693 (write-region 697 (write-region
694 "any text" nil file-notify--test-tmpfile nil 'no-message) 698 "any text" nil file-notify--test-tmpfile nil 'no-message)
@@ -734,6 +738,11 @@ delivered."
734 '(created created changed changed deleted stopped)) 738 '(created created changed changed deleted stopped))
735 ((string-equal (file-notify--test-library) "kqueue") 739 ((string-equal (file-notify--test-library) "kqueue")
736 '(created changed created changed deleted stopped)) 740 '(created changed created changed deleted stopped))
741 ;; inotify on emba does not detect `deleted' and
742 ;; `stopped' events of the directory.
743 ((and (string-equal (file-notify--test-library) "inotify")
744 (getenv "EMACS_EMBA_CI"))
745 '(created changed created changed deleted deleted))
737 (t '(created changed created changed 746 (t '(created changed created changed
738 deleted deleted deleted stopped))) 747 deleted deleted deleted stopped)))
739 (write-region 748 (write-region
@@ -786,6 +795,11 @@ delivered."
786 '(created created deleted deleted stopped)) 795 '(created created deleted deleted stopped))
787 ((string-equal (file-notify--test-library) "kqueue") 796 ((string-equal (file-notify--test-library) "kqueue")
788 '(created changed renamed deleted stopped)) 797 '(created changed renamed deleted stopped))
798 ;; inotify on emba does not detect `deleted' and
799 ;; `stopped' events of the directory.
800 ((and (string-equal (file-notify--test-library) "inotify")
801 (getenv "EMACS_EMBA_CI"))
802 '(created changed renamed deleted))
789 (t '(created changed renamed deleted deleted stopped))) 803 (t '(created changed renamed deleted deleted stopped)))
790 (write-region 804 (write-region
791 "any text" nil file-notify--test-tmpfile nil 'no-message) 805 "any text" nil file-notify--test-tmpfile nil 'no-message)
@@ -946,7 +960,6 @@ delivered."
946 960
947(ert-deftest file-notify-test05-file-validity () 961(ert-deftest file-notify-test05-file-validity ()
948 "Check `file-notify-valid-p' for files." 962 "Check `file-notify-valid-p' for files."
949 :tags (if (getenv "EMACS_EMBA_CI") '(:unstable))
950 (skip-unless (file-notify--test-local-enabled)) 963 (skip-unless (file-notify--test-local-enabled))
951 964
952 (unwind-protect 965 (unwind-protect
@@ -1004,62 +1017,66 @@ delivered."
1004 ;; Cleanup. 1017 ;; Cleanup.
1005 (file-notify--test-cleanup)) 1018 (file-notify--test-cleanup))
1006 1019
1007 (unwind-protect 1020 ;; inotify on emba does not detect `deleted' and
1008 (let ((file-notify--test-tmpdir 1021 ;; `stopped' events of the directory.
1009 (make-temp-file "file-notify-test-parent" t))) 1022 (unless (and (string-equal (file-notify--test-library) "inotify")
1010 (should 1023 (getenv "EMACS_EMBA_CI"))
1011 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name) 1024 (unwind-protect
1012 file-notify--test-desc 1025 (let ((file-notify--test-tmpdir
1013 (file-notify-add-watch 1026 (make-temp-file "file-notify-test-parent" t)))
1014 file-notify--test-tmpdir 1027 (should
1015 '(change) #'file-notify--test-event-handler))) 1028 (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)
1016 (should (file-notify-valid-p file-notify--test-desc)) 1029 file-notify--test-desc
1017 (file-notify--test-with-events 1030 (file-notify-add-watch
1018 (cond 1031 file-notify--test-tmpdir
1019 ;; w32notify does not raise `deleted' and `stopped' events 1032 '(change) #'file-notify--test-event-handler)))
1020 ;; for the watched directory. 1033 (should (file-notify-valid-p file-notify--test-desc))
1021 ((string-equal (file-notify--test-library) "w32notify") 1034 (file-notify--test-with-events
1022 '(created changed deleted)) 1035 (cond
1023 ;; gvfs-monitor-dir on cygwin does not detect the `created' 1036 ;; w32notify does not raise `deleted' and `stopped'
1024 ;; event reliably. 1037 ;; events for the watched directory.
1025 ((string-equal (file-notify--test-library) "gvfs-monitor-dir.exe") 1038 ((string-equal (file-notify--test-library) "w32notify")
1026 '((deleted stopped) 1039 '(created changed deleted))
1027 (created deleted stopped))) 1040 ;; gvfs-monitor-dir on cygwin does not detect the
1028 ;; There are two `deleted' events, for the file and for the 1041 ;; `created' event reliably.
1029 ;; directory. Except for cygwin and kqueue. And cygwin 1042 ((string-equal
1030 ;; does not raise a `changed' event. 1043 (file-notify--test-library) "gvfs-monitor-dir.exe")
1031 ((eq system-type 'cygwin) 1044 '((deleted stopped)
1032 '(created deleted stopped)) 1045 (created deleted stopped)))
1033 ((string-equal (file-notify--test-library) "kqueue") 1046 ;; There are two `deleted' events, for the file and for
1034 '(created changed deleted stopped)) 1047 ;; the directory. Except for cygwin and kqueue. And
1035 (t '(created changed deleted deleted stopped))) 1048 ;; cygwin does not raise a `changed' event.
1036 (write-region 1049 ((eq system-type 'cygwin)
1037 "any text" nil file-notify--test-tmpfile nil 'no-message) 1050 '(created deleted stopped))
1038 (file-notify--test-read-event) 1051 ((string-equal (file-notify--test-library) "kqueue")
1039 (delete-directory file-notify--test-tmpdir 'recursive)) 1052 '(created changed deleted stopped))
1040 ;; After deleting the parent directory, the descriptor must 1053 (t '(created changed deleted deleted stopped)))
1041 ;; not be valid anymore. 1054 (write-region
1042 (should-not (file-notify-valid-p file-notify--test-desc)) 1055 "any text" nil file-notify--test-tmpfile nil 'no-message)
1043 ;; w32notify doesn't generate `stopped' events when the parent 1056 (file-notify--test-read-event)
1044 ;; directory is deleted, which doesn't provide a chance for 1057 (delete-directory file-notify--test-tmpdir 'recursive))
1045 ;; filenotify.el to remove the descriptor from the internal 1058 ;; After deleting the parent directory, the descriptor must
1046 ;; hash table it maintains. So we must remove the descriptor 1059 ;; not be valid anymore.
1047 ;; manually. 1060 (should-not (file-notify-valid-p file-notify--test-desc))
1048 (if (string-equal (file-notify--test-library) "w32notify") 1061 ;; w32notify doesn't generate `stopped' events when the
1049 (file-notify--rm-descriptor file-notify--test-desc)) 1062 ;; parent directory is deleted, which doesn't provide a
1063 ;; chance for filenotify.el to remove the descriptor from
1064 ;; the internal hash table it maintains. So we must remove
1065 ;; the descriptor manually.
1066 (if (string-equal (file-notify--test-library) "w32notify")
1067 (file-notify--rm-descriptor file-notify--test-desc))
1050 1068
1051 ;; The environment shall be cleaned up. 1069 ;; The environment shall be cleaned up.
1052 (file-notify--test-cleanup-p)) 1070 (file-notify--test-cleanup-p))
1053 1071
1054 ;; Cleanup. 1072 ;; Cleanup.
1055 (file-notify--test-cleanup))) 1073 (file-notify--test-cleanup))))
1056 1074
1057(file-notify--deftest-remote file-notify-test05-file-validity 1075(file-notify--deftest-remote file-notify-test05-file-validity
1058 "Check `file-notify-valid-p' via file notification for remote files.") 1076 "Check `file-notify-valid-p' via file notification for remote files.")
1059 1077
1060(ert-deftest file-notify-test06-dir-validity () 1078(ert-deftest file-notify-test06-dir-validity ()
1061 "Check `file-notify-valid-p' for directories." 1079 "Check `file-notify-valid-p' for directories."
1062 :tags (if (getenv "EMACS_EMBA_CI") '(:unstable))
1063 (skip-unless (file-notify--test-local-enabled)) 1080 (skip-unless (file-notify--test-local-enabled))
1064 1081
1065 (unwind-protect 1082 (unwind-protect
@@ -1087,39 +1104,42 @@ delivered."
1087 ;; Cleanup. 1104 ;; Cleanup.
1088 (file-notify--test-cleanup)) 1105 (file-notify--test-cleanup))
1089 1106
1090 (unwind-protect 1107 ;; inotify on emba does not detect `deleted' and
1091 (progn 1108 ;; `stopped' events of the directory.
1092 (should 1109 (unless (and (string-equal (file-notify--test-library) "inotify")
1093 (setq file-notify--test-tmpfile 1110 (getenv "EMACS_EMBA_CI"))
1094 (make-temp-file "file-notify-test-parent" t))) 1111 (unwind-protect
1095 (should 1112 (progn
1096 (setq file-notify--test-desc 1113 (should
1097 (file-notify-add-watch 1114 (setq file-notify--test-tmpfile
1098 file-notify--test-tmpfile '(change) #'ignore))) 1115 (make-temp-file "file-notify-test-parent" t)))
1099 (should (file-notify-valid-p file-notify--test-desc)) 1116 (should
1100 ;; After deleting the directory, the descriptor must not be 1117 (setq file-notify--test-desc
1101 ;; valid anymore. 1118 (file-notify-add-watch
1102 (delete-directory file-notify--test-tmpfile 'recursive) 1119 file-notify--test-tmpfile '(change) #'ignore)))
1103 (file-notify--wait-for-events 1120 (should (file-notify-valid-p file-notify--test-desc))
1104 (file-notify--test-timeout) 1121 ;; After deleting the directory, the descriptor must not be
1105 (not (file-notify-valid-p file-notify--test-desc))) 1122 ;; valid anymore.
1106 (should-not (file-notify-valid-p file-notify--test-desc)) 1123 (delete-directory file-notify--test-tmpfile 'recursive)
1107 (if (string-equal (file-notify--test-library) "w32notify") 1124 (file-notify--wait-for-events
1108 (file-notify--rm-descriptor file-notify--test-desc)) 1125 (file-notify--test-timeout)
1126 (not (file-notify-valid-p file-notify--test-desc)))
1127 (should-not (file-notify-valid-p file-notify--test-desc))
1128 (if (string-equal (file-notify--test-library) "w32notify")
1129 (file-notify--rm-descriptor file-notify--test-desc))
1109 1130
1110 ;; The environment shall be cleaned up. 1131 ;; The environment shall be cleaned up.
1111 (file-notify--test-cleanup-p)) 1132 (file-notify--test-cleanup-p))
1112 1133
1113 ;; Cleanup. 1134 ;; Cleanup.
1114 (file-notify--test-cleanup))) 1135 (file-notify--test-cleanup))))
1115 1136
1116(file-notify--deftest-remote file-notify-test06-dir-validity 1137(file-notify--deftest-remote file-notify-test06-dir-validity
1117 "Check `file-notify-valid-p' via file notification for remote directories.") 1138 "Check `file-notify-valid-p' via file notification for remote directories.")
1118 1139
1119(ert-deftest file-notify-test07-many-events () 1140(ert-deftest file-notify-test07-many-events ()
1120 "Check that events are not dropped." 1141 "Check that events are not dropped."
1121 :tags (if (getenv "EMACS_EMBA_CI") 1142 :tags '(:expensive-test)
1122 '(:expensive-test :unstable) '(:expensive-test))
1123 (skip-unless (file-notify--test-local-enabled)) 1143 (skip-unless (file-notify--test-local-enabled))
1124 1144
1125 (should 1145 (should
@@ -1178,7 +1198,9 @@ delivered."
1178 (file-notify--test-read-event) 1198 (file-notify--test-read-event)
1179 (delete-file file))) 1199 (delete-file file)))
1180 (delete-directory file-notify--test-tmpfile) 1200 (delete-directory file-notify--test-tmpfile)
1181 (if (string-equal (file-notify--test-library) "w32notify") 1201 (if (or (string-equal (file-notify--test-library) "w32notify")
1202 (and (string-equal (file-notify--test-library) "inotify")
1203 (getenv "EMACS_EMBA_CI")))
1182 (file-notify--rm-descriptor file-notify--test-desc)) 1204 (file-notify--rm-descriptor file-notify--test-desc))
1183 1205
1184 ;; The environment shall be cleaned up. 1206 ;; The environment shall be cleaned up.
@@ -1278,8 +1300,7 @@ descriptors that were issued when registering the watches. This
1278test caters for the situation in bug#22736 where the callback for 1300test caters for the situation in bug#22736 where the callback for
1279the directory received events for the file with the descriptor of 1301the directory received events for the file with the descriptor of
1280the file watch." 1302the file watch."
1281 :tags (if (getenv "EMACS_EMBA_CI") 1303 :tags '(:expensive-test)
1282 '(:expensive-test :unstable) '(:expensive-test))
1283 (skip-unless (file-notify--test-local-enabled)) 1304 (skip-unless (file-notify--test-local-enabled))
1284 1305
1285 ;; A directory to be watched. 1306 ;; A directory to be watched.
@@ -1388,11 +1409,20 @@ the file watch."
1388 ;; w32notify does not raise `deleted' and `stopped' 1409 ;; w32notify does not raise `deleted' and `stopped'
1389 ;; events for the watched directory. 1410 ;; events for the watched directory.
1390 ((string-equal (file-notify--test-library) "w32notify") '()) 1411 ((string-equal (file-notify--test-library) "w32notify") '())
1412 ;; inotify on emba does not detect `deleted' and
1413 ;; `stopped' events of the directory.
1414 ((and (string-equal (file-notify--test-library) "inotify")
1415 (getenv "EMACS_EMBA_CI"))
1416 '())
1391 (t '(deleted stopped)))))) 1417 (t '(deleted stopped))))))
1392 (delete-directory file-notify--test-tmpfile 'recursive)) 1418 (delete-directory file-notify--test-tmpfile 'recursive))
1393 (should-not (file-notify-valid-p file-notify--test-desc1)) 1419 (unless (and (string-equal (file-notify--test-library) "inotify")
1394 (should-not (file-notify-valid-p file-notify--test-desc2)) 1420 (getenv "EMACS_EMBA_CI"))
1395 (when (string-equal (file-notify--test-library) "w32notify") 1421 (should-not (file-notify-valid-p file-notify--test-desc1))
1422 (should-not (file-notify-valid-p file-notify--test-desc2)))
1423 (when (or (string-equal (file-notify--test-library) "w32notify")
1424 (and (string-equal (file-notify--test-library) "inotify")
1425 (getenv "EMACS_EMBA_CI")))
1396 (file-notify--rm-descriptor file-notify--test-desc1) 1426 (file-notify--rm-descriptor file-notify--test-desc1)
1397 (file-notify--rm-descriptor file-notify--test-desc2)) 1427 (file-notify--rm-descriptor file-notify--test-desc2))
1398 1428