aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2016-03-25 14:36:14 +0100
committerMichael Albinus2016-03-25 14:36:14 +0100
commitc62371c23bde6c5cd4b0c711ff1754a8809a63d3 (patch)
tree57d41cfd20b3a052cc8888f260448547a6f7ae90
parentc8874e2113221a08252113b6d46ecc7066c62c8c (diff)
downloademacs-c62371c23bde6c5cd4b0c711ff1754a8809a63d3.tar.gz
emacs-c62371c23bde6c5cd4b0c711ff1754a8809a63d3.zip
Cleanup file notification code in Tramp
* lisp/net/tramp-sh.el (tramp-sh-handle-file-notify-add-watch): Make `events' a list of symbols for "inotifywait". (tramp-sh-gvfs-monitor-dir-process-filter): Make event a list. Call `file-notify-handle-event' for better traces. (tramp-sh-inotifywait-process-filter): Check for expected events. Call `file-notify-handle-event' for better traces.
-rw-r--r--lisp/net/tramp-sh.el87
1 files changed, 50 insertions, 37 deletions
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 4ff21c1df4b..402e1cc3332 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -3674,7 +3674,12 @@ Fall back to normal file name handler if no Tramp handler exists."
3674 (concat "create,modify,move,moved_from,moved_to,move_self," 3674 (concat "create,modify,move,moved_from,moved_to,move_self,"
3675 "delete,delete_self,ignored")) 3675 "delete,delete_self,ignored"))
3676 ((memq 'attribute-change flags) "attrib,ignored")) 3676 ((memq 'attribute-change flags) "attrib,ignored"))
3677 sequence `(,command "-mq" "-e" ,events ,localname))) 3677 sequence `(,command "-mq" "-e" ,events ,localname)
3678 ;; Make events a list of symbols.
3679 events
3680 (mapcar
3681 (lambda (x) (intern-soft (replace-regexp-in-string "_" "-" x)))
3682 (split-string events "," 'omit))))
3678 ;; None. 3683 ;; None.
3679 (t (tramp-error 3684 (t (tramp-error
3680 v 'file-notify-error 3685 v 'file-notify-error
@@ -3695,7 +3700,7 @@ Fall back to normal file name handler if no Tramp handler exists."
3695 (mapconcat 'identity sequence " ")) 3700 (mapconcat 'identity sequence " "))
3696 (tramp-message v 6 "Run `%s', %S" (mapconcat 'identity sequence " ") p) 3701 (tramp-message v 6 "Run `%s', %S" (mapconcat 'identity sequence " ") p)
3697 (tramp-set-connection-property p "vector" v) 3702 (tramp-set-connection-property p "vector" v)
3698 ;; Needed for `tramp-sh-gvfs-monitor-dir-process-filter'. 3703 ;; Needed for process filter.
3699 (process-put p 'events events) 3704 (process-put p 'events events)
3700 (process-put p 'watch-name localname) 3705 (process-put p 'watch-name localname)
3701 (set-process-query-on-exit-flag p nil) 3706 (set-process-query-on-exit-flag p nil)
@@ -3711,7 +3716,8 @@ Fall back to normal file name handler if no Tramp handler exists."
3711(defun tramp-sh-gvfs-monitor-dir-process-filter (proc string) 3716(defun tramp-sh-gvfs-monitor-dir-process-filter (proc string)
3712 "Read output from \"gvfs-monitor-dir\" and add corresponding \ 3717 "Read output from \"gvfs-monitor-dir\" and add corresponding \
3713file-notify events." 3718file-notify events."
3714 (let ((remote-prefix 3719 (let ((events (process-get proc 'events))
3720 (remote-prefix
3715 (with-current-buffer (process-buffer proc) 3721 (with-current-buffer (process-buffer proc)
3716 (file-remote-p default-directory))) 3722 (file-remote-p default-directory)))
3717 (rest-string (process-get proc 'rest-string))) 3723 (rest-string (process-get proc 'rest-string)))
@@ -3737,23 +3743,26 @@ file-notify events."
3737 (object 3743 (object
3738 (list 3744 (list
3739 proc 3745 proc
3740 (intern-soft 3746 (list
3741 (replace-regexp-in-string 3747 (intern-soft
3742 "_" "-" (downcase (match-string 4 string)))) 3748 (replace-regexp-in-string
3749 "_" "-" (downcase (match-string 4 string)))))
3743 ;; File names are returned as absolute paths. We must 3750 ;; File names are returned as absolute paths. We must
3744 ;; add the remote prefix. 3751 ;; add the remote prefix.
3745 (concat remote-prefix file) 3752 (concat remote-prefix file)
3746 (when file1 (concat remote-prefix file1))))) 3753 (when file1 (concat remote-prefix file1)))))
3747 (setq string (replace-match "" nil nil string)) 3754 (setq string (replace-match "" nil nil string))
3748 ;; Remove watch when file or directory to be watched is deleted. 3755 ;; Remove watch when file or directory to be watched is deleted.
3749 (when (and (member (cadr object) '(moved deleted)) 3756 (when (and (member (caadr object) '(moved deleted))
3750 (string-equal file (process-get proc 'watch-name))) 3757 (string-equal file (process-get proc 'watch-name)))
3751 (delete-process proc)) 3758 (delete-process proc))
3752 ;; Usually, we would add an Emacs event now. Unfortunately, 3759 ;; Usually, we would add an Emacs event now. Unfortunately,
3753 ;; `unread-command-events' does not accept several events at 3760 ;; `unread-command-events' does not accept several events at
3754 ;; once. Therefore, we apply the callback directly. 3761 ;; once. Therefore, we apply the handler directly.
3755 (when (member (cadr object) (process-get proc 'events)) 3762 (when (member (caadr object) events)
3756 (tramp-compat-funcall 'file-notify-callback object)))) 3763 (tramp-compat-funcall
3764 'file-notify-handle-event
3765 `(file-notify ,object file-notify-callback)))))
3757 3766
3758 ;; Save rest of the string. 3767 ;; Save rest of the string.
3759 (when (zerop (length string)) (setq string nil)) 3768 (when (zerop (length string)) (setq string nil))
@@ -3762,33 +3771,37 @@ file-notify events."
3762 3771
3763(defun tramp-sh-inotifywait-process-filter (proc string) 3772(defun tramp-sh-inotifywait-process-filter (proc string)
3764 "Read output from \"inotifywait\" and add corresponding file-notify events." 3773 "Read output from \"inotifywait\" and add corresponding file-notify events."
3765 (tramp-message proc 6 "%S\n%s" proc string) 3774 (let ((events (process-get proc 'events)))
3766 (dolist (line (split-string string "[\n\r]+" 'omit)) 3775 (tramp-message proc 6 "%S\n%s" proc string)
3767 ;; Check, whether there is a problem. 3776 (dolist (line (split-string string "[\n\r]+" 'omit))
3768 (unless 3777 ;; Check, whether there is a problem.
3769 (string-match 3778 (unless
3770 (concat "^[^[:blank:]]+" 3779 (string-match
3771 "[[:blank:]]+\\([^[:blank:]]+\\)+" 3780 (concat "^[^[:blank:]]+"
3772 "\\([[:blank:]]+\\([^\n\r]+\\)\\)?") 3781 "[[:blank:]]+\\([^[:blank:]]+\\)+"
3773 line) 3782 "\\([[:blank:]]+\\([^\n\r]+\\)\\)?")
3774 (tramp-error proc 'file-notify-error "%s" line)) 3783 line)
3775 3784 (tramp-error proc 'file-notify-error "%s" line))
3776 (let ((object 3785
3777 (list 3786 (let ((object
3778 proc 3787 (list
3779 (mapcar 3788 proc
3780 (lambda (x) 3789 (mapcar
3781 (intern-soft 3790 (lambda (x)
3782 (replace-regexp-in-string "_" "-" (downcase x)))) 3791 (intern-soft
3783 (split-string (match-string 1 line) "," 'omit)) 3792 (replace-regexp-in-string "_" "-" (downcase x))))
3784 (match-string 3 line)))) 3793 (split-string (match-string 1 line) "," 'omit))
3785 ;; Remove watch when file or directory to be watched is deleted. 3794 (match-string 3 line))))
3786 (when (equal (cadr object) 'ignored) 3795 ;; Remove watch when file or directory to be watched is deleted.
3787 (delete-process proc)) 3796 (when (member (caadr object) '(move-self delete-self ignored))
3788 ;; Usually, we would add an Emacs event now. Unfortunately, 3797 (delete-process proc))
3789 ;; `unread-command-events' does not accept several events at 3798 ;; Usually, we would add an Emacs event now. Unfortunately,
3790 ;; once. Therefore, we apply the callback directly. 3799 ;; `unread-command-events' does not accept several events at
3791 (tramp-compat-funcall 'file-notify-callback object)))) 3800 ;; once. Therefore, we apply the handler directly.
3801 (when (member (caadr object) events)
3802 (tramp-compat-funcall
3803 'file-notify-handle-event
3804 `(file-notify ,object file-notify-callback)))))))
3792 3805
3793;;; Internal Functions: 3806;;; Internal Functions:
3794 3807