Commit f6f92e87 authored by Michael Albinus's avatar Michael Albinus

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.
parent a85472bb
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment