Function: tramp-get-remote-path

tramp-get-remote-path is an autoloaded and byte-compiled function defined in tramp-sh.el.gz.

Signature

(tramp-get-remote-path VEC)

Documentation

Compile list of remote directories for PATH.

Nonexistent directories are removed from spec.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp-sh.el.gz
;;;###tramp-autoload
(defun tramp-get-remote-path (vec)
  "Compile list of remote directories for PATH.
Nonexistent directories are removed from spec."
  (with-current-buffer (tramp-get-connection-buffer vec)
    ;; Expand connection-local variables.
    (tramp-set-connection-local-variables vec)
    (with-tramp-connection-property
	;; When `tramp-own-remote-path' is in `tramp-remote-path', we
	;; cache the result for the session only.  Otherwise, the
	;; result is cached persistently.
	(if (memq 'tramp-own-remote-path tramp-remote-path)
	    (tramp-get-process vec) vec)
	"remote-path"
      (let* ((remote-path (copy-tree tramp-remote-path))
	     (elt1 (memq 'tramp-default-remote-path remote-path))
	     (elt2 (memq 'tramp-own-remote-path remote-path))
	     (default-remote-path
	       (when elt1
		 (or
		  (tramp-send-command-and-read
		   vec
                   (format
                    "echo \\\"`getconf PATH 2>%s`\\\""
                    (tramp-get-remote-null-device vec))
                   'noerror)
		  ;; Default if "getconf" is not available.
		  (progn
		    (tramp-message
		     vec 3
		     "`getconf PATH' not successful, using default value \"%s\"."
		     "/bin:/usr/bin")
		    "/bin:/usr/bin"))))
	     (own-remote-path
	      ;; The login shell could return more than just the $PATH
	      ;; string.  So we use `tramp-end-of-heredoc' as marker.
	      (when elt2
		(or
		 (tramp-send-command-and-read
		  vec
		  (format
		   "%s %s %s 'echo %s \\\"$PATH\\\"'"
		   (tramp-get-method-parameter vec 'tramp-remote-shell)
		   (string-join
		    (tramp-get-method-parameter vec 'tramp-remote-shell-login)
		    " ")
		   (string-join
		    (tramp-get-method-parameter vec 'tramp-remote-shell-args)
		    " ")
		   (tramp-shell-quote-argument tramp-end-of-heredoc))
		  'noerror (rx (literal tramp-end-of-heredoc)))
		 (progn
		   (tramp-warning
		    vec "Could not retrieve `tramp-own-remote-path'")
		   nil)))))

	;; Replace place holder `tramp-default-remote-path'.
	(when elt1
	  (setcdr elt1
		  (append
                   (split-string (or default-remote-path "") ":" 'omit)
		   (cdr elt1)))
	  (setq remote-path (delq 'tramp-default-remote-path remote-path)))

	;; Replace place holder `tramp-own-remote-path'.
	(when elt2
	  (setcdr elt2
		  (append
                   (split-string (or own-remote-path "") ":" 'omit)
		   (cdr elt2)))
	  (setq remote-path (delq 'tramp-own-remote-path remote-path)))

	;; Remove double entries.
	(setq remote-path
	      (cl-remove-duplicates
	       remote-path :test #'string-equal :from-end t))

	;; Remove non-existing directories.
	(let (remote-file-name-inhibit-cache)
	  (tramp-bundle-read-file-names vec remote-path)
	  (cl-remove-if
	   (lambda (x) (not (tramp-get-file-property vec x "file-directory-p")))
	   remote-path))))))