]> code.delx.au - gnu-emacs/commitdiff
Introduce `file-notify-valid-p'
authorMichael Albinus <michael.albinus@gmx.de>
Sun, 13 Sep 2015 19:16:40 +0000 (21:16 +0200)
committerMichael Albinus <michael.albinus@gmx.de>
Sun, 13 Sep 2015 19:16:40 +0000 (21:16 +0200)
* lisp/filenotify.el (file-notify-valid-p): New defun.
(gfile-valid-p, w32notify-valid-p): Make them an alias to `identity'.

* lisp/net/tramp-adb.el (tramp-adb-file-name-handler-alist)
* lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist)
* lisp/net/tramp-sh.el (tramp-sh-file-name-handler-alist)
* lisp/net/tramp-smb.el (tramp-smb-file-name-handler-alist)
<file-notify-valid-p>: Add handler.

* lisp/net/tramp.el (tramp-file-name-for-operation):
Add `file-notify-valid-p'.
(tramp-handle-file-notify-valid-p): New defun.

* src/inotify.c (Finotify_valid_p): New defun.
(syms_of_inotify): Declare Sinotify_valid_p.

lisp/filenotify.el
lisp/net/tramp-adb.el
lisp/net/tramp-gvfs.el
lisp/net/tramp-sh.el
lisp/net/tramp-smb.el
lisp/net/tramp.el
src/inotify.c

index 89fc3733eba14491fa2ac56546cccd81f0a21f75..9a48c5ee97956cfecc604f0261e616dd62cb7448 100644 (file)
@@ -357,6 +357,38 @@ DESCRIPTOR should be an object returned by `file-notify-add-watch'."
            ((eq file-notify--library 'w32notify) 'w32notify-rm-watch))
           desc))))))
 
+;; Temporary declarations.
+(defalias 'gfile-valid-p 'identity)
+(defalias 'w32notify-valid-p 'identity)
+
+(defun file-notify-valid-p (descriptor)
+  "Check a watch specified by its DESCRIPTOR.
+DESCRIPTOR should be an object returned by `file-notify-add-watch'."
+  (let* ((desc (if (consp descriptor) (car descriptor) descriptor))
+        (file (if (consp descriptor) (cdr descriptor)))
+         (registered (gethash desc file-notify-descriptors))
+        (dir (car registered))
+        handler)
+
+    (when (stringp dir)
+      (setq handler (find-file-name-handler dir 'file-notify-valid-p))
+
+      (and (or ;; It is a directory.
+               (not file)
+               ;; The file is registered.
+               (assoc file (cdr registered)))
+           (if handler
+               ;; A file name handler could exist even if there is no
+               ;; local file notification support.
+               (funcall handler 'file-notify-valid-p descriptor)
+             (funcall
+              (cond
+               ((eq file-notify--library 'gfilenotify) 'gfile-valid-p)
+               ((eq file-notify--library 'inotify) 'inotify-valid-p)
+               ((eq file-notify--library 'w32notify) 'w32notify-valid-p))
+              desc))
+           t))))
+
 ;; The end:
 (provide 'filenotify)
 
index f818fcd61d62063462d497a6ed7ed2bfca0eb2f5..2a7f1a52f13451609f4f63b18c24c4ac496e297c 100644 (file)
@@ -132,6 +132,7 @@ It is used for TCP/IP devices."
     (file-newer-than-file-p . tramp-handle-file-newer-than-file-p)
     (file-notify-add-watch . tramp-handle-file-notify-add-watch)
     (file-notify-rm-watch . tramp-handle-file-notify-rm-watch)
+    (file-notify-valid-p . tramp-handle-file-notify-valid-p)
     (file-ownership-preserved-p . ignore)
     (file-readable-p . tramp-handle-file-exists-p)
     (file-regular-p . tramp-handle-file-regular-p)
index 4dfdcd76e663ba31c29f8bdad1f8c6e884f4ec35..cf42b5951f78b93012be1f2c646fb3f58aeb39c3 100644 (file)
@@ -443,6 +443,7 @@ Every entry is a list (NAME ADDRESS).")
     (file-newer-than-file-p . tramp-handle-file-newer-than-file-p)
     (file-notify-add-watch . tramp-gvfs-handle-file-notify-add-watch)
     (file-notify-rm-watch . tramp-handle-file-notify-rm-watch)
+    (file-notify-valid-p . tramp-handle-file-notify-valid-p)
     (file-ownership-preserved-p . ignore)
     (file-readable-p . tramp-gvfs-handle-file-readable-p)
     (file-regular-p . tramp-handle-file-regular-p)
index d9490a0c04b0fa9beb776a98c698f29bc0f48114..8598f0e758af26f66c7adf396d75d92176fd19b5 100644 (file)
@@ -1008,6 +1008,7 @@ of command line.")
     (file-newer-than-file-p . tramp-sh-handle-file-newer-than-file-p)
     (file-notify-add-watch . tramp-sh-handle-file-notify-add-watch)
     (file-notify-rm-watch . tramp-handle-file-notify-rm-watch)
+    (file-notify-valid-p . tramp-handle-file-notify-valid-p)
     (file-ownership-preserved-p . tramp-sh-handle-file-ownership-preserved-p)
     (file-readable-p . tramp-sh-handle-file-readable-p)
     (file-regular-p . tramp-handle-file-regular-p)
index c4f0f1f500a2cf6452d1bf4419a7ddc8180f296b..5910d1fd3a46968882e3b671cdf63771eaf78f65 100644 (file)
@@ -247,6 +247,7 @@ See `tramp-actions-before-shell' for more info.")
     (file-newer-than-file-p . tramp-handle-file-newer-than-file-p)
     (file-notify-add-watch . tramp-handle-file-notify-add-watch)
     (file-notify-rm-watch . tramp-handle-file-notify-rm-watch)
+    (file-notify-valid-p . tramp-handle-file-notify-valid-p)
     (file-ownership-preserved-p . ignore)
     (file-readable-p . tramp-handle-file-exists-p)
     (file-regular-p . tramp-handle-file-regular-p)
index 0969048c433fffa2e4a5657ea452bea5c64fc85d..8b6ad7f1dc3b9c3982e05111a496d35c747bd83c 100644 (file)
@@ -2070,7 +2070,7 @@ ARGS are the arguments OPERATION has been called with."
                  'dired-print-file 'dired-shell-call-process))
     default-directory)
    ;; PROC.
-   ((eq operation 'file-notify-rm-watch)
+   ((member operation (list 'file-notify-rm-watch 'file-notify-valid-p))
     (when (processp (nth 0 args))
       (with-current-buffer (process-buffer (nth 0 args))
        default-directory)))
@@ -3421,6 +3421,10 @@ of."
   (tramp-message proc 6 "Kill %S" proc)
   (kill-process proc))
 
+(defun tramp-handle-file-notify-valid-p (proc)
+  "Like `file-notify-valid-p' for Tramp files."
+  (and proc (processp proc) (memq (process-status proc) '(run open))))
+
 ;;; Functions for establishing connection:
 
 ;; The following functions are actions to be taken when seeing certain
@@ -3615,7 +3619,7 @@ This is needed in order to hide `last-coding-system-used', which is set
 for process communication also."
   (with-current-buffer (process-buffer proc)
     ;; FIXME: If there is a gateway process, we need communication
-    ;; between several processes.  Too complicated to implement, so we
+    ;; between several processes.  Too complicate to implement, so we
     ;; read output from all processes.
     (let ((p (if (tramp-get-connection-property proc "gateway" nil) nil proc))
          buffer-read-only last-coding-system-used)
index eddad73e8f748d9dc4f50074868630ffcf64aa9e..b73e8733829f3729377d02e990c2a9c9af81ed2b 100644 (file)
@@ -367,6 +367,16 @@ See inotify_rm_watch(2) for more information.
   return Qt;
 }
 
+DEFUN ("inotify-valid-p", Finotify_valid_p, Sinotify_valid_p, 1, 1, 0,
+       doc: /* "Check a watch specified by its WATCH-DESCRIPTOR.
+
+WATCH-DESCRIPTOR should be an object returned by `inotify-add-watch'.  */)
+     (Lisp_Object watch_descriptor)
+{
+  Lisp_Object watch_object = Fassoc (watch_descriptor, watch_list);
+  return NILP (watch_object) ? Qnil : Qt;
+}
+
 void
 syms_of_inotify (void)
 {
@@ -401,6 +411,7 @@ syms_of_inotify (void)
 
   defsubr (&Sinotify_add_watch);
   defsubr (&Sinotify_rm_watch);
+  defsubr (&Sinotify_valid_p);
 
   staticpro (&watch_list);