Function: tramp-smb-notify-process-filter
tramp-smb-notify-process-filter is a byte-compiled function defined in
tramp-smb.el.gz.
Signature
(tramp-smb-notify-process-filter PROC STRING)
Documentation
Read output from "notify" and add corresponding file-notify events.
Source Code
;; Defined in /usr/src/emacs/lisp/net/tramp-smb.el.gz
;; FileChangeNotify subsystem was added to Smaba 4.3.0.
;; <https://www.samba.org/samba/history/samba-4.3.0.html>
(defun tramp-smb-notify-process-filter (proc string)
"Read output from \"notify\" and add corresponding `file-notify' events."
(let ((events (process-get proc 'tramp-events)))
(tramp-message proc 6 "%S\n%s" proc string)
(dolist (line (split-string string (rx (+ (any "\r\n"))) 'omit))
(catch 'next
;; Watched directory is removed.
(when (string-match-p "NT_STATUS_DELETE_PENDING" line)
(setq line (concat "0002 " (process-get proc 'tramp-watch-name))))
;; Stopped.
(when (string-match-p tramp-smb-prompt line)
(throw 'next 'next))
;; Check, whether there is a problem.
(unless (string-match
(rx bol (group (+ digit))
(+ blank) (group (+ (not (any "\r\n")))))
line)
(tramp-error proc 'file-notify-error line))
;; See libsmbclient.h.
;; #define SMBC_NOTIFY_ACTION_ADDED 1
;; #define SMBC_NOTIFY_ACTION_REMOVED 2
;; #define SMBC_NOTIFY_ACTION_MODIFIED 3
;; #define SMBC_NOTIFY_ACTION_OLD_NAME 4
;; #define SMBC_NOTIFY_ACTION_NEW_NAME 5
;; #define SMBC_NOTIFY_ACTION_ADDED_STREAM 6
;; #define SMBC_NOTIFY_ACTION_REMOVED_STREAM 7
;; #define SMBC_NOTIFY_ACTION_MODIFIED_STREAM 8
(let ((object
(list
proc
(pcase (string-to-number (match-string 1 line))
(1 '(added))
(2 '(removed))
(3 '(modified))
(4 '(renamed-from))
(5 '(renamed-to))
;; Ignore stream events.
(_ (throw 'next 'next)))
(string-replace "\\" "/" (match-string 2 line)))))
;; Add an Emacs event now.
;; `insert-special-event' exists since Emacs 31.
(when (member (caadr object) events)
(tramp-compat-funcall
(if (fboundp 'insert-special-event)
'insert-special-event
(lookup-key special-event-map [file-notify]))
`(file-notify ,object file-notify-callback))))))))