master 65b1e84397c: Handle older inotifywait versions in Tramp

Michael Albinus via Mailing list for Emacs changes <[email protected]>
Newsgroups gmane.emacs.diffs
Message-ID <[email protected]>
branch: master
commit 65b1e84397c55bd435b08f6660be193d054fd7af
Author: Michael Albinus <[email protected]>
Commit: Michael Albinus <[email protected]>

    Handle older inotifywait versions in Tramp
    
    * lisp/net/tramp-sh.el (tramp-remote-inotifywait-with-P): New defun.
    (tramp-sh-handle-file-notify-add-watch): Use it.
    
    * lisp/net/tramp.el (with-tramp-progress-reporter):
    Let-bind `inhibit-message'.
---
 lisp/net/tramp-sh.el | 20 ++++++++++++++++++--
 lisp/net/tramp.el    |  7 +++++--
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 8c4be32f9b2..889c9bda189 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -3897,8 +3897,10 @@ Fall back to normal file name handler if no Tramp handler exists."
 	      ;; "%c" is not documented as format specifier, but it
 	      ;; has been added to version 3.20 (likely), see
 	      ;; <https://github.com/inotify-tools/inotify-tools/issues/72>
-	      sequence `(,command "-mqP" "-e" ,events
-			 "--format=%c %e %f" ,localname)
+	      sequence
+	      `(,command
+		,(if (tramp-remote-inotifywait-with-P v) "-mqP"  "-mq")
+		"-e" ,events "--format=%c %e %f" ,localname)
 	      ;; Make events a list of symbols.
 	      events
 	      (mapcar
@@ -4056,6 +4058,8 @@ Fall back to normal file name handler if no Tramp handler exists."
 	      (or (match-string 3 line)
 		  (file-name-nondirectory
 		   (process-get proc 'tramp-watch-name)))
+	      ;; Older inotifywait versions print "%c" here.  This is
+	      ;; converted to "0".
 	      (string-to-number (match-string 1 line) 16))))
         ;; Add an Emacs event now.
 	;; `insert-special-event' exists since Emacs 31.
@@ -6136,6 +6140,18 @@ Nonexistent directories are removed from spec."
     (tramp-message vec 5 "Finding a suitable `inotifywait' command")
     (tramp-find-executable vec "inotifywait" (tramp-get-remote-path vec) t t)))
 
+(defun tramp-remote-inotifywait-with-P (vec)
+  "Check, whether remote `inotifywait' option \"-P\" is applicable."
+  (with-tramp-connection-property vec "inotifywait-P"
+    (tramp-message vec 5 "Checking, whether `inotifywait -P' works")
+    (let ((result
+	   (tramp-send-command-and-read
+	    vec
+	    (format
+	     "echo \\\"`%s -P 2>&1`\\\"" (tramp-get-remote-inotifywait vec))
+	    'noerror)))
+      (string-match-p "No files specified to watch!" result))))
+
 (defun tramp-get-remote-id (vec)
   "Determine remote `id' command."
   (with-tramp-connection-property vec "id"
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index eb0bc649d69..cb89428886e 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -2254,10 +2254,13 @@ without a visible progress reporter."
 		      (or tramp-inhibit-progress-reporter tm)))
 		 ,@body)
 	     (setq cookie "done"))
-         ;; Stop progress reporter.
+	 ;; Stop progress reporter.  We suppress the message in the
+	 ;; message buffer and echo area; proper handling is performed
+	 ;; by `tramp-message'.
 	 (when (and tm pr)
 	   (cancel-timer tm)
-	   (let (message-log-max)
+	   (let ((inhibit-message t)
+		 message-log-max)
 	     (progress-reporter-done pr)))
          (tramp-message ,vec ,level "%s...%s" ,message cookie)))))
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.