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
	 (with-tramp-connection-property vec "pipe-buf"
	   (tramp-send-command-and-read
	    vec
            (format "getconf PIPE_BUF / 2>%s || echo 4096"
                    (tramp-get-remote-null-device vec))
            'noerror)))
	tmpfile chunk chunksize)
    (tramp-message vec 5 "Setting $PATH environment variable")
    (if (tramp-compat-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.
      (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" tmpfile))
      (tramp-send-command vec (format "rm -f %s" tmpfile)))))