emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master f6f92e8: Introduce `file-notify-valid-p'


From: Michael Albinus
Subject: [Emacs-diffs] master f6f92e8: Introduce `file-notify-valid-p'
Date: Sun, 13 Sep 2015 19:16:50 +0000

branch: master
commit f6f92e87692c22840deee068408a418d6e04b7e3
Author: Michael Albinus <address@hidden>
Commit: Michael Albinus <address@hidden>

    Introduce `file-notify-valid-p'
    
    * 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     |   32 ++++++++++++++++++++++++++++++++
 lisp/net/tramp-adb.el  |    1 +
 lisp/net/tramp-gvfs.el |    1 +
 lisp/net/tramp-sh.el   |    1 +
 lisp/net/tramp-smb.el  |    1 +
 lisp/net/tramp.el      |    8 ++++++--
 src/inotify.c          |   11 +++++++++++
 7 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/lisp/filenotify.el b/lisp/filenotify.el
index 89fc373..9a48c5e 100644
--- a/lisp/filenotify.el
+++ b/lisp/filenotify.el
@@ -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)
 
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index f818fcd..2a7f1a5 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -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)
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el
index 4dfdcd7..cf42b59 100644
--- a/lisp/net/tramp-gvfs.el
+++ b/lisp/net/tramp-gvfs.el
@@ -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)
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index d9490a0..8598f0e 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -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)
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el
index c4f0f1f..5910d1f 100644
--- a/lisp/net/tramp-smb.el
+++ b/lisp/net/tramp-smb.el
@@ -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)
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 0969048..8b6ad7f 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -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)
diff --git a/src/inotify.c b/src/inotify.c
index eddad73..b73e873 100644
--- a/src/inotify.c
+++ b/src/inotify.c
@@ -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);
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]