;; are already loaded. This results in
;; recursive loading. Therefore, we load the
;; Tramp packages locally.
- (when (and (listp sf) (eq (car sf) 'autoload))
+ (when (autoloadp sf)
(let ((default-directory
(tramp-compat-temporary-file-directory)))
(load (cadr sf) 'noerror 'nomessage)))
;;;###autoload
(tramp-register-autoload-file-name-handlers)
+(defun tramp-use-absolute-autoload-file-names ()
+ "Change Tramp autoload objects to use absolute file names.
+This avoids problems during autoload, when `load-path' contains
+remote file names."
+ ;; We expect all other Tramp files in the same directory as tramp.el.
+ (let* ((dir (expand-file-name (file-name-directory (locate-library "tramp"))))
+ (files-regexp
+ (format
+ "^%s$"
+ (regexp-opt
+ (mapcar
+ 'file-name-sans-extension
+ (directory-files dir nil "^tramp.+\\.elc?$"))
+ 'paren))))
+ (mapatoms
+ (lambda (atom)
+ (when (and (functionp atom)
+ (autoloadp (symbol-function atom))
+ (string-match files-regexp (cadr (symbol-function atom))))
+ (ignore-errors
+ (setf (cadr (symbol-function atom))
+ (expand-file-name (cadr (symbol-function atom)) dir))))))))
+
+(eval-after-load 'tramp (tramp-use-absolute-autoload-file-names))
+
(defun tramp-register-file-name-handlers ()
"Add Tramp file name handlers to `file-name-handler-alist'."
;; Remove autoloaded handlers from file name handler alist. Useful,
(mapconcat 'shell-quote-argument load-path " -L ")
(shell-quote-argument code)))))))
-(ert-deftest tramp-test38-unload ()
+(ert-deftest tramp-test38-remote-load-path ()
+ "Check that Tramp autoloads its packages with remote `load-path'."
+ ;; `tramp-cleanup-all-connections' is autoloaded from tramp-cmds.el.
+ ;; It shall still work, when a remote file name is in the
+ ;; `load-path'.
+ (let ((code
+ "(let ((force-load-messages t)\
+ (load-path (cons \"/foo:bar:\" load-path)))\
+ (tramp-cleanup-all-connections))"))
+ (should
+ (string-match
+ (format
+ "Loading %s"
+ (expand-file-name
+ "tramp-cmds" (file-name-directory (locate-library "tramp"))))
+ (shell-command-to-string
+ (format
+ "%s -batch -Q -L %s -l tramp-sh --eval %s"
+ (expand-file-name invocation-name invocation-directory)
+ (mapconcat 'shell-quote-argument load-path " -L ")
+ (shell-quote-argument code)))))))
+
+(ert-deftest tramp-test39-unload ()
"Check that Tramp and its subpackages unload completely.
Since it unloads Tramp, it shall be the last test to run."
;; Mark as failed until all symbols are unbound.