From 0577bd0cf9aca220c0ecba217ac9a9522ffa990d Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Sun, 25 Jul 2021 12:05:01 +0200 Subject: [PATCH] Use `file-name-concat' in Tramp * lisp/net/tramp-compat.el (tramp-compat-file-name-concat): New defalias. * lisp/net/tramp.el (tramp-handle-expand-file-name): * lisp/net/tramp-adb.el (tramp-adb-handle-directory-files-and-attributes): * lisp/net/tramp-gvfs.el (tramp-gvfs-handle-expand-file-name): * lisp/net/tramp-sh.el (tramp-sh-handle-expand-file-name): * lisp/net/tramp-smb.el (tramp-smb-handle-expand-file-name): * lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-expand-file-name): Use it. --- lisp/net/tramp-adb.el | 4 ++-- lisp/net/tramp-compat.el | 14 ++++++++++++++ lisp/net/tramp-gvfs.el | 2 +- lisp/net/tramp-sh.el | 2 +- lisp/net/tramp-smb.el | 2 +- lisp/net/tramp-sudoedit.el | 2 +- lisp/net/tramp.el | 2 +- 7 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index b081e5957a3..5e0accc142a 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -327,9 +327,9 @@ arguments to pass to the OPERATION." v (format "%s -d -a -l %s %s" (tramp-adb-get-ls-command v) (tramp-shell-quote-argument - (concat (file-name-as-directory localname) ".")) + (tramp-compat-file-name-concat localname ".")) (tramp-shell-quote-argument - (concat (file-name-as-directory localname) "..")))) + (tramp-compat-file-name-concat localname "..")))) (widen))) (tramp-adb-sh-fix-ls-output) (let ((result (tramp-do-parse-file-attributes-with-ls diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el index 9d5e5f787b6..6e464073379 100644 --- a/lisp/net/tramp-compat.el +++ b/lisp/net/tramp-compat.el @@ -363,6 +363,20 @@ A nil value for either argument stands for the current time." ".#" (file-name-nondirectory filename)) (file-name-directory filename))))) +;; Function `file-name-concat' is new in Emacs 28.1. +(defalias 'tramp-compat-file-name-concat + (if (fboundp 'file-name-concat) + #'file-name-concat + (lambda (directory &rest components) + (unless (null directory) + (let ((components (delq nil components)) + file-name-handler-alist) + (if (null components) + directory + (tramp-compat-file-name-concat + (concat (file-name-as-directory directory) (car components)) + (cdr components)))))))) + (dolist (elt (all-completions "tramp-compat-" obarray 'functionp)) (put (intern elt) 'tramp-suppress-trace t)) diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index 022fdeeb885..db561b4fd0c 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el @@ -1142,7 +1142,7 @@ file names." (when (zerop (length name)) (setq name ".")) ;; Unless NAME is absolute, concat DIR and NAME. (unless (file-name-absolute-p name) - (setq name (concat (file-name-as-directory dir) name))) + (setq name (tramp-compat-file-name-concat dir name))) ;; If NAME is not a Tramp file, run the real handler. (if (not (tramp-tramp-file-p name)) (tramp-run-real-handler #'expand-file-name (list name nil)) diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 41ab1045c24..a6569e0cdd2 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -2681,7 +2681,7 @@ the result will be a local, non-Tramp, file name." (tramp-run-real-handler #'expand-file-name (list name dir)) ;; Unless NAME is absolute, concat DIR and NAME. (unless (file-name-absolute-p name) - (setq name (concat (file-name-as-directory dir) name))) + (setq name (tramp-compat-file-name-concat dir name))) ;; If connection is not established yet, run the real handler. (if (not (tramp-connectable-p name)) (tramp-run-real-handler #'expand-file-name (list name nil)) diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el index 4e4f5548e20..3d5be61d3f0 100644 --- a/lisp/net/tramp-smb.el +++ b/lisp/net/tramp-smb.el @@ -722,7 +722,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." (when (zerop (length name)) (setq name ".")) ;; Unless NAME is absolute, concat DIR and NAME. (unless (file-name-absolute-p name) - (setq name (concat (file-name-as-directory dir) name))) + (setq name (tramp-compat-file-name-concat dir name))) ;; If NAME is not a Tramp file, run the real handler. (if (not (tramp-tramp-file-p name)) (tramp-run-real-handler #'expand-file-name (list name nil)) diff --git a/lisp/net/tramp-sudoedit.el b/lisp/net/tramp-sudoedit.el index 45d9fab986c..177dde67cca 100644 --- a/lisp/net/tramp-sudoedit.el +++ b/lisp/net/tramp-sudoedit.el @@ -353,7 +353,7 @@ the result will be a local, non-Tramp, file name." (when (zerop (length name)) (setq name ".")) ;; Unless NAME is absolute, concat DIR and NAME. (unless (file-name-absolute-p name) - (setq name (concat (file-name-as-directory dir) name))) + (setq name (tramp-compat-file-name-concat dir name))) (with-parsed-tramp-file-name name nil ;; Tilde expansion if necessary. We cannot accept "~/", because ;; under sudo "~/" is expanded to the local user home directory diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 59c4f33f5ef..4db0b2e6723 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -3346,7 +3346,7 @@ User is always nil." (when (zerop (length name)) (setq name ".")) ;; Unless NAME is absolute, concat DIR and NAME. (unless (file-name-absolute-p name) - (setq name (concat (file-name-as-directory dir) name))) + (setq name (tramp-compat-file-name-concat dir name))) ;; If NAME is not a Tramp file, run the real handler. (if (not (tramp-tramp-file-p name)) (tramp-run-real-handler #'expand-file-name (list name nil)) -- 2.39.2