From 4ba47f7830058acf53d4fc900ff0e370171f1412 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Tue, 5 Nov 2024 15:57:42 +0100 Subject: [PATCH] Several Tramp cleanups * lisp/net/tramp-adb.el (tramp-adb-maybe-open-connection): Move setting of sentinel up. * lisp/net/tramp-cache.el (tramp-get-connection-property) (tramp-set-connection-property): Don't raise a debug message for the `tramp-cache-version' key. * lisp/net/tramp.el (tramp-convert-file-attributes): Don't cache "file-attributes-ID-FORMAT". * test/lisp/net/tramp-tests.el (tramp--test-enabled): Cleanup also `tramp-compat-temporary-file-directory'. (tramp-test32-shell-command): Use `async-shell-command-width' of 512. (tramp-test36-vc-registered): Remove double let* entry. (cherry picked from commit 1e3d72d962b8b736741747a5ec4595e08965ef49) --- lisp/net/tramp-adb.el | 9 +-- lisp/net/tramp-cache.el | 6 +- lisp/net/tramp.el | 111 ++++++++++++++++++++++------------- test/lisp/net/tramp-tests.el | 13 ++-- 4 files changed, 87 insertions(+), 52 deletions(-) diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index 4fba731509b..ad82aad6a32 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -1126,6 +1126,11 @@ connection if a previous connection has died for some reason." tramp-adb-program args))) (prompt (md5 (concat (prin1-to-string process-environment) (current-time-string))))) + + ;; Set sentinel. Initialize variables. + (set-process-sentinel p #'tramp-process-sentinel) + (tramp-post-process-creation p vec) + ;; Wait for initial prompt. On some devices, it needs ;; an initial RET, in order to get it. (sleep-for 0.1) @@ -1134,10 +1139,6 @@ connection if a previous connection has died for some reason." (unless (process-live-p p) (tramp-error vec 'file-error "Terminated!")) - ;; Set sentinel. Initialize variables. - (set-process-sentinel p #'tramp-process-sentinel) - (tramp-post-process-creation p vec) - ;; Set connection-local variables. (tramp-set-connection-local-variables vec) diff --git a/lisp/net/tramp-cache.el b/lisp/net/tramp-cache.el index a5bdacb4d91..16893ea8c82 100644 --- a/lisp/net/tramp-cache.el +++ b/lisp/net/tramp-cache.el @@ -396,7 +396,8 @@ the connection, return DEFAULT." (not (and (processp key) (not (process-live-p key))))) (setq value cached cache-used t)) - (tramp-message key 7 "%s %s; cache used: %s" property value cache-used) + (unless (eq key tramp-cache-version) + (tramp-message key 7 "%s %s; cache used: %s" property value cache-used)) value)) ;;;###tramp-autoload @@ -413,7 +414,8 @@ Return VALUE." (puthash property value hash)) (setq tramp-cache-data-changed (or tramp-cache-data-changed (tramp-file-name-p key))) - (tramp-message key 7 "%s %s" property value) + (unless (eq key tramp-cache-version) + (tramp-message key 7 "%s %s" property value)) value) ;;;###tramp-autoload diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 96717ca6ea8..55eae7d1850 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -6376,14 +6376,50 @@ Convert file mode bits to string and set virtual device number. Set file uid and gid according to ID-FORMAT. LOCALNAME is used to cache the result. Return the modified ATTR." (declare (indent 3) (debug t)) - `(with-tramp-file-property - ,vec ,localname (format "file-attributes-%s" (or ,id-format 'integer)) - (when-let - ((result - (with-tramp-file-property ,vec ,localname "file-attributes" - (when-let ((attr ,attr)) - (save-match-data - ;; Remove ANSI control escape sequences from symlink. + `(when-let* + ((result + (with-tramp-file-property ,vec ,localname "file-attributes" + (when-let* ((attr ,attr)) + (save-match-data + ;; Remove ANSI control escape sequences from symlink. + (when (stringp (car attr)) + (while (string-match ansi-color-control-seq-regexp (car attr)) + (setcar attr (replace-match "" nil nil (car attr))))) + ;; Convert uid and gid. Use `tramp-unknown-id-integer' + ;; as indication of unusable value. + (when (consp (nth 2 attr)) + (when (and (numberp (cdr (nth 2 attr))) + (< (cdr (nth 2 attr)) 0)) + (setcdr (car (nthcdr 2 attr)) tramp-unknown-id-integer)) + (when (and (floatp (cdr (nth 2 attr))) + (<= (cdr (nth 2 attr)) most-positive-fixnum)) + (setcdr (car (nthcdr 2 attr)) (round (cdr (nth 2 attr)))))) + (when (consp (nth 3 attr)) + (when (and (numberp (cdr (nth 3 attr))) + (< (cdr (nth 3 attr)) 0)) + (setcdr (car (nthcdr 3 attr)) tramp-unknown-id-integer)) + (when (and (floatp (cdr (nth 3 attr))) + (<= (cdr (nth 3 attr)) most-positive-fixnum)) + (setcdr (car (nthcdr 3 attr)) (round (cdr (nth 3 attr)))))) + ;; Convert last access time. + (unless (listp (nth 4 attr)) + (setcar (nthcdr 4 attr) (seconds-to-time (nth 4 attr)))) + ;; Convert last modification time. + (unless (listp (nth 5 attr)) + (setcar (nthcdr 5 attr) (seconds-to-time (nth 5 attr)))) + ;; Convert last status change time. + (unless (listp (nth 6 attr)) + (setcar (nthcdr 6 attr) (seconds-to-time (nth 6 attr)))) + ;; Convert file size. + (when (< (nth 7 attr) 0) + (setcar (nthcdr 7 attr) -1)) + (when (and (floatp (nth 7 attr)) + (<= (nth 7 attr) most-positive-fixnum)) + (setcar (nthcdr 7 attr) (round (nth 7 attr)))) + ;; Convert file mode bits to string. + (unless (stringp (nth 8 attr)) + (setcar (nthcdr 8 attr) + (tramp-file-mode-from-int (nth 8 attr))) (when (stringp (car attr)) (while (string-match ansi-color-control-seq-regexp (car attr)) (setcar attr (replace-match "" nil nil (car attr))))) @@ -6450,38 +6486,33 @@ to cache the result. Return the modified ATTR." (let ((high (nth 10 attr)) middle low) (if (<= high most-positive-fixnum) - (floor high) - ;; The low 16 bits. - (setq low (mod high #x10000) - high (/ high #x10000)) - (if (<= high most-positive-fixnum) - (cons (floor high) (floor low)) - ;; The middle 24 bits. - (setq middle (mod high #x1000000) - high (/ high #x1000000)) - (cons (floor high) - (cons (floor middle) (floor low)))))) - ;; Inodes can be incredible huge. We - ;; must hide this. - (error (tramp-get-inode ,vec))))) - ;; Set virtual device number. - (setcar (nthcdr 11 attr) - (tramp-get-device ,vec)) - ;; Set SELinux context. - (when (stringp (nth 12 attr)) - (tramp-set-file-property - ,vec ,localname "file-selinux-context" - (split-string (nth 12 attr) ":" 'omit))) - ;; Remove optional entries. - (setcdr (nthcdr 11 attr) nil) - attr))))) - - ;; Return normalized result. - (append (tramp-compat-take 2 result) - (if (eq ,id-format 'string) - (list (car (nth 2 result)) (car (nth 3 result))) - (list (cdr (nth 2 result)) (cdr (nth 3 result)))) - (nthcdr 4 result))))) + (cons (floor high) (floor low)) + ;; The middle 24 bits. + (setq middle (mod high #x1000000) + high (/ high #x1000000)) + (cons (floor high) + (cons (floor middle) (floor low)))))) + ;; Inodes can be incredible huge. We must + ;; hide this. + (error (tramp-get-inode ,vec))))) + ;; Set virtual device number. + (setcar (nthcdr 11 attr) + (tramp-get-device ,vec)) + ;; Set SELinux context. + (when (stringp (nth 12 attr)) + (tramp-set-file-property + ,vec ,localname "file-selinux-context" + (split-string (nth 12 attr) ":" 'omit))) + ;; Remove optional entries. + (setcdr (nthcdr 11 attr) nil) + attr))))) + + ;; Return normalized result. + (append (tramp-compat-take 2 result) + (if (eq ,id-format 'string) + (list (car (nth 2 result)) (car (nth 3 result))) + (list (cdr (nth 2 result)) (cdr (nth 3 result)))) + (nthcdr 4 result)))) (defun tramp-get-home-directory (vec &optional user) "The remote home directory for connection VEC as local file name. diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 768adf3d629..a27756c1cbf 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -158,6 +158,7 @@ being the result.") (when (cdr tramp--test-enabled-checked) ;; Remove old test files. (dolist (dir `(,temporary-file-directory + ,tramp-compat-temporary-file-directory ,ert-remote-temporary-file-directory)) (dolist (file (directory-files dir 'full (rx bos (? ".#") "tramp-test"))) (ignore-errors @@ -5090,7 +5091,7 @@ If UNSTABLE is non-nil, the test is tagged as `:unstable'." direct-async-process-profile) connection-local-criteria-alist))) (skip-unless (tramp-direct-async-process-p)) - (when-let ((result (ert-test-most-recent-result ert-test))) + (when-let* ((result (ert-test-most-recent-result ert-test))) (skip-unless (< (ert-test-result-duration result) 300))) ;; We do expect an established connection already, ;; `file-truename' does it by side-effect. Suppress @@ -5630,7 +5631,9 @@ INPUT, if non-nil, is a string sent to the process." ;; Test `async-shell-command-width'. (when (and (tramp--test-asynchronous-processes-p) (tramp--test-sh-p)) - (let* ((async-shell-command-width 1024) + (let* (;; Since Fedora 41, this seems to be the upper limit. Used + ;; to be 1024 before. + (async-shell-command-width 512) (default-directory ert-remote-temporary-file-directory) (cols (ignore-errors (read (tramp--test-shell-command-to-string-asynchronously @@ -6150,6 +6153,7 @@ INPUT, if non-nil, is a string sent to the process." (tmp-name1 (tramp--test-make-temp-name nil quoted)) (tmp-name2 (expand-file-name "foo" tmp-name1)) (tramp-remote-process-environment tramp-remote-process-environment) + ;; Suppress nasty messages. (inhibit-message t) (vc-handled-backends (cond @@ -6172,9 +6176,7 @@ INPUT, if non-nil, is a string sent to the process." (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password) '(Bzr)) - (t nil))) - ;; Suppress nasty messages. - (inhibit-message t)) + (t nil)))) (skip-unless vc-handled-backends) (unless quoted (tramp--test-message "%s" vc-handled-backends)) @@ -7947,7 +7949,6 @@ If INTERACTIVE is non-nil, the tests are run interactively." ;; * file-equal-p (partly done in `tramp-test21-file-links') ;; * file-in-directory-p ;; * file-name-case-insensitive-p -;; * memory-info ;; * tramp-get-home-directory ;; * tramp-set-file-uid-gid -- 2.39.5