Function: tramp-sh-handle-file-truename

tramp-sh-handle-file-truename is a byte-compiled function defined in tramp-sh.el.gz.

Signature

(tramp-sh-handle-file-truename FILENAME)

Documentation

Like file-truename for Tramp files.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp-sh.el.gz
(defun tramp-sh-handle-file-truename (filename)
  "Like `file-truename' for Tramp files."
  ;; Preserve trailing "/".
  (funcall
   (if (directory-name-p filename) #'file-name-as-directory #'identity)
   ;; Quote properly.
   (funcall
    (if (tramp-compat-file-name-quoted-p filename)
	#'tramp-compat-file-name-quote #'identity)
    (with-parsed-tramp-file-name
	(tramp-compat-file-name-unquote (expand-file-name filename)) nil
      (tramp-make-tramp-file-name
       v
       (with-tramp-file-property v localname "file-truename"
	 (let (result)			; result steps in reverse order
	   (tramp-message v 4 "Finding true name for `%s'" filename)
	   (cond
	    ;; Use GNU readlink --canonicalize-missing where available.
	    ((tramp-get-remote-readlink v)
	     (tramp-send-command-and-check
	      v
	      (format "%s --canonicalize-missing %s"
		      (tramp-get-remote-readlink v)
		      (tramp-shell-quote-argument localname)))
	     (with-current-buffer (tramp-get-connection-buffer v)
	       (goto-char (point-min))
	       (setq result (buffer-substring (point-min) (point-at-eol)))))

	    ;; Use Perl implementation.
	    ((and (tramp-get-remote-perl v)
		  (tramp-get-connection-property v "perl-file-spec" nil)
		  (tramp-get-connection-property v "perl-cwd-realpath" nil))
	     (tramp-maybe-send-script
	      v tramp-perl-file-truename "tramp_perl_file_truename")
	     (setq result
		   (tramp-send-command-and-read
		    v
		    (format "tramp_perl_file_truename %s"
			    (tramp-shell-quote-argument localname)))))

	    ;; Do it yourself.
	    (t (setq
		result
		(tramp-file-local-name (tramp-handle-file-truename filename)))))

	   ;; Detect cycle.
	   (when (and (file-symlink-p filename)
		      (string-equal result localname))
	     (tramp-error
	      v 'file-error
	      "Apparent cycle of symbolic links for %s" filename))
	   ;; If the resulting localname looks remote, we must quote it
	   ;; for security reasons.
	   (when (file-remote-p result)
	     (setq result (tramp-compat-file-name-quote result 'top)))
	   (tramp-message v 4 "True name of `%s' is `%s'" localname result)
	   result))
       'nohop)))))