Function: tramp-smb-handle-file-notify-add-watch
tramp-smb-handle-file-notify-add-watch is a byte-compiled function
defined in tramp-smb.el.gz.
Signature
(tramp-smb-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-smb.el.gz
;; The "notify" command has been added to smbclient 4.3.0.
(defun tramp-smb-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
(let ((default-directory (file-name-directory file-name))
(command (format "notify %s" (tramp-smb-shell-quote-localname v)))
(events
(cond
((memq 'change flags)
'(added removed modified renamed-from renamed-to))
((memq 'attribute-change flags) '(modified))))
p)
;; Start process.
(with-tramp-saved-connection-properties
v '(" process-name" " process-buffer")
;; Set the new process properties.
(tramp-set-connection-property
v " process-name" (tramp-get-unique-process-name "smb-notify"))
(tramp-set-connection-property
v " process-buffer" (generate-new-buffer " *smb-notify*"))
(tramp-flush-connection-property v " process-exit-status")
(tramp-smb-send-command v command 'nooutput)
(setq p (tramp-get-connection-process v))
;; Return the process object as watch-descriptor.
(if (not (processp p))
(tramp-error
v 'file-notify-error
"`%s' failed to start on remote host" command)
;; Needed for process filter.
(process-put p 'tramp-events events)
(process-put p 'tramp-watch-name localname)
(set-process-filter p #'tramp-smb-notify-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. The existence of the "ADMIN$"
;; share is an indication for a remote MS Windows host.
(tramp-set-connection-property
p "file-monitor"
(if (member
"ADMIN$" (directory-files (tramp-make-tramp-file-name v "/")))
'SMBWindows 'SMBSamba))
p)))))