[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 6c1190c: Extend abbreviate-file-name for further Tramp methods.
From: |
Michael Albinus |
Subject: |
master 6c1190c: Extend abbreviate-file-name for further Tramp methods. |
Date: |
Thu, 18 Nov 2021 09:06:33 -0500 (EST) |
branch: master
commit 6c1190c74936f132cb4173335cb037de89ef8aa7
Author: Michael Albinus <michael.albinus@gmx.de>
Commit: Michael Albinus <michael.albinus@gmx.de>
Extend abbreviate-file-name for further Tramp methods.
* lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist):
Add 'abbreviate-file-name'.
(tramp-gvfs-handle-expand-file-name):
* lisp/net/tramp.el (tramp-handle-expand-file-name): Handle case
that tilde cannot be expanded.
* test/lisp/net/tramp-tests.el (tramp-test07-abbreviate-file-name):
Extend test.
---
lisp/net/tramp-gvfs.el | 25 ++++++++++++-------------
lisp/net/tramp.el | 9 ++++++---
test/lisp/net/tramp-tests.el | 5 ++++-
3 files changed, 22 insertions(+), 17 deletions(-)
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el
index a4a7bac..ab71c9c 100644
--- a/lisp/net/tramp-gvfs.el
+++ b/lisp/net/tramp-gvfs.el
@@ -744,7 +744,7 @@ It has been changed in GVFS 1.14.")
;; New handlers should be added here.
;;;###tramp-autoload
(defconst tramp-gvfs-file-name-handler-alist
- '(;; `abbreviate-file-name' performed by default handler.
+ '((abbreviate-file-name . tramp-handle-abbreviate-file-name)
(access-file . tramp-handle-access-file)
(add-name-to-file . tramp-handle-add-name-to-file)
;; `byte-compiler-base-file-name' performed by default handler.
@@ -1149,15 +1149,12 @@ file names."
(make-tramp-file-name
:method method :user user :domain domain
:host host :port port :localname "/" :hop hop)))
- (setq localname
- (replace-match
- (tramp-get-connection-property v "default-location" "~")
- nil t localname 1)))
- ;; Tilde expansion is not possible.
- (when (string-match-p "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname)
- (tramp-error
- v 'file-error
- "Cannot expand tilde in file `%s'" name))
+ (unless (string-empty-p
+ (tramp-get-connection-property v "default-location" ""))
+ (setq localname
+ (replace-match
+ (tramp-get-connection-property v "default-location" "~")
+ nil t localname 1))))
(unless (tramp-run-real-handler #'file-name-absolute-p (list localname))
(setq localname (concat "/" localname)))
;; We do not pass "/..".
@@ -1172,10 +1169,12 @@ file names."
;; Do not keep "/..".
(when (string-match-p "^/\\.\\.?$" localname)
(setq localname "/"))
- ;; No tilde characters in file name, do normal
- ;; `expand-file-name' (this does "/./" and "/../").
+ ;; Do normal `expand-file-name' (this does "/./" and "/../"),
+ ;; unless there are tilde characters in file name.
(tramp-make-tramp-file-name
- v (tramp-run-real-handler #'expand-file-name (list localname))))))
+ v (if (string-match-p "\\`~" localname)
+ localname
+ (tramp-run-real-handler #'expand-file-name (list localname)))))))
(defun tramp-gvfs-get-directory-attributes (directory)
"Return GVFS attributes association list of all files in DIRECTORY."
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 7927ddd..f43c1d8 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -3454,13 +3454,16 @@ User is always nil."
;; Do not keep "/..".
(when (string-match-p "^/\\.\\.?$" localname)
(setq localname "/"))
- ;; Do normal `expand-file-name' (this does "/./" and "/../").
+ ;; Do normal `expand-file-name' (this does "/./" and "/../"),
+ ;; unless there are tilde characters in file name.
;; `default-directory' is bound, because on Windows there would
;; be problems with UNC shares or Cygwin mounts.
(let ((default-directory tramp-compat-temporary-file-directory))
(tramp-make-tramp-file-name
- v (tramp-drop-volume-letter
- (tramp-run-real-handler #'expand-file-name (list localname))))))))
+ v (if (string-match-p "\\`~" localname)
+ localname
+ (tramp-drop-volume-letter
+ (tramp-run-real-handler #'expand-file-name (list
localname)))))))))
(defun tramp-handle-file-accessible-directory-p (filename)
"Like `file-accessible-directory-p' for Tramp files."
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 482d3ff..98269d5 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -2295,7 +2295,10 @@ This checks also `file-name-as-directory',
`file-name-directory',
(skip-unless (tramp--test-emacs29-p))
(let* ((remote-host (file-remote-p tramp-test-temporary-file-directory))
- (home-dir (expand-file-name (concat remote-host "~"))))
+ ;; Not all methods can expand "~".
+ (home-dir (ignore-errors (expand-file-name (concat remote-host
"~")))))
+ (skip-unless home-dir)
+
;; Check home-dir abbreviation.
(unless (string-suffix-p "~" home-dir)
(should (equal (abbreviate-file-name (concat home-dir "/foo/bar"))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 6c1190c: Extend abbreviate-file-name for further Tramp methods.,
Michael Albinus <=