Function: tramp-set-remote-path
tramp-set-remote-path is a byte-compiled function defined in
tramp-sh.el.gz.
Signature
(tramp-set-remote-path VEC)
Documentation
Set the remote environment PATH to existing directories.
I.e., for each directory in tramp-remote-path, it is tested
whether it exists and if so, it is added to the environment
variable PATH.
Source Code
;; Defined in /usr/src/emacs/lisp/net/tramp-sh.el.gz
;; On hydra.nixos.org, the $PATH environment variable is too long to
;; send it. This is likely not due to PATH_MAX, but PIPE_BUF. We
;; check it, and use a temporary file in case of. See Bug#33781.
(defun tramp-set-remote-path (vec)
"Set the remote environment PATH to existing directories.
I.e., for each directory in `tramp-remote-path', it is tested
whether it exists and if so, it is added to the environment
variable PATH."
(let ((command
(format
"PATH=%s && export PATH"
(string-join (tramp-get-remote-path vec) ":")))
(pipe-buf (tramp-get-remote-pipe-buf vec))
tmpfile chunk chunksize)
(tramp-message vec 5 "Setting $PATH environment variable")
(if (length< command pipe-buf)
(tramp-send-command vec command)
;; Use a temporary file. We cannot use `write-region' because
;; setting the remote path happens in the early connection
;; handshake, and not all external tools are determined yet.
;; Furthermore, we know that the COMMAND is too long, due to a
;; very long remote-path. Set it temporarily to something
;; short.
(with-tramp-saved-connection-property (tramp-get-process vec) "remote-path"
(tramp-set-connection-property
(tramp-get-process vec) "remote-path" '("/bin" "/usr/bin"))
(setq command (concat command "\n")
tmpfile (tramp-make-tramp-temp-file vec))
(while (not (string-empty-p command))
(setq chunksize (min (length command) (/ pipe-buf 2))
chunk (substring command 0 chunksize)
command (substring command chunksize))
(tramp-send-command
vec (format "printf \"%%b\" \"$*\" %s >>%s"
(tramp-shell-quote-argument chunk)
(tramp-shell-quote-argument tmpfile))))
(tramp-send-command vec (format ". %s && rm -f %s" tmpfile tmpfile))))))