Function: tramp-find-inline-encoding
tramp-find-inline-encoding is a byte-compiled function defined in
tramp-sh.el.gz.
Signature
(tramp-find-inline-encoding VEC)
Documentation
Find an inline transfer encoding that works.
Goes through the list tramp-local-coding-commands and
tramp-remote-coding-commands.
Source Code
;; Defined in /usr/src/emacs/lisp/net/tramp-sh.el.gz
(defun tramp-find-inline-encoding (vec)
"Find an inline transfer encoding that works.
Goes through the list `tramp-local-coding-commands' and
`tramp-remote-coding-commands'."
(save-excursion
(let ((local-commands tramp-local-coding-commands)
(magic "xyzzy")
(p (tramp-get-connection-process vec))
loc-enc loc-dec rem-enc rem-dec rem-test litem ritem found)
(while (and local-commands (not found))
(setq litem (pop local-commands))
(catch 'wont-work-local
(let ((format (nth 0 litem))
(remote-commands tramp-remote-coding-commands))
(setq loc-enc (nth 1 litem)
loc-dec (nth 2 litem))
;; If the local encoder or decoder is a string, the
;; corresponding command has to work locally.
(if (not (stringp loc-enc))
(tramp-message
vec 5 "Checking local encoding function `%s'" loc-enc)
(tramp-message
vec 5 "Checking local encoding command `%s' for sanity" loc-enc)
(unless (stringp (setq loc-enc (tramp-expand-script nil loc-enc)))
(throw 'wont-work-local nil))
(unless (zerop (tramp-call-local-coding-command loc-enc nil nil))
(throw 'wont-work-local nil)))
(if (not (stringp loc-dec))
(tramp-message
vec 5 "Checking local decoding function `%s'" loc-dec)
(tramp-message
vec 5 "Checking local decoding command `%s' for sanity" loc-dec)
(unless (stringp (setq loc-dec (tramp-expand-script nil loc-dec)))
(throw 'wont-work-local nil))
(unless (zerop (tramp-call-local-coding-command loc-dec nil nil))
(throw 'wont-work-local nil)))
;; Search for remote coding commands with the same format
(while (and remote-commands (not found))
(setq ritem (pop remote-commands))
(catch 'wont-work-remote
(when (equal format (nth 0 ritem))
(setq rem-enc (nth 1 ritem)
rem-dec (nth 2 ritem)
rem-test (nth 3 ritem))
;; Check the remote test command if exists.
(when (stringp rem-test)
(tramp-message
vec 5 "Checking remote test command `%s'" rem-test)
(unless (tramp-send-command-and-check vec rem-test t)
(throw 'wont-work-remote nil)))
;; Check if remote encoding and decoding commands can be
;; called remotely with null input and output. This makes
;; sure there are no syntax errors and the command is really
;; found. Note that we do not redirect stdout to /dev/null,
;; for two reasons: when checking the decoding command, we
;; actually check the output it gives. And also, when
;; redirecting "mimencode" output to /dev/null, then as root
;; it might change the permissions of /dev/null!
(unless (stringp rem-enc)
(let ((name (symbol-name rem-enc))
(value (symbol-value rem-enc)))
(while (string-match "-" name)
(setq name (replace-match "_" nil t name)))
(unless (tramp-expand-script vec value)
(throw 'wont-work-remote nil))
(tramp-maybe-send-script vec value name)
(setq rem-enc name)))
(tramp-message
vec 5
"Checking remote encoding command `%s' for sanity" rem-enc)
(unless (tramp-send-command-and-check
vec
(format
"%s <%s" rem-enc (tramp-get-remote-null-device vec))
t)
(throw 'wont-work-remote nil))
(unless (stringp rem-dec)
(let ((name (symbol-name rem-dec))
(value (symbol-value rem-dec)))
(while (string-match "-" name)
(setq name (replace-match "_" nil t name)))
(unless (tramp-expand-script vec value)
(throw 'wont-work-remote nil))
(tramp-maybe-send-script vec value name)
(setq rem-dec name)))
(tramp-message
vec 5
"Checking remote decoding command `%s' for sanity" rem-dec)
(unless (tramp-send-command-and-check
vec
(format "echo %s | %s | %s" magic rem-enc rem-dec)
t)
(throw 'wont-work-remote nil))
(with-current-buffer (tramp-get-connection-buffer vec)
(goto-char (point-min))
(unless (looking-at-p (rx (literal magic)))
(throw 'wont-work-remote nil)))
;; `rem-enc' and `rem-dec' could be a string meanwhile.
(setq rem-enc (nth 1 ritem)
rem-dec (nth 2 ritem)
found t)))))))
(when found
;; Set connection properties. Since the commands are risky
;; (due to output direction), we cache them in the process cache.
(tramp-message vec 5 "Using local encoding `%s'" loc-enc)
(tramp-set-connection-property p "local-encoding" loc-enc)
(tramp-message vec 5 "Using local decoding `%s'" loc-dec)
(tramp-set-connection-property p "local-decoding" loc-dec)
(tramp-message vec 5 "Using remote encoding `%s'" rem-enc)
(tramp-set-connection-property p "remote-encoding" rem-enc)
(tramp-message vec 5 "Using remote decoding `%s'" rem-dec)
(tramp-set-connection-property p "remote-decoding" rem-dec)))))