Function: tramp-gvfs-monitor-process-filter

tramp-gvfs-monitor-process-filter is a byte-compiled function defined in tramp-gvfs.el.gz.

Signature

(tramp-gvfs-monitor-process-filter PROC STRING)

Documentation

Read output from "gvfs-monitor-file" and add corresponding file-notify events.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp-gvfs.el.gz
(defun tramp-gvfs-monitor-process-filter (proc string)
  "Read output from \"gvfs-monitor-file\" and add corresponding \
`file-notify' events."
  (let* ((events (process-get proc 'events))
	 (rest-string (process-get proc 'rest-string))
	 (dd (with-current-buffer (process-buffer proc) default-directory))
	 (ddu (regexp-quote (tramp-gvfs-url-file-name dd))))
    (when rest-string
      (tramp-message proc 10 "Previous string:\n%s" rest-string))
    (tramp-message proc 6 "%S\n%s" proc string)
    (setq string (concat rest-string string)
          ;; Fix action names.
          string (tramp-compat-string-replace
                  "attributes changed" "attribute-changed" string)
          string (tramp-compat-string-replace
                  "changes done" "changes-done-hint" string)
          string (tramp-compat-string-replace
                  "renamed to" "moved" string))
    ;; https://bugs.launchpad.net/bugs/1742946
    (when
	(string-match-p "Monitoring not supported\\|No locations given" string)
      (delete-process proc))

    (while (string-match
	    (eval-when-compile
	      (concat "^.+:"
		      "[[:space:]]\\(.+\\):"
		      "[[:space:]]" (regexp-opt tramp-gio-events t)
		      "\\([[:space:]]\\(.+\\)\\)?$"))
	    string)

      (let ((file (match-string 1 string))
	    (file1 (match-string 4 string))
	    (action (intern-soft (match-string 2 string))))
	(setq string (replace-match "" nil nil string))
	;; File names are returned as URL paths.  We must convert them.
	(when (string-match ddu file)
	  (setq file (replace-match dd nil nil file)))
	(while (string-match-p "%\\([[:xdigit:]]\\{2\\}\\)" file)
	  (setq file (url-unhex-string file)))
	(when (string-match ddu (or file1 ""))
	  (setq file1 (replace-match dd nil nil file1)))
	(while (string-match-p "%\\([[:xdigit:]]\\{2\\}\\)" (or file1 ""))
	  (setq file1 (url-unhex-string file1)))
	;; Remove watch when file or directory to be watched is deleted.
	(when (and (member action '(moved deleted))
		   (string-equal file (process-get proc 'watch-name)))
	  (delete-process proc))
	;; Usually, we would add an Emacs event now.  Unfortunately,
	;; `unread-command-events' does not accept several events at
	;; once.  Therefore, we apply the callback directly.
	(when (member action events)
	  (tramp-compat-funcall
           'file-notify-callback (list proc action file file1)))))

    ;; Save rest of the string.
    (when (zerop (length string)) (setq string nil))
    (when string (tramp-message proc 10 "Rest string:\n%s" string))
    (process-put proc 'rest-string string)))