aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2016-05-02 09:02:27 +0200
committerMichael Albinus2016-05-02 09:02:27 +0200
commit1997d09f78b9b7a5c2d4068e0a7c7282978742fa (patch)
tree9acfcfa39c7a3bbb2fb0387b15aa5517760fb2dc
parent1cad62d81c9217e157274f89da37c0ffeaff4ce7 (diff)
downloademacs-1997d09f78b9b7a5c2d4068e0a7c7282978742fa.tar.gz
emacs-1997d09f78b9b7a5c2d4068e0a7c7282978742fa.zip
Fix Bug#10085
* lisp/net/tramp.el (tramp-find-foreign-file-name-handler): Add optional arguments OPERATION and COMPETION. Handle `file-name-as-directory', `file-name-directory' and `file-name-nondirectory' also in completion mode. (tramp-file-name-handler): Use it. (Bug#10085) * test/lisp/net/tramp-tests.el (tramp-test06-directory-file-name): Extend test.
-rw-r--r--lisp/net/tramp.el17
-rw-r--r--test/lisp/net/tramp-tests.el14
2 files changed, 26 insertions, 5 deletions
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 4edca5a5998..3da60e93b78 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -1944,7 +1944,8 @@ ARGS are the arguments OPERATION has been called with."
1944 ;; Unknown file primitive. 1944 ;; Unknown file primitive.
1945 (t (error "unknown file I/O primitive: %s" operation)))) 1945 (t (error "unknown file I/O primitive: %s" operation))))
1946 1946
1947(defun tramp-find-foreign-file-name-handler (filename) 1947(defun tramp-find-foreign-file-name-handler
1948 (filename &optional operation completion)
1948 "Return foreign file name handler if exists." 1949 "Return foreign file name handler if exists."
1949 (when (tramp-tramp-file-p filename) 1950 (when (tramp-tramp-file-p filename)
1950 (let ((v (tramp-dissect-file-name filename t)) 1951 (let ((v (tramp-dissect-file-name filename t))
@@ -1952,11 +1953,17 @@ ARGS are the arguments OPERATION has been called with."
1952 elt res) 1953 elt res)
1953 ;; When we are not fully sure that filename completion is safe, 1954 ;; When we are not fully sure that filename completion is safe,
1954 ;; we should not return a handler. 1955 ;; we should not return a handler.
1955 (when (or (tramp-file-name-method v) (tramp-file-name-user v) 1956 (when (or (not completion)
1957 (tramp-file-name-method v) (tramp-file-name-user v)
1956 (and (tramp-file-name-host v) 1958 (and (tramp-file-name-host v)
1957 (not (member (tramp-file-name-host v) 1959 (not (member (tramp-file-name-host v)
1958 (mapcar 'car tramp-methods)))) 1960 (mapcar 'car tramp-methods))))
1959 (not (tramp-completion-mode-p))) 1961 ;; Some operations are safe by default.
1962 (member
1963 operation
1964 '(file-name-as-directory
1965 file-name-directory
1966 file-name-nondirectory)))
1960 (while handler 1967 (while handler
1961 (setq elt (car handler) 1968 (setq elt (car handler)
1962 handler (cdr handler)) 1969 handler (cdr handler))
@@ -1984,7 +1991,9 @@ Falls back to normal file name handler if no Tramp file name handler exists."
1984 (tramp-replace-environment-variables 1991 (tramp-replace-environment-variables
1985 (apply 'tramp-file-name-for-operation operation args))) 1992 (apply 'tramp-file-name-for-operation operation args)))
1986 (completion (tramp-completion-mode-p)) 1993 (completion (tramp-completion-mode-p))
1987 (foreign (tramp-find-foreign-file-name-handler filename)) 1994 (foreign
1995 (tramp-find-foreign-file-name-handler
1996 filename operation completion))
1988 result) 1997 result)
1989 (with-parsed-tramp-file-name filename nil 1998 (with-parsed-tramp-file-name filename nil
1990 ;; Call the backend function. 1999 ;; Call the backend function.
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index a12ee387576..5090a5b0e41 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -637,7 +637,19 @@ This checks also `file-name-as-directory', `file-name-directory',
637 (should 637 (should
638 (string-equal (file-name-nondirectory "/method:host:/path/to/file/") "")) 638 (string-equal (file-name-nondirectory "/method:host:/path/to/file/") ""))
639 (should-not 639 (should-not
640 (unhandled-file-name-directory "/method:host:/path/to/file"))) 640 (unhandled-file-name-directory "/method:host:/path/to/file"))
641
642 ;; Bug#10085.
643 (dolist (n-e '(nil t))
644 (let ((non-essential n-e))
645 (dolist (file
646 `(,(file-remote-p tramp-test-temporary-file-directory 'method)
647 ,(file-remote-p tramp-test-temporary-file-directory 'host)))
648 (setq file (format "/%s:" file))
649 (should (string-equal (directory-file-name file) file))
650 (should (string-equal (file-name-as-directory file) (concat file "./")))
651 (should (string-equal (file-name-directory file) file))
652 (should (string-equal (file-name-nondirectory file) ""))))))
641 653
642(ert-deftest tramp-test07-file-exists-p () 654(ert-deftest tramp-test07-file-exists-p ()
643 "Check `file-exist-p', `write-region' and `delete-file'." 655 "Check `file-exist-p', `write-region' and `delete-file'."