aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorMichael Albinus2018-02-03 18:49:56 +0100
committerMichael Albinus2018-02-03 18:49:56 +0100
commita2cb52cd2e7c497df51d751b91b331f59f9637e7 (patch)
tree837fb576472a2ca5b0fc283a3f30eb496f6dc871 /lisp
parentf7c8a12b12f5344100d3da192c0ec80f69ed55a9 (diff)
downloademacs-a2cb52cd2e7c497df51d751b91b331f59f9637e7.tar.gz
emacs-a2cb52cd2e7c497df51d751b91b331f59f9637e7.zip
Prevent loading tramp-archive when it cannot be used
* lisp/files.el (locate-dominating-file): Check, that FILE is a directory when traversing the tree. * lisp/net/tramp-archive.el (tramp-archive-enabled): New defvar. (tramp-archive-file-name-regexp): Protect against errors. (tramp-archive-file-name-handler) (tramp-register-archive-file-name-handler): Use it. (all) Call `tramp-register-archive-file-name-handler'. * lisp/net/tramp.el (tramp-register-file-name-handlers): Use `tramp-archive-enabled'. * test/lisp/net/tramp-archive-tests.el (all): Use `tramp-archive-enabled' instead of `tramp-gvfs-enabled'. (tramp-archive--test-emacs27-p): New defun. (tramp-archive-test42-auto-load): Skip for older Emacsen. (tramp-archive-test42-delay-load): Skip for older Emacsen. Test also behavior when `tramp-archive-enabled' is nil.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/files.el3
-rw-r--r--lisp/net/tramp-archive.el23
-rw-r--r--lisp/net/tramp.el9
3 files changed, 24 insertions, 11 deletions
diff --git a/lisp/files.el b/lisp/files.el
index e884a3acc18..414eb3f93af 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -963,7 +963,8 @@ the function needs to examine, starting with FILE."
963 (null file) 963 (null file)
964 (string-match locate-dominating-stop-dir-regexp file))) 964 (string-match locate-dominating-stop-dir-regexp file)))
965 (setq try (if (stringp name) 965 (setq try (if (stringp name)
966 (file-exists-p (expand-file-name name file)) 966 (and (file-directory-p file)
967 (file-exists-p (expand-file-name name file)))
967 (funcall name file))) 968 (funcall name file)))
968 (cond (try (setq root file)) 969 (cond (try (setq root file))
969 ((equal file (setq file (file-name-directory 970 ((equal file (setq file (file-name-directory
diff --git a/lisp/net/tramp-archive.el b/lisp/net/tramp-archive.el
index 23191f11f3e..ac1c4e1448d 100644
--- a/lisp/net/tramp-archive.el
+++ b/lisp/net/tramp-archive.el
@@ -112,6 +112,14 @@
112(defvar url-handler-regexp) 112(defvar url-handler-regexp)
113(defvar url-tramp-protocols) 113(defvar url-tramp-protocols)
114 114
115;; We cannot check `tramp-gvfs-enabled' in loaddefs.el, because this
116;; would load Tramp. So we make a cheaper check.
117;;;###autoload
118(defvar tramp-archive-enabled (featurep 'dbusbind)
119 "Non-nil when GVFS is available.")
120
121(setq tramp-archive-enabled tramp-gvfs-enabled)
122
115;; <https://github.com/libarchive/libarchive/wiki/LibarchiveFormats> 123;; <https://github.com/libarchive/libarchive/wiki/LibarchiveFormats>
116;;;###autoload 124;;;###autoload
117(defconst tramp-archive-suffixes 125(defconst tramp-archive-suffixes
@@ -169,7 +177,7 @@ It must be supported by libarchive(3).")
169 177
170;;;###tramp-autoload 178;;;###tramp-autoload
171(defconst tramp-archive-file-name-regexp 179(defconst tramp-archive-file-name-regexp
172 (tramp-archive-autoload-file-name-regexp) 180 (ignore-errors (tramp-archive-autoload-file-name-regexp))
173 "Regular expression matching archive file names.") 181 "Regular expression matching archive file names.")
174 182
175;;;###tramp-autoload 183;;;###tramp-autoload
@@ -291,7 +299,7 @@ pass to the OPERATION."
291 (tramp-archive-run-real-handler 'file-directory-p (list archive))) 299 (tramp-archive-run-real-handler 'file-directory-p (list archive)))
292 (tramp-archive-run-real-handler operation args) 300 (tramp-archive-run-real-handler operation args)
293 ;; Now run the handler. 301 ;; Now run the handler.
294 (unless tramp-gvfs-enabled 302 (unless tramp-archive-enabled
295 (tramp-compat-user-error nil "Package `tramp-archive' not supported")) 303 (tramp-compat-user-error nil "Package `tramp-archive' not supported"))
296 (let ((tramp-methods (cons `(,tramp-archive-method) tramp-methods)) 304 (let ((tramp-methods (cons `(,tramp-archive-method) tramp-methods))
297 (tramp-gvfs-methods tramp-archive-all-gvfs-methods) 305 (tramp-gvfs-methods tramp-archive-all-gvfs-methods)
@@ -308,14 +316,17 @@ pass to the OPERATION."
308;;;###autoload 316;;;###autoload
309(progn (defun tramp-register-archive-file-name-handler () 317(progn (defun tramp-register-archive-file-name-handler ()
310 "Add archive file name handler to `file-name-handler-alist'." 318 "Add archive file name handler to `file-name-handler-alist'."
311 (add-to-list 'file-name-handler-alist 319 (when tramp-archive-enabled
312 (cons (tramp-archive-autoload-file-name-regexp) 320 (add-to-list 'file-name-handler-alist
313 'tramp-autoload-file-name-handler)) 321 (cons (tramp-archive-autoload-file-name-regexp)
314 (put 'tramp-archive-file-name-handler 'safe-magic t))) 322 'tramp-autoload-file-name-handler))
323 (put 'tramp-archive-file-name-handler 'safe-magic t))))
315 324
316;;;###autoload 325;;;###autoload
317(add-hook 'after-init-hook 'tramp-register-archive-file-name-handler) 326(add-hook 'after-init-hook 'tramp-register-archive-file-name-handler)
318 327
328(tramp-register-archive-file-name-handler)
329
319;; Mark `operations' the handler is responsible for. 330;; Mark `operations' the handler is responsible for.
320(put 'tramp-archive-file-name-handler 'operations 331(put 'tramp-archive-file-name-handler 'operations
321 (mapcar 'car tramp-archive-file-name-handler-alist)) 332 (mapcar 'car tramp-archive-file-name-handler-alist))
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 5a2e358daa1..09abd482260 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -2401,10 +2401,11 @@ remote file names."
2401 (put 'tramp-completion-file-name-handler 'operations 2401 (put 'tramp-completion-file-name-handler 'operations
2402 (mapcar 'car tramp-completion-file-name-handler-alist)) 2402 (mapcar 'car tramp-completion-file-name-handler-alist))
2403 2403
2404 (add-to-list 'file-name-handler-alist 2404 (when (bound-and-true-p tramp-archive-enabled)
2405 (cons tramp-archive-file-name-regexp 2405 (add-to-list 'file-name-handler-alist
2406 'tramp-archive-file-name-handler)) 2406 (cons tramp-archive-file-name-regexp
2407 (put 'tramp-archive-file-name-handler 'safe-magic t) 2407 'tramp-archive-file-name-handler))
2408 (put 'tramp-archive-file-name-handler 'safe-magic t))
2408 2409
2409 ;; If jka-compr or epa-file are already loaded, move them to the 2410 ;; If jka-compr or epa-file are already loaded, move them to the
2410 ;; front of `file-name-handler-alist'. 2411 ;; front of `file-name-handler-alist'.