Function: tramp-gvfs-handle-file-notify-add-watch

tramp-gvfs-handle-file-notify-add-watch is a byte-compiled function defined in tramp-gvfs.el.gz.

Signature

(tramp-gvfs-handle-file-notify-add-watch FILE-NAME FLAGS CALLBACK)

Documentation

Like file-notify-add-watch for Tramp files.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp-gvfs.el.gz
(defun tramp-gvfs-handle-file-notify-add-watch (file-name flags _callback)
  "Like `file-notify-add-watch' for Tramp files."
  (setq file-name (expand-file-name file-name))
  (with-parsed-tramp-file-name file-name nil
    ;; TODO: We cannot watch directories, because `gio monitor' is not
    ;; supported for gvfs-mounted directories.  However,
    ;; `file-notify-add-watch' uses directories.
    (when (or (not (tramp-gvfs-gio-tool-p v)) (file-directory-p file-name))
      (tramp-error
       v 'file-notify-error "Monitoring not supported for `%s'" file-name))
    (let* ((default-directory (file-name-directory file-name))
	   (events
	    (cond
	     ((and (memq 'change flags) (memq 'attribute-change flags))
	      '(created changed changes-done-hint moved deleted
			attribute-changed unmounted))
	     ((memq 'change flags)
	      '(created changed changes-done-hint moved deleted unmounted))
	     ((memq 'attribute-change flags) '(attribute-changed unmounted))))
	   (p (apply
	       #'tramp-start-process v
	       "gvfs-monitor" (generate-new-buffer " *gvfs-monitor*")
	       `("gio" "monitor" ,(tramp-gvfs-url-file-name file-name)))))
      (if (not (processp p))
	  (tramp-error
	   v 'file-notify-error "Monitoring not supported for `%s'" file-name)
	;; Needed for process filter.
	(process-put p 'tramp-events events)
	(process-put p 'tramp-watch-name localname)
	(set-process-filter p #'tramp-gvfs-monitor-process-filter)
	(set-process-sentinel p #'tramp-file-notify-process-sentinel)
	;; There might be an error if the monitor is not supported.
	;; Give the filter a chance to read the output.
	(while (tramp-accept-process-output p))
	(unless (process-live-p p)
	  (tramp-error
	   p 'file-notify-error "Monitoring not supported for `%s'" file-name))
	;; Set "file-monitor" property.  We believe, that "gio
	;; monitor" uses polling when applied for mounted files.
	(tramp-set-connection-property p "file-monitor" 'GPollFileMonitor)
	p))))