aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2023-01-28 10:26:44 +0100
committerMichael Albinus2023-01-28 10:26:44 +0100
commit0820a81ec7a1dcd421b3eec345a38d8405ee00a0 (patch)
treefb1688e5e46b89bfba5786e0d79555e0e706d490
parentcd42244fca8785fb57c25c731afcf3227c2ad14b (diff)
downloademacs-0820a81ec7a1dcd421b3eec345a38d8405ee00a0.tar.gz
emacs-0820a81ec7a1dcd421b3eec345a38d8405ee00a0.zip
Tramp cleanup from recent test campaign
* lisp/net/tramp.el (tramp-barf-if-file-missing): Fix docstring. (tramp-handle-file-directory-p): Don't suppress errors. (tramp-handle-shell-command): * lisp/net/tramp-adb.el (tramp-adb-handle-make-process): Make insertion of a stderr file more robust. * lisp/net/tramp-archive.el (tramp-archive-handle-directory-files): Use `tramp-barf-if-file-missing'. * lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-file-name-all-completions): Protect against errors from `file-directory-p'. * lisp/net/tramp.el (tramp-wrong-passwd-regexp): * lisp/net/tramp-adb.el (tramp-adb-prompt): * lisp/net/tramp-sh.el (tramp-sh-inotifywait-process-filter): * lisp/net/tramp-smb.el (tramp-smb-maybe-open-connection): Unify regexps. * test/lisp/net/tramp-tests.el (tramp-test48-auto-load) (tramp-test48-delay-load): Unify regexps.
-rw-r--r--lisp/net/tramp-adb.el18
-rw-r--r--lisp/net/tramp-archive.el33
-rw-r--r--lisp/net/tramp-sh.el2
-rw-r--r--lisp/net/tramp-smb.el2
-rw-r--r--lisp/net/tramp-sudoedit.el2
-rw-r--r--lisp/net/tramp.el44
-rw-r--r--test/lisp/net/tramp-tests.el8
7 files changed, 58 insertions, 51 deletions
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index 10f33e5f929..38fd8a4e258 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -55,7 +55,7 @@ It is used for TCP/IP devices."
55(defconst tramp-adb-method "adb" 55(defconst tramp-adb-method "adb"
56 "When this method name is used, forward all calls to Android Debug Bridge.") 56 "When this method name is used, forward all calls to Android Debug Bridge.")
57 57
58(defcustom tramp-adb-prompt (rx bol (* (not (any "#$\n\r"))) (any "#$") blank) 58(defcustom tramp-adb-prompt (rx bol (* (not (any "#$\r\n"))) (any "#$") blank)
59 "Regexp used as prompt in almquist shell." 59 "Regexp used as prompt in almquist shell."
60 :type 'regexp 60 :type 'regexp
61 :version "28.1" 61 :version "28.1"
@@ -1005,17 +1005,19 @@ implementation will be used."
1005 ;; file will exist until the process is 1005 ;; file will exist until the process is
1006 ;; deleted. 1006 ;; deleted.
1007 (when (bufferp stderr) 1007 (when (bufferp stderr)
1008 (with-current-buffer stderr 1008 (ignore-errors
1009 (insert-file-contents-literally 1009 (with-current-buffer stderr
1010 remote-tmpstderr 'visit)) 1010 (insert-file-contents-literally
1011 remote-tmpstderr 'visit)))
1011 ;; Delete tmpstderr file. 1012 ;; Delete tmpstderr file.
1012 (add-function 1013 (add-function
1013 :after (process-sentinel p) 1014 :after (process-sentinel p)
1014 (lambda (_proc _msg) 1015 (lambda (_proc _msg)
1015 (with-current-buffer stderr 1016 (ignore-errors
1016 (insert-file-contents-literally 1017 (with-current-buffer stderr
1017 remote-tmpstderr 'visit nil nil 'replace)) 1018 (insert-file-contents-literally
1018 (delete-file remote-tmpstderr)))) 1019 remote-tmpstderr 'visit nil nil 'replace))
1020 (delete-file remote-tmpstderr)))))
1019 ;; Return process. 1021 ;; Return process.
1020 p)))) 1022 p))))
1021 1023
diff --git a/lisp/net/tramp-archive.el b/lisp/net/tramp-archive.el
index 7c1f578d085..97adb36c4af 100644
--- a/lisp/net/tramp-archive.el
+++ b/lisp/net/tramp-archive.el
@@ -611,23 +611,22 @@ offered."
611(defun tramp-archive-handle-directory-files 611(defun tramp-archive-handle-directory-files
612 (directory &optional full match nosort count) 612 (directory &optional full match nosort count)
613 "Like `directory-files' for Tramp files." 613 "Like `directory-files' for Tramp files."
614 (unless (file-exists-p directory) 614 (tramp-barf-if-file-missing (tramp-dissect-file-name directory) directory
615 (tramp-error (tramp-dissect-file-name directory) 'file-missing directory)) 615 (when (file-directory-p directory)
616 (when (file-directory-p directory) 616 (setq directory (file-name-as-directory (expand-file-name directory)))
617 (setq directory (file-name-as-directory (expand-file-name directory))) 617 (let ((temp (nreverse (file-name-all-completions "" directory)))
618 (let ((temp (nreverse (file-name-all-completions "" directory))) 618 result item)
619 result item) 619
620 620 (while temp
621 (while temp 621 (setq item (directory-file-name (pop temp)))
622 (setq item (directory-file-name (pop temp))) 622 (when (or (null match) (string-match-p match item))
623 (when (or (null match) (string-match-p match item)) 623 (push (if full (concat directory item) item)
624 (push (if full (concat directory item) item) 624 result)))
625 result))) 625 (unless nosort
626 (unless nosort 626 (setq result (sort result #'string<)))
627 (setq result (sort result #'string<))) 627 (when (and (natnump count) (> count 0))
628 (when (and (natnump count) (> count 0)) 628 (setq result (tramp-compat-ntake count result)))
629 (setq result (tramp-compat-ntake count result))) 629 result))))
630 result)))
631 630
632(defun tramp-archive-handle-dired-uncache (dir) 631(defun tramp-archive-handle-dired-uncache (dir)
633 "Like `dired-uncache' for file archives." 632 "Like `dired-uncache' for file archives."
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 25bc59eb4ff..48d91bd733e 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -3877,7 +3877,7 @@ Fall back to normal file name handler if no Tramp handler exists."
3877 "Read output from \"inotifywait\" and add corresponding `file-notify' events." 3877 "Read output from \"inotifywait\" and add corresponding `file-notify' events."
3878 (let ((events (process-get proc 'events))) 3878 (let ((events (process-get proc 'events)))
3879 (tramp-message proc 6 "%S\n%s" proc string) 3879 (tramp-message proc 6 "%S\n%s" proc string)
3880 (dolist (line (split-string string "[\n\r]+" 'omit)) 3880 (dolist (line (split-string string (rx (+ (any "\r\n"))) 'omit))
3881 ;; Check, whether there is a problem. 3881 ;; Check, whether there is a problem.
3882 (unless (string-match 3882 (unless (string-match
3883 (rx bol (+ (not blank)) (+ blank) (group (+ (not blank))) 3883 (rx bol (+ (not blank)) (+ blank) (group (+ (not blank)))
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el
index a9cec17f536..b2272f804e0 100644
--- a/lisp/net/tramp-smb.el
+++ b/lisp/net/tramp-smb.el
@@ -1878,7 +1878,7 @@ If ARGUMENT is non-nil, use it as argument for
1878 (setq tramp-smb-version (shell-command-to-string command)) 1878 (setq tramp-smb-version (shell-command-to-string command))
1879 (tramp-message vec 6 command) 1879 (tramp-message vec 6 command)
1880 (tramp-message vec 6 "\n%s" tramp-smb-version) 1880 (tramp-message vec 6 "\n%s" tramp-smb-version)
1881 (if (string-match (rx (+ (any " \t\n\r")) eos) tramp-smb-version) 1881 (if (string-match (rx (+ (any " \t\r\n")) eos) tramp-smb-version)
1882 (setq tramp-smb-version 1882 (setq tramp-smb-version
1883 (replace-match "" nil nil tramp-smb-version)))) 1883 (replace-match "" nil nil tramp-smb-version))))
1884 1884
diff --git a/lisp/net/tramp-sudoedit.el b/lisp/net/tramp-sudoedit.el
index 486a22a60e1..1f646253579 100644
--- a/lisp/net/tramp-sudoedit.el
+++ b/lisp/net/tramp-sudoedit.el
@@ -477,7 +477,7 @@ the result will be a local, non-Tramp, file name."
477 "" (file-name-unquote localname))) 477 "" (file-name-unquote localname)))
478 (mapcar 478 (mapcar
479 (lambda (f) 479 (lambda (f)
480 (if (file-directory-p (expand-file-name f directory)) 480 (if (ignore-errors (file-directory-p (expand-file-name f directory)))
481 (file-name-as-directory f) 481 (file-name-as-directory f)
482 f)) 482 f))
483 (delq 483 (delq
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index f38e570700e..50e1e2479d5 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -82,6 +82,7 @@
82(progn 82(progn
83 (defvar tramp--startup-hook nil 83 (defvar tramp--startup-hook nil
84 "Forms to be executed at the end of tramp.el.") 84 "Forms to be executed at the end of tramp.el.")
85
85 (put 'tramp--startup-hook 'tramp-suppress-trace t) 86 (put 'tramp--startup-hook 'tramp-suppress-trace t)
86 87
87 (defmacro tramp--with-startup (&rest body) 88 (defmacro tramp--with-startup (&rest body)
@@ -657,14 +658,13 @@ The `sudo' program appears to insert a `^@' character into the prompt."
657(defcustom tramp-wrong-passwd-regexp 658(defcustom tramp-wrong-passwd-regexp
658 (rx bol (* nonl) 659 (rx bol (* nonl)
659 (| "Permission denied" 660 (| "Permission denied"
660 (: "Login " (| "Incorrect" "incorrect"))
661 "Connection refused"
662 "Connection closed"
663 "Timeout, server not responding." 661 "Timeout, server not responding."
664 "Sorry, try again." 662 "Sorry, try again."
665 "Name or service not known" 663 "Name or service not known"
666 "Host key verification failed." 664 "Host key verification failed."
667 "No supported authentication methods left to try!" 665 "No supported authentication methods left to try!"
666 (: "Login " (| "Incorrect" "incorrect"))
667 (: "Connection " (| "refused" "closed"))
668 (: "Received signal " (+ digit))) 668 (: "Received signal " (+ digit)))
669 (* nonl)) 669 (* nonl))
670 "Regexp matching a `login failed' message. 670 "Regexp matching a `login failed' message.
@@ -787,6 +787,7 @@ It shall be used in combination with `generate-new-buffer-name'.")
787(defvar tramp-temp-buffer-file-name nil 787(defvar tramp-temp-buffer-file-name nil
788 "File name of a persistent local temporary file. 788 "File name of a persistent local temporary file.
789Useful for \"rsync\" like methods.") 789Useful for \"rsync\" like methods.")
790
790(make-variable-buffer-local 'tramp-temp-buffer-file-name) 791(make-variable-buffer-local 'tramp-temp-buffer-file-name)
791(put 'tramp-temp-buffer-file-name 'permanent-local t) 792(put 'tramp-temp-buffer-file-name 'permanent-local t)
792 793
@@ -1404,6 +1405,7 @@ the (optional) timestamp of last activity on this connection.")
1404 "Password save function. 1405 "Password save function.
1405Will be called once the password has been verified by successful 1406Will be called once the password has been verified by successful
1406authentication.") 1407authentication.")
1408
1407(put 'tramp-password-save-function 'tramp-suppress-trace t) 1409(put 'tramp-password-save-function 'tramp-suppress-trace t)
1408 1410
1409(defvar tramp-password-prompt-not-unique nil 1411(defvar tramp-password-prompt-not-unique nil
@@ -2299,12 +2301,12 @@ the resulting error message."
2299 (progn ,@body) 2301 (progn ,@body)
2300 (error (tramp-message ,vec-or-proc 3 ,format ,err) nil)))) 2302 (error (tramp-message ,vec-or-proc 3 ,format ,err) nil))))
2301 2303
2302;; This macro shall optimize the cases where an `file-exists-p' call 2304;; This macro shall optimize the cases where a `file-exists-p' call is
2303;; is invoked first. Often, the file exists, so the remote command is 2305;; invoked first. Often, the file exists, so the remote command is
2304;; superfluous. 2306;; superfluous.
2305(defmacro tramp-barf-if-file-missing (vec filename &rest body) 2307(defmacro tramp-barf-if-file-missing (vec filename &rest body)
2306 "Execute BODY and return the result. 2308 "Execute BODY and return the result.
2307In case if an error, raise a `file-missing' error if FILENAME 2309In case of an error, raise a `file-missing' error if FILENAME
2308does not exist, otherwise propagate the error." 2310does not exist, otherwise propagate the error."
2309 (declare (indent 2) (debug (symbolp form body))) 2311 (declare (indent 2) (debug (symbolp form body)))
2310 (let ((err (make-symbol "err"))) 2312 (let ((err (make-symbol "err")))
@@ -3935,9 +3937,10 @@ Let-bind it when necessary.")
3935(defun tramp-handle-file-directory-p (filename) 3937(defun tramp-handle-file-directory-p (filename)
3936 "Like `file-directory-p' for Tramp files." 3938 "Like `file-directory-p' for Tramp files."
3937 ;; `file-truename' could raise an error, for example due to a cyclic 3939 ;; `file-truename' could raise an error, for example due to a cyclic
3938 ;; symlink. 3940 ;; symlink. We don't protect this despite it, because other errors
3939 (ignore-errors 3941 ;; might be worth to be visible, for example impossibility to mount
3940 (eq (file-attribute-type (file-attributes (file-truename filename))) t))) 3942 ;; in tramp-gvfs.el.
3943 (eq (file-attribute-type (file-attributes (file-truename filename))) t))
3941 3944
3942(defun tramp-handle-file-equal-p (filename1 filename2) 3945(defun tramp-handle-file-equal-p (filename1 filename2)
3943 "Like `file-equalp-p' for Tramp files." 3946 "Like `file-equalp-p' for Tramp files."
@@ -5152,17 +5155,19 @@ support symbolic links."
5152 (add-function 5155 (add-function
5153 :after (process-sentinel p) 5156 :after (process-sentinel p)
5154 (lambda (_proc _string) 5157 (lambda (_proc _string)
5155 (with-current-buffer error-buffer 5158 (ignore-errors
5156 (insert-file-contents-literally 5159 (with-current-buffer error-buffer
5157 error-file nil nil nil 'replace)) 5160 (insert-file-contents-literally
5158 (delete-file error-file)))) 5161 error-file nil nil nil 'replace))
5162 (delete-file error-file)))))
5159 (display-buffer output-buffer '(nil (allow-no-window . t))))) 5163 (display-buffer output-buffer '(nil (allow-no-window . t)))))
5160 5164
5161 ;; Insert error messages if they were separated. 5165 ;; Insert error messages if they were separated.
5162 (when (and error-file (not (process-live-p p))) 5166 (when (and error-file (not (process-live-p p)))
5163 (with-current-buffer error-buffer 5167 (ignore-errors
5164 (insert-file-contents-literally error-file)) 5168 (with-current-buffer error-buffer
5165 (delete-file error-file)))) 5169 (insert-file-contents-literally error-file))
5170 (delete-file error-file)))))
5166 5171
5167 ;; Synchronous case. 5172 ;; Synchronous case.
5168 (prog1 5173 (prog1
@@ -5170,9 +5175,10 @@ support symbolic links."
5170 (process-file-shell-command command nil buffer) 5175 (process-file-shell-command command nil buffer)
5171 ;; Insert error messages if they were separated. 5176 ;; Insert error messages if they were separated.
5172 (when error-file 5177 (when error-file
5173 (with-current-buffer error-buffer 5178 (ignore-errors
5174 (insert-file-contents-literally error-file)) 5179 (with-current-buffer error-buffer
5175 (delete-file error-file)) 5180 (insert-file-contents-literally error-file))
5181 (delete-file error-file)))
5176 (if current-buffer-p 5182 (if current-buffer-p
5177 ;; This is like exchange-point-and-mark, but doesn't 5183 ;; This is like exchange-point-and-mark, but doesn't
5178 ;; activate the mark. It is cleaner to avoid activation, 5184 ;; activate the mark. It is cleaner to avoid activation,
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 59e160c9d71..338482d2b61 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -7488,7 +7488,7 @@ process sentinels. They shall not disturb each other."
7488 ert-remote-temporary-file-directory))) 7488 ert-remote-temporary-file-directory)))
7489 (should 7489 (should
7490 (string-match-p 7490 (string-match-p
7491 (rx "Tramp loaded: t" (+ (any "\n\r"))) 7491 (rx "Tramp loaded: t" (+ (any "\r\n")))
7492 (shell-command-to-string 7492 (shell-command-to-string
7493 (format 7493 (format
7494 "%s -batch -Q -L %s --eval %s" 7494 "%s -batch -Q -L %s --eval %s"
@@ -7516,9 +7516,9 @@ process sentinels. They shall not disturb each other."
7516 (should 7516 (should
7517 (string-match-p 7517 (string-match-p
7518 (rx 7518 (rx
7519 "Tramp loaded: nil" (+ (any "\n\r")) 7519 "Tramp loaded: nil" (+ (any "\r\n"))
7520 "Tramp loaded: nil" (+ (any "\n\r")) 7520 "Tramp loaded: nil" (+ (any "\r\n"))
7521 "Tramp loaded: " (literal (symbol-name tm)) (+ (any "\n\r"))) 7521 "Tramp loaded: " (literal (symbol-name tm)) (+ (any "\r\n")))
7522 (shell-command-to-string 7522 (shell-command-to-string
7523 (format 7523 (format
7524 "%s -batch -Q -L %s --eval %s" 7524 "%s -batch -Q -L %s --eval %s"