1 ;;; tramp-sh.el --- Tramp access functions for (s)sh-like connections
3 ;; Copyright (C) 1998-2015 Free Software Foundation, Inc.
5 ;; (copyright statements below in code to be updated with the above notice)
7 ;; Author: Kai Großjohann <kai.grossjohann@gmx.net>
8 ;; Michael Albinus <michael.albinus@gmx.de>
9 ;; Keywords: comm, processes
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
31 ;; Pacify byte-compiler.
35 (defvar directory-sep-char
)
36 (defvar tramp-gw-tunnel-method
)
37 (defvar tramp-gw-socks-method
)
38 (defvar vc-handled-backends
)
39 (defvar vc-bzr-program
)
40 (defvar vc-git-program
)
41 (defvar vc-hg-program
)
43 (defcustom tramp-inline-compress-start-size
4096
44 "The minimum size of compressing where inline transfer.
45 When inline transfer, compress transferred data of file
46 whose size is this value or above (up to `tramp-copy-size-limit').
47 If it is nil, no compression at all will be applied."
49 :type
'(choice (const nil
) integer
))
51 (defcustom tramp-copy-size-limit
10240
52 "The maximum file size where inline copying is preferred over an \
54 If it is nil, out-of-the-band copy will be used without a check."
56 :type
'(choice (const nil
) integer
))
59 (defcustom tramp-terminal-type
"dumb"
60 "Value of TERM environment variable for logging in to remote host.
61 Because Tramp wants to parse the output of the remote shell, it is easily
62 confused by ANSI color escape sequences and suchlike. Often, shell init
63 files conditionalize this setup based on the TERM environment variable."
68 (defcustom tramp-histfile-override
"/dev/null"
69 "When invoking a shell, override the HISTFILE with this value.
70 By default, the HISTFILE is set to the \"/dev/null\" value, which
71 is special on Unix systems and indicates the shell history should
72 not be logged (this avoids clutter due to Tramp commands).
74 If you set this variable to nil, however, the *override* is
75 disabled, so the history will go to the default storage
76 location, e.g. \"$HOME/.sh_history\"."
79 :type
'(choice (const :tag
"Do not override HISTFILE" nil
)
80 (const :tag
"Empty the history (/dev/null)" "/dev/null")
81 (string :tag
"Redirect to a file")))
84 (defconst tramp-color-escape-sequence-regexp
"\e[[;0-9]+m"
85 "Escape sequences produced by the \"ls\" command.")
87 ;; ksh on OpenBSD 4.5 requires that $PS1 contains a `#' character for
88 ;; root users. It uses the `$' character for other users. In order
89 ;; to guarantee a proper prompt, we use "#$ " for the prompt.
91 (defvar tramp-end-of-output
94 (md5 (concat (prin1-to-string process-environment
) (current-time-string))))
95 "String used to recognize end of output.
96 The '$' character at the end is quoted; the string cannot be
97 detected as prompt when being sent on echoing hosts, therefore.")
100 (defconst tramp-initial-end-of-output
"#$ "
101 "Prompt when establishing a connection.")
103 (defconst tramp-end-of-heredoc
(md5 tramp-end-of-output
)
104 "String used to recognize end of heredoc strings.")
106 ;; Initialize `tramp-methods' with the supported methods.
108 (add-to-list 'tramp-methods
110 (tramp-login-program "rsh")
111 (tramp-login-args (("%h") ("-l" "%u")))
112 (tramp-remote-shell "/bin/sh")
113 (tramp-remote-shell-args ("-c"))
114 (tramp-copy-program "rcp")
115 (tramp-copy-args (("-p" "%k") ("-r")))
116 (tramp-copy-keep-date t
)
117 (tramp-copy-recursive t
)))
119 (add-to-list 'tramp-methods
121 (tramp-login-program "remsh")
122 (tramp-login-args (("%h") ("-l" "%u")))
123 (tramp-remote-shell "/bin/sh")
124 (tramp-remote-shell-args ("-c"))
125 (tramp-copy-program "rcp")
126 (tramp-copy-args (("-p" "%k")))
127 (tramp-copy-keep-date t
)))
129 (add-to-list 'tramp-methods
131 (tramp-login-program "ssh")
132 (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c")
133 ("-e" "none") ("%h")))
134 (tramp-async-args (("-q")))
135 (tramp-remote-shell "/bin/sh")
136 (tramp-remote-shell-args ("-c"))
137 (tramp-copy-program "scp")
138 (tramp-copy-args (("-P" "%p") ("-p" "%k") ("-q") ("-r") ("%c")))
139 (tramp-copy-keep-date t
)
140 (tramp-copy-recursive t
)
141 (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null")
142 ("-o" "UserKnownHostsFile=/dev/null")
143 ("-o" "StrictHostKeyChecking=no")))
144 (tramp-default-port 22)))
146 (add-to-list 'tramp-methods
148 (tramp-login-program "ssh")
149 (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c")
150 ("-e" "none") ("-t" "-t") ("%h") ("/bin/sh")))
151 (tramp-async-args (("-q")))
152 (tramp-remote-shell "/bin/sh")
153 (tramp-remote-shell-args ("-c"))
154 (tramp-copy-program "scp")
155 (tramp-copy-args (("-P" "%p") ("-p" "%k")
156 ("-q") ("-r") ("%c")))
157 (tramp-copy-keep-date t
)
158 (tramp-copy-recursive t
)
159 (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null")
160 ("-o" "UserKnownHostsFile=/dev/null")
161 ("-o" "StrictHostKeyChecking=no")))
162 (tramp-default-port 22)))
164 (add-to-list 'tramp-methods
166 (tramp-login-program "ssh")
167 (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c")
168 ("-e" "none") ("%h")))
169 (tramp-async-args (("-q")))
170 (tramp-remote-shell "/bin/sh")
171 (tramp-remote-shell-args ("-c"))
172 (tramp-copy-program "rsync")
173 (tramp-copy-args (("-t" "%k") ("-r")))
174 (tramp-copy-env (("RSYNC_RSH") ("ssh" "%c")))
175 (tramp-copy-keep-date t
)
176 (tramp-copy-keep-tmpfile t
)
177 (tramp-copy-recursive t
)))
179 (add-to-list 'tramp-methods
181 (tramp-login-program "rsh")
182 (tramp-login-args (("%h") ("-l" "%u")))
183 (tramp-remote-shell "/bin/sh")
184 (tramp-remote-shell-args ("-c"))))
186 (add-to-list 'tramp-methods
188 (tramp-login-program "remsh")
189 (tramp-login-args (("%h") ("-l" "%u")))
190 (tramp-remote-shell "/bin/sh")
191 (tramp-remote-shell-args ("-c"))))
193 (add-to-list 'tramp-methods
195 (tramp-login-program "ssh")
196 (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c")
197 ("-e" "none") ("%h")))
198 (tramp-async-args (("-q")))
199 (tramp-remote-shell "/bin/sh")
200 (tramp-remote-shell-args ("-c"))
201 (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null")
202 ("-o" "UserKnownHostsFile=/dev/null")
203 ("-o" "StrictHostKeyChecking=no")))
204 (tramp-default-port 22)))
206 (add-to-list 'tramp-methods
208 (tramp-login-program "ssh")
209 (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c")
210 ("-e" "none") ("-t" "-t") ("%h") ("/bin/sh")))
211 (tramp-async-args (("-q")))
212 (tramp-remote-shell "/bin/sh")
213 (tramp-remote-shell-args ("-c"))
214 (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null")
215 ("-o" "UserKnownHostsFile=/dev/null")
216 ("-o" "StrictHostKeyChecking=no")))
217 (tramp-default-port 22)))
219 (add-to-list 'tramp-methods
221 (tramp-login-program "telnet")
222 (tramp-login-args (("%h") ("%p") ("2>/dev/null")))
223 (tramp-remote-shell "/bin/sh")
224 (tramp-remote-shell-args ("-c"))
225 (tramp-default-port 23)))
227 (add-to-list 'tramp-methods
229 (tramp-login-program "telnet")
230 (tramp-login-args (("%h") ("%p") ("2>/dev/null")))
231 (tramp-remote-shell "/bin/sh")
232 (tramp-remote-shell-args ("-c"))
233 (tramp-copy-program "nc")
234 ;; We use "-v" for better error tracking.
235 (tramp-copy-args (("-w" "1") ("-v") ("%h") ("%r")))
236 (tramp-remote-copy-program "nc")
237 ;; We use "-p" as required for newer busyboxes. For older
238 ;; busybox/nc versions, the value must be (("-l") ("%r")). This
239 ;; can be achieved by tweaking `tramp-connection-properties'.
240 (tramp-remote-copy-args (("-l") ("-p" "%r")))
241 (tramp-default-port 23)))
243 (add-to-list 'tramp-methods
245 (tramp-login-program "su")
246 (tramp-login-args (("-") ("%u")))
247 (tramp-remote-shell "/bin/sh")
248 (tramp-remote-shell-args ("-c"))
249 (tramp-connection-timeout 10)))
251 (add-to-list 'tramp-methods
253 (tramp-login-program "sudo")
254 (tramp-login-args (("-u" "%u") ("-s") ("-H") ("-p" "Password:")))
255 ;; Local $SHELL could be a nasty one, like zsh or fish. Let's override it.
256 (tramp-login-env (("SHELL") ("/bin/sh")))
257 (tramp-remote-shell "/bin/sh")
258 (tramp-remote-shell-args ("-c"))
259 (tramp-connection-timeout 10)))
261 (add-to-list 'tramp-methods
263 (tramp-login-program "ksu")
264 (tramp-login-args (("%u") ("-q")))
265 (tramp-remote-shell "/bin/sh")
266 (tramp-remote-shell-args ("-c"))
267 (tramp-connection-timeout 10)))
269 (add-to-list 'tramp-methods
271 (tramp-login-program "krlogin")
272 (tramp-login-args (("%h") ("-l" "%u") ("-x")))
273 (tramp-remote-shell "/bin/sh")
274 (tramp-remote-shell-args ("-c"))))
276 (add-to-list 'tramp-methods
278 (tramp-login-program "plink")
279 ;; ("%h") must be a single element, see `tramp-compute-multi-hops'.
280 (tramp-login-args (("-l" "%u") ("-P" "%p") ("-ssh") ("-t")
283 "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=%s'"
285 tramp-initial-end-of-output
))
287 (tramp-remote-shell "/bin/sh")
288 (tramp-remote-shell-args ("-c"))
289 (tramp-default-port 22)))
291 (add-to-list 'tramp-methods
293 (tramp-login-program "plink")
294 (tramp-login-args (("-load") ("%h") ("-t") ("\"")
296 "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=%s'"
298 tramp-initial-end-of-output
))
300 (tramp-remote-shell "/bin/sh")
301 (tramp-remote-shell-args ("-c"))))
303 (add-to-list 'tramp-methods
305 (tramp-login-program "plink")
306 (tramp-login-args (("-l" "%u") ("-P" "%p") ("-ssh") ("-t")
309 "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=%s'"
311 tramp-initial-end-of-output
))
313 (tramp-remote-shell "/bin/sh")
314 (tramp-remote-shell-args ("-c"))
315 (tramp-copy-program "pscp")
316 (tramp-copy-args (("-l" "%u") ("-P" "%p") ("-scp") ("-p" "%k")
318 (tramp-copy-keep-date t
)
319 (tramp-copy-recursive t
)
320 (tramp-default-port 22)))
322 (add-to-list 'tramp-methods
324 (tramp-login-program "plink")
325 (tramp-login-args (("-l" "%u") ("-P" "%p") ("-ssh") ("-t")
328 "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=%s'"
330 tramp-initial-end-of-output
))
332 (tramp-remote-shell "/bin/sh")
333 (tramp-remote-shell-args ("-c"))
334 (tramp-copy-program "pscp")
335 (tramp-copy-args (("-l" "%u") ("-P" "%p") ("-sftp") ("-p" "%k")
337 (tramp-copy-keep-date t
)
338 (tramp-copy-recursive t
)))
340 (add-to-list 'tramp-methods
342 (tramp-login-program "fsh")
343 (tramp-login-args (("%h") ("-l" "%u") ("sh" "-i")))
344 (tramp-remote-shell "/bin/sh")
345 (tramp-remote-shell-args ("-i") ("-c"))
346 (tramp-copy-program "fcp")
347 (tramp-copy-args (("-p" "%k")))
348 (tramp-copy-keep-date t
)))
351 (add-to-list 'tramp-default-method-alist
352 `(,tramp-local-host-regexp
"\\`root\\'" "su"))
355 (add-to-list 'tramp-default-user-alist
356 `(,(concat "\\`" (regexp-opt '("su" "sudo" "ksu")) "\\'")
358 ;; Do not add "ssh" based methods, otherwise ~/.ssh/config would be ignored.
359 ;; Do not add "plink" based methods, they ask interactively for the user.
361 (add-to-list 'tramp-default-user-alist
365 '("rcp" "remcp" "rsh" "telnet" "nc" "krlogin" "fcp"))
367 nil
,(user-login-name)))
370 (defconst tramp-completion-function-alist-rsh
371 '((tramp-parse-rhosts "/etc/hosts.equiv")
372 (tramp-parse-rhosts "~/.rhosts"))
373 "Default list of (FUNCTION FILE) pairs to be examined for rsh methods.")
376 (defconst tramp-completion-function-alist-ssh
377 '((tramp-parse-rhosts "/etc/hosts.equiv")
378 (tramp-parse-rhosts "/etc/shosts.equiv")
379 (tramp-parse-shosts "/etc/ssh_known_hosts")
380 (tramp-parse-sconfig "/etc/ssh_config")
381 (tramp-parse-shostkeys "/etc/ssh2/hostkeys")
382 (tramp-parse-sknownhosts "/etc/ssh2/knownhosts")
383 (tramp-parse-rhosts "~/.rhosts")
384 (tramp-parse-rhosts "~/.shosts")
385 (tramp-parse-shosts "~/.ssh/known_hosts")
386 (tramp-parse-sconfig "~/.ssh/config")
387 (tramp-parse-shostkeys "~/.ssh2/hostkeys")
388 (tramp-parse-sknownhosts "~/.ssh2/knownhosts"))
389 "Default list of (FUNCTION FILE) pairs to be examined for ssh methods.")
392 (defconst tramp-completion-function-alist-telnet
393 '((tramp-parse-hosts "/etc/hosts"))
394 "Default list of (FUNCTION FILE) pairs to be examined for telnet methods.")
397 (defconst tramp-completion-function-alist-su
398 '((tramp-parse-passwd "/etc/passwd"))
399 "Default list of (FUNCTION FILE) pairs to be examined for su methods.")
402 (defconst tramp-completion-function-alist-putty
404 ,(if (memq system-type
'(windows-nt))
405 "HKEY_CURRENT_USER\\Software\\SimonTatham\\PuTTY\\Sessions"
406 "~/.putty/sessions")))
407 "Default list of (FUNCTION REGISTRY) pairs to be examined for putty sessions.")
410 (eval-after-load 'tramp
412 (tramp-set-completion-function "rcp" tramp-completion-function-alist-rsh
)
413 (tramp-set-completion-function "remcp" tramp-completion-function-alist-rsh
)
414 (tramp-set-completion-function "scp" tramp-completion-function-alist-ssh
)
415 (tramp-set-completion-function "scpx" tramp-completion-function-alist-ssh
)
416 (tramp-set-completion-function "rsync" tramp-completion-function-alist-ssh
)
417 (tramp-set-completion-function "rsh" tramp-completion-function-alist-rsh
)
418 (tramp-set-completion-function "remsh" tramp-completion-function-alist-rsh
)
419 (tramp-set-completion-function "ssh" tramp-completion-function-alist-ssh
)
420 (tramp-set-completion-function "sshx" tramp-completion-function-alist-ssh
)
421 (tramp-set-completion-function
422 "telnet" tramp-completion-function-alist-telnet
)
423 (tramp-set-completion-function "nc" tramp-completion-function-alist-telnet
)
424 (tramp-set-completion-function "su" tramp-completion-function-alist-su
)
425 (tramp-set-completion-function "sudo" tramp-completion-function-alist-su
)
426 (tramp-set-completion-function "ksu" tramp-completion-function-alist-su
)
427 (tramp-set-completion-function
428 "krlogin" tramp-completion-function-alist-rsh
)
429 (tramp-set-completion-function "plink" tramp-completion-function-alist-ssh
)
430 (tramp-set-completion-function
431 "plinkx" tramp-completion-function-alist-putty
)
432 (tramp-set-completion-function "pscp" tramp-completion-function-alist-ssh
)
433 (tramp-set-completion-function "psftp" tramp-completion-function-alist-ssh
)
434 (tramp-set-completion-function "fcp" tramp-completion-function-alist-ssh
)))
436 ;; "getconf PATH" yields:
437 ;; HP-UX: /usr/bin:/usr/ccs/bin:/opt/ansic/bin:/opt/langtools/bin:/opt/fortran/bin
438 ;; Solaris: /usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/opt/SUNWspro/bin
439 ;; GNU/Linux (Debian, Suse): /bin:/usr/bin
440 ;; FreeBSD: /usr/bin:/bin:/usr/sbin:/sbin: - beware trailing ":"!
443 (defcustom tramp-remote-path
444 '(tramp-default-remote-path "/bin" "/usr/bin" "/sbin" "/usr/sbin"
445 "/usr/local/bin" "/usr/local/sbin" "/local/bin" "/local/freeware/bin"
446 "/local/gnu/bin" "/usr/freeware/bin" "/usr/pkg/bin" "/usr/contrib/bin"
447 "/opt/bin" "/opt/sbin" "/opt/local/bin")
448 "List of directories to search for executables on remote host.
449 For every remote host, this variable will be set buffer local,
450 keeping the list of existing directories on that host.
452 You can use `~' in this list, but when searching for a shell which groks
453 tilde expansion, all directory names starting with `~' will be ignored.
455 `Default Directories' represent the list of directories given by
456 the command \"getconf PATH\". It is recommended to use this
457 entry on top of this list, because these are the default
458 directories for POSIX compatible commands. On remote hosts which
459 do not offer the getconf command (like cygwin), the value
460 \"/bin:/usr/bin\" is used instead of.
462 `Private Directories' are the settings of the $PATH environment,
463 as given in your `~/.profile'."
465 :type
'(repeat (choice
466 (const :tag
"Default Directories" tramp-default-remote-path
)
467 (const :tag
"Private Directories" tramp-own-remote-path
)
468 (string :tag
"Directory"))))
471 (defcustom tramp-remote-process-environment
472 `("TMOUT=0" "LC_CTYPE=''"
473 ,(format "TERM=%s" tramp-terminal-type
)
474 "EMACS=t" ;; Deprecated.
475 ,(format "INSIDE_EMACS='%s,tramp:%s'" emacs-version tramp-version
)
476 "CDPATH=" "HISTORY=" "MAIL=" "MAILCHECK=" "MAILPATH=" "PAGER=\"\""
477 "autocorrect=" "correct=")
478 "List of environment variables to be set on the remote host.
480 Each element should be a string of the form ENVVARNAME=VALUE. An
481 entry ENVVARNAME= disables the corresponding environment variable,
482 which might have been set in the init files like ~/.profile.
484 Special handling is applied to the PATH environment, which should
485 not be set here. Instead, it should be set via `tramp-remote-path'."
488 :type
'(repeat string
))
490 (defcustom tramp-sh-extra-args
'(("/bash\\'" .
"-norc -noprofile"))
491 "Alist specifying extra arguments to pass to the remote shell.
492 Entries are (REGEXP . ARGS) where REGEXP is a regular expression
493 matching the shell file name and ARGS is a string specifying the
496 This variable is only used when Tramp needs to start up another shell
497 for tilde expansion. The extra arguments should typically prevent the
498 shell from reading its init file."
500 ;; This might be the wrong way to test whether the widget type
501 ;; `alist' is available. Who knows the right way to test it?
502 :type
(if (get 'alist
'widget-type
)
503 '(alist :key-type string
:value-type string
)
504 '(repeat (cons string string
))))
506 (defconst tramp-actions-before-shell
507 '((tramp-login-prompt-regexp tramp-action-login
)
508 (tramp-password-prompt-regexp tramp-action-password
)
509 (tramp-wrong-passwd-regexp tramp-action-permission-denied
)
510 (shell-prompt-pattern tramp-action-succeed
)
511 (tramp-shell-prompt-pattern tramp-action-succeed
)
512 (tramp-yesno-prompt-regexp tramp-action-yesno
)
513 (tramp-yn-prompt-regexp tramp-action-yn
)
514 (tramp-terminal-prompt-regexp tramp-action-terminal
)
515 (tramp-process-alive-regexp tramp-action-process-alive
))
516 "List of pattern/action pairs.
517 Whenever a pattern matches, the corresponding action is performed.
518 Each item looks like (PATTERN ACTION).
520 The PATTERN should be a symbol, a variable. The value of this
521 variable gives the regular expression to search for. Note that the
522 regexp must match at the end of the buffer, \"\\'\" is implicitly
525 The ACTION should also be a symbol, but a function. When the
526 corresponding PATTERN matches, the ACTION function is called.")
528 (defconst tramp-actions-copy-out-of-band
529 '((tramp-password-prompt-regexp tramp-action-password
)
530 (tramp-wrong-passwd-regexp tramp-action-permission-denied
)
531 (tramp-copy-failed-regexp tramp-action-permission-denied
)
532 (tramp-process-alive-regexp tramp-action-out-of-band
))
533 "List of pattern/action pairs.
534 This list is used for copying/renaming with out-of-band methods.
536 See `tramp-actions-before-shell' for more info.")
538 (defconst tramp-uudecode
539 "(echo begin 600 %t; tail -n +2) | uudecode
542 "Shell function to implement `uudecode' to standard output.
543 Many systems support `uudecode -o /dev/stdout' or `uudecode -o -'
544 for this or `uudecode -p', but some systems don't, and for them
545 we have this shell function.")
547 (defconst tramp-perl-file-truename
550 use Cwd \"realpath\";
553 my ($volume, @dirs) = @_;
554 my $real = realpath(File::Spec->catpath(
555 $volume, File::Spec->catdir(@dirs), \"\"));
557 my ($vol, $dir) = File::Spec->splitpath($real, 1);
558 return ($vol, File::Spec->splitdir($dir));
561 my $last = pop(@dirs);
562 ($volume, @dirs) = recursive($volume, @dirs);
564 return ($volume, @dirs);
568 $result = realpath($ARGV[0]);
570 my ($vol, $dir) = File::Spec->splitpath($ARGV[0], 1);
571 ($vol, @dirs) = recursive($vol, File::Spec->splitdir($dir));
573 $result = File::Spec->catpath($vol, File::Spec->catdir(@dirs), \"\");
576 if ($ARGV[0] =~ /\\/$/) {
577 $result = $result . \"/\";
580 print \"\\\"$result\\\"\\n\";
581 ' \"$1\" 2>/dev/null"
582 "Perl script to produce output suitable for use with `file-truename'
583 on the remote file system.
584 Escape sequence %s is replaced with name of Perl binary.
585 This string is passed to `format', so percent characters need to be doubled.")
587 (defconst tramp-perl-file-name-all-completions
597 opendir(d, $ARGV[0]) || die(\"$ARGV[0]: $!\\nfail\\n\");
598 @files = readdir(d); closedir(d);
599 foreach $f (@files) {
600 if (case(substr($f, 0, length($ARGV[1]))) eq case($ARGV[1])) {
601 if (-d \"$ARGV[0]/$f\") {
610 ' \"$1\" \"$2\" \"$3\" 2>/dev/null"
611 "Perl script to produce output suitable for use with
612 `file-name-all-completions' on the remote file system. Escape
613 sequence %s is replaced with name of Perl binary. This string is
614 passed to `format', so percent characters need to be doubled.")
616 ;; Perl script to implement `file-attributes' in a Lisp `read'able
617 ;; output. If you are hacking on this, note that you get *no* output
618 ;; unless this spits out a complete line, including the '\n' at the
620 ;; The device number is returned as "-1", because there will be a virtual
621 ;; device number set in `tramp-sh-handle-file-attributes'.
622 (defconst tramp-perl-file-attributes
624 @stat = lstat($ARGV[0]);
629 if (($stat[2] & 0170000) == 0120000)
631 $type = readlink($ARGV[0]);
632 $type = \"\\\"$type\\\"\";
634 elsif (($stat[2] & 0170000) == 040000)
642 $uid = ($ARGV[1] eq \"integer\") ? $stat[4] : \"\\\"\" . getpwuid($stat[4]) . \"\\\"\";
643 $gid = ($ARGV[1] eq \"integer\") ? $stat[5] : \"\\\"\" . getgrgid($stat[5]) . \"\\\"\";
645 \"(%%s %%u %%s %%s (%%u %%u) (%%u %%u) (%%u %%u) %%u.0 %%u t (%%u . %%u) -1)\\n\",
650 $stat[8] >> 16 & 0xffff,
652 $stat[9] >> 16 & 0xffff,
654 $stat[10] >> 16 & 0xffff,
658 $stat[1] >> 16 & 0xffff,
660 );' \"$1\" \"$2\" 2>/dev/null"
661 "Perl script to produce output suitable for use with `file-attributes'
662 on the remote file system.
663 Escape sequence %s is replaced with name of Perl binary.
664 This string is passed to `format', so percent characters need to be doubled.")
666 (defconst tramp-perl-directory-files-and-attributes
668 chdir($ARGV[0]) or printf(\"\\\"Cannot change to $ARGV[0]: $''!''\\\"\\n\"), exit();
669 opendir(DIR,\".\") or printf(\"\\\"Cannot open directory $ARGV[0]: $''!''\\\"\\n\"), exit();
670 @list = readdir(DIR);
674 for($i = 0; $i < $n; $i++)
676 $filename = $list[$i];
677 @stat = lstat($filename);
678 if (($stat[2] & 0170000) == 0120000)
680 $type = readlink($filename);
681 $type = \"\\\"$type\\\"\";
683 elsif (($stat[2] & 0170000) == 040000)
691 $uid = ($ARGV[1] eq \"integer\") ? $stat[4] : \"\\\"\" . getpwuid($stat[4]) . \"\\\"\";
692 $gid = ($ARGV[1] eq \"integer\") ? $stat[5] : \"\\\"\" . getgrgid($stat[5]) . \"\\\"\";
694 \"(\\\"%%s\\\" %%s %%u %%s %%s (%%u %%u) (%%u %%u) (%%u %%u) %%u.0 %%u t (%%u . %%u) (%%u . %%u))\\n\",
700 $stat[8] >> 16 & 0xffff,
702 $stat[9] >> 16 & 0xffff,
704 $stat[10] >> 16 & 0xffff,
708 $stat[1] >> 16 & 0xffff,
710 $stat[0] >> 16 & 0xffff,
713 printf(\")\\n\");' \"$1\" \"$2\" 2>/dev/null"
714 "Perl script implementing `directory-files-attributes' as Lisp `read'able
716 Escape sequence %s is replaced with name of Perl binary.
717 This string is passed to `format', so percent characters need to be doubled.")
719 ;; These two use base64 encoding.
720 (defconst tramp-perl-encode-with-module
721 "%s -MMIME::Base64 -0777 -ne 'print encode_base64($_)' 2>/dev/null"
722 "Perl program to use for encoding a file.
723 Escape sequence %s is replaced with name of Perl binary.
724 This string is passed to `format', so percent characters need to be doubled.
725 This implementation requires the MIME::Base64 Perl module to be installed
726 on the remote host.")
728 (defconst tramp-perl-decode-with-module
729 "%s -MMIME::Base64 -0777 -ne 'print decode_base64($_)' 2>/dev/null"
730 "Perl program to use for decoding a file.
731 Escape sequence %s is replaced with name of Perl binary.
732 This string is passed to `format', so percent characters need to be doubled.
733 This implementation requires the MIME::Base64 Perl module to be installed
734 on the remote host.")
736 (defconst tramp-perl-encode
738 # This script contributed by Juanma Barranquero <lektu@terra.es>.
739 # Copyright (C) 2002-2015 Free Software Foundation, Inc.
744 map {(substr(unpack(q(B8), chr $i++), 2, 6), $_)}
745 split //, q(ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/);
749 # We read in chunks of 54 bytes, to generate output lines
750 # of 72 chars (plus end of line)
751 while (read STDIN, $data, 54) {
754 # Only for the last chunk, and only if did not fill the last three-byte packet
756 my $mod = length($data) %% 3;
757 $pad = q(=) x (3 - $mod) if $mod;
760 # Not the fastest method, but it is simple: unpack to binary string, split
761 # by groups of 6 bits and convert back from binary to byte; then map into
762 # the translation table
766 (substr(unpack(q(B*), $data) . q(00000), 0, 432) =~ /....../g)),
770 "Perl program to use for encoding a file.
771 Escape sequence %s is replaced with name of Perl binary.
772 This string is passed to `format', so percent characters need to be doubled.")
774 (defconst tramp-perl-decode
776 # This script contributed by Juanma Barranquero <lektu@terra.es>.
777 # Copyright (C) 2002-2015 Free Software Foundation, Inc.
782 map {($_, substr(unpack(q(B8), chr $i++), 2, 6))}
783 split //, q(ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/)
786 my %%bytes = map {(unpack(q(B8), chr $_), chr $_)} 0 .. 255;
790 # We are going to accumulate into $pending to accept any line length
791 # (we do not check they are <= 76 chars as the RFC says)
794 while (my $data = <STDIN>) {
797 # If we find one or two =, we have reached the end and
798 # any following data is to be discarded
799 my $finished = $data =~ s/(==?).*/$1/;
802 my $len = length($pending);
803 my $chunk = substr($pending, 0, $len & ~3);
804 $pending = substr($pending, $len & ~3 + 1);
806 # Easy method: translate from chars to (pregenerated) six-bit packets, join,
807 # split in 8-bit chunks and convert back to char.
810 ((join q(), map {$trans{$_} || q()} split //, $chunk) =~ /......../g);
814 "Perl program to use for decoding a file.
815 Escape sequence %s is replaced with name of Perl binary.
816 This string is passed to `format', so percent characters need to be doubled.")
818 (defconst tramp-perl-pack
819 "%s -e 'binmode STDIN; binmode STDOUT; print pack(q{u*}, join q{}, <>)'"
820 "Perl program to use for encoding a file.
821 Escape sequence %s is replaced with name of Perl binary.")
823 (defconst tramp-perl-unpack
824 "%s -e 'binmode STDIN; binmode STDOUT; print unpack(q{u*}, join q{}, <>)'"
825 "Perl program to use for decoding a file.
826 Escape sequence %s is replaced with name of Perl binary.")
828 (defconst tramp-vc-registered-read-file-names
831 if %s \"$file\"; then
832 echo \"(\\\"$file\\\" \\\"file-exists-p\\\" t)\"
834 echo \"(\\\"$file\\\" \\\"file-exists-p\\\" nil)\"
836 if %s \"$file\"; then
837 echo \"(\\\"$file\\\" \\\"file-readable-p\\\" t)\"
839 echo \"(\\\"$file\\\" \\\"file-readable-p\\\" nil)\"
843 "Script to check existence of VC related files.
844 It must be send formatted with two strings; the tests for file
845 existence, and file readability. Input shall be read via
846 here-document, otherwise the command could exceed maximum length
849 ;; New handlers should be added here.
850 (defconst tramp-sh-file-name-handler-alist
851 '(;; `access-file' performed by default handler.
852 (add-name-to-file . tramp-sh-handle-add-name-to-file
)
853 ;; `byte-compiler-base-file-name' performed by default handler.
854 (copy-directory . tramp-sh-handle-copy-directory
)
855 (copy-file . tramp-sh-handle-copy-file
)
856 (delete-directory . tramp-sh-handle-delete-directory
)
857 (delete-file . tramp-sh-handle-delete-file
)
858 ;; `diff-latest-backup-file' performed by default handler.
859 (directory-file-name . tramp-handle-directory-file-name
)
860 (directory-files . tramp-handle-directory-files
)
861 (directory-files-and-attributes
862 . tramp-sh-handle-directory-files-and-attributes
)
863 ;; `dired-call-process' performed by default handler.
864 (dired-compress-file . tramp-sh-handle-dired-compress-file
)
865 (dired-recursive-delete-directory
866 . tramp-sh-handle-dired-recursive-delete-directory
)
867 (dired-uncache . tramp-handle-dired-uncache
)
868 (expand-file-name . tramp-sh-handle-expand-file-name
)
869 (file-accessible-directory-p . tramp-handle-file-accessible-directory-p
)
870 (file-acl . tramp-sh-handle-file-acl
)
871 (file-attributes . tramp-sh-handle-file-attributes
)
872 (file-directory-p . tramp-sh-handle-file-directory-p
)
873 ;; `file-equal-p' performed by default handler.
874 (file-executable-p . tramp-sh-handle-file-executable-p
)
875 (file-exists-p . tramp-sh-handle-file-exists-p
)
876 ;; `file-in-directory-p' performed by default handler.
877 (file-local-copy . tramp-sh-handle-file-local-copy
)
878 (file-modes . tramp-handle-file-modes
)
879 (file-name-all-completions . tramp-sh-handle-file-name-all-completions
)
880 (file-name-as-directory . tramp-handle-file-name-as-directory
)
881 (file-name-completion . tramp-handle-file-name-completion
)
882 (file-name-directory . tramp-handle-file-name-directory
)
883 (file-name-nondirectory . tramp-handle-file-name-nondirectory
)
884 ;; `file-name-sans-versions' performed by default handler.
885 (file-newer-than-file-p . tramp-sh-handle-file-newer-than-file-p
)
886 (file-notify-add-watch . tramp-sh-handle-file-notify-add-watch
)
887 (file-notify-rm-watch . tramp-handle-file-notify-rm-watch
)
888 (file-ownership-preserved-p . tramp-sh-handle-file-ownership-preserved-p
)
889 (file-readable-p . tramp-sh-handle-file-readable-p
)
890 (file-regular-p . tramp-handle-file-regular-p
)
891 (file-remote-p . tramp-handle-file-remote-p
)
892 (file-selinux-context . tramp-sh-handle-file-selinux-context
)
893 (file-symlink-p . tramp-handle-file-symlink-p
)
894 (file-truename . tramp-sh-handle-file-truename
)
895 (file-writable-p . tramp-sh-handle-file-writable-p
)
896 (find-backup-file-name . tramp-handle-find-backup-file-name
)
897 ;; `find-file-noselect' performed by default handler.
898 ;; `get-file-buffer' performed by default handler.
899 (insert-directory . tramp-sh-handle-insert-directory
)
900 (insert-file-contents . tramp-handle-insert-file-contents
)
901 (insert-file-contents-literally
902 . tramp-sh-handle-insert-file-contents-literally
)
903 (load . tramp-handle-load
)
904 (make-auto-save-file-name . tramp-handle-make-auto-save-file-name
)
905 (make-directory . tramp-sh-handle-make-directory
)
906 (make-symbolic-link . tramp-sh-handle-make-symbolic-link
)
907 (process-file . tramp-sh-handle-process-file
)
908 (rename-file . tramp-sh-handle-rename-file
)
909 (set-file-acl . tramp-sh-handle-set-file-acl
)
910 (set-file-modes . tramp-sh-handle-set-file-modes
)
911 (set-file-selinux-context . tramp-sh-handle-set-file-selinux-context
)
912 (set-file-times . tramp-sh-handle-set-file-times
)
913 (set-visited-file-modtime . tramp-sh-handle-set-visited-file-modtime
)
914 (shell-command . tramp-handle-shell-command
)
915 (start-file-process . tramp-sh-handle-start-file-process
)
916 (substitute-in-file-name . tramp-handle-substitute-in-file-name
)
917 (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory
)
918 (vc-registered . tramp-sh-handle-vc-registered
)
919 (verify-visited-file-modtime . tramp-sh-handle-verify-visited-file-modtime
)
920 (write-region . tramp-sh-handle-write-region
))
921 "Alist of handler functions.
922 Operations not mentioned here will be handled by the normal Emacs functions.")
924 ;; This must be the last entry, because `identity' always matches.
926 (add-to-list 'tramp-foreign-file-name-handler-alist
927 '(identity . tramp-sh-file-name-handler
) 'append
)
929 ;;; File Name Handler Functions:
931 (defun tramp-sh-handle-make-symbolic-link
932 (filename linkname
&optional ok-if-already-exists
)
933 "Like `make-symbolic-link' for Tramp files.
934 If LINKNAME is a non-Tramp file, it is used verbatim as the target of
935 the symlink. If LINKNAME is a Tramp file, only the localname component is
936 used as the target of the symlink.
938 If LINKNAME is a Tramp file and the localname component is relative, then
939 it is expanded first, before the localname component is taken. Note that
940 this can give surprising results if the user/host for the source and
941 target of the symlink differ."
942 (with-parsed-tramp-file-name linkname l
943 (let ((ln (tramp-get-remote-ln l
))
944 (cwd (tramp-run-real-handler
945 'file-name-directory
(list l-localname
))))
949 "Making a symbolic link. ln(1) does not exist on the remote host."))
951 ;; Do the 'confirm if exists' thing.
952 (when (file-exists-p linkname
)
954 (if (or (null ok-if-already-exists
) ; not allowed to exist
955 (and (numberp ok-if-already-exists
)
958 "File %s already exists; make it a link anyway? "
961 l
'file-already-exists
"File %s already exists" l-localname
)
962 (delete-file linkname
)))
964 ;; If FILENAME is a Tramp name, use just the localname component.
965 (when (tramp-tramp-file-p filename
)
967 (tramp-file-name-localname
968 (tramp-dissect-file-name (expand-file-name filename
)))))
970 (tramp-flush-file-property l
(file-name-directory l-localname
))
971 (tramp-flush-file-property l l-localname
)
973 ;; Right, they are on the same host, regardless of user, method,
974 ;; etc. We now make the link on the remote machine. This will
975 ;; occur as the user that FILENAME belongs to.
976 (tramp-send-command-and-check
979 "cd %s && %s -sf %s %s"
980 (tramp-shell-quote-argument cwd
)
982 (tramp-shell-quote-argument filename
)
983 (tramp-shell-quote-argument l-localname
))
986 (defun tramp-sh-handle-file-truename (filename)
987 "Like `file-truename' for Tramp files."
990 (with-parsed-tramp-file-name (expand-file-name filename
) nil
991 (tramp-make-tramp-file-name
993 (with-tramp-file-property v localname
"file-truename"
994 (let ((result nil
)) ; result steps in reverse order
995 (tramp-message v
4 "Finding true name for `%s'" filename
)
997 ;; Use GNU readlink --canonicalize-missing where available.
998 ((tramp-get-remote-readlink v
)
999 (tramp-send-command-and-check
1001 (format "%s --canonicalize-missing %s"
1002 (tramp-get-remote-readlink v
)
1003 (tramp-shell-quote-argument localname
)))
1004 (with-current-buffer (tramp-get-connection-buffer v
)
1005 (goto-char (point-min))
1006 (setq result
(buffer-substring (point-min) (point-at-eol)))))
1008 ;; Use Perl implementation.
1009 ((and (tramp-get-remote-perl v
)
1010 (tramp-get-connection-property v
"perl-file-spec" nil
)
1011 (tramp-get-connection-property v
"perl-cwd-realpath" nil
))
1012 (tramp-maybe-send-script
1013 v tramp-perl-file-truename
"tramp_perl_file_truename")
1015 (tramp-send-command-and-read
1017 (format "tramp_perl_file_truename %s"
1018 (tramp-shell-quote-argument localname
)))))
1020 ;; Do it yourself. We bind `directory-sep-char' here for
1021 ;; XEmacs on Windows, which would otherwise use backslash.
1022 (t (let* ((directory-sep-char ?
/)
1023 (steps (tramp-compat-split-string localname
"/"))
1024 (localnamedir (tramp-run-real-handler
1025 'file-name-as-directory
(list localname
)))
1026 (is-dir (string= localname localnamedir
))
1029 ;; Don't make the following value larger than
1030 ;; necessary. People expect an error message in
1031 ;; a timely fashion when something is wrong;
1032 ;; otherwise they might think that Emacs is hung.
1033 ;; Of course, correctness has to come first.
1036 (while (and steps
(< numchase numchase-limit
))
1037 (setq thisstep
(pop steps
))
1040 (mapconcat 'identity
1041 (append '("") (reverse result
) (list thisstep
))
1043 (setq symlink-target
1044 (nth 0 (file-attributes
1045 (tramp-make-tramp-file-name
1047 (mapconcat 'identity
1052 (cond ((string= "." thisstep
)
1053 (tramp-message v
5 "Ignoring step `.'"))
1054 ((string= ".." thisstep
)
1055 (tramp-message v
5 "Processing step `..'")
1057 ((stringp symlink-target
)
1058 ;; It's a symlink, follow it.
1060 v
5 "Follow symlink to %s" symlink-target
)
1061 (setq numchase
(1+ numchase
))
1062 (when (file-name-absolute-p symlink-target
)
1064 ;; If the symlink was absolute, we'll get a
1065 ;; string like "/user@host:/some/target";
1066 ;; extract the "/some/target" part from it.
1067 (when (tramp-tramp-file-p symlink-target
)
1068 (unless (tramp-equal-remote filename symlink-target
)
1071 "Symlink target `%s' on wrong host"
1073 (setq symlink-target localname
))
1075 (append (tramp-compat-split-string
1080 (setq result
(cons thisstep result
)))))
1081 (when (>= numchase numchase-limit
)
1084 "Maximum number (%d) of symlinks exceeded" numchase-limit
))
1085 (setq result
(reverse result
))
1086 ;; Combine list to form string.
1089 (mapconcat 'identity
(cons "" result
) "/")
1092 (or (string= "" result
)
1093 (not (string= (substring result -
1) "/"))))
1094 (setq result
(concat result
"/"))))))
1096 (tramp-message v
4 "True name of `%s' is `%s'" localname result
)
1099 ;; Preserve trailing "/".
1100 (if (string-equal (file-name-nondirectory filename
) "") "/" "")))
1104 (defun tramp-sh-handle-file-exists-p (filename)
1105 "Like `file-exists-p' for Tramp files."
1106 (with-parsed-tramp-file-name filename nil
1107 (with-tramp-file-property v localname
"file-exists-p"
1108 (or (not (null (tramp-get-file-property
1109 v localname
"file-attributes-integer" nil
)))
1110 (not (null (tramp-get-file-property
1111 v localname
"file-attributes-string" nil
)))
1112 (tramp-send-command-and-check
1116 (tramp-get-file-exists-command v
)
1117 (tramp-shell-quote-argument localname
)))))))
1119 (defun tramp-sh-handle-file-attributes (filename &optional id-format
)
1120 "Like `file-attributes' for Tramp files."
1121 (unless id-format
(setq id-format
'integer
))
1123 ;; Don't modify `last-coding-system-used' by accident.
1124 (let ((last-coding-system-used last-coding-system-used
))
1125 (with-parsed-tramp-file-name (expand-file-name filename
) nil
1126 (with-tramp-file-property
1127 v localname
(format "file-attributes-%s" id-format
)
1129 (tramp-convert-file-attributes
1133 ((tramp-get-remote-stat v
)
1134 (tramp-do-file-attributes-with-stat v localname id-format
))
1135 ((tramp-get-remote-perl v
)
1136 (tramp-do-file-attributes-with-perl v localname id-format
))
1138 ;; The scripts could fail, for example with huge file size.
1139 (tramp-do-file-attributes-with-ls v localname id-format
)))))))))
1141 (defun tramp-do-file-attributes-with-ls (vec localname
&optional id-format
)
1142 "Implement `file-attributes' for Tramp files using the ls(1) command."
1144 res-inode res-filemodes res-numlinks
1145 res-uid res-gid res-size res-symlink-target
)
1146 (tramp-message vec
5 "file attributes with ls: %s" localname
)
1149 (format "(%s %s || %s -h %s) && %s %s %s"
1150 (tramp-get-file-exists-command vec
)
1151 (tramp-shell-quote-argument localname
)
1152 (tramp-get-test-command vec
)
1153 (tramp-shell-quote-argument localname
)
1154 (tramp-get-ls-command vec
)
1155 (if (eq id-format
'integer
) "-ildn" "-ild")
1156 (tramp-shell-quote-argument localname
)))
1157 ;; parse `ls -l' output ...
1158 (with-current-buffer (tramp-get-buffer vec
)
1159 (when (> (buffer-size) 0)
1160 (goto-char (point-min))
1164 (read (current-buffer))
1165 (invalid-read-syntax
1166 (when (and (equal (cadr err
)
1167 "Integer constant overflow in reader")
1169 "^[0-9]+\\([0-9][0-9][0-9][0-9][0-9]\\)\\'"
1171 (let* ((big (read (substring (car (cddr err
)) 0
1172 (match-beginning 1))))
1173 (small (read (match-string 1 (car (cddr err
)))))
1174 (twiddle (/ small
65536)))
1175 (cons (+ big twiddle
)
1176 (- small
(* twiddle
65536))))))))
1177 ;; ... file mode flags
1178 (setq res-filemodes
(symbol-name (read (current-buffer))))
1180 (setq res-numlinks
(read (current-buffer)))
1182 (setq res-uid
(read (current-buffer)))
1183 (setq res-gid
(read (current-buffer)))
1184 (if (eq id-format
'integer
)
1186 (unless (numberp res-uid
) (setq res-uid -
1))
1187 (unless (numberp res-gid
) (setq res-gid -
1)))
1189 (unless (stringp res-uid
) (setq res-uid
(symbol-name res-uid
)))
1190 (unless (stringp res-gid
) (setq res-gid
(symbol-name res-gid
)))))
1192 (setq res-size
(read (current-buffer)))
1193 ;; From the file modes, figure out other stuff.
1194 (setq symlinkp
(eq ?l
(aref res-filemodes
0)))
1195 (setq dirp
(eq ?d
(aref res-filemodes
0)))
1196 ;; if symlink, find out file name pointed to
1198 (search-forward "-> ")
1199 (setq res-symlink-target
(buffer-substring (point) (point-at-eol))))
1200 ;; return data gathered
1202 ;; 0. t for directory, string (name linked to) for symbolic
1204 (or dirp res-symlink-target
)
1205 ;; 1. Number of links to file.
1211 ;; 4. Last access time, as a list of integers. Normally this
1212 ;; would be in the same format as `current-time', but the
1213 ;; subseconds part is not currently implemented, and (0 0)
1214 ;; denotes an unknown time.
1215 ;; 5. Last modification time, likewise.
1216 ;; 6. Last status change time, likewise.
1217 '(0 0) '(0 0) '(0 0) ;CCC how to find out?
1218 ;; 7. Size in bytes (-1, if number is out of range).
1220 ;; 8. File modes, as a string of ten letters or dashes as in ls -l.
1222 ;; 9. t if file's gid would change if file were deleted and
1223 ;; recreated. Will be set in `tramp-convert-file-attributes'
1225 ;; 10. inode number.
1227 ;; 11. Device number. Will be replaced by a virtual device number.
1231 (defun tramp-do-file-attributes-with-perl
1232 (vec localname
&optional id-format
)
1233 "Implement `file-attributes' for Tramp files using a Perl script."
1234 (tramp-message vec
5 "file attributes with perl: %s" localname
)
1235 (tramp-maybe-send-script
1236 vec tramp-perl-file-attributes
"tramp_perl_file_attributes")
1237 (tramp-send-command-and-read
1239 (format "tramp_perl_file_attributes %s %s"
1240 (tramp-shell-quote-argument localname
) id-format
)))
1242 (defun tramp-do-file-attributes-with-stat
1243 (vec localname
&optional id-format
)
1244 "Implement `file-attributes' for Tramp files using stat(1) command."
1245 (tramp-message vec
5 "file attributes with stat: %s" localname
)
1246 (tramp-send-command-and-read
1249 ;; On Opsware, pdksh (which is the true name of ksh there) doesn't
1250 ;; parse correctly the sequence "((". Therefore, we add a space.
1251 "( (%s %s || %s -h %s) && %s -c '((\"%%N\") %%h %s %s %%Xe0 %%Ye0 %%Ze0 %%se0 \"%%A\" t %%ie0 -1)' %s || echo nil)"
1252 (tramp-get-file-exists-command vec
)
1253 (tramp-shell-quote-argument localname
)
1254 (tramp-get-test-command vec
)
1255 (tramp-shell-quote-argument localname
)
1256 (tramp-get-remote-stat vec
)
1257 (if (eq id-format
'integer
) "%ue0" "\"%U\"")
1258 (if (eq id-format
'integer
) "%ge0" "\"%G\"")
1259 (tramp-shell-quote-argument localname
))))
1261 (defun tramp-sh-handle-set-visited-file-modtime (&optional time-list
)
1262 "Like `set-visited-file-modtime' for Tramp files."
1263 (unless (buffer-file-name)
1264 (error "Can't set-visited-file-modtime: buffer `%s' not visiting a file"
1267 (tramp-run-real-handler 'set-visited-file-modtime
(list time-list
))
1268 (let ((f (buffer-file-name))
1270 (with-parsed-tramp-file-name f nil
1271 (let* ((remote-file-name-inhibit-cache t
)
1272 (attr (file-attributes f
))
1273 ;; '(-1 65535) means file doesn't exists yet.
1274 (modtime (or (nth 5 attr
) '(-1 65535))))
1275 (when (boundp 'last-coding-system-used
)
1276 (setq coding-system-used
(symbol-value 'last-coding-system-used
)))
1277 ;; We use '(0 0) as a don't-know value. See also
1278 ;; `tramp-do-file-attributes-with-ls'.
1279 (if (not (equal modtime
'(0 0)))
1280 (tramp-run-real-handler 'set-visited-file-modtime
(list modtime
))
1284 (format "%s -ild %s"
1285 (tramp-get-ls-command v
)
1286 (tramp-shell-quote-argument localname
)))
1287 (setq attr
(buffer-substring (point) (point-at-eol))))
1288 (tramp-set-file-property
1289 v localname
"visited-file-modtime-ild" attr
))
1290 (when (boundp 'last-coding-system-used
)
1291 (set 'last-coding-system-used coding-system-used
))
1294 ;; This function makes the same assumption as
1295 ;; `tramp-sh-handle-set-visited-file-modtime'.
1296 (defun tramp-sh-handle-verify-visited-file-modtime (&optional buf
)
1297 "Like `verify-visited-file-modtime' for Tramp files.
1298 At the time `verify-visited-file-modtime' calls this function, we
1299 already know that the buffer is visiting a file and that
1300 `visited-file-modtime' does not return 0. Do not call this
1301 function directly, unless those two cases are already taken care
1303 (with-current-buffer (or buf
(current-buffer))
1304 (let ((f (buffer-file-name)))
1305 ;; There is no file visiting the buffer, or the buffer has no
1306 ;; recorded last modification time, or there is no established
1309 (eq (visited-file-modtime) 0)
1310 (not (tramp-file-name-handler 'file-remote-p f nil
'connected
)))
1312 (with-parsed-tramp-file-name f nil
1313 (let* ((remote-file-name-inhibit-cache t
)
1314 (attr (file-attributes f
))
1315 (modtime (nth 5 attr
))
1316 (mt (visited-file-modtime)))
1319 ;; File exists, and has a known modtime.
1320 ((and attr
(not (equal modtime
'(0 0))))
1321 (< (abs (tramp-time-diff
1323 ;; For compatibility, deal with both the old
1324 ;; (HIGH . LOW) and the new (HIGH LOW) return
1325 ;; values of `visited-file-modtime'.
1327 (list (car mt
) (cdr mt
))
1330 ;; Modtime has the don't know value.
1334 (format "%s -ild %s"
1335 (tramp-get-ls-command v
)
1336 (tramp-shell-quote-argument localname
)))
1337 (with-current-buffer (tramp-get-buffer v
)
1338 (setq attr
(buffer-substring (point) (point-at-eol))))
1341 (tramp-get-file-property
1342 v localname
"visited-file-modtime-ild" "")))
1343 ;; If file does not exist, say it is not modified if and
1344 ;; only if that agrees with the buffer's record.
1345 (t (equal mt
'(-1 65535))))))))))
1347 (defun tramp-sh-handle-set-file-modes (filename mode
)
1348 "Like `set-file-modes' for Tramp files."
1349 (with-parsed-tramp-file-name filename nil
1350 (tramp-flush-file-property v localname
)
1351 ;; FIXME: extract the proper text from chmod's stderr.
1352 (tramp-barf-unless-okay
1354 (format "chmod %s %s"
1355 (tramp-compat-decimal-to-octal mode
)
1356 (tramp-shell-quote-argument localname
))
1357 "Error while changing file's mode %s" filename
)))
1359 (defun tramp-sh-handle-set-file-times (filename &optional time
)
1360 "Like `set-file-times' for Tramp files."
1361 (if (tramp-tramp-file-p filename
)
1362 (with-parsed-tramp-file-name filename nil
1363 (when (tramp-get-remote-touch v
)
1364 (tramp-flush-file-property v localname
)
1365 (let ((time (if (or (null time
) (equal time
'(0 0)))
1368 ;; With GNU Emacs, `format-time-string' has an
1369 ;; optional parameter UNIVERSAL. This is preferred,
1370 ;; because we could handle the case when the remote
1371 ;; host is located in a different time zone as the
1373 (utc (not (featurep 'xemacs
))))
1374 (tramp-send-command-and-check
1377 (if utc
"env TZ=UTC" "")
1378 (tramp-get-remote-touch v
)
1379 (if (tramp-get-connection-property v
"touch-t" nil
)
1382 (format-time-string "%Y%m%d%H%M.%S" time t
)
1383 (format-time-string "%Y%m%d%H%M.%S" time
)))
1385 (tramp-shell-quote-argument localname
))))))
1387 ;; We handle also the local part, because in older Emacsen,
1388 ;; without `set-file-times', this function is an alias for this.
1389 ;; We are local, so we don't need the UTC settings.
1392 nil
"touch" nil nil nil
"-t"
1393 (format-time-string "%Y%m%d%H%M.%S" time
)
1394 (tramp-shell-quote-argument filename
)))))
1396 (defun tramp-set-file-uid-gid (filename &optional uid gid
)
1397 "Set the ownership for FILENAME.
1398 If UID and GID are provided, these values are used; otherwise uid
1399 and gid of the corresponding user is taken. Both parameters must
1400 be non-negative integers."
1401 ;; Modern Unices allow chown only for root. So we might need
1402 ;; another implementation, see `dired-do-chown'. OTOH, it is mostly
1403 ;; working with su(do)? when it is needed, so it shall succeed in
1404 ;; the majority of cases.
1405 ;; Don't modify `last-coding-system-used' by accident.
1406 (let ((last-coding-system-used last-coding-system-used
))
1407 (if (tramp-tramp-file-p filename
)
1408 (with-parsed-tramp-file-name filename nil
1409 (if (and (zerop (user-uid)) (tramp-local-host-p v
))
1410 ;; If we are root on the local host, we can do it directly.
1411 (tramp-set-file-uid-gid localname uid gid
)
1412 (let ((uid (or (and (natnump uid
) uid
)
1413 (tramp-get-remote-uid v
'integer
)))
1414 (gid (or (and (natnump gid
) gid
)
1415 (tramp-get-remote-gid v
'integer
))))
1418 "chown %d:%d %s" uid gid
1419 (tramp-shell-quote-argument localname
))))))
1421 ;; We handle also the local part, because there doesn't exist
1422 ;; `set-file-uid-gid'. On W32 "chown" might not work.
1423 (let ((uid (or (and (natnump uid
) uid
) (tramp-get-local-uid 'integer
)))
1424 (gid (or (and (natnump gid
) gid
) (tramp-get-local-gid 'integer
))))
1426 nil
"chown" nil nil nil
1427 (format "%d:%d" uid gid
) (tramp-shell-quote-argument filename
))))))
1429 (defun tramp-remote-selinux-p (vec)
1430 "Check, whether SELINUX is enabled on the remote host."
1431 (with-tramp-connection-property
1432 (tramp-get-connection-process vec
) "selinux-p"
1433 (let ((result (tramp-find-executable
1434 vec
"getenforce" (tramp-get-remote-path vec
) t t
)))
1437 (tramp-send-command-and-read
1438 vec
(format "echo \\\"`%S`\\\"" result
))
1441 (defun tramp-sh-handle-file-selinux-context (filename)
1442 "Like `file-selinux-context' for Tramp files."
1443 (with-parsed-tramp-file-name filename nil
1444 (with-tramp-file-property v localname
"file-selinux-context"
1445 (let ((context '(nil nil nil nil
))
1446 (regexp (concat "\\([a-z0-9_]+\\):" "\\([a-z0-9_]+\\):"
1447 "\\([a-z0-9_]+\\):" "\\([a-z0-9_]+\\)")))
1448 (when (and (tramp-remote-selinux-p v
)
1449 (tramp-send-command-and-check
1452 (tramp-get-ls-command v
)
1453 (tramp-shell-quote-argument localname
))))
1454 (with-current-buffer (tramp-get-connection-buffer v
)
1455 (goto-char (point-min))
1456 (when (re-search-forward regexp
(point-at-eol) t
)
1457 (setq context
(list (match-string 1) (match-string 2)
1458 (match-string 3) (match-string 4))))))
1459 ;; Return the context.
1462 (defun tramp-sh-handle-set-file-selinux-context (filename context
)
1463 "Like `set-file-selinux-context' for Tramp files."
1464 (with-parsed-tramp-file-name filename nil
1465 (if (and (consp context
)
1466 (tramp-remote-selinux-p v
)
1467 (tramp-send-command-and-check
1468 v
(format "chcon %s %s %s %s %s"
1469 (if (stringp (nth 0 context
))
1470 (format "--user=%s" (nth 0 context
)) "")
1471 (if (stringp (nth 1 context
))
1472 (format "--role=%s" (nth 1 context
)) "")
1473 (if (stringp (nth 2 context
))
1474 (format "--type=%s" (nth 2 context
)) "")
1475 (if (stringp (nth 3 context
))
1476 (format "--range=%s" (nth 3 context
)) "")
1477 (tramp-shell-quote-argument localname
))))
1479 (tramp-set-file-property v localname
"file-selinux-context" context
)
1481 (tramp-set-file-property v localname
"file-selinux-context" 'undef
)
1484 (defun tramp-remote-acl-p (vec)
1485 "Check, whether ACL is enabled on the remote host."
1486 (with-tramp-connection-property (tramp-get-connection-process vec
) "acl-p"
1487 (tramp-send-command-and-check vec
"getfacl /")))
1489 (defun tramp-sh-handle-file-acl (filename)
1490 "Like `file-acl' for Tramp files."
1491 (with-parsed-tramp-file-name filename nil
1492 (with-tramp-file-property v localname
"file-acl"
1493 (when (and (tramp-remote-acl-p v
)
1494 (tramp-send-command-and-check
1496 "getfacl -ac %s 2>/dev/null"
1497 (tramp-shell-quote-argument localname
))))
1498 (with-current-buffer (tramp-get-connection-buffer v
)
1499 (goto-char (point-max))
1500 (delete-blank-lines)
1501 (when (> (point-max) (point-min))
1502 (tramp-compat-funcall
1503 'substring-no-properties
(buffer-string))))))))
1505 (defun tramp-sh-handle-set-file-acl (filename acl-string
)
1506 "Like `set-file-acl' for Tramp files."
1507 (with-parsed-tramp-file-name (expand-file-name filename
) nil
1508 (if (and (stringp acl-string
) (tramp-remote-acl-p v
)
1511 v
(format "setfacl --set-file=- %s <<'%s'\n%s\n%s\n"
1512 (tramp-shell-quote-argument localname
)
1513 tramp-end-of-heredoc
1515 tramp-end-of-heredoc
))
1516 (tramp-send-command-and-check v nil
)))
1519 (tramp-set-file-property v localname
"file-acl" acl-string
)
1521 ;; In case of errors, we return `nil'.
1522 (tramp-set-file-property v localname
"file-acl-string" 'undef
)
1525 ;; Simple functions using the `test' command.
1527 (defun tramp-sh-handle-file-executable-p (filename)
1528 "Like `file-executable-p' for Tramp files."
1529 (with-parsed-tramp-file-name filename nil
1530 (with-tramp-file-property v localname
"file-executable-p"
1531 ;; Examine `file-attributes' cache to see if request can be
1532 ;; satisfied without remote operation.
1533 (or (tramp-check-cached-permissions v ?x
)
1534 (tramp-run-test "-x" filename
)))))
1536 (defun tramp-sh-handle-file-readable-p (filename)
1537 "Like `file-readable-p' for Tramp files."
1538 (with-parsed-tramp-file-name filename nil
1539 (with-tramp-file-property v localname
"file-readable-p"
1540 ;; Examine `file-attributes' cache to see if request can be
1541 ;; satisfied without remote operation.
1542 (or (tramp-check-cached-permissions v ?r
)
1543 (tramp-run-test "-r" filename
)))))
1545 ;; When the remote shell is started, it looks for a shell which groks
1546 ;; tilde expansion. Here, we assume that all shells which grok tilde
1547 ;; expansion will also provide a `test' command which groks `-nt' (for
1548 ;; newer than). If this breaks, tell me about it and I'll try to do
1549 ;; something smarter about it.
1550 (defun tramp-sh-handle-file-newer-than-file-p (file1 file2
)
1551 "Like `file-newer-than-file-p' for Tramp files."
1552 (cond ((not (file-exists-p file1
))
1554 ((not (file-exists-p file2
))
1556 ;; We are sure both files exist at this point.
1559 ;; We try to get the mtime of both files. If they are not
1560 ;; equal to the "dont-know" value, then we subtract the times
1561 ;; and obtain the result.
1562 (let ((fa1 (file-attributes file1
))
1563 (fa2 (file-attributes file2
)))
1564 (if (and (not (equal (nth 5 fa1
) '(0 0)))
1565 (not (equal (nth 5 fa2
) '(0 0))))
1566 (> 0 (tramp-time-diff (nth 5 fa2
) (nth 5 fa1
)))
1567 ;; If one of them is the dont-know value, then we can
1568 ;; still try to run a shell command on the remote host.
1569 ;; However, this only works if both files are Tramp
1570 ;; files and both have the same method, same user, same
1572 (unless (tramp-equal-remote file1 file2
)
1573 (with-parsed-tramp-file-name
1574 (if (tramp-tramp-file-p file1
) file1 file2
) nil
1577 "Files %s and %s must have same method, user, host"
1579 (with-parsed-tramp-file-name file1 nil
1581 (tramp-get-test-nt-command v
) file1 file2
))))))))
1583 ;; Functions implemented using the basic functions above.
1585 (defun tramp-sh-handle-file-directory-p (filename)
1586 "Like `file-directory-p' for Tramp files."
1587 (with-parsed-tramp-file-name filename nil
1588 ;; `file-directory-p' is used as predicate for file name completion.
1589 ;; Sometimes, when a connection is not established yet, it is
1590 ;; desirable to return t immediately for "/method:foo:". It can
1591 ;; be expected that this is always a directory.
1592 (or (zerop (length localname
))
1593 (with-tramp-file-property v localname
"file-directory-p"
1594 (tramp-run-test "-d" filename
)))))
1596 (defun tramp-sh-handle-file-writable-p (filename)
1597 "Like `file-writable-p' for Tramp files."
1598 (with-parsed-tramp-file-name filename nil
1599 (with-tramp-file-property v localname
"file-writable-p"
1600 (if (file-exists-p filename
)
1601 ;; Examine `file-attributes' cache to see if request can be
1602 ;; satisfied without remote operation.
1603 (or (tramp-check-cached-permissions v ?w
)
1604 (tramp-run-test "-w" filename
))
1605 ;; If file doesn't exist, check if directory is writable.
1606 (and (tramp-run-test "-d" (file-name-directory filename
))
1607 (tramp-run-test "-w" (file-name-directory filename
)))))))
1609 (defun tramp-sh-handle-file-ownership-preserved-p (filename &optional group
)
1610 "Like `file-ownership-preserved-p' for Tramp files."
1611 (with-parsed-tramp-file-name filename nil
1612 (with-tramp-file-property v localname
"file-ownership-preserved-p"
1613 (let ((attributes (file-attributes filename
)))
1614 ;; Return t if the file doesn't exist, since it's true that no
1615 ;; information would be lost by an (attempted) delete and create.
1616 (or (null attributes
)
1618 (= (nth 2 attributes
) (tramp-get-remote-uid v
'integer
))
1620 (= (nth 3 attributes
) (tramp-get-remote-gid v
'integer
)))))))))
1622 ;; Directory listings.
1624 (defun tramp-sh-handle-directory-files-and-attributes
1625 (directory &optional full match nosort id-format
)
1626 "Like `directory-files-and-attributes' for Tramp files."
1627 (if (with-parsed-tramp-file-name directory nil
1628 (not (or (tramp-get-remote-stat v
) (tramp-get-remote-perl v
))))
1629 (tramp-handle-directory-files-and-attributes
1630 directory full match nosort id-format
)
1633 (unless id-format
(setq id-format
'integer
))
1634 (when (file-directory-p directory
)
1635 (setq directory
(expand-file-name directory
))
1638 (with-parsed-tramp-file-name directory nil
1639 (with-tramp-file-property
1641 (format "directory-files-and-attributes-%s" id-format
)
1646 (tramp-convert-file-attributes v
(cdr x
))))
1648 ((tramp-get-remote-stat v
)
1649 (tramp-do-directory-files-and-attributes-with-stat
1650 v localname id-format
))
1651 ((tramp-get-remote-perl v
)
1652 (tramp-do-directory-files-and-attributes-with-perl
1653 v localname id-format
)))))))))
1657 (setq item
(pop temp
))
1658 (when (or (null match
) (string-match match
(car item
)))
1660 (setcar item
(expand-file-name (car item
) directory
)))
1661 (push item result
)))
1665 (sort result
(lambda (x y
) (string< (car x
) (car y
)))))))))
1667 (defun tramp-do-directory-files-and-attributes-with-perl
1668 (vec localname
&optional id-format
)
1669 "Implement `directory-files-and-attributes' for Tramp files using a Perl script."
1670 (tramp-message vec
5 "directory-files-and-attributes with perl: %s" localname
)
1671 (tramp-maybe-send-script
1672 vec tramp-perl-directory-files-and-attributes
1673 "tramp_perl_directory_files_and_attributes")
1675 (tramp-send-command-and-read
1677 (format "tramp_perl_directory_files_and_attributes %s %s"
1678 (tramp-shell-quote-argument localname
) id-format
))))
1679 (when (stringp object
) (tramp-error vec
'file-error object
))
1682 (defun tramp-do-directory-files-and-attributes-with-stat
1683 (vec localname
&optional id-format
)
1684 "Implement `directory-files-and-attributes' for Tramp files using stat(1) command."
1685 (tramp-message vec
5 "directory-files-and-attributes with stat: %s" localname
)
1686 (tramp-send-command-and-read
1690 ;; We must care about file names with spaces, or starting with
1691 ;; "-"; this would confuse xargs. "ls -aQ" might be a solution,
1692 ;; but it does not work on all remote systems. Therefore, we
1693 ;; quote the file names via sed.
1694 "cd %s; echo \"(\"; (%s -a | sed -e s/\\$/\\\"/g -e s/^/\\\"/g | "
1696 "'(\"%%n\" (\"%%N\") %%h %s %s %%Xe0 %%Ye0 %%Ze0 %%se0 \"%%A\" t %%ie0 -1)'"
1697 " 2>/dev/null); echo \")\"")
1698 (tramp-shell-quote-argument localname
)
1699 (tramp-get-ls-command vec
)
1700 (tramp-get-remote-stat vec
)
1701 (if (eq id-format
'integer
) "%ue0" "\"%U\"")
1702 (if (eq id-format
'integer
) "%ge0" "\"%G\""))))
1704 ;; This function should return "foo/" for directories and "bar" for
1706 (defun tramp-sh-handle-file-name-all-completions (filename directory
)
1707 "Like `file-name-all-completions' for Tramp files."
1708 (unless (save-match-data (string-match "/" filename
))
1709 (with-parsed-tramp-file-name (expand-file-name directory
) nil
1716 ;; Try cache entries for `filename', `filename' with last
1717 ;; character removed, `filename' with last two characters
1718 ;; removed, ..., and finally the empty string - all
1719 ;; concatenated to the local directory name.
1720 (let ((remote-file-name-inhibit-cache
1721 (or remote-file-name-inhibit-cache
1722 tramp-completion-reread-directory-timeout
)))
1724 ;; This is inefficient for very long file names, pity
1725 ;; `reduce' is not available...
1732 (tramp-get-file-property
1734 (concat localname
(substring filename
0 x
))
1735 "file-name-all-completions"
1737 (when cache-hit
(list cache-hit
))))
1738 ;; We cannot use a length of 0, because file properties
1739 ;; for "foo" and "foo/" are identical.
1740 (tramp-compat-number-sequence (length filename
) 1 -
1)))))
1742 ;; Cache expired or no matching cache entry found so we need
1743 ;; to perform a remote operation.
1745 ;; Get a list of directories and files, including reliably
1746 ;; tagging the directories with a trailing '/'. Because I
1747 ;; rock. --daniel@danann.net
1749 ;; Changed to perform `cd' in the same remote op and only
1750 ;; get entries starting with `filename'. Capture any `cd'
1751 ;; error messages. Ensure any `cd' and `echo' aliases are
1755 (if (tramp-get-remote-perl v
)
1757 (tramp-maybe-send-script
1758 v tramp-perl-file-name-all-completions
1759 "tramp_perl_file_name_all_completions")
1760 (format "tramp_perl_file_name_all_completions %s %s %d"
1761 (tramp-shell-quote-argument localname
)
1762 (tramp-shell-quote-argument filename
)
1764 ;; `read-file-name-completion-ignore-case'
1765 ;; is introduced with Emacs 22.1.
1767 'read-file-name-completion-ignore-case
)
1768 'read-file-name-completion-ignore-case
1769 'completion-ignore-case
))
1773 "(\\cd %s 2>&1 && (%s %s -a 2>/dev/null"
1774 ;; `ls' with wildcard might fail with `Argument
1775 ;; list too long' error in some corner cases; if
1776 ;; `ls' fails after `cd' succeeded, chances are
1777 ;; that's the case, so let's retry without
1778 ;; wildcard. This will return "too many" entries
1779 ;; but that isn't harmful.
1780 " || %s -a 2>/dev/null)"
1781 " | while IFS= read f; do"
1782 " if %s -d \"$f\" 2>/dev/null;"
1783 " then \\echo \"$f/\"; else \\echo \"$f\"; fi; done"
1784 " && \\echo ok) || \\echo fail")
1785 (tramp-shell-quote-argument localname
)
1786 (tramp-get-ls-command v
)
1787 ;; When `filename' is empty, just `ls' without
1788 ;; `filename' argument is more efficient than `ls *'
1789 ;; for very large directories and might avoid the
1790 ;; `Argument list too long' error.
1792 ;; With and only with wildcard, we need to add
1793 ;; `-d' to prevent `ls' from descending into
1795 (if (zerop (length filename
))
1797 (concat (tramp-shell-quote-argument filename
) "* -d"))
1798 (tramp-get-ls-command v
)
1799 (tramp-get-test-command v
))))
1801 ;; Now grab the output.
1802 (with-current-buffer (tramp-get-buffer v
)
1803 (goto-char (point-max))
1805 ;; Check result code, found in last line of output.
1807 (if (looking-at "^fail$")
1809 ;; Grab error message from line before last line
1810 ;; (it was put there by `cd 2>&1').
1814 "tramp-sh-handle-file-name-all-completions: %s"
1815 (buffer-substring (point) (point-at-eol))))
1816 ;; For peace of mind, if buffer doesn't end in `fail'
1817 ;; then it should end in `ok'. If neither are in the
1818 ;; buffer something went seriously wrong on the remote
1820 (unless (looking-at "^ok$")
1824 tramp-sh-handle-file-name-all-completions: internal error accessing `%s': `%s'"
1825 (tramp-shell-quote-argument localname
) (buffer-string))))
1827 (while (zerop (forward-line -
1))
1828 (push (buffer-substring (point) (point-at-eol)) result
)))
1830 ;; Because the remote op went through OK we know the
1831 ;; directory we `cd'-ed to exists.
1832 (tramp-set-file-property v localname
"file-exists-p" t
)
1834 ;; Because the remote op went through OK we know every
1835 ;; file listed by `ls' exists.
1836 (mapc (lambda (entry)
1837 (tramp-set-file-property
1838 v
(concat localname entry
) "file-exists-p" t
))
1841 ;; Store result in the cache.
1842 (tramp-set-file-property
1843 v
(concat localname filename
)
1844 "file-name-all-completions" result
))))))))
1848 (defun tramp-sh-handle-add-name-to-file
1849 (filename newname
&optional ok-if-already-exists
)
1850 "Like `add-name-to-file' for Tramp files."
1851 (unless (tramp-equal-remote filename newname
)
1852 (with-parsed-tramp-file-name
1853 (if (tramp-tramp-file-p filename
) filename newname
) nil
1856 "add-name-to-file: %s"
1857 "only implemented for same method, same user, same host")))
1858 (with-parsed-tramp-file-name filename v1
1859 (with-parsed-tramp-file-name newname v2
1860 (let ((ln (when v1
(tramp-get-remote-ln v1
))))
1861 (when (and (numberp ok-if-already-exists
)
1862 (file-exists-p newname
)
1865 "File %s already exists; make it a new name anyway? "
1868 v2
'file-error
"add-name-to-file: file %s already exists" newname
))
1869 (when ok-if-already-exists
(setq ln
(concat ln
" -f")))
1870 (tramp-flush-file-property v2
(file-name-directory v2-localname
))
1871 (tramp-flush-file-property v2 v2-localname
)
1872 (tramp-barf-unless-okay
1874 (format "%s %s %s" ln
1875 (tramp-shell-quote-argument v1-localname
)
1876 (tramp-shell-quote-argument v2-localname
))
1877 "error with add-name-to-file, see buffer `%s' for details"
1880 (defun tramp-sh-handle-copy-file
1881 (filename newname
&optional ok-if-already-exists keep-date
1882 preserve-uid-gid preserve-extended-attributes
)
1883 "Like `copy-file' for Tramp files."
1884 (setq filename
(expand-file-name filename
))
1885 (setq newname
(expand-file-name newname
))
1887 ;; At least one file a Tramp file?
1888 ((or (tramp-tramp-file-p filename
)
1889 (tramp-tramp-file-p newname
))
1890 (tramp-do-copy-or-rename-file
1891 'copy filename newname ok-if-already-exists keep-date
1892 preserve-uid-gid preserve-extended-attributes
))
1894 (preserve-extended-attributes
1895 (tramp-run-real-handler
1897 (list filename newname ok-if-already-exists keep-date
1898 preserve-uid-gid preserve-extended-attributes
)))
1900 (tramp-run-real-handler
1902 (list filename newname ok-if-already-exists keep-date preserve-uid-gid
)))
1904 (tramp-run-real-handler
1905 'copy-file
(list filename newname ok-if-already-exists keep-date
)))))
1907 (defun tramp-sh-handle-copy-directory
1908 (dirname newname
&optional keep-date parents copy-contents
)
1909 "Like `copy-directory' for Tramp files."
1910 (let ((t1 (tramp-tramp-file-p dirname
))
1911 (t2 (tramp-tramp-file-p newname
)))
1912 (with-parsed-tramp-file-name (if t1 dirname newname
) nil
1913 (if (and (not copy-contents
)
1914 (tramp-get-method-parameter method
'tramp-copy-recursive
)
1915 ;; When DIRNAME and NEWNAME are remote, they must have
1917 (or (null t1
) (null t2
)
1919 (tramp-file-name-method (tramp-dissect-file-name dirname
))
1920 (tramp-file-name-method
1921 (tramp-dissect-file-name newname
)))))
1922 ;; scp or rsync DTRT.
1924 (setq dirname
(directory-file-name (expand-file-name dirname
))
1925 newname
(directory-file-name (expand-file-name newname
)))
1926 (if (and (file-directory-p newname
)
1927 (not (string-equal (file-name-nondirectory dirname
)
1928 (file-name-nondirectory newname
))))
1931 (file-name-nondirectory dirname
) newname
)))
1932 (if (not (file-directory-p (file-name-directory newname
)))
1933 (make-directory (file-name-directory newname
) parents
))
1934 (tramp-do-copy-or-rename-file-out-of-band
1935 'copy dirname newname keep-date
))
1936 ;; We must do it file-wise.
1937 (tramp-run-real-handler
1940 (list dirname newname keep-date parents copy-contents
)
1941 (list dirname newname keep-date parents
))))
1943 ;; When newname did exist, we have wrong cached values.
1945 (with-parsed-tramp-file-name newname nil
1946 (tramp-flush-file-property v
(file-name-directory localname
))
1947 (tramp-flush-file-property v localname
))))))
1949 (defun tramp-sh-handle-rename-file
1950 (filename newname
&optional ok-if-already-exists
)
1951 "Like `rename-file' for Tramp files."
1952 ;; Check if both files are local -- invoke normal rename-file.
1953 ;; Otherwise, use Tramp from local system.
1954 (setq filename
(expand-file-name filename
))
1955 (setq newname
(expand-file-name newname
))
1956 ;; At least one file a Tramp file?
1957 (if (or (tramp-tramp-file-p filename
)
1958 (tramp-tramp-file-p newname
))
1959 (tramp-do-copy-or-rename-file
1960 'rename filename newname ok-if-already-exists t t
)
1961 (tramp-run-real-handler
1962 'rename-file
(list filename newname ok-if-already-exists
))))
1964 (defun tramp-do-copy-or-rename-file
1965 (op filename newname
&optional ok-if-already-exists keep-date
1966 preserve-uid-gid preserve-extended-attributes
)
1967 "Copy or rename a remote file.
1968 OP must be `copy' or `rename' and indicates the operation to perform.
1969 FILENAME specifies the file to copy or rename, NEWNAME is the name of
1970 the new file (for copy) or the new name of the file (for rename).
1971 OK-IF-ALREADY-EXISTS means don't barf if NEWNAME exists already.
1972 KEEP-DATE means to make sure that NEWNAME has the same timestamp
1973 as FILENAME. PRESERVE-UID-GID, when non-nil, instructs to keep
1974 the uid and gid if both files are on the same host.
1975 PRESERVE-EXTENDED-ATTRIBUTES activates selinux and acl commands.
1977 This function is invoked by `tramp-sh-handle-copy-file' and
1978 `tramp-sh-handle-rename-file'. It is an error if OP is neither
1979 of `copy' and `rename'. FILENAME and NEWNAME must be absolute
1981 (unless (memq op
'(copy rename
))
1982 (error "Unknown operation `%s', must be `copy' or `rename'" op
))
1983 (let ((t1 (tramp-tramp-file-p filename
))
1984 (t2 (tramp-tramp-file-p newname
))
1985 (length (nth 7 (file-attributes (file-truename filename
))))
1986 (attributes (and preserve-extended-attributes
1987 (apply 'file-extended-attributes
(list filename
)))))
1989 (with-parsed-tramp-file-name (if t1 filename newname
) nil
1990 (when (and (not ok-if-already-exists
) (file-exists-p newname
))
1992 v
'file-already-exists
"File %s already exists" newname
))
1994 (with-tramp-progress-reporter
1995 v
0 (format "%s %s to %s"
1996 (if (eq op
'copy
) "Copying" "Renaming")
2000 ;; Both are Tramp files.
2002 (with-parsed-tramp-file-name filename v1
2003 (with-parsed-tramp-file-name newname v2
2005 ;; Shortcut: if method, host, user are the same for
2006 ;; both files, we invoke `cp' or `mv' on the remote
2008 ((tramp-equal-remote filename newname
)
2009 (tramp-do-copy-or-rename-file-directly
2011 ok-if-already-exists keep-date preserve-uid-gid
))
2013 ;; Try out-of-band operation.
2015 (tramp-method-out-of-band-p v1 length
)
2016 (tramp-method-out-of-band-p v2 length
))
2017 (tramp-do-copy-or-rename-file-out-of-band
2018 op filename newname keep-date
))
2020 ;; No shortcut was possible. So we copy the file
2021 ;; first. If the operation was `rename', we go back
2022 ;; and delete the original file (if the copy was
2023 ;; successful). The approach is simple-minded: we
2024 ;; create a new buffer, insert the contents of the
2025 ;; source file into it, then write out the buffer to
2026 ;; the target file. The advantage is that it doesn't
2027 ;; matter which file name handlers are used for the
2028 ;; source and target file.
2030 (tramp-do-copy-or-rename-file-via-buffer
2031 op filename newname keep-date
))))))
2033 ;; One file is a Tramp file, the other one is local.
2036 ;; Fast track on local machine.
2037 ((tramp-local-host-p v
)
2038 (tramp-do-copy-or-rename-file-directly
2040 ok-if-already-exists keep-date preserve-uid-gid
))
2042 ;; If the Tramp file has an out-of-band method, the
2043 ;; corresponding copy-program can be invoked.
2044 ((tramp-method-out-of-band-p v length
)
2045 (tramp-do-copy-or-rename-file-out-of-band
2046 op filename newname keep-date
))
2048 ;; Use the inline method via a Tramp buffer.
2049 (t (tramp-do-copy-or-rename-file-via-buffer
2050 op filename newname keep-date
))))
2053 ;; One of them must be a Tramp file.
2054 (error "Tramp implementation says this cannot happen")))
2056 ;; Handle `preserve-extended-attributes'. We ignore possible
2057 ;; errors, because ACL strings could be incompatible.
2060 (apply 'set-file-extended-attributes
(list newname attributes
))))
2062 ;; In case of `rename', we must flush the cache of the source file.
2063 (when (and t1
(eq op
'rename
))
2064 (with-parsed-tramp-file-name filename v1
2065 (tramp-flush-file-property v1
(file-name-directory v1-localname
))
2066 (tramp-flush-file-property v1 v1-localname
)))
2068 ;; When newname did exist, we have wrong cached values.
2070 (with-parsed-tramp-file-name newname v2
2071 (tramp-flush-file-property v2
(file-name-directory v2-localname
))
2072 (tramp-flush-file-property v2 v2-localname
)))))))
2074 (defun tramp-do-copy-or-rename-file-via-buffer (op filename newname keep-date
)
2075 "Use an Emacs buffer to copy or rename a file.
2076 First arg OP is either `copy' or `rename' and indicates the operation.
2077 FILENAME is the source file, NEWNAME the target file.
2078 KEEP-DATE is non-nil if NEWNAME should have the same timestamp as FILENAME."
2080 ;; We must disable multibyte, because binary data shall not be
2081 ;; converted. We remove `tramp-file-name-handler' from
2082 ;; `inhibit-file-name-handlers'; otherwise the file name handler
2083 ;; for `insert-file-contents' might be deactivated in some corner
2085 (set-buffer-multibyte nil
)
2086 (let ((coding-system-for-read 'binary
)
2087 (jka-compr-inhibit t
)
2088 (inhibit-file-name-handlers
2089 (remq 'tramp-file-name-handler inhibit-file-name-handlers
)))
2090 (insert-file-contents-literally filename
))
2091 ;; We don't want the target file to be compressed, so we let-bind
2092 ;; `jka-compr-inhibit' to t.
2093 (let ((coding-system-for-write 'binary
)
2094 (jka-compr-inhibit t
))
2095 (write-region (point-min) (point-max) newname nil
'no-message
)))
2096 ;; KEEP-DATE handling.
2097 (when keep-date
(set-file-times newname
(nth 5 (file-attributes filename
))))
2099 (set-file-modes newname
(tramp-default-file-modes filename
))
2100 ;; If the operation was `rename', delete the original file.
2101 (unless (eq op
'copy
) (delete-file filename
)))
2103 (defun tramp-do-copy-or-rename-file-directly
2104 (op filename newname ok-if-already-exists keep-date preserve-uid-gid
)
2105 "Invokes `cp' or `mv' on the remote system.
2106 OP must be one of `copy' or `rename', indicating `cp' or `mv',
2107 respectively. FILENAME specifies the file to copy or rename,
2108 NEWNAME is the name of the new file (for copy) or the new name of
2109 the file (for rename). Both files must reside on the same host.
2110 KEEP-DATE means to make sure that NEWNAME has the same timestamp
2111 as FILENAME. PRESERVE-UID-GID, when non-nil, instructs to keep
2112 the uid and gid from FILENAME."
2113 (let ((t1 (tramp-tramp-file-p filename
))
2114 (t2 (tramp-tramp-file-p newname
))
2115 (file-times (nth 5 (file-attributes filename
)))
2116 (file-modes (tramp-default-file-modes filename
)))
2117 (with-parsed-tramp-file-name (if t1 filename newname
) nil
2118 (let* ((cmd (cond ((and (eq op
'copy
) preserve-uid-gid
) "cp -f -p")
2119 ((eq op
'copy
) "cp -f")
2120 ((eq op
'rename
) "mv -f")
2123 "Unknown operation `%s', must be `copy' or `rename'"
2127 (tramp-file-name-handler 'file-remote-p filename
'localname
)
2131 (tramp-file-name-handler 'file-remote-p newname
'localname
)
2133 (prefix (file-remote-p (if t1 filename newname
)))
2137 ;; Both files are on a remote host, with same user.
2140 (tramp-send-command-and-check
2141 v
(format "%s %s %s" cmd
2142 (tramp-shell-quote-argument localname1
)
2143 (tramp-shell-quote-argument localname2
))))
2144 (with-current-buffer (tramp-get-buffer v
)
2145 (goto-char (point-min))
2149 ;; Mask cp -f error.
2151 tramp-operation-not-permitted-regexp nil t
))
2153 (tramp-error-with-buffer
2155 "Copying directly failed, see buffer `%s' for details."
2158 ;; We are on the local host.
2161 ;; We can do it directly.
2162 ((let (file-name-handler-alist)
2163 (and (file-readable-p localname1
)
2164 ;; No sticky bit when renaming.
2168 (file-modes (file-name-directory localname1
))
2169 (tramp-compat-octal-to-decimal "1000"))))
2170 (file-writable-p (file-name-directory localname2
))
2171 (or (file-directory-p localname2
)
2172 (file-writable-p localname2
))))
2174 (tramp-compat-copy-file
2175 localname1 localname2 ok-if-already-exists
2176 keep-date preserve-uid-gid
)
2177 (tramp-run-real-handler
2178 'rename-file
(list localname1 localname2 ok-if-already-exists
))))
2180 ;; We can do it directly with `tramp-send-command'
2181 ((and (file-readable-p (concat prefix localname1
))
2183 (file-name-directory (concat prefix localname2
)))
2184 (or (file-directory-p (concat prefix localname2
))
2185 (file-writable-p (concat prefix localname2
))))
2186 (tramp-do-copy-or-rename-file-directly
2187 op
(concat prefix localname1
) (concat prefix localname2
)
2188 ok-if-already-exists keep-date t
)
2189 ;; We must change the ownership to the local user.
2190 (tramp-set-file-uid-gid
2191 (concat prefix localname2
)
2192 (tramp-get-local-uid 'integer
)
2193 (tramp-get-local-gid 'integer
)))
2195 ;; We need a temporary file in between.
2197 ;; Create the temporary file.
2198 (let ((tmpfile (tramp-compat-make-temp-file localname1
)))
2203 (tramp-barf-unless-okay
2206 (tramp-shell-quote-argument localname1
)
2207 (tramp-shell-quote-argument tmpfile
))
2208 "Copying directly failed, see buffer `%s' for details."
2209 (tramp-get-buffer v
))
2210 ;; We must change the ownership as remote user.
2211 ;; Since this does not work reliable, we also
2212 ;; give read permissions.
2214 (concat prefix tmpfile
)
2215 (tramp-compat-octal-to-decimal "0777"))
2216 (tramp-set-file-uid-gid
2217 (concat prefix tmpfile
)
2218 (tramp-get-local-uid 'integer
)
2219 (tramp-get-local-gid 'integer
)))
2222 (tramp-compat-copy-file
2223 localname1 tmpfile t
2224 keep-date preserve-uid-gid
)
2225 (tramp-run-real-handler
2227 (list localname1 tmpfile t
)))
2228 ;; We must change the ownership as local user.
2229 ;; Since this does not work reliable, we also
2230 ;; give read permissions.
2232 tmpfile
(tramp-compat-octal-to-decimal "0777"))
2233 (tramp-set-file-uid-gid
2235 (tramp-get-remote-uid v
'integer
)
2236 (tramp-get-remote-gid v
'integer
))))
2238 ;; Move the temporary file to its destination.
2241 (tramp-barf-unless-okay
2244 (tramp-shell-quote-argument tmpfile
)
2245 (tramp-shell-quote-argument localname2
))
2246 "Copying directly failed, see buffer `%s' for details."
2247 (tramp-get-buffer v
)))
2249 (tramp-run-real-handler
2251 (list tmpfile localname2 ok-if-already-exists
)))))
2254 (ignore-errors (delete-file tmpfile
)))))))))
2256 ;; Set the time and mode. Mask possible errors.
2259 (set-file-times newname file-times
)
2260 (set-file-modes newname file-modes
))))))
2262 (defun tramp-do-copy-or-rename-file-out-of-band (op filename newname keep-date
)
2263 "Invoke `scp' program to copy.
2264 The method used must be an out-of-band method."
2265 (let* ((t1 (tramp-tramp-file-p filename
))
2266 (t2 (tramp-tramp-file-p newname
))
2267 (orig-vec (tramp-dissect-file-name (if t1 filename newname
)))
2268 copy-program copy-args copy-env copy-keep-date port listener spec
2269 options source target remote-copy-program remote-copy-args
)
2271 (with-parsed-tramp-file-name (if t1 filename newname
) nil
2274 ;; Both are Tramp files. We shall optimize it when the
2275 ;; methods for FILENAME and NEWNAME are the same.
2276 (let* ((dir-flag (file-directory-p filename
))
2277 (tmpfile (tramp-compat-make-temp-file localname dir-flag
)))
2281 (file-name-nondirectory newname
) tmpfile
)))
2284 (tramp-do-copy-or-rename-file-out-of-band
2285 op filename tmpfile keep-date
)
2286 (tramp-do-copy-or-rename-file-out-of-band
2287 'rename tmpfile newname keep-date
))
2291 (tramp-compat-delete-directory
2292 (expand-file-name ".." tmpfile
) 'recursive
)
2293 (delete-file tmpfile
)))))
2295 ;; Set variables for computing the prompt for reading
2297 (setq tramp-current-method
(tramp-file-name-method v
)
2298 tramp-current-user
(or (tramp-file-name-user v
)
2299 (tramp-get-connection-property
2301 tramp-current-host
(tramp-file-name-real-host v
))
2303 ;; Expand hops. Might be necessary for gateway methods.
2304 (setq v
(car (tramp-compute-multi-hops v
)))
2305 (aset v
3 localname
)
2307 ;; Check which ones of source and target are Tramp files.
2309 (tramp-make-copy-program-file-name v
)
2310 (shell-quote-argument filename
))
2312 (if (and (file-directory-p filename
)
2314 (file-name-nondirectory filename
)
2315 (file-name-nondirectory newname
)))
2316 'file-name-directory
2319 (tramp-make-copy-program-file-name v
)
2320 (shell-quote-argument newname
))))
2322 ;; Check for host and port number. We cannot use
2323 ;; `tramp-file-name-port', because this returns also
2324 ;; `tramp-default-port', which might clash with settings in
2326 (setq host
(tramp-file-name-host v
)
2328 (when (string-match tramp-host-with-port-regexp host
)
2329 (setq port
(string-to-number (match-string 2 host
))
2330 host
(string-to-number (match-string 1 host
))))
2332 ;; Check for user. There might be an interactive setting.
2333 (setq user
(or (tramp-file-name-user v
)
2334 (tramp-get-connection-property v
"login-as" nil
)))
2336 ;; Check for listener port.
2337 (when (tramp-get-method-parameter method
'tramp-remote-copy-args
)
2338 (setq listener
(number-to-string (+ 50000 (random 10000))))
2340 (zerop (tramp-call-process v
"nc" nil nil nil
"-z" host listener
))
2341 (setq listener
(number-to-string (+ 50000 (random 10000))))))
2343 ;; Compose copy command.
2344 (setq host
(or host
"")
2347 spec
(format-spec-make
2348 ?t
(tramp-get-connection-property
2349 (tramp-get-connection-process v
) "temp-file" ""))
2350 options
(format-spec
2351 (if tramp-use-ssh-controlmaster-options
2352 tramp-ssh-controlmaster-options
"")
2354 spec
(format-spec-make
2355 ?h host ?u user ?p port ?r listener ?c options
2356 ?k
(if keep-date
" " ""))
2357 copy-program
(tramp-get-method-parameter
2358 method
'tramp-copy-program
)
2359 copy-keep-date
(tramp-get-method-parameter
2360 method
'tramp-copy-keep-date
)
2364 ;; " " has either been a replacement of "%k" (when
2365 ;; keep-date argument is non-nil), or a replacement
2366 ;; for the whole keep-date sublist.
2370 (tramp-get-method-parameter method
'tramp-copy-args
)
2375 (let ((y (mapcar (lambda (z) (format-spec z spec
)) x
)))
2376 (if (member "" y
) '(" ") y
))))))
2383 (setq x
(mapcar (lambda (y) (format-spec y spec
)) x
))
2384 (unless (member "" x
) (mapconcat 'identity x
" ")))
2385 (tramp-get-method-parameter method
'tramp-copy-env
)))
2388 (tramp-get-method-parameter method
'tramp-remote-copy-program
))
2393 (tramp-get-connection-property v
"remote-copy-args" nil
)
2394 (tramp-get-method-parameter method
'tramp-remote-copy-args
)))
2395 (setq remote-copy-args
2398 (let ((y (mapcar (lambda (z) (format-spec z spec
)) x
)))
2399 (if (member "" y
) '(" ") y
)))))
2401 ;; Check for local copy program.
2402 (unless (executable-find copy-program
)
2404 v
'file-error
"Cannot find local copy program: %s" copy-program
))
2406 ;; Install listener on the remote side. The prompt must be
2407 ;; consumed later on, when the process does not listen anymore.
2408 (when remote-copy-program
2409 (unless (with-tramp-connection-property
2410 v
(concat "remote-copy-program-" remote-copy-program
)
2411 (tramp-find-executable
2412 v remote-copy-program
(tramp-get-remote-path v
)))
2415 "Cannot find remote listener: %s" remote-copy-program
))
2416 (setq remote-copy-program
2420 (list remote-copy-program
) remote-copy-args
2421 (list (if t1
(concat "<" source
) (concat ">" target
)) "&"))
2423 (tramp-send-command v remote-copy-program
)
2427 "Listener process not running on remote host: `%s'"
2428 remote-copy-program
))
2429 (tramp-send-command v
(format "netstat -l | grep -q :%s" listener
))
2430 (while (not (tramp-send-command-and-check v nil
))
2432 v
(format "netstat -l | grep -q :%s" listener
)))))
2436 ;; The default directory must be remote.
2437 (let ((default-directory
2438 (file-name-directory (if t1 filename newname
)))
2439 (process-environment (copy-sequence process-environment
)))
2440 ;; Set the transfer process properties.
2441 (tramp-set-connection-property
2442 v
"process-name" (buffer-name (current-buffer)))
2443 (tramp-set-connection-property
2444 v
"process-buffer" (current-buffer))
2447 orig-vec
6 "%s=\"%s\"" (car copy-env
) (cadr copy-env
))
2448 (setenv (pop copy-env
) (pop copy-env
)))
2453 (if remote-copy-program
2454 (list (if t1
(concat ">" target
) (concat "<" source
)))
2455 (list source target
))))
2457 ;; Use an asynchronous process. By this, password can
2458 ;; be handled. We don't set a timeout, because the
2459 ;; copying of large files can last longer than 60
2461 (let ((p (apply 'start-process-shell-command
2462 (tramp-get-connection-name v
)
2463 (tramp-get-connection-buffer v
)
2467 (list "&&" "echo" "tramp_exit_status" "0"
2468 "||" "echo" "tramp_exit_status" "1")))))
2471 (mapconcat 'identity
(process-command p
) " "))
2472 (tramp-set-connection-property p
"vector" orig-vec
)
2473 (tramp-compat-set-process-query-on-exit-flag p nil
)
2475 ;; We must adapt `tramp-local-end-of-line' for
2476 ;; sending the password.
2477 (let ((tramp-local-end-of-line tramp-rsh-end-of-line
))
2478 (tramp-process-actions
2479 p v nil tramp-actions-copy-out-of-band
))
2481 ;; Check the return code.
2482 (goto-char (point-max))
2484 (re-search-backward "tramp_exit_status [0-9]+" nil t
)
2486 orig-vec
'file-error
2487 "Couldn't find exit status of `%s'"
2488 (mapconcat 'identity
(process-command p
) " ")))
2489 (skip-chars-forward "^ ")
2490 (unless (zerop (read (current-buffer)))
2493 orig-vec
'file-error
2494 "Error copying: `%s'"
2495 (buffer-substring (point-min) (point-at-eol))))))
2497 ;; Reset the transfer process properties.
2498 (tramp-set-connection-property v
"process-name" nil
)
2499 (tramp-set-connection-property v
"process-buffer" nil
)
2500 ;; Clear the remote prompt.
2501 (when (and remote-copy-program
2502 (not (tramp-send-command-and-check v nil
)))
2503 ;; Houston, we have a problem! Likely, the listener is
2504 ;; still running, so let's clear everything (but the
2505 ;; cached password).
2506 (tramp-cleanup-connection v
'keep-debug
'keep-password
))))
2508 ;; Handle KEEP-DATE argument.
2509 (when (and keep-date
(not copy-keep-date
))
2510 (set-file-times newname
(nth 5 (file-attributes filename
))))
2513 (unless (and keep-date copy-keep-date
)
2515 (set-file-modes newname
(tramp-default-file-modes filename
)))))
2517 ;; If the operation was `rename', delete the original file.
2518 (unless (eq op
'copy
)
2519 (if (file-regular-p filename
)
2520 (delete-file filename
)
2521 (tramp-compat-delete-directory filename
'recursive
))))))
2523 (defun tramp-sh-handle-make-directory (dir &optional parents
)
2524 "Like `make-directory' for Tramp files."
2525 (setq dir
(expand-file-name dir
))
2526 (with-parsed-tramp-file-name dir nil
2527 (tramp-flush-directory-property v
(file-name-directory localname
))
2529 (tramp-barf-unless-okay
2531 (if parents
"mkdir -p" "mkdir")
2532 (tramp-shell-quote-argument localname
))
2533 "Couldn't make directory %s" dir
))))
2535 (defun tramp-sh-handle-delete-directory (directory &optional recursive
)
2536 "Like `delete-directory' for Tramp files."
2537 (setq directory
(expand-file-name directory
))
2538 (with-parsed-tramp-file-name directory nil
2539 (tramp-flush-file-property v
(file-name-directory localname
))
2540 (tramp-flush-directory-property v localname
)
2541 (tramp-barf-unless-okay
2543 (if recursive
"rm -rf" "rmdir")
2544 (tramp-shell-quote-argument localname
))
2545 "Couldn't delete %s" directory
)))
2547 (defun tramp-sh-handle-delete-file (filename &optional trash
)
2548 "Like `delete-file' for Tramp files."
2549 (setq filename
(expand-file-name filename
))
2550 (with-parsed-tramp-file-name filename nil
2551 (tramp-flush-file-property v
(file-name-directory localname
))
2552 (tramp-flush-file-property v localname
)
2553 (tramp-barf-unless-okay
2555 (or (and trash
(tramp-get-remote-trash v
)) "rm -f")
2556 (tramp-shell-quote-argument localname
))
2557 "Couldn't delete %s" filename
)))
2561 ;; CCC: This does not seem to be enough. Something dies when
2562 ;; we try and delete two directories under Tramp :/
2563 (defun tramp-sh-handle-dired-recursive-delete-directory (filename)
2564 "Recursively delete the directory given.
2565 This is like `dired-recursive-delete-directory' for Tramp files."
2566 (with-parsed-tramp-file-name filename nil
2567 ;; Run a shell command 'rm -r <localname>'.
2568 ;; Code shamelessly stolen from the dired implementation and, um, hacked :)
2569 (unless (file-exists-p filename
)
2570 (tramp-error v
'file-error
"No such directory: %s" filename
))
2571 ;; Which is better, -r or -R? (-r works for me <daniel@danann.net>).
2574 (format "rm -rf %s" (tramp-shell-quote-argument localname
))
2575 ;; Don't read the output, do it explicitly.
2577 ;; Wait for the remote system to return to us...
2578 ;; This might take a while, allow it plenty of time.
2579 (tramp-wait-for-output (tramp-get-connection-process v
) 120)
2580 ;; Make sure that it worked...
2581 (tramp-flush-file-property v
(file-name-directory localname
))
2582 (tramp-flush-directory-property v localname
)
2583 (and (file-exists-p filename
)
2585 v
'file-error
"Failed to recursively delete %s" filename
))))
2587 (defun tramp-sh-handle-dired-compress-file (file &rest _ok-flag
)
2588 "Like `dired-compress-file' for Tramp files."
2589 ;; OK-FLAG is valid for XEmacs only, but not implemented.
2590 ;; Code stolen mainly from dired-aux.el.
2591 (with-parsed-tramp-file-name file nil
2592 (tramp-flush-file-property v localname
)
2595 (if (not (featurep 'xemacs
))
2597 (symbol-value 'dired-compress-file-suffixes
)
2598 ;; XEmacs has `dired-compression-method-alist', which is
2599 ;; transformed into `dired-compress-file-suffixes' structure.
2602 (list (concat (regexp-quote (nth 1 x
)) "\\'")
2604 (mapconcat 'identity
(nth 3 x
) " ")))
2605 (symbol-value 'dired-compression-method-alist
))))
2607 ;; See if any suffix rule matches this file name.
2609 (let (case-fold-search)
2610 (if (string-match (car (car suffixes
)) localname
)
2611 (setq suffix
(car suffixes
) suffixes nil
))
2612 (setq suffixes
(cdr suffixes
))))
2614 (cond ((file-symlink-p file
)
2616 ((and suffix
(nth 2 suffix
))
2617 ;; We found an uncompression rule.
2618 (with-tramp-progress-reporter
2619 v
0 (format "Uncompressing %s" file
)
2620 (when (tramp-send-command-and-check
2621 v
(concat (nth 2 suffix
) " "
2622 (tramp-shell-quote-argument localname
)))
2623 ;; `dired-remove-file' is not defined in XEmacs.
2624 (tramp-compat-funcall 'dired-remove-file file
)
2625 (string-match (car suffix
) file
)
2626 (concat (substring file
0 (match-beginning 0))))))
2628 ;; We don't recognize the file as compressed, so compress it.
2630 (with-tramp-progress-reporter v
0 (format "Compressing %s" file
)
2631 (when (tramp-send-command-and-check
2632 v
(concat "gzip -f "
2633 (tramp-shell-quote-argument localname
)))
2634 ;; `dired-remove-file' is not defined in XEmacs.
2635 (tramp-compat-funcall 'dired-remove-file file
)
2636 (cond ((file-exists-p (concat file
".gz"))
2637 (concat file
".gz"))
2638 ((file-exists-p (concat file
".z"))
2642 (defun tramp-sh-handle-insert-directory
2643 (filename switches
&optional wildcard full-directory-p
)
2644 "Like `insert-directory' for Tramp files."
2645 (setq filename
(expand-file-name filename
))
2646 (unless switches
(setq switches
""))
2647 (with-parsed-tramp-file-name filename nil
2648 (if (and (featurep 'ls-lisp
)
2649 (not (symbol-value 'ls-lisp-use-insert-directory-program
)))
2650 (tramp-handle-insert-directory
2651 filename switches wildcard full-directory-p
)
2652 (when (stringp switches
)
2653 (setq switches
(split-string switches
)))
2654 (when (and (member "--dired" switches
)
2655 (not (tramp-get-ls-command-with-dired v
)))
2656 (setq switches
(delete "--dired" switches
)))
2658 (setq wildcard
(tramp-run-real-handler
2659 'file-name-nondirectory
(list localname
)))
2660 (setq localname
(tramp-run-real-handler
2661 'file-name-directory
(list localname
))))
2662 (unless (or full-directory-p
(member "-d" switches
))
2663 (setq switches
(append switches
'("-d"))))
2664 (setq switches
(mapconcat 'tramp-shell-quote-argument switches
" "))
2666 (setq switches
(concat switches
" " wildcard
)))
2668 v
4 "Inserting directory `ls %s %s', wildcard %s, fulldir %s"
2669 switches filename
(if wildcard
"yes" "no")
2670 (if full-directory-p
"yes" "no"))
2671 ;; If `full-directory-p', we just say `ls -l FILENAME'.
2672 ;; Else we chdir to the parent directory, then say `ls -ld BASENAME'.
2673 (if full-directory-p
2676 (format "%s %s %s 2>/dev/null"
2677 (tramp-get-ls-command v
)
2681 (tramp-shell-quote-argument (concat localname
".")))))
2682 (tramp-barf-unless-okay
2684 (format "cd %s" (tramp-shell-quote-argument
2685 (tramp-run-real-handler
2686 'file-name-directory
(list localname
))))
2688 (tramp-shell-quote-argument
2689 (tramp-run-real-handler 'file-name-directory
(list localname
))))
2692 (format "%s %s %s 2>/dev/null"
2693 (tramp-get-ls-command v
)
2697 (tramp-run-real-handler
2698 'file-name-nondirectory
(list localname
)))))
2700 (tramp-shell-quote-argument
2701 (tramp-run-real-handler
2702 'file-name-nondirectory
(list localname
)))))))
2705 (let ((beg (point)))
2706 (narrow-to-region (point) (point))
2707 ;; We cannot use `insert-buffer-substring' because the Tramp
2708 ;; buffer changes its contents before insertion due to calling
2709 ;; `expand-file' and alike.
2711 (with-current-buffer (tramp-get-buffer v
)
2714 ;; Check for "--dired" output.
2716 (when (looking-at "//SUBDIRED//")
2718 (when (looking-at "//DIRED//\\s-+")
2719 (let ((databeg (match-end 0))
2720 (end (point-at-eol)))
2721 ;; Now read the numeric positions of file names.
2723 (while (< (point) end
)
2724 (let ((start (+ beg
(read (current-buffer))))
2725 (end (+ beg
(read (current-buffer)))))
2726 (if (memq (char-after end
) '(?
\n ?\
))
2727 ;; End is followed by \n or by " -> ".
2728 (put-text-property start end
'dired-filename t
))))))
2729 ;; Remove trailing lines.
2730 (goto-char (point-at-bol))
2731 (while (looking-at "//")
2733 (delete-region (match-beginning 0) (point)))
2735 ;; Some busyboxes are reluctant to discard colors.
2737 (string-match "color" (tramp-get-connection-property v
"ls" ""))
2739 (while (re-search-forward tramp-color-escape-sequence-regexp nil t
)
2740 (replace-match "")))
2742 ;; Decode the output, it could be multibyte.
2743 (decode-coding-region
2745 (or file-name-coding-system
2746 (and (boundp 'default-file-name-coding-system
)
2747 (symbol-value 'default-file-name-coding-system
))))
2749 ;; The inserted file could be from somewhere else.
2750 (when (and (not wildcard
) (not full-directory-p
))
2751 (goto-char (point-max))
2752 (when (file-symlink-p filename
)
2753 (goto-char (search-backward "->" beg
'noerror
)))
2755 (if (zerop (length (file-name-nondirectory filename
)))
2757 (file-name-nondirectory filename
))
2759 (replace-match (file-relative-name filename
) t
))
2761 (goto-char (point-max)))))))
2763 ;; Canonicalization of file names.
2765 (defun tramp-sh-handle-expand-file-name (name &optional dir
)
2766 "Like `expand-file-name' for Tramp files.
2767 If the localname part of the given file name starts with \"/../\" then
2768 the result will be a local, non-Tramp, file name."
2769 ;; If DIR is not given, use `default-directory' or "/".
2770 (setq dir
(or dir default-directory
"/"))
2771 ;; Unless NAME is absolute, concat DIR and NAME.
2772 (unless (file-name-absolute-p name
)
2773 (setq name
(concat (file-name-as-directory dir
) name
)))
2774 ;; If NAME is not a Tramp file, run the real handler.
2775 (if (not (tramp-connectable-p name
))
2776 (tramp-run-real-handler 'expand-file-name
(list name nil
))
2778 (with-parsed-tramp-file-name name nil
2779 (unless (tramp-run-real-handler 'file-name-absolute-p
(list localname
))
2780 (setq localname
(concat "~/" localname
)))
2781 ;; Tilde expansion if necessary. This needs a shell which
2782 ;; groks tilde expansion! The function `tramp-find-shell' is
2783 ;; supposed to find such a shell on the remote host. Please
2784 ;; tell me about it when this doesn't work on your system.
2785 (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname
)
2786 (let ((uname (match-string 1 localname
))
2787 (fname (match-string 2 localname
)))
2788 ;; We cannot simply apply "~/", because under sudo "~/" is
2789 ;; expanded to the local user home directory but to the
2790 ;; root home directory. On the other hand, using always
2791 ;; the default user name for tilde expansion is not
2792 ;; appropriate either, because ssh and companions might
2793 ;; use a user name from the config file.
2794 (when (and (string-equal uname
"~")
2795 (string-match "\\`su\\(do\\)?\\'" method
))
2796 (setq uname
(concat uname user
)))
2798 (with-tramp-connection-property v uname
2800 v
(format "cd %s; pwd" (tramp-shell-quote-argument uname
)))
2801 (with-current-buffer (tramp-get-buffer v
)
2802 (goto-char (point-min))
2803 (buffer-substring (point) (point-at-eol)))))
2804 (setq localname
(concat uname fname
))))
2805 ;; There might be a double slash, for example when "~/"
2806 ;; expands to "/". Remove this.
2807 (while (string-match "//" localname
)
2808 (setq localname
(replace-match "/" t t localname
)))
2809 ;; No tilde characters in file name, do normal
2810 ;; `expand-file-name' (this does "/./" and "/../"). We bind
2811 ;; `directory-sep-char' here for XEmacs on Windows, which would
2812 ;; otherwise use backslash. `default-directory' is bound,
2813 ;; because on Windows there would be problems with UNC shares or
2815 (let ((directory-sep-char ?
/)
2816 (default-directory (tramp-compat-temporary-file-directory)))
2817 (tramp-make-tramp-file-name
2819 (tramp-drop-volume-letter
2820 (tramp-run-real-handler
2821 'expand-file-name
(list localname
)))
2824 ;;; Remote commands:
2826 (defun tramp-process-sentinel (proc event
)
2827 "Flush file caches."
2828 (unless (memq (process-status proc
) '(run open
))
2829 (let ((vec (tramp-get-connection-property proc
"vector" nil
)))
2831 (tramp-message vec
5 "Sentinel called: `%S' `%s'" proc event
)
2832 (tramp-flush-connection-property proc
)
2833 (tramp-flush-directory-property vec
"")))))
2835 ;; We use BUFFER also as connection buffer during setup. Because of
2836 ;; this, its original contents must be saved, and restored once
2837 ;; connection has been setup.
2838 (defun tramp-sh-handle-start-file-process (name buffer program
&rest args
)
2839 "Like `start-file-process' for Tramp files."
2840 (with-parsed-tramp-file-name (expand-file-name default-directory
) nil
2841 (let* (;; When PROGRAM matches "*sh", and the first arg is "-c",
2842 ;; it might be that the arguments exceed the command line
2843 ;; length. Therefore, we modify the command.
2844 (heredoc (and (stringp program
)
2845 (string-match "sh$" program
)
2846 (string-equal "-c" (car args
))
2847 (= (length args
) 2)))
2848 ;; When PROGRAM is nil, we just provide a tty.
2849 (args (if (not heredoc
) args
2851 (while (and (< i
(length (cadr args
)))
2852 (string-match " " (cadr args
) i
))
2855 (list (replace-match " \\\\\n" nil nil
(cadr args
))))
2856 (setq i
(+ i
250))))
2858 ;; Use a human-friendly prompt, for example for `shell'.
2859 (prompt (format "PS1=%s"
2861 (file-remote-p default-directory
)
2862 tramp-initial-end-of-output
)))
2863 ;; We use as environment the difference to toplevel
2864 ;; `process-environment'.
2869 (cons prompt
(nreverse (copy-sequence process-environment
)))
2871 (or (member elt
(default-toplevel-value 'process-environment
))
2872 (setq env
(cons elt env
)))))
2874 (when (stringp program
)
2875 (format "cd %s && exec %s env %s %s"
2876 (tramp-shell-quote-argument localname
)
2877 (if heredoc
(format "<<'%s'" tramp-end-of-heredoc
) "")
2878 (mapconcat 'tramp-shell-quote-argument env
" ")
2880 (format "%s\n(\n%s\n) </dev/tty\n%s"
2881 program
(car args
) tramp-end-of-heredoc
)
2882 (mapconcat 'tramp-shell-quote-argument
2883 (cons program args
) " ")))))
2884 (tramp-process-connection-type
2885 (or (null program
) tramp-process-connection-type
))
2886 (bmp (and (buffer-live-p buffer
) (buffer-modified-p buffer
)))
2889 ;; We do not want to raise an error when
2890 ;; `start-file-process' has been started several times in
2891 ;; `eshell' and friends.
2892 (tramp-current-connection nil
))
2895 ;; BUFFER can be nil. We use a temporary buffer.
2896 (setq buffer
(generate-new-buffer tramp-temp-buffer-name
)))
2897 (while (get-process name1
)
2898 ;; NAME must be unique as process name.
2900 name1
(format "%s<%d>" name i
)))
2902 ;; Set the new process properties.
2903 (tramp-set-connection-property v
"process-name" name
)
2904 (tramp-set-connection-property v
"process-buffer" buffer
)
2906 (with-current-buffer (tramp-get-connection-buffer v
)
2908 ;; We catch this event. Otherwise, `start-process' could
2909 ;; be called on the local host.
2912 ;; Activate narrowing in order to save BUFFER
2913 ;; contents. Clear also the modification time;
2914 ;; otherwise we might be interrupted by
2915 ;; `verify-visited-file-modtime'.
2916 (let ((buffer-undo-list t
)
2917 (buffer-read-only nil
)
2919 (clear-visited-file-modtime)
2920 (narrow-to-region (point-max) (point-max))
2921 ;; We call `tramp-maybe-open-connection', in order
2922 ;; to cleanup the prompt afterwards.
2924 (tramp-maybe-open-connection v
)
2926 (delete-region mark
(point))
2927 (narrow-to-region (point-max) (point-max))
2930 ;; Send the command.
2931 (tramp-send-command v command nil t
) ; nooutput
2932 ;; Check, whether a pty is associated.
2933 (unless (tramp-compat-process-get
2934 (tramp-get-connection-process v
) 'remote-tty
)
2937 "pty association is not supported for `%s'" name
))))
2938 (let ((p (tramp-get-connection-process v
)))
2939 ;; Set query flag and process marker for this
2940 ;; process. We ignore errors, because the process
2941 ;; could have finished already.
2943 (tramp-compat-set-process-query-on-exit-flag p t
)
2944 (set-marker (process-mark p
) (point)))
2949 (if (string-match tramp-temp-buffer-name
(buffer-name))
2951 (set-process-buffer (tramp-get-connection-process v
) nil
)
2952 (kill-buffer (current-buffer)))
2953 (set-buffer-modified-p bmp
))
2954 (tramp-set-connection-property v
"process-name" nil
)
2955 (tramp-set-connection-property v
"process-buffer" nil
))))))
2957 (defun tramp-sh-handle-process-file
2958 (program &optional infile destination display
&rest args
)
2959 "Like `process-file' for Tramp files."
2960 ;; The implementation is not complete yet.
2961 (when (and (numberp destination
) (zerop destination
))
2962 (error "Implementation does not handle immediate return"))
2964 (with-parsed-tramp-file-name default-directory nil
2965 (let (command env input tmpinput stderr tmpstderr outbuf ret
)
2967 (setq command
(mapconcat 'tramp-shell-quote-argument
2968 (cons program args
) " "))
2969 ;; We use as environment the difference to toplevel `process-environment'.
2971 (dolist (elt (nreverse (copy-sequence process-environment
)) env
)
2972 (or (member elt
(default-toplevel-value 'process-environment
))
2973 (setq env
(cons elt env
)))))
2978 (mapconcat 'tramp-shell-quote-argument env
" ") command
)))
2981 (setq input
"/dev/null")
2982 (setq infile
(expand-file-name infile
))
2983 (if (tramp-equal-remote default-directory infile
)
2984 ;; INFILE is on the same remote host.
2985 (setq input
(with-parsed-tramp-file-name infile nil localname
))
2986 ;; INFILE must be copied to remote host.
2987 (setq input
(tramp-make-tramp-temp-file v
)
2988 tmpinput
(tramp-make-tramp-file-name method user host input
))
2989 (copy-file infile tmpinput t
)))
2990 (when input
(setq command
(format "%s <%s" command input
)))
2992 ;; Determine output.
2995 ((bufferp destination
)
2996 (setq outbuf destination
))
2998 ((stringp destination
)
2999 (setq outbuf
(get-buffer-create destination
)))
3000 ;; (REAL-DESTINATION ERROR-DESTINATION)
3001 ((consp destination
)
3004 ((bufferp (car destination
))
3005 (setq outbuf
(car destination
)))
3006 ((stringp (car destination
))
3007 (setq outbuf
(get-buffer-create (car destination
))))
3009 (setq outbuf
(current-buffer))))
3012 ((stringp (cadr destination
))
3013 (setcar (cdr destination
) (expand-file-name (cadr destination
)))
3014 (if (tramp-equal-remote default-directory
(cadr destination
))
3015 ;; stderr is on the same remote host.
3016 (setq stderr
(with-parsed-tramp-file-name
3017 (cadr destination
) nil localname
))
3018 ;; stderr must be copied to remote host. The temporary
3019 ;; file must be deleted after execution.
3020 (setq stderr
(tramp-make-tramp-temp-file v
)
3021 tmpstderr
(tramp-make-tramp-file-name
3022 method user host stderr
))))
3023 ;; stderr to be discarded.
3024 ((null (cadr destination
))
3025 (setq stderr
"/dev/null"))))
3028 (setq outbuf
(current-buffer))))
3029 (when stderr
(setq command
(format "%s 2>%s" command stderr
)))
3031 ;; Send the command. It might not return in time, so we protect
3032 ;; it. Call it in a subshell, in order to preserve working
3037 (if (tramp-send-command-and-check
3038 v
(format "\\cd %s; %s"
3039 (tramp-shell-quote-argument localname
)
3043 ;; We should add the output anyway.
3045 (with-current-buffer outbuf
3047 (with-current-buffer (tramp-get-connection-buffer v
)
3049 (when (and display
(get-buffer-window outbuf t
)) (redisplay))))
3050 ;; When the user did interrupt, we should do it also. We use
3051 ;; return code -1 as marker.
3053 (kill-buffer (tramp-get-connection-buffer v
))
3057 (kill-buffer (tramp-get-connection-buffer v
))
3060 ;; Provide error file.
3061 (when tmpstderr
(rename-file tmpstderr
(cadr destination
) t
))
3063 ;; Cleanup. We remove all file cache values for the connection,
3064 ;; because the remote process could have changed them.
3065 (when tmpinput
(delete-file tmpinput
))
3067 ;; `process-file-side-effects' has been introduced with GNU
3068 ;; Emacs 23.2. If set to `nil', no remote file will be changed
3069 ;; by `program'. If it doesn't exist, we assume its default
3071 (unless (and (boundp 'process-file-side-effects
)
3072 (not (symbol-value 'process-file-side-effects
)))
3073 (tramp-flush-directory-property v
""))
3075 ;; Return exit status.
3080 (defun tramp-sh-handle-file-local-copy (filename)
3081 "Like `file-local-copy' for Tramp files."
3082 (with-parsed-tramp-file-name filename nil
3083 (unless (file-exists-p filename
)
3086 "Cannot make local copy of non-existing file `%s'" filename
))
3088 (let* ((size (nth 7 (file-attributes (file-truename filename
))))
3089 (rem-enc (tramp-get-inline-coding v
"remote-encoding" size
))
3090 (loc-dec (tramp-get-inline-coding v
"local-decoding" size
))
3091 (tmpfile (tramp-compat-make-temp-file filename
)))
3095 ;; `copy-file' handles direct copy and out-of-band methods.
3096 ((or (tramp-local-host-p v
)
3097 (tramp-method-out-of-band-p v size
))
3098 (copy-file filename tmpfile t t
))
3100 ;; Use inline encoding for file transfer.
3103 (with-tramp-progress-reporter
3105 (format "Encoding remote file `%s' with `%s'" filename rem-enc
)
3106 (tramp-barf-unless-okay
3107 v
(format rem-enc
(tramp-shell-quote-argument localname
))
3108 "Encoding remote file failed"))
3110 (with-tramp-progress-reporter
3111 v
3 (format "Decoding local file `%s' with `%s'"
3113 (if (functionp loc-dec
)
3114 ;; If local decoding is a function, we call it.
3115 ;; We must disable multibyte, because
3116 ;; `uudecode-decode-region' doesn't handle it
3119 (set-buffer-multibyte nil
)
3120 (insert-buffer-substring (tramp-get-buffer v
))
3121 (funcall loc-dec
(point-min) (point-max))
3122 ;; Unset `file-name-handler-alist'. Otherwise,
3123 ;; epa-file gets confused.
3124 (let (file-name-handler-alist
3125 (coding-system-for-write 'binary
))
3127 (point-min) (point-max) tmpfile nil
'no-message
)))
3129 ;; If tramp-decoding-function is not defined for this
3130 ;; method, we invoke tramp-decoding-command instead.
3131 (let ((tmpfile2 (tramp-compat-make-temp-file filename
)))
3132 ;; Unset `file-name-handler-alist'. Otherwise,
3133 ;; epa-file gets confused.
3134 (let (file-name-handler-alist
3135 (coding-system-for-write 'binary
))
3136 (with-current-buffer (tramp-get-buffer v
)
3138 (point-min) (point-max) tmpfile2 nil
'no-message
)))
3140 (tramp-call-local-coding-command
3141 loc-dec tmpfile2 tmpfile
)
3142 (delete-file tmpfile2
)))))
3144 ;; Set proper permissions.
3145 (set-file-modes tmpfile
(tramp-default-file-modes filename
))
3146 ;; Set local user ownership.
3147 (tramp-set-file-uid-gid tmpfile
)))
3149 ;; Oops, I don't know what to do.
3151 v
'file-error
"Wrong method specification for `%s'" method
)))
3155 (delete-file tmpfile
)
3156 (signal (car err
) (cdr err
))))
3158 (run-hooks 'tramp-handle-file-local-copy-hook
)
3161 ;; This is needed for XEmacs only. Code stolen from files.el.
3162 (defun tramp-sh-handle-insert-file-contents-literally
3163 (filename &optional visit beg end replace
)
3164 "Like `insert-file-contents-literally' for Tramp files."
3165 (let ((format-alist nil
)
3166 (after-insert-file-functions nil
)
3167 (coding-system-for-read 'no-conversion
)
3168 (coding-system-for-write 'no-conversion
)
3169 (find-buffer-file-type-function
3170 (if (fboundp 'find-buffer-file-type
)
3171 (symbol-function 'find-buffer-file-type
)
3173 (inhibit-file-name-handlers '(jka-compr-handler image-file-handler
))
3174 (inhibit-file-name-operation 'insert-file-contents
))
3177 (fset 'find-buffer-file-type
(lambda (_filename) t
))
3178 (insert-file-contents filename visit beg end replace
))
3180 (if find-buffer-file-type-function
3181 (fset 'find-buffer-file-type find-buffer-file-type-function
)
3182 (fmakunbound 'find-buffer-file-type
)))))
3184 ;; CCC grok LOCKNAME
3185 (defun tramp-sh-handle-write-region
3186 (start end filename
&optional append visit lockname confirm
)
3187 "Like `write-region' for Tramp files."
3188 (setq filename
(expand-file-name filename
))
3189 (with-parsed-tramp-file-name filename nil
3190 ;; Following part commented out because we don't know what to do about
3191 ;; file locking, and it does not appear to be a problem to ignore it.
3192 ;; Ange-ftp ignores it, too.
3193 ;; (when (and lockname (stringp lockname))
3194 ;; (setq lockname (expand-file-name lockname)))
3195 ;; (unless (or (eq lockname nil)
3196 ;; (string= lockname filename))
3198 ;; "tramp-sh-handle-write-region: LOCKNAME must be nil or equal FILENAME"))
3200 ;; XEmacs takes a coding system as the seventh argument, not `confirm'.
3201 (when (and (not (featurep 'xemacs
)) confirm
(file-exists-p filename
))
3202 (unless (y-or-n-p (format "File %s exists; overwrite anyway? " filename
))
3203 (tramp-error v
'file-error
"File not overwritten")))
3205 (let ((uid (or (nth 2 (tramp-compat-file-attributes filename
'integer
))
3206 (tramp-get-remote-uid v
'integer
)))
3207 (gid (or (nth 3 (tramp-compat-file-attributes filename
'integer
))
3208 (tramp-get-remote-gid v
'integer
))))
3210 (if (and (tramp-local-host-p v
)
3211 ;; `file-writable-p' calls `file-expand-file-name'. We
3212 ;; cannot use `tramp-run-real-handler' therefore.
3213 (let (file-name-handler-alist)
3215 (file-writable-p (file-name-directory localname
))
3216 (or (file-directory-p localname
)
3217 (file-writable-p localname
)))))
3218 ;; Short track: if we are on the local host, we can run directly.
3219 (tramp-run-real-handler
3221 (list start end localname append
'no-message lockname confirm
))
3223 (let* ((modes (save-excursion (tramp-default-file-modes filename
)))
3224 ;; We use this to save the value of
3225 ;; `last-coding-system-used' after writing the tmp
3226 ;; file. At the end of the function, we set
3227 ;; `last-coding-system-used' to this saved value. This
3228 ;; way, any intermediary coding systems used while
3229 ;; talking to the remote shell or suchlike won't hose
3230 ;; this variable. This approach was snarfed from
3233 ;; Write region into a tmp file. This isn't really
3234 ;; needed if we use an encoding function, but currently
3235 ;; we use it always because this makes the logic
3236 ;; simpler. We must also set `temporary-file-directory',
3237 ;; because it could point to a remote directory.
3238 (temporary-file-directory
3239 (tramp-compat-temporary-file-directory))
3240 (tmpfile (or tramp-temp-buffer-file-name
3241 (tramp-compat-make-temp-file filename
))))
3243 ;; If `append' is non-nil, we copy the file locally, and let
3244 ;; the native `write-region' implementation do the job.
3245 (when append
(copy-file filename tmpfile
'ok
))
3247 ;; We say `no-message' here because we don't want the
3248 ;; visited file modtime data to be clobbered from the temp
3249 ;; file. We call `set-visited-file-modtime' ourselves later
3250 ;; on. We must ensure that `file-coding-system-alist'
3251 ;; matches `tmpfile'.
3252 (let (file-name-handler-alist
3253 (file-coding-system-alist
3254 (tramp-find-file-name-coding-system-alist filename tmpfile
)))
3256 (tramp-run-real-handler
3258 (list start end tmpfile append
'no-message lockname confirm
))
3260 (setq tramp-temp-buffer-file-name nil
)
3261 (delete-file tmpfile
)
3262 (signal (car err
) (cdr err
))))
3264 ;; Now, `last-coding-system-used' has the right value. Remember it.
3265 (when (boundp 'last-coding-system-used
)
3266 (setq coding-system-used
3267 (symbol-value 'last-coding-system-used
))))
3269 ;; The permissions of the temporary file should be set. If
3270 ;; FILENAME does not exist (eq modes nil) it has been
3271 ;; renamed to the backup file. This case `save-buffer'
3272 ;; handles permissions.
3273 ;; Ensure that it is still readable.
3277 (logior (or modes
0) (tramp-compat-octal-to-decimal "0400"))))
3279 ;; This is a bit lengthy due to the different methods
3280 ;; possible for file transfer. First, we check whether the
3281 ;; method uses an scp program. If so, we call it.
3282 ;; Otherwise, both encoding and decoding command must be
3283 ;; specified. However, if the method _also_ specifies an
3284 ;; encoding function, then that is used for encoding the
3285 ;; contents of the tmp file.
3286 (let* ((size (nth 7 (file-attributes tmpfile
)))
3287 (rem-dec (tramp-get-inline-coding v
"remote-decoding" size
))
3288 (loc-enc (tramp-get-inline-coding v
"local-encoding" size
)))
3290 ;; `copy-file' handles direct copy and out-of-band methods.
3291 ((or (tramp-local-host-p v
)
3292 (tramp-method-out-of-band-p v size
))
3293 (if (and (not (stringp start
))
3294 (= (or end
(point-max)) (point-max))
3295 (= (or start
(point-min)) (point-min))
3296 (tramp-get-method-parameter
3297 method
'tramp-copy-keep-tmpfile
))
3299 (setq tramp-temp-buffer-file-name tmpfile
)
3301 ;; We keep the local file for performance
3302 ;; reasons, useful for "rsync".
3303 (copy-file tmpfile filename t
)
3305 (setq tramp-temp-buffer-file-name nil
)
3306 (delete-file tmpfile
)
3307 (signal (car err
) (cdr err
)))))
3308 (setq tramp-temp-buffer-file-name nil
)
3309 ;; Don't rename, in order to keep context in SELinux.
3311 (copy-file tmpfile filename t
)
3312 (delete-file tmpfile
))))
3314 ;; Use inline file transfer.
3319 (set-buffer-multibyte nil
)
3320 ;; Use encoding function or command.
3321 (with-tramp-progress-reporter
3322 v
3 (format "Encoding local file `%s' using `%s'"
3324 (if (functionp loc-enc
)
3325 ;; The following `let' is a workaround for
3326 ;; the base64.el that comes with pgnus-0.84.
3327 ;; If both of the following conditions are
3328 ;; satisfied, it tries to write to a local
3329 ;; file in default-directory, but at this
3330 ;; point, default-directory is remote.
3331 ;; (`call-process-region' can't write to
3332 ;; remote files, it seems.) The file in
3333 ;; question is a tmp file anyway.
3334 (let ((coding-system-for-read 'binary
)
3336 (tramp-compat-temporary-file-directory)))
3337 (insert-file-contents-literally tmpfile
)
3338 (funcall loc-enc
(point-min) (point-max)))
3340 (unless (zerop (tramp-call-local-coding-command
3344 (concat "Cannot write to `%s', "
3345 "local encoding command `%s' failed")
3346 filename loc-enc
))))
3348 ;; Send buffer into remote decoding command which
3349 ;; writes to remote file. Because this happens on
3350 ;; the remote host, we cannot use the function.
3351 (with-tramp-progress-reporter
3352 v
3 (format "Decoding remote file `%s' using `%s'"
3354 (goto-char (point-max))
3355 (unless (bolp) (newline))
3359 (concat rem-dec
" <<'%s'\n%s%s")
3360 (tramp-shell-quote-argument localname
)
3361 tramp-end-of-heredoc
3363 tramp-end-of-heredoc
))
3364 (tramp-barf-unless-okay
3366 "Couldn't write region to `%s', decode using `%s' failed"
3368 ;; When `file-precious-flag' is set, the region is
3369 ;; written to a temporary file. Check that the
3370 ;; checksum is equal to that from the local tmpfile.
3371 (when file-precious-flag
3374 ;; cksum runs locally, if possible.
3375 (zerop (tramp-call-process v
"cksum" tmpfile t
))
3376 ;; cksum runs remotely.
3377 (tramp-send-command-and-check
3380 "cksum <%s" (tramp-shell-quote-argument localname
)))
3381 ;; ... they are different.
3385 (with-current-buffer (tramp-get-buffer v
)
3389 (concat "Couldn't write region to `%s',"
3390 " decode using `%s' failed")
3391 filename rem-dec
)))))
3394 (delete-file tmpfile
)))
3396 ;; That's not expected.
3400 (concat "Method `%s' should specify both encoding and "
3401 "decoding command or an scp program")
3404 ;; Make `last-coding-system-used' have the right value.
3405 (when coding-system-used
3406 (set 'last-coding-system-used coding-system-used
))))
3408 (tramp-flush-file-property v
(file-name-directory localname
))
3409 (tramp-flush-file-property v localname
)
3411 ;; We must protect `last-coding-system-used', now we have set it
3412 ;; to its correct value.
3413 (let (last-coding-system-used (need-chown t
))
3414 ;; Set file modification time.
3415 (when (or (eq visit t
) (stringp visit
))
3416 (let ((file-attr (tramp-compat-file-attributes filename
'integer
)))
3417 (set-visited-file-modtime
3418 ;; We must pass modtime explicitly, because FILENAME can
3419 ;; be different from (buffer-file-name), f.e. if
3420 ;; `file-precious-flag' is set.
3422 (when (and (= (nth 2 file-attr
) uid
)
3423 (= (nth 3 file-attr
) gid
))
3424 (setq need-chown nil
))))
3426 ;; Set the ownership.
3428 (tramp-set-file-uid-gid filename uid gid
))
3429 (when (or (eq visit t
) (null visit
) (stringp visit
))
3430 (tramp-message v
0 "Wrote %s" filename
))
3431 (run-hooks 'tramp-handle-write-region-hook
)))))
3433 (defvar tramp-vc-registered-file-names nil
3434 "List used to collect file names, which are checked during `vc-registered'.")
3436 ;; VC backends check for the existence of various different special
3437 ;; files. This is very time consuming, because every single check
3438 ;; requires a remote command (the file cache must be invalidated).
3439 ;; Therefore, we apply a kind of optimization. We install the file
3440 ;; name handler `tramp-vc-file-name-handler', which does nothing but
3441 ;; remembers all file names for which `file-exists-p' or
3442 ;; `file-readable-p' has been applied. A first run of `vc-registered'
3443 ;; is performed. Afterwards, a script is applied for all collected
3444 ;; file names, using just one remote command. The result of this
3445 ;; script is used to fill the file cache with actual values. Now we
3446 ;; can reset the file name handlers, and we make a second run of
3447 ;; `vc-registered', which returns the expected result without sending
3448 ;; any other remote command.
3449 (defun tramp-sh-handle-vc-registered (file)
3450 "Like `vc-registered' for Tramp files."
3451 (tramp-compat-with-temp-message ""
3452 (with-parsed-tramp-file-name file nil
3453 (with-tramp-progress-reporter
3454 v
3 (format "Checking `vc-registered' for %s" file
)
3456 ;; There could be new files, created by the vc backend. We
3457 ;; cannot reuse the old cache entries, therefore. In
3458 ;; `tramp-get-file-property', `remote-file-name-inhibit-cache'
3459 ;; could also be a timestamp as `current-time' returns. This
3460 ;; means invalidate all cache entries with an older timestamp.
3461 (let (tramp-vc-registered-file-names
3462 (remote-file-name-inhibit-cache (current-time))
3463 (file-name-handler-alist
3464 `((,tramp-file-name-regexp . tramp-vc-file-name-handler
))))
3466 ;; Here we collect only file names, which need an operation.
3467 (ignore-errors (tramp-run-real-handler 'vc-registered
(list file
)))
3468 (tramp-message v
10 "\n%s" tramp-vc-registered-file-names
)
3470 ;; Send just one command, in order to fill the cache.
3471 (when tramp-vc-registered-file-names
3472 (tramp-maybe-send-script
3474 (format tramp-vc-registered-read-file-names
3475 (tramp-get-file-exists-command v
)
3476 (format "%s -r" (tramp-get-test-command v
)))
3477 "tramp_vc_registered_read_file_names")
3482 ;; We cannot use `tramp-send-command-and-read',
3483 ;; because this does not cooperate well with
3484 ;; heredoc documents.
3488 "tramp_vc_registered_read_file_names <<'%s'\n%s\n%s\n"
3489 tramp-end-of-heredoc
3490 (mapconcat 'tramp-shell-quote-argument
3491 tramp-vc-registered-file-names
3493 tramp-end-of-heredoc
))
3494 (with-current-buffer (tramp-get-connection-buffer v
)
3495 ;; Read the expression.
3496 (goto-char (point-min))
3497 (read (current-buffer)))))
3499 (tramp-set-file-property
3500 v
(car elt
) (cadr elt
) (cadr (cdr elt
))))))
3502 ;; Second run. Now all `file-exists-p' or `file-readable-p'
3503 ;; calls shall be answered from the file cache. We unset
3504 ;; `process-file-side-effects' and `remote-file-name-inhibit-cache'
3505 ;; in order to keep the cache.
3506 (let ((vc-handled-backends vc-handled-backends
)
3507 remote-file-name-inhibit-cache process-file-side-effects
)
3508 ;; Reduce `vc-handled-backends' in order to minimize process calls.
3509 (when (and (memq 'Bzr vc-handled-backends
)
3510 (boundp 'vc-bzr-program
)
3511 (not (with-tramp-connection-property v vc-bzr-program
3512 (tramp-find-executable
3513 v vc-bzr-program
(tramp-get-remote-path v
)))))
3514 (setq vc-handled-backends
(remq 'Bzr vc-handled-backends
)))
3515 (when (and (memq 'Git vc-handled-backends
)
3516 (boundp 'vc-git-program
)
3517 (not (with-tramp-connection-property v vc-git-program
3518 (tramp-find-executable
3519 v vc-git-program
(tramp-get-remote-path v
)))))
3520 (setq vc-handled-backends
(remq 'Git vc-handled-backends
)))
3521 (when (and (memq 'Hg vc-handled-backends
)
3522 (boundp 'vc-hg-program
)
3523 (not (with-tramp-connection-property v vc-hg-program
3524 (tramp-find-executable
3525 v vc-hg-program
(tramp-get-remote-path v
)))))
3526 (setq vc-handled-backends
(remq 'Hg vc-handled-backends
)))
3529 (tramp-run-real-handler 'vc-registered
(list file
))))))))
3531 ;;;###tramp-autoload
3532 (defun tramp-sh-file-name-handler (operation &rest args
)
3533 "Invoke remote-shell Tramp file name handler.
3534 Fall back to normal file name handler if no Tramp handler exists."
3535 (when (and tramp-locked
(not tramp-locker
))
3536 (setq tramp-locked nil
)
3538 (car-safe tramp-current-connection
) 'file-error
3539 "Forbidden reentrant call of Tramp"))
3540 (let ((tl tramp-locked
))
3541 (setq tramp-locked t
)
3543 (let ((tramp-locker t
))
3545 (let ((fn (assoc operation tramp-sh-file-name-handler-alist
)))
3547 (apply (cdr fn
) args
)
3548 (tramp-run-real-handler operation args
)))))
3549 (setq tramp-locked tl
))))
3551 (defun tramp-vc-file-name-handler (operation &rest args
)
3552 "Invoke special file name handler, which collects files to be handled."
3555 (tramp-replace-environment-variables
3556 (apply 'tramp-file-name-for-operation operation args
)))
3557 (fn (assoc operation tramp-sh-file-name-handler-alist
)))
3558 (with-parsed-tramp-file-name filename nil
3560 ;; That's what we want: file names, for which checks are
3561 ;; applied. We assume that VC uses only `file-exists-p' and
3562 ;; `file-readable-p' checks; otherwise we must extend the
3563 ;; list. We do not perform any action, but return nil, in
3564 ;; order to keep `vc-registered' running.
3565 ((and fn
(memq operation
'(file-exists-p file-readable-p
)))
3566 (add-to-list 'tramp-vc-registered-file-names localname
'append
)
3568 ;; `process-file' and `start-file-process' shall be ignored.
3569 ((and fn
(eq operation
'process-file
) 0))
3570 ((and fn
(eq operation
'start-file-process
) nil
))
3571 ;; Tramp file name handlers like `expand-file-name'. They
3573 (fn (save-match-data (apply (cdr fn
) args
)))
3574 ;; Default file name handlers, we don't care.
3575 (t (tramp-run-real-handler operation args
)))))))
3577 (defun tramp-sh-handle-file-notify-add-watch (file-name flags _callback
)
3578 "Like `file-notify-add-watch' for Tramp files."
3579 (setq file-name
(expand-file-name file-name
))
3580 (with-parsed-tramp-file-name file-name nil
3581 (let* ((default-directory (file-name-directory file-name
))
3582 command events filter p sequence
)
3584 ;; gvfs-monitor-dir.
3585 ((setq command
(tramp-get-remote-gvfs-monitor-dir v
))
3586 (setq filter
'tramp-sh-file-gvfs-monitor-dir-process-filter
3587 sequence
`(,command
,localname
)))
3589 ((setq command
(tramp-get-remote-inotifywait v
))
3590 (setq filter
'tramp-sh-file-inotifywait-process-filter
3593 ((and (memq 'change flags
) (memq 'attribute-change flags
))
3594 "create,modify,move,delete,attrib")
3595 ((memq 'change flags
) "create,modify,move,delete")
3596 ((memq 'attribute-change flags
) "attrib"))
3597 sequence
`(,command
"-mq" "-e" ,events
,localname
)))
3600 v
'file-notify-error
3601 "No file notification program found on %s"
3602 (file-remote-p file-name
))))
3606 (file-name-nondirectory command
)
3607 (generate-new-buffer
3608 (format " *%s*" (file-name-nondirectory command
)))
3610 ;; Return the process object as watch-descriptor.
3611 (if (not (processp p
))
3613 v
'file-notify-error
3614 "`%s' failed to start on remote host"
3615 (mapconcat 'identity sequence
" "))
3616 (tramp-message v
6 "Run `%s', %S" (mapconcat 'identity sequence
" ") p
)
3617 (tramp-set-connection-property p
"vector" v
)
3618 (tramp-compat-set-process-query-on-exit-flag p nil
)
3619 (set-process-filter p filter
)
3622 (defun tramp-sh-file-gvfs-monitor-dir-process-filter (proc string
)
3623 "Read output from \"gvfs-monitor-dir\" and add corresponding file-notify events."
3624 (let ((remote-prefix
3625 (with-current-buffer (process-buffer proc
)
3626 (file-remote-p default-directory
)))
3627 (rest-string (tramp-compat-process-get proc
'rest-string
)))
3629 (tramp-message proc
10 "Previous string:\n%s" rest-string
))
3630 (tramp-message proc
6 "%S\n%s" proc string
)
3631 (setq string
(concat rest-string string
)
3632 ;; Attribute change is returned in unused wording.
3633 string
(tramp-compat-replace-regexp-in-string
3634 "ATTRIB CHANGED" "ATTRIBUTE_CHANGED" string
))
3636 (while (string-match
3638 "Directory Monitor Event:[\n\r]+"
3639 "Child = \\([^\n\r]+\\)[\n\r]+"
3640 "\\(Other = \\([^\n\r]+\\)[\n\r]+\\)?"
3641 "Event = \\([^[:blank:]]+\\)[\n\r]+")
3647 (tramp-compat-replace-regexp-in-string
3648 "_" "-" (downcase (match-string 4 string
))))
3649 ;; File names are returned as absolute paths. We must
3650 ;; add the remote prefix.
3651 (concat remote-prefix
(match-string 1 string
))
3652 (when (match-string 3 string
)
3653 (concat remote-prefix
(match-string 3 string
))))))
3654 (setq string
(replace-match "" nil nil string
))
3655 ;; Usually, we would add an Emacs event now. Unfortunately,
3656 ;; `unread-command-events' does not accept several events at
3657 ;; once. Therefore, we apply the callback directly.
3658 (tramp-compat-funcall 'file-notify-callback object
)))
3660 ;; Save rest of the string.
3661 (when (zerop (length string
)) (setq string nil
))
3662 (when string
(tramp-message proc
10 "Rest string:\n%s" string
))
3663 (tramp-compat-process-put proc
'rest-string string
)))
3665 (defun tramp-sh-file-inotifywait-process-filter (proc string
)
3666 "Read output from \"inotifywait\" and add corresponding file-notify events."
3667 (tramp-message proc
6 "%S\n%s" proc string
)
3668 (dolist (line (split-string string
"[\n\r]+" 'omit-nulls
))
3669 ;; Check, whether there is a problem.
3672 (concat "^[^[:blank:]]+"
3673 "[[:blank:]]+\\([^[:blank:]]+\\)+"
3674 "\\([[:blank:]]+\\([^\n\r]+\\)\\)?")
3676 (tramp-error proc
'file-notify-error
"%s" line
))
3684 (tramp-compat-replace-regexp-in-string "_" "-" (downcase x
))))
3685 (split-string (match-string 1 line
) "," 'omit-nulls
))
3686 (match-string 3 line
))))
3687 ;; Usually, we would add an Emacs event now. Unfortunately,
3688 ;; `unread-command-events' does not accept several events at
3689 ;; once. Therefore, we apply the callback directly.
3690 (tramp-compat-funcall 'file-notify-callback object
))))
3692 ;;; Internal Functions:
3694 (defun tramp-maybe-send-script (vec script name
)
3695 "Define in remote shell function NAME implemented as SCRIPT.
3696 Only send the definition if it has not already been done."
3697 ;; We cannot let-bind (tramp-get-connection-process vec) because it
3699 (let ((scripts (tramp-get-connection-property
3700 (tramp-get-connection-process vec
) "scripts" nil
)))
3701 (unless (member name scripts
)
3702 (with-tramp-progress-reporter vec
5 (format "Sending script `%s'" name
)
3703 ;; The script could contain a call of Perl. This is masked with `%s'.
3704 (when (and (string-match "%s" script
)
3705 (not (tramp-get-remote-perl vec
)))
3706 (tramp-error vec
'file-error
"No Perl available on remote host"))
3707 (tramp-barf-unless-okay
3709 (format "%s () {\n%s\n}" name
3710 (format script
(tramp-get-remote-perl vec
)))
3711 "Script %s sending failed" name
)
3712 (tramp-set-connection-property
3713 (tramp-get-connection-process vec
) "scripts" (cons name scripts
))))))
3715 (defun tramp-set-auto-save ()
3716 (when (and ;; ange-ftp has its own auto-save mechanism
3717 (eq (tramp-find-foreign-file-name-handler (buffer-file-name))
3718 'tramp-sh-file-name-handler
)
3720 (auto-save-mode 1)))
3721 (add-hook 'find-file-hooks
'tramp-set-auto-save t
)
3722 (add-hook 'tramp-unload-hook
3724 (remove-hook 'find-file-hooks
'tramp-set-auto-save
)))
3726 (defun tramp-run-test (switch filename
)
3727 "Run `test' on the remote system, given a SWITCH and a FILENAME.
3728 Returns the exit code of the `test' program."
3729 (with-parsed-tramp-file-name filename nil
3730 (tramp-send-command-and-check
3734 (tramp-get-test-command v
)
3736 (tramp-shell-quote-argument localname
)))))
3738 (defun tramp-run-test2 (format-string file1 file2
)
3739 "Run `test'-like program on the remote system, given FILE1, FILE2.
3740 FORMAT-STRING contains the program name, switches, and place holders.
3741 Returns the exit code of the `test' program. Barfs if the methods,
3742 hosts, or files, disagree."
3743 (unless (tramp-equal-remote file1 file2
)
3744 (with-parsed-tramp-file-name (if (tramp-tramp-file-p file1
) file1 file2
) nil
3747 "tramp-run-test2 only implemented for same method, user, host")))
3748 (with-parsed-tramp-file-name file1 v1
3749 (with-parsed-tramp-file-name file1 v2
3750 (tramp-send-command-and-check
3752 (format format-string
3753 (tramp-shell-quote-argument v1-localname
)
3754 (tramp-shell-quote-argument v2-localname
))))))
3756 (defun tramp-find-executable
3757 (vec progname dirlist
&optional ignore-tilde ignore-path
)
3758 "Searches for PROGNAME in $PATH and all directories mentioned in DIRLIST.
3759 First arg VEC specifies the connection, PROGNAME is the program
3760 to search for, and DIRLIST gives the list of directories to
3761 search. If IGNORE-TILDE is non-nil, directory names starting
3762 with `~' will be ignored. If IGNORE-PATH is non-nil, searches
3765 Returns the absolute file name of PROGNAME, if found, and nil otherwise.
3767 This function expects to be in the right *tramp* buffer."
3768 (with-current-buffer (tramp-get-connection-buffer vec
)
3770 ;; Check whether the executable is in $PATH. "which(1)" does not
3771 ;; report always a correct error code; therefore we check the
3772 ;; number of words it returns. "SunOS 5.10" (and maybe "SunOS
3773 ;; 5.11") have problems with this command, we disable the call
3775 (unless (or ignore-path
3777 (regexp-opt '("SunOS 5.10" "SunOS 5.11"))
3778 (tramp-get-connection-property vec
"uname" "")))
3779 (tramp-send-command vec
(format "which \\%s | wc -w" progname
))
3780 (goto-char (point-min))
3781 (if (looking-at "^\\s-*1$")
3782 (setq result
(concat "\\" progname
))))
3785 ;; Remove all ~/foo directories from dirlist. In XEmacs,
3786 ;; `remove' is in CL, and we want to avoid CL dependencies.
3789 (setq d
(car dirlist
))
3790 (setq dirlist
(cdr dirlist
))
3791 (unless (char-equal ?~
(aref d
0))
3792 (setq newdl
(cons d newdl
))))
3793 (setq dirlist
(nreverse newdl
))))
3796 (format (concat "while read d; "
3797 "do if test -x $d/%s -a -f $d/%s; "
3798 "then echo tramp_executable $d/%s; "
3799 "break; fi; done <<'%s'\n"
3801 progname progname progname
3802 tramp-end-of-heredoc
3803 (mapconcat 'identity dirlist
"\n")
3804 tramp-end-of-heredoc
))
3805 (goto-char (point-max))
3806 (when (search-backward "tramp_executable " nil t
)
3807 (skip-chars-forward "^ ")
3808 (skip-chars-forward " ")
3809 (setq result
(buffer-substring (point) (point-at-eol)))))
3812 (defun tramp-set-remote-path (vec)
3813 "Sets the remote environment PATH to existing directories.
3814 I.e., for each directory in `tramp-remote-path', it is tested
3815 whether it exists and if so, it is added to the environment
3817 (tramp-message vec
5 "Setting $PATH environment variable")
3819 vec
(format "PATH=%s; export PATH"
3820 (mapconcat 'identity
(tramp-get-remote-path vec
) ":"))))
3822 ;; ------------------------------------------------------------
3823 ;; -- Communication with external shell --
3824 ;; ------------------------------------------------------------
3826 (defun tramp-find-file-exists-command (vec)
3827 "Find a command on the remote host for checking if a file exists.
3828 Here, we are looking for a command which has zero exit status if the
3829 file exists and nonzero exit status otherwise."
3830 (let ((existing "/")
3832 (tramp-shell-quote-argument "/ this file does not exist "))
3834 ;; The algorithm is as follows: we try a list of several commands.
3835 ;; For each command, we first run `$cmd /' -- this should return
3836 ;; true, as the root directory always exists. And then we run
3837 ;; `$cmd /this\ file\ does\ not\ exist ', hoping that the file indeed
3838 ;; does not exist. This should return false. We use the first
3839 ;; command we find that seems to work.
3840 ;; The list of commands to try is as follows:
3841 ;; `ls -d' This works on most systems, but NetBSD 1.4
3842 ;; has a bug: `ls' always returns zero exit
3843 ;; status, even for files which don't exist.
3844 ;; `test -e' Some Bourne shells have a `test' builtin
3845 ;; which does not know the `-e' option.
3846 ;; `/bin/test -e' For those, the `test' binary on disk normally
3847 ;; provides the option. Alas, the binary
3848 ;; is sometimes `/bin/test' and sometimes it's
3850 ;; `/usr/bin/test -e' In case `/bin/test' does not exist.
3853 (and (setq result
(format "%s -e" (tramp-get-test-command vec
)))
3854 (tramp-send-command-and-check
3855 vec
(format "%s %s" result existing
))
3856 (not (tramp-send-command-and-check
3857 vec
(format "%s %s" result nonexistent
)))))
3859 (and (setq result
"/bin/test -e")
3860 (tramp-send-command-and-check
3861 vec
(format "%s %s" result existing
))
3862 (not (tramp-send-command-and-check
3863 vec
(format "%s %s" result nonexistent
)))))
3865 (and (setq result
"/usr/bin/test -e")
3866 (tramp-send-command-and-check
3867 vec
(format "%s %s" result existing
))
3868 (not (tramp-send-command-and-check
3869 vec
(format "%s %s" result nonexistent
)))))
3871 (and (setq result
(format "%s -d" (tramp-get-ls-command vec
)))
3872 (tramp-send-command-and-check
3873 vec
(format "%s %s" result existing
))
3874 (not (tramp-send-command-and-check
3875 vec
(format "%s %s" result nonexistent
))))))
3877 vec
'file-error
"Couldn't find command to check if file exists"))
3880 (defun tramp-open-shell (vec shell
)
3881 "Opens shell SHELL."
3882 (with-tramp-progress-reporter
3883 vec
5 (format "Opening remote shell `%s'" shell
)
3884 ;; Find arguments for this shell.
3885 (let ((alist tramp-sh-extra-args
)
3887 (while (and alist
(null extra-args
))
3888 (setq item
(pop alist
))
3889 (when (string-match (car item
) shell
)
3890 (setq extra-args
(cdr item
))))
3891 ;; It is useful to set the prompt in the following command
3892 ;; because some people have a setting for $PS1 which /bin/sh
3893 ;; doesn't know about and thus /bin/sh will display a strange
3894 ;; prompt. For example, if $PS1 has "${CWD}" in the value, then
3895 ;; ksh will display the current working directory but /bin/sh
3896 ;; will display a dollar sign. The following command line sets
3897 ;; $PS1 to a sane value, and works under Bourne-ish shells as
3898 ;; well as csh-like shells. We also unset the variable $ENV
3899 ;; because that is read by some sh implementations (eg, bash
3900 ;; when called as sh) on startup; this way, we avoid the startup
3901 ;; file clobbering $PS1. $PROMPT_COMMAND is another way to set
3902 ;; the prompt in /bin/bash, it must be discarded as well.
3905 "exec env ENV=''%s PROMPT_COMMAND='' PS1=%s PS2='' PS3='' %s %s"
3906 (if tramp-histfile-override
3907 (concat " HISTFILE=" tramp-histfile-override
)
3909 (tramp-shell-quote-argument tramp-end-of-output
)
3910 shell
(or extra-args
""))
3912 (tramp-set-connection-property
3913 (tramp-get-connection-process vec
) "remote-shell" shell
)))
3915 (defun tramp-find-shell (vec)
3916 "Opens a shell on the remote host which groks tilde expansion."
3917 (with-current-buffer (tramp-get-buffer vec
)
3918 (let ((default-shell
3920 (tramp-get-connection-property
3921 (tramp-get-connection-process vec
) "remote-shell" nil
)
3922 (tramp-get-method-parameter
3923 (tramp-file-name-method vec
) 'tramp-remote-shell
)))
3926 (with-tramp-connection-property vec
"remote-shell"
3927 ;; CCC: "root" does not exist always, see QNAP 459.
3928 ;; Which check could we apply instead?
3929 (tramp-send-command vec
"echo ~root" t
)
3930 (if (or (string-match "^~root$" (buffer-string))
3931 ;; The default shell (ksh93) of OpenSolaris and
3932 ;; Solaris is buggy. We've got reports for
3933 ;; "SunOS 5.10" and "SunOS 5.11" so far.
3934 (string-match (regexp-opt '("SunOS 5.10" "SunOS 5.11"))
3935 (tramp-get-connection-property
3938 (or (tramp-find-executable
3939 vec
"bash" (tramp-get-remote-path vec
) t t
)
3940 (tramp-find-executable
3941 vec
"ksh" (tramp-get-remote-path vec
) t t
)
3942 ;; Maybe it works at least for some other commands.
3948 "Couldn't find a remote shell which groks tilde "
3949 "expansion, using `%s'")
3954 ;; Open a new shell if needed.
3955 (unless (string-equal shell default-shell
)
3957 vec
5 "Starting remote shell `%s' for tilde expansion" shell
)
3958 (tramp-open-shell vec shell
)))))
3960 ;; Utility functions.
3962 (defun tramp-barf-if-no-shell-prompt (proc timeout
&rest error-args
)
3963 "Wait for shell prompt and barf if none appears.
3964 Looks at process PROC to see if a shell prompt appears in TIMEOUT
3965 seconds. If not, it produces an error message with the given ERROR-ARGS."
3966 (let ((vec (tramp-get-connection-property proc
"vector" nil
)))
3968 (tramp-wait-for-regexp
3971 "\\(%s\\|%s\\)\\'" shell-prompt-pattern tramp-shell-prompt-pattern
))
3973 (delete-process proc
)
3974 (apply 'tramp-error-with-buffer
3975 (tramp-get-connection-buffer vec
) vec
'file-error error-args
)))))
3977 (defun tramp-open-connection-setup-interactive-shell (proc vec
)
3978 "Set up an interactive shell.
3979 Mainly sets the prompt and the echo correctly. PROC is the shell
3980 process to set up. VEC specifies the connection."
3981 (let ((tramp-end-of-output tramp-initial-end-of-output
))
3984 (or (tramp-get-connection-property vec
"remote-shell" nil
)
3985 (tramp-get-method-parameter
3986 (tramp-file-name-method vec
) 'tramp-remote-shell
)))
3989 (tramp-message vec
5 "Setting up remote shell environment")
3990 (tramp-send-command vec
"stty -inlcr -echo kill '^U' erase '^H'" t
)
3991 ;; Check whether the echo has really been disabled. Some
3992 ;; implementations, like busybox of embedded GNU/Linux, don't
3993 ;; support disabling.
3994 (tramp-send-command vec
"echo foo" t
)
3995 (with-current-buffer (process-buffer proc
)
3996 (goto-char (point-min))
3997 (when (looking-at "echo foo")
3998 (tramp-set-connection-property proc
"remote-echo" t
)
3999 (tramp-message vec
5 "Remote echo still on. Ok.")
4000 ;; Make sure backspaces and their echo are enabled and no line
4001 ;; width magic interferes with them.
4002 (tramp-send-command vec
"stty icanon erase ^H cols 32767" t
))))
4004 (tramp-message vec
5 "Setting shell prompt")
4006 vec
(format "PS1=%s PS2='' PS3='' PROMPT_COMMAND=''"
4007 (tramp-shell-quote-argument tramp-end-of-output
)) t
)
4009 ;; Try to set up the coding system correctly.
4010 ;; CCC this can't be the right way to do it. Hm.
4011 (tramp-message vec
5 "Determining coding system")
4012 (with-current-buffer (process-buffer proc
)
4013 (if (featurep 'mule
)
4014 ;; Use MULE to select the right EOL convention for communicating
4015 ;; with the process.
4016 (let ((cs (or (and (memq 'utf-8
(coding-system-list))
4017 (string-match "utf8" (tramp-get-remote-locale vec
))
4018 (cons 'utf-8
'utf-8
))
4019 (tramp-compat-funcall 'process-coding-system proc
)
4020 (cons 'undecided
'undecided
)))
4021 cs-decode cs-encode
)
4022 (when (symbolp cs
) (setq cs
(cons cs cs
)))
4023 (setq cs-decode
(car cs
))
4024 (setq cs-encode
(cdr cs
))
4025 (unless cs-decode
(setq cs-decode
'undecided
))
4026 (unless cs-encode
(setq cs-encode
'undecided
))
4027 (setq cs-encode
(tramp-compat-coding-system-change-eol-conversion
4029 (tramp-send-command vec
"echo foo ; echo bar" t
)
4030 (goto-char (point-min))
4031 (when (search-forward "\r" nil t
)
4032 (setq cs-decode
(tramp-compat-coding-system-change-eol-conversion
4034 (tramp-compat-funcall
4035 'set-buffer-process-coding-system cs-decode cs-encode
)
4037 vec
5 "Setting coding system to `%s' and `%s'" cs-decode cs-encode
))
4038 ;; Look for ^M and do something useful if found.
4039 (when (search-forward "\r" nil t
)
4040 ;; We have found a ^M but cannot frob the process coding system
4041 ;; because we're running on a non-MULE Emacs. Let's try
4043 (tramp-send-command vec
"stty -onlcr" t
))))
4045 (tramp-send-command vec
"set +o vi +o emacs" t
)
4047 ;; Check whether the output of "uname -sr" has been changed. If
4048 ;; yes, this is a strong indication that we must expire all
4049 ;; connection properties. We start again with
4050 ;; `tramp-maybe-open-connection', it will be caught there.
4051 (tramp-message vec
5 "Checking system information")
4052 (let ((old-uname (tramp-get-connection-property vec
"uname" nil
))
4054 (tramp-set-connection-property
4056 (tramp-send-command-and-read vec
"echo \\\"`uname -sr`\\\""))))
4057 (when (and (stringp old-uname
) (not (string-equal old-uname new-uname
)))
4060 "Connection reset, because remote host changed from `%s' to `%s'"
4061 old-uname new-uname
)
4062 ;; We want to keep the password.
4063 (tramp-cleanup-connection vec t t
)
4064 (throw 'uname-changed
(tramp-maybe-open-connection vec
))))
4066 ;; Check whether the remote host suffers from buggy
4067 ;; `send-process-string'. This is known for FreeBSD (see comment in
4068 ;; `send_process', file process.c). I've tested sending 624 bytes
4069 ;; successfully, sending 625 bytes failed. Emacs makes a hack when
4070 ;; this host type is detected locally. It cannot handle remote
4072 (with-tramp-connection-property proc
"chunksize"
4074 ((and (integerp tramp-chunksize
) (> tramp-chunksize
0))
4078 vec
5 "Checking remote host type for `send-process-string' bug")
4080 "^FreeBSD" (tramp-get-connection-property vec
"uname" ""))
4083 ;; Set remote PATH variable.
4084 (tramp-set-remote-path vec
)
4086 ;; Search for a good shell before searching for a command which
4087 ;; checks if a file exists. This is done because Tramp wants to use
4088 ;; "test foo; echo $?" to check if various conditions hold, and
4089 ;; there are buggy /bin/sh implementations which don't execute the
4090 ;; "echo $?" part if the "test" part has an error. In particular,
4091 ;; the OpenSolaris /bin/sh is a problem. There are also other
4092 ;; problems with /bin/sh of OpenSolaris, like redirection of stderr
4093 ;; in function declarations, or changing HISTFILE in place.
4094 ;; Therefore, OpenSolaris' /bin/sh is replaced by bash, when
4096 (tramp-find-shell vec
)
4098 ;; Disable unexpected output.
4099 (tramp-send-command vec
"mesg n; biff n" t
)
4101 ;; IRIX64 bash expands "!" even when in single quotes. This
4102 ;; destroys our shell functions, we must disable it. See
4103 ;; <http://stackoverflow.com/questions/3291692/irix-bash-shell-expands-expression-in-single-quotes-yet-shouldnt>.
4104 (when (string-match "^IRIX64" (tramp-get-connection-property vec
"uname" ""))
4105 (tramp-send-command vec
"set +H" t
))
4107 ;; On BSD-like systems, ?\t is expanded to spaces. Suppress this.
4108 (when (string-match "BSD\\|Darwin"
4109 (tramp-get-connection-property vec
"uname" ""))
4110 (tramp-send-command vec
"stty -oxtabs" t
))
4112 ;; Set `remote-tty' process property.
4113 (let ((tty (tramp-send-command-and-read vec
"echo \\\"`tty`\\\"" 'noerror
)))
4114 (unless (zerop (length tty
))
4115 (tramp-compat-process-put proc
'remote-tty tty
)))
4117 ;; Dump stty settings in the traces.
4118 (when (>= tramp-verbose
9)
4119 (tramp-send-command vec
"stty -a" t
))
4121 ;; Set the environment.
4122 (tramp-message vec
5 "Setting default environment")
4124 (let ((env (append `(,(tramp-get-remote-locale vec
))
4125 (copy-sequence tramp-remote-process-environment
)))
4128 (setq item
(tramp-compat-split-string (car env
) "="))
4129 (setcdr item
(mapconcat 'identity
(cdr item
) "="))
4130 (if (and (stringp (cdr item
)) (not (string-equal (cdr item
) "")))
4131 (push (format "%s %s" (car item
) (cdr item
)) vars
)
4132 (push (car item
) unset
))
4133 (setq env
(cdr env
)))
4137 (format "while read var val; do export $var=$val; done <<'%s'\n%s\n%s"
4138 tramp-end-of-heredoc
4139 (mapconcat 'identity vars
"\n")
4140 tramp-end-of-heredoc
)
4144 vec
(format "unset %s" (mapconcat 'identity unset
" ")) t
))))
4146 ;; Old text from documentation of tramp-methods:
4147 ;; Using a uuencode/uudecode inline method is discouraged, please use one
4148 ;; of the base64 methods instead since base64 encoding is much more
4149 ;; reliable and the commands are more standardized between the different
4150 ;; Unix versions. But if you can't use base64 for some reason, please
4151 ;; note that the default uudecode command does not work well for some
4152 ;; Unices, in particular AIX and Irix. For AIX, you might want to use
4153 ;; the following command for uudecode:
4155 ;; sed '/^begin/d;/^[` ]$/d;/^end/d' | iconv -f uucode -t ISO8859-1
4157 ;; For Irix, no solution is known yet.
4159 (autoload 'uudecode-decode-region
"uudecode")
4161 (defconst tramp-local-coding-commands
4162 `((b64 base64-encode-region base64-decode-region
)
4163 (uu tramp-uuencode-region uudecode-decode-region
)
4164 (pack ,(format tramp-perl-pack
"perl") ,(format tramp-perl-unpack
"perl")))
4165 "List of local coding commands for inline transfer.
4166 Each item is a list that looks like this:
4168 \(FORMAT ENCODING DECODING\)
4170 FORMAT is symbol describing the encoding/decoding format. It can be
4171 `b64' for base64 encoding, `uu' for uu encoding, or `pack' for simple packing.
4173 ENCODING and DECODING can be strings, giving commands, or symbols,
4174 giving functions. If they are strings, then they can contain
4175 the \"%s\" format specifier. If that specifier is present, the input
4176 file name will be put into the command line at that spot. If the
4177 specifier is not present, the input should be read from standard
4180 If they are functions, they will be called with two arguments, start
4181 and end of region, and are expected to replace the region contents
4182 with the encoded or decoded results, respectively.")
4184 (defconst tramp-remote-coding-commands
4185 '((b64 "base64" "base64 -d -i")
4186 ;; "-i" is more robust with older base64 from GNU coreutils.
4187 ;; However, I don't know whether all base64 versions do supports
4189 (b64 "base64" "base64 -d")
4190 (b64 "mimencode -b" "mimencode -u -b")
4191 (b64 "mmencode -b" "mmencode -u -b")
4192 (b64 "recode data..base64" "recode base64..data")
4193 (b64 tramp-perl-encode-with-module tramp-perl-decode-with-module
)
4194 (b64 tramp-perl-encode tramp-perl-decode
)
4195 (uu "uuencode xxx" "uudecode -o /dev/stdout" "test -c /dev/stdout")
4196 (uu "uuencode xxx" "uudecode -o -")
4197 (uu "uuencode xxx" "uudecode -p")
4198 (uu "uuencode xxx" tramp-uudecode
)
4199 (pack tramp-perl-pack tramp-perl-unpack
))
4200 "List of remote coding commands for inline transfer.
4201 Each item is a list that looks like this:
4203 \(FORMAT ENCODING DECODING [TEST]\)
4205 FORMAT is a symbol describing the encoding/decoding format. It can be
4206 `b64' for base64 encoding, `uu' for uu encoding, or `pack' for simple packing.
4208 ENCODING and DECODING can be strings, giving commands, or symbols,
4209 giving variables. If they are strings, then they can contain
4210 the \"%s\" format specifier. If that specifier is present, the input
4211 file name will be put into the command line at that spot. If the
4212 specifier is not present, the input should be read from standard
4215 If they are variables, this variable is a string containing a
4216 Perl or Shell implementation for this functionality. This
4217 program will be transferred to the remote host, and it is
4218 available as shell function with the same name. A \"%t\" format
4219 specifier in the variable value denotes a temporary file.
4221 The optional TEST command can be used for further tests, whether
4222 ENCODING and DECODING are applicable.")
4224 (defun tramp-find-inline-encoding (vec)
4225 "Find an inline transfer encoding that works.
4226 Goes through the list `tramp-local-coding-commands' and
4227 `tramp-remote-coding-commands'."
4229 (let ((local-commands tramp-local-coding-commands
)
4231 (p (tramp-get-connection-process vec
))
4232 loc-enc loc-dec rem-enc rem-dec rem-test litem ritem found
)
4233 (while (and local-commands
(not found
))
4234 (setq litem
(pop local-commands
))
4235 (catch 'wont-work-local
4236 (let ((format (nth 0 litem
))
4237 (remote-commands tramp-remote-coding-commands
))
4238 (setq loc-enc
(nth 1 litem
))
4239 (setq loc-dec
(nth 2 litem
))
4240 ;; If the local encoder or decoder is a string, the
4241 ;; corresponding command has to work locally.
4242 (if (not (stringp loc-enc
))
4244 vec
5 "Checking local encoding function `%s'" loc-enc
)
4246 vec
5 "Checking local encoding command `%s' for sanity" loc-enc
)
4247 (unless (zerop (tramp-call-local-coding-command
4249 (throw 'wont-work-local nil
)))
4250 (if (not (stringp loc-dec
))
4252 vec
5 "Checking local decoding function `%s'" loc-dec
)
4254 vec
5 "Checking local decoding command `%s' for sanity" loc-dec
)
4255 (unless (zerop (tramp-call-local-coding-command
4257 (throw 'wont-work-local nil
)))
4258 ;; Search for remote coding commands with the same format
4259 (while (and remote-commands
(not found
))
4260 (setq ritem
(pop remote-commands
))
4261 (catch 'wont-work-remote
4262 (when (equal format
(nth 0 ritem
))
4263 (setq rem-enc
(nth 1 ritem
))
4264 (setq rem-dec
(nth 2 ritem
))
4265 (setq rem-test
(nth 3 ritem
))
4266 ;; Check the remote test command if exists.
4267 (when (stringp rem-test
)
4269 vec
5 "Checking remote test command `%s'" rem-test
)
4270 (unless (tramp-send-command-and-check vec rem-test t
)
4271 (throw 'wont-work-remote nil
)))
4272 ;; Check if remote perl exists when necessary.
4273 (when (and (not (stringp rem-enc
))
4274 (not (tramp-get-remote-perl vec
)))
4275 (throw 'wont-work-remote nil
))
4276 ;; Check if remote encoding and decoding commands can be
4277 ;; called remotely with null input and output. This makes
4278 ;; sure there are no syntax errors and the command is really
4279 ;; found. Note that we do not redirect stdout to /dev/null,
4280 ;; for two reasons: when checking the decoding command, we
4281 ;; actually check the output it gives. And also, when
4282 ;; redirecting "mimencode" output to /dev/null, then as root
4283 ;; it might change the permissions of /dev/null!
4284 (when (not (stringp rem-enc
))
4285 (let ((name (symbol-name rem-enc
)))
4286 (while (string-match (regexp-quote "-") name
)
4287 (setq name
(replace-match "_" nil t name
)))
4288 (tramp-maybe-send-script vec
(symbol-value rem-enc
) name
)
4289 (setq rem-enc name
)))
4292 "Checking remote encoding command `%s' for sanity" rem-enc
)
4293 (unless (tramp-send-command-and-check
4294 vec
(format "%s </dev/null" rem-enc
) t
)
4295 (throw 'wont-work-remote nil
))
4297 (when (not (stringp rem-dec
))
4298 (let ((name (symbol-name rem-dec
))
4299 (value (symbol-value rem-dec
))
4301 (while (string-match (regexp-quote "-") name
)
4302 (setq name
(replace-match "_" nil t name
)))
4303 (when (string-match "\\(^\\|[^%]\\)%t" value
)
4307 tramp-temp-name-prefix
4308 (tramp-get-remote-tmpdir vec
)))
4314 (tramp-file-name-handler
4315 'file-remote-p tmpfile
'localname
)))))
4316 (tramp-maybe-send-script vec value name
)
4317 (setq rem-dec name
)))
4320 "Checking remote decoding command `%s' for sanity" rem-dec
)
4321 (unless (tramp-send-command-and-check
4323 (format "echo %s | %s | %s" magic rem-enc rem-dec
)
4325 (throw 'wont-work-remote nil
))
4327 (with-current-buffer (tramp-get-buffer vec
)
4328 (goto-char (point-min))
4329 (unless (looking-at (regexp-quote magic
))
4330 (throw 'wont-work-remote nil
)))
4332 ;; `rem-enc' and `rem-dec' could be a string meanwhile.
4333 (setq rem-enc
(nth 1 ritem
))
4334 (setq rem-dec
(nth 2 ritem
))
4335 (setq found t
)))))))
4338 ;; Set connection properties. Since the commands are risky
4339 ;; (due to output direction), we cache them in the process cache.
4340 (tramp-message vec
5 "Using local encoding `%s'" loc-enc
)
4341 (tramp-set-connection-property p
"local-encoding" loc-enc
)
4342 (tramp-message vec
5 "Using local decoding `%s'" loc-dec
)
4343 (tramp-set-connection-property p
"local-decoding" loc-dec
)
4344 (tramp-message vec
5 "Using remote encoding `%s'" rem-enc
)
4345 (tramp-set-connection-property p
"remote-encoding" rem-enc
)
4346 (tramp-message vec
5 "Using remote decoding `%s'" rem-dec
)
4347 (tramp-set-connection-property p
"remote-decoding" rem-dec
)))))
4349 (defun tramp-call-local-coding-command (cmd input output
)
4350 "Call the local encoding or decoding command.
4351 If CMD contains \"%s\", provide input file INPUT there in command.
4352 Otherwise, INPUT is passed via standard input.
4353 INPUT can also be nil which means `/dev/null'.
4354 OUTPUT can be a string (which specifies a file name), or t (which
4355 means standard output and thus the current buffer), or nil (which
4358 nil tramp-encoding-shell
4359 (when (and input
(not (string-match "%s" cmd
))) input
)
4360 (if (eq output t
) t nil
)
4362 tramp-encoding-command-switch
4364 (if (string-match "%s" cmd
) (format cmd input
) cmd
)
4365 (if (stringp output
) (concat " >" output
) ""))))
4367 (defconst tramp-inline-compress-commands
4368 '(("gzip" "gzip -d")
4369 ("bzip2" "bzip2 -d")
4371 ("compress" "compress -d"))
4372 "List of compress and decompress commands for inline transfer.
4373 Each item is a list that looks like this:
4375 \(COMPRESS DECOMPRESS\)
4377 COMPRESS or DECOMPRESS are strings with the respective commands.")
4379 (defun tramp-find-inline-compress (vec)
4380 "Find an inline transfer compress command that works.
4381 Goes through the list `tramp-inline-compress-commands'."
4383 (let ((commands tramp-inline-compress-commands
)
4385 (p (tramp-get-connection-process vec
))
4386 item compress decompress found
)
4387 (while (and commands
(not found
))
4389 (setq item
(pop commands
)
4390 compress
(nth 0 item
)
4391 decompress
(nth 1 item
))
4394 "Checking local compress commands `%s', `%s' for sanity"
4395 compress decompress
)
4398 (tramp-call-local-coding-command
4400 ;; Windows shells need the program file name after
4401 ;; the pipe symbol be quoted if they use forward
4402 ;; slashes as directory separators.
4403 (if (memq system-type
'(windows-nt))
4404 "echo %s | \"%s\" | \"%s\""
4405 "echo %s | %s | %s")
4406 magic compress decompress
) nil nil
))
4410 "Checking remote compress commands `%s', `%s' for sanity"
4411 compress decompress
)
4412 (unless (tramp-send-command-and-check
4413 vec
(format "echo %s | %s | %s" magic compress decompress
) t
)
4417 ;; Did we find something?
4420 ;; Set connection properties. Since the commands are
4421 ;; risky (due to output direction), we cache them in the
4424 vec
5 "Using inline transfer compress command `%s'" compress
)
4425 (tramp-set-connection-property p
"inline-compress" compress
)
4427 vec
5 "Using inline transfer decompress command `%s'" decompress
)
4428 (tramp-set-connection-property p
"inline-decompress" decompress
))
4430 (tramp-set-connection-property p
"inline-compress" nil
)
4431 (tramp-set-connection-property p
"inline-decompress" nil
)
4433 vec
2 "Couldn't find an inline transfer compress command")))))
4435 (defun tramp-compute-multi-hops (vec)
4436 "Expands VEC according to `tramp-default-proxies-alist'.
4437 Gateway hops are already opened."
4438 (let ((target-alist `(,vec
))
4439 (hops (or (tramp-file-name-hop vec
) ""))
4443 ;; Ad-hoc proxy definitions.
4444 (dolist (proxy (reverse (split-string hops tramp-postfix-hop-regexp
'omit
)))
4445 (let ((user (tramp-file-name-user item
))
4446 (host (tramp-file-name-host item
))
4448 tramp-prefix-format proxy tramp-postfix-host-format
)))
4450 vec
5 "Add proxy (\"%s\" \"%s\" \"%s\")"
4451 (and (stringp host
) (regexp-quote host
))
4452 (and (stringp user
) (regexp-quote user
))
4456 'tramp-default-proxies-alist
4457 (list (and (stringp host
) (regexp-quote host
))
4458 (and (stringp user
) (regexp-quote user
))
4460 (setq item
(tramp-dissect-file-name proxy
))))
4461 ;; Save the new value.
4462 (when (and hops tramp-save-ad-hoc-proxies
)
4463 (customize-save-variable
4464 'tramp-default-proxies-alist tramp-default-proxies-alist
))
4466 ;; Look for proxy hosts to be passed.
4467 (setq choices tramp-default-proxies-alist
)
4469 (setq item
(pop choices
)
4470 proxy
(eval (nth 2 item
)))
4473 (string-match (or (eval (nth 0 item
)) "")
4474 (or (tramp-file-name-host (car target-alist
)) ""))
4476 (string-match (or (eval (nth 1 item
)) "")
4477 (or (tramp-file-name-user (car target-alist
)) "")))
4479 ;; No more hops needed.
4481 ;; Replace placeholders.
4486 ?u
(or (tramp-file-name-user (car target-alist
)) "")
4487 ?h
(or (tramp-file-name-host (car target-alist
)) ""))))
4488 (with-parsed-tramp-file-name proxy l
4490 (push l target-alist
)
4491 ;; Start next search.
4492 (setq choices tramp-default-proxies-alist
)))))
4495 (when (and (boundp 'tramp-gw-tunnel-method
) (boundp 'tramp-gw-socks-method
)
4498 "^\\(%s\\|%s\\)$" tramp-gw-tunnel-method tramp-gw-socks-method
)
4499 (tramp-file-name-method (car target-alist
))))
4500 (let ((gw (pop target-alist
))
4501 (hop (pop target-alist
)))
4502 ;; Is the method prepared for gateways?
4503 (unless (tramp-file-name-port hop
)
4506 "Connection `%s' is not supported for gateway access." hop
))
4507 ;; Open the gateway connection.
4510 (tramp-file-name-method hop
) (tramp-file-name-user hop
)
4511 (tramp-compat-funcall 'tramp-gw-open-connection vec gw hop
) nil nil
)
4513 ;; For the password prompt, we need the correct values.
4514 ;; Therefore, we must remember the gateway vector. But we
4515 ;; cannot do it as connection property, because it shouldn't
4516 ;; be persistent. And we have no started process yet either.
4517 (let ((tramp-verbose 0))
4518 (tramp-set-file-property (car target-alist
) "" "gateway" hop
))))
4520 ;; Foreign and out-of-band methods are not supported for multi-hops.
4521 (when (cdr target-alist
)
4522 (setq choices target-alist
)
4524 (setq item
(pop choices
))
4528 (tramp-get-method-parameter
4529 (tramp-file-name-method item
) 'tramp-login-program
))
4530 (tramp-get-method-parameter
4531 (tramp-file-name-method item
) 'tramp-copy-program
))
4534 "Method `%s' is not supported for multi-hops."
4535 (tramp-file-name-method item
)))))
4537 ;; In case the host name is not used for the remote shell
4538 ;; command, the user could be misguided by applying a random
4540 (let* ((v (car target-alist
))
4541 (method (tramp-file-name-method v
))
4542 (host (tramp-file-name-host v
)))
4545 ;; There are multi-hops.
4547 ;; The host name is used for the remote shell command.
4549 '("%h") (tramp-get-method-parameter method
'tramp-login-args
))
4550 ;; The host is local. We cannot use `tramp-local-host-p'
4551 ;; here, because it opens a connection as well.
4552 (string-match tramp-local-host-regexp host
))
4555 "Host `%s' looks like a remote host, `%s' can only use the local host"
4561 (defun tramp-maybe-open-connection (vec)
4562 "Maybe open a connection VEC.
4563 Does not do anything if a connection is already open, but re-opens the
4564 connection if a previous connection has died for some reason."
4565 (tramp-check-proper-method-and-host vec
)
4567 (let ((p (tramp-get-connection-process vec
))
4568 (process-name (tramp-get-connection-property vec
"process-name" nil
))
4569 (process-environment (copy-sequence process-environment
))
4570 (pos (with-current-buffer (tramp-get-connection-buffer vec
) (point))))
4572 ;; If Tramp opens the same connection within a short time frame,
4573 ;; there is a problem. We shall signal this.
4574 (unless (or (and p
(processp p
) (memq (process-status p
) '(run open
)))
4575 (not (equal (butlast (append vec nil
) 2)
4576 (car tramp-current-connection
)))
4578 (current-time) (cdr tramp-current-connection
))
4579 (or tramp-connection-min-time-diff
0)))
4580 (throw 'suppress
'suppress
))
4582 ;; If too much time has passed since last command was sent, look
4583 ;; whether process is still alive. If it isn't, kill it. When
4584 ;; using ssh, it can sometimes happen that the remote end has hung
4585 ;; up but the local ssh client doesn't recognize this until it
4586 ;; tries to send some data to the remote end. So that's why we
4587 ;; try to send a command from time to time, then look again
4588 ;; whether the process is really alive.
4590 (when (and (> (tramp-time-diff
4592 (tramp-get-connection-property
4593 p
"last-cmd-time" '(0 0 0)))
4595 p
(processp p
) (memq (process-status p
) '(run open
)))
4596 (tramp-send-command vec
"echo are you awake" t t
)
4597 (unless (and (memq (process-status p
) '(run open
))
4598 (tramp-wait-for-output p
10))
4599 ;; The error will be caught locally.
4600 (tramp-error vec
'file-error
"Awake did fail")))
4602 (tramp-cleanup-connection vec t
)
4605 ;; New connection must be opened.
4607 (unless (and p
(processp p
) (memq (process-status p
) '(run open
)))
4609 ;; If `non-essential' is non-nil, don't reopen a new connection.
4610 (when (and (boundp 'non-essential
) (symbol-value 'non-essential
))
4611 (throw 'non-essential
'non-essential
))
4613 (with-tramp-progress-reporter
4615 (if (zerop (length (tramp-file-name-user vec
)))
4616 (format "Opening connection for %s using %s"
4617 (tramp-file-name-host vec
)
4618 (tramp-file-name-method vec
))
4619 (format "Opening connection for %s@%s using %s"
4620 (tramp-file-name-user vec
)
4621 (tramp-file-name-host vec
)
4622 (tramp-file-name-method vec
)))
4624 (catch 'uname-changed
4625 ;; Start new process.
4626 (when (and p
(processp p
))
4628 (setenv "TERM" tramp-terminal-type
)
4629 (setenv "LC_ALL" "en_US.utf8")
4630 (when tramp-histfile-override
4631 (setenv "HISTFILE" tramp-histfile-override
))
4632 (setenv "PROMPT_COMMAND")
4633 (setenv "PS1" tramp-initial-end-of-output
)
4634 (let* ((target-alist (tramp-compute-multi-hops vec
))
4635 ;; We will apply `tramp-ssh-controlmaster-options'
4636 ;; only for the first hop.
4637 (options (if tramp-use-ssh-controlmaster-options
4638 tramp-ssh-controlmaster-options
""))
4639 (process-connection-type tramp-process-connection-type
)
4640 (process-adaptive-read-buffering nil
)
4641 (coding-system-for-read nil
)
4642 ;; This must be done in order to avoid our file
4644 (p (let ((default-directory
4645 (tramp-compat-temporary-file-directory)))
4648 (tramp-get-connection-name vec
)
4649 (tramp-get-connection-buffer vec
)
4650 (if tramp-encoding-command-interactive
4651 (list tramp-encoding-shell
4652 tramp-encoding-command-interactive
)
4653 (list tramp-encoding-shell
))))))
4655 ;; Set sentinel and query flag.
4656 (tramp-set-connection-property p
"vector" vec
)
4657 (set-process-sentinel p
'tramp-process-sentinel
)
4658 (tramp-compat-set-process-query-on-exit-flag p nil
)
4659 (setq tramp-current-connection
4660 (cons (butlast (append vec nil
) 2) (current-time))
4661 tramp-current-host
(system-name))
4664 vec
6 "%s" (mapconcat 'identity
(process-command p
) " "))
4666 ;; Check whether process is alive.
4667 (tramp-barf-if-no-shell-prompt
4669 "Couldn't find local shell prompt for %s" tramp-encoding-shell
)
4671 ;; Now do all the connections as specified.
4673 (let* ((hop (car target-alist
))
4674 (l-method (tramp-file-name-method hop
))
4675 (l-user (tramp-file-name-user hop
))
4676 (l-host (tramp-file-name-host hop
))
4679 (tramp-get-method-parameter
4680 l-method
'tramp-login-program
))
4682 (tramp-get-method-parameter
4683 l-method
'tramp-login-args
))
4685 (tramp-get-method-parameter
4686 l-method
'tramp-login-env
))
4688 (tramp-get-method-parameter
4689 l-method
'tramp-async-args
))
4691 (tramp-get-method-parameter
4692 l-method
'tramp-connection-timeout
))
4694 (tramp-get-method-parameter l-method
'tramp-gw-args
))
4695 (gw (let ((tramp-verbose 0))
4696 (tramp-get-file-property hop
"" "gateway" nil
)))
4697 (g-method (and gw
(tramp-file-name-method gw
)))
4698 (g-user (and gw
(tramp-file-name-user gw
)))
4699 (g-host (and gw
(tramp-file-name-real-host gw
)))
4700 (command login-program
)
4701 ;; We don't create the temporary file. In
4702 ;; fact, it is just a prefix for the
4703 ;; ControlPath option of ssh; the real
4704 ;; temporary file has another name, and it is
4705 ;; created and protected by ssh. It is also
4706 ;; removed by ssh when the connection is
4707 ;; closed. The temporary file name is cached
4708 ;; in the main connection process, therefore
4709 ;; we cannot use `tramp-get-connection-process'.
4711 (with-tramp-connection-property
4712 (get-process (tramp-buffer-name vec
)) "temp-file"
4715 tramp-temp-name-prefix
4716 (tramp-compat-temporary-file-directory)))))
4719 ;; Add arguments for asynchronous processes.
4720 (when (and process-name async-args
)
4721 (setq login-args
(append async-args login-args
)))
4723 ;; Add gateway arguments if necessary.
4725 (tramp-set-connection-property p
"gateway" t
)
4727 (setq login-args
(append gw-args login-args
))))
4729 ;; Check for port number. Until now, there's no
4730 ;; need for handling like method, user, host.
4731 (when (string-match tramp-host-with-port-regexp l-host
)
4732 (setq l-port
(match-string 2 l-host
)
4733 l-host
(match-string 1 l-host
)))
4735 ;; Check, whether there is a restricted shell.
4736 (dolist (elt tramp-restricted-shell-hosts-alist
)
4737 (when (string-match elt tramp-current-host
)
4740 ;; Set variables for computing the prompt for
4741 ;; reading password. They can also be derived
4743 (setq tramp-current-method
(or g-method l-method
)
4744 tramp-current-user
(or g-user l-user
)
4745 tramp-current-host
(or g-host l-host
))
4747 ;; Add login environment.
4753 (setq x
(mapcar (lambda (y) (format-spec y spec
)) x
))
4754 (unless (member "" x
) (mapconcat 'identity x
" ")))
4761 (tramp-shell-quote-argument (pop login-env
))
4763 (setq command
(concat "env " command
)))
4765 ;; Replace `login-args' place holders.
4767 l-host
(or l-host
"")
4768 l-user
(or l-user
"")
4769 l-port
(or l-port
"")
4770 spec
(format-spec-make ?t tmpfile
)
4771 options
(format-spec options spec
)
4772 spec
(format-spec-make
4773 ?h l-host ?u l-user ?p l-port ?c options
)
4776 ;; We do not want to see the trailing local
4777 ;; prompt in `start-file-process'.
4778 (unless r-shell
"exec ")
4782 (setq x
(mapcar (lambda (y) (format-spec y spec
)) x
))
4783 (unless (member "" x
) (mapconcat 'identity x
" ")))
4785 ;; Local shell could be a Windows COMSPEC. It
4786 ;; doesn't know the ";" syntax, but we must exit
4787 ;; always for `start-file-process'. It could
4788 ;; also be a restricted shell, which does not
4790 (when r-shell
" && exit || exit")))
4792 ;; Send the command.
4793 (tramp-message vec
3 "Sending command `%s'" command
)
4794 (tramp-send-command vec command t t
)
4795 (tramp-process-actions
4796 p vec pos tramp-actions-before-shell
4797 (or connection-timeout tramp-connection-timeout
))
4799 vec
3 "Found remote shell prompt on `%s'" l-host
))
4802 target-alist
(cdr target-alist
)))
4804 ;; Make initial shell settings.
4805 (tramp-open-connection-setup-interactive-shell p vec
)))))
4807 ;; When the user did interrupt, we must cleanup.
4809 (tramp-cleanup-connection vec t
)
4810 ;; Propagate the quit signal.
4811 (signal (car err
) (cdr err
))))))
4813 (defun tramp-send-command (vec command
&optional neveropen nooutput
)
4814 "Send the COMMAND to connection VEC.
4815 Erases temporary buffer before sending the command. If optional
4816 arg NEVEROPEN is non-nil, never try to open the connection. This
4817 is meant to be used from `tramp-maybe-open-connection' only. The
4818 function waits for output unless NOOUTPUT is set."
4819 (unless neveropen
(tramp-maybe-open-connection vec
))
4820 (let ((p (tramp-get-connection-process vec
)))
4821 (when (tramp-get-connection-property p
"remote-echo" nil
)
4822 ;; We mark the command string that it can be erased in the output buffer.
4823 (tramp-set-connection-property p
"check-remote-echo" t
)
4824 ;; If we put `tramp-echo-mark' after a trailing newline (which
4825 ;; is assumed to be unquoted) `tramp-send-string' doesn't see
4826 ;; that newline and adds `tramp-rsh-end-of-line' right after
4827 ;; `tramp-echo-mark', so the remote shell sees two consecutive
4828 ;; trailing line endings and sends two prompts after executing
4829 ;; the command, which confuses `tramp-wait-for-output'.
4830 (when (and (not (string= command
""))
4831 (string-equal (substring command -
1) "\n"))
4832 (setq command
(substring command
0 -
1)))
4833 ;; No need to restore a trailing newline here since `tramp-send-string'
4834 ;; makes sure that the string ends in `tramp-rsh-end-of-line', anyway.
4835 (setq command
(format "%s%s%s" tramp-echo-mark command tramp-echo-mark
)))
4836 ;; Send the command.
4837 (tramp-message vec
6 "%s" command
)
4838 (tramp-send-string vec command
)
4839 (unless nooutput
(tramp-wait-for-output p
))))
4841 (defun tramp-wait-for-output (proc &optional timeout
)
4842 "Wait for output from remote command."
4843 (unless (buffer-live-p (process-buffer proc
))
4844 (delete-process proc
)
4845 (tramp-error proc
'file-error
"Process `%s' not available, try again" proc
))
4846 (with-current-buffer (process-buffer proc
)
4847 (let* (;; Initially, `tramp-end-of-output' is "#$ ". There might
4848 ;; be leading escape sequences, which must be ignored.
4849 (regexp (format "[^#$\n]*%s\r?$" (regexp-quote tramp-end-of-output
)))
4850 ;; Sometimes, the commands do not return a newline but a
4851 ;; null byte before the shell prompt, for example "git
4852 ;; ls-files -c -z ...".
4853 (regexp1 (format "\\(^\\|\000\\)%s" regexp
))
4854 (found (tramp-wait-for-regexp proc timeout regexp1
)))
4856 (let (buffer-read-only)
4857 ;; A simple-minded busybox has sent " ^H" sequences.
4859 (goto-char (point-min))
4860 (when (re-search-forward "^\\(.\b\\)+$" (point-at-eol) t
)
4862 (delete-region (point-min) (point)))
4863 ;; Delete the prompt.
4864 (goto-char (point-max))
4865 (re-search-backward regexp nil t
)
4866 (delete-region (point) (point-max)))
4870 "[[Remote prompt `%s' not found in %d secs]]"
4871 tramp-end-of-output timeout
)
4874 "[[Remote prompt `%s' not found]]" tramp-end-of-output
)))
4875 ;; Return value is whether end-of-output sentinel was found.
4878 (defun tramp-send-command-and-check
4879 (vec command
&optional subshell dont-suppress-err
)
4880 "Run COMMAND and check its exit status.
4881 Sends `echo $?' along with the COMMAND for checking the exit status.
4882 If COMMAND is nil, just sends `echo $?'. Returns `t' if the exit
4883 status is 0, and `nil' otherwise.
4885 If the optional argument SUBSHELL is non-nil, the command is
4886 executed in a subshell, ie surrounded by parentheses. If
4887 DONT-SUPPRESS-ERR is non-nil, stderr won't be sent to /dev/null."
4890 (concat (if subshell
"( " "")
4892 (if command
(if dont-suppress-err
"; " " 2>/dev/null; ") "")
4893 "echo tramp_exit_status $?"
4894 (if subshell
" )" "")))
4895 (with-current-buffer (tramp-get-connection-buffer vec
)
4896 (goto-char (point-max))
4897 (unless (re-search-backward "tramp_exit_status [0-9]+" nil t
)
4899 vec
'file-error
"Couldn't find exit status of `%s'" command
))
4900 (skip-chars-forward "^ ")
4902 (zerop (read (current-buffer)))
4903 (let (buffer-read-only)
4904 (delete-region (match-beginning 0) (point-max))))))
4906 (defun tramp-barf-unless-okay (vec command fmt
&rest args
)
4907 "Run COMMAND, check exit status, throw error if exit status not okay.
4908 Similar to `tramp-send-command-and-check' but accepts two more arguments
4909 FMT and ARGS which are passed to `error'."
4910 (or (tramp-send-command-and-check vec command
)
4911 (apply 'tramp-error vec
'file-error fmt args
)))
4913 (defun tramp-send-command-and-read (vec command
&optional noerror marker
)
4914 "Run COMMAND and return the output, which must be a Lisp expression.
4915 If MARKER is a regexp, read the output after that string.
4916 In case there is no valid Lisp expression and NOERROR is nil, it
4919 (tramp-send-command-and-check vec command
)
4920 (tramp-barf-unless-okay
4921 vec command
"`%s' returns with error" command
))
4922 (with-current-buffer (tramp-get-connection-buffer vec
)
4923 (goto-char (point-min))
4925 (when (stringp marker
)
4927 (re-search-forward marker
)
4928 (error (unless noerror
4931 "`%s' does not return the marker `%s': `%s'"
4932 command marker
(buffer-string))))))
4933 ;; Read the expression.
4935 (prog1 (read (current-buffer))
4937 (when (re-search-forward "\\S-" (point-at-eol) t
)
4939 (error (unless noerror
4942 "`%s' does not return a valid Lisp expression: `%s'"
4943 command
(buffer-string))))))))
4945 (defun tramp-convert-file-attributes (vec attr
)
4946 "Convert `file-attributes' ATTR generated by perl script, stat or ls.
4947 Convert file mode bits to string and set virtual device number.
4950 ;; Remove color escape sequences from symlink.
4951 (when (stringp (car attr
))
4952 (while (string-match tramp-color-escape-sequence-regexp
(car attr
))
4953 (setcar attr
(replace-match "" nil nil
(car attr
)))))
4954 ;; Convert uid and gid. Use -1 as indication of unusable value.
4955 (when (and (numberp (nth 2 attr
)) (< (nth 2 attr
) 0))
4956 (setcar (nthcdr 2 attr
) -
1))
4957 (when (and (floatp (nth 2 attr
))
4958 (<= (nth 2 attr
) (tramp-compat-most-positive-fixnum)))
4959 (setcar (nthcdr 2 attr
) (round (nth 2 attr
))))
4960 (when (and (numberp (nth 3 attr
)) (< (nth 3 attr
) 0))
4961 (setcar (nthcdr 3 attr
) -
1))
4962 (when (and (floatp (nth 3 attr
))
4963 (<= (nth 3 attr
) (tramp-compat-most-positive-fixnum)))
4964 (setcar (nthcdr 3 attr
) (round (nth 3 attr
))))
4965 ;; Convert last access time.
4966 (unless (listp (nth 4 attr
))
4967 (setcar (nthcdr 4 attr
)
4968 (list (floor (nth 4 attr
) 65536)
4969 (floor (mod (nth 4 attr
) 65536)))))
4970 ;; Convert last modification time.
4971 (unless (listp (nth 5 attr
))
4972 (setcar (nthcdr 5 attr
)
4973 (list (floor (nth 5 attr
) 65536)
4974 (floor (mod (nth 5 attr
) 65536)))))
4975 ;; Convert last status change time.
4976 (unless (listp (nth 6 attr
))
4977 (setcar (nthcdr 6 attr
)
4978 (list (floor (nth 6 attr
) 65536)
4979 (floor (mod (nth 6 attr
) 65536)))))
4980 ;; Convert file size.
4981 (when (< (nth 7 attr
) 0)
4982 (setcar (nthcdr 7 attr
) -
1))
4983 (when (and (floatp (nth 7 attr
))
4984 (<= (nth 7 attr
) (tramp-compat-most-positive-fixnum)))
4985 (setcar (nthcdr 7 attr
) (round (nth 7 attr
))))
4986 ;; Convert file mode bits to string.
4987 (unless (stringp (nth 8 attr
))
4988 (setcar (nthcdr 8 attr
) (tramp-file-mode-from-int (nth 8 attr
)))
4989 (when (stringp (car attr
))
4990 (aset (nth 8 attr
) 0 ?l
)))
4991 ;; Convert directory indication bit.
4992 (when (string-match "^d" (nth 8 attr
))
4994 ;; Convert symlink from `tramp-do-file-attributes-with-stat'.
4995 (when (consp (car attr
))
4996 (if (and (stringp (caar attr
))
4997 (string-match ".+ -> .\\(.+\\)." (caar attr
)))
4998 (setcar attr
(match-string 1 (caar attr
)))
5000 ;; Set file's gid change bit.
5001 (setcar (nthcdr 9 attr
)
5002 (if (numberp (nth 3 attr
))
5003 (not (= (nth 3 attr
)
5004 (tramp-get-remote-gid vec
'integer
)))
5007 (tramp-get-remote-gid vec
'string
)))))
5009 (unless (listp (nth 10 attr
))
5010 (setcar (nthcdr 10 attr
)
5012 (cons (floor (nth 10 attr
) 65536)
5013 (floor (mod (nth 10 attr
) 65536)))
5014 ;; Inodes can be incredible huge. We must hide this.
5015 (error (tramp-get-inode vec
)))))
5016 ;; Set virtual device number.
5017 (setcar (nthcdr 11 attr
)
5018 (tramp-get-device vec
))
5021 (defun tramp-shell-case-fold (string)
5022 "Converts STRING to shell glob pattern which ignores case."
5025 (if (equal (downcase c
) (upcase c
))
5027 (format "[%c%c]" (downcase c
) (upcase c
))))
5031 (defun tramp-make-copy-program-file-name (vec)
5032 "Create a file name suitable to be passed to `scp' or `nc' and workalikes."
5033 (let ((method (tramp-file-name-method vec
))
5034 (user (tramp-file-name-user vec
))
5035 (host (tramp-file-name-real-host vec
))
5036 (localname (tramp-shell-quote-argument
5037 (tramp-file-name-localname vec
))))
5039 ((tramp-get-method-parameter method
'tramp-remote-copy-program
)
5041 ((not (zerop (length user
)))
5042 (shell-quote-argument (format "%s@%s:%s" user host localname
)))
5043 (t (shell-quote-argument (format "%s:%s" host localname
))))))
5045 (defun tramp-method-out-of-band-p (vec size
)
5046 "Return t if this is an out-of-band method, nil otherwise."
5048 ;; It shall be an out-of-band method.
5049 (tramp-get-method-parameter (tramp-file-name-method vec
) 'tramp-copy-program
)
5050 ;; There must be a size, otherwise the file doesn't exist.
5052 ;; Either the file size is large enough, or (in rare cases) there
5053 ;; does not exist a remote encoding.
5054 (or (null tramp-copy-size-limit
)
5055 (> size tramp-copy-size-limit
)
5056 (null (tramp-get-inline-coding vec
"remote-encoding" size
)))))
5058 ;; Variables local to connection.
5060 (defun tramp-get-remote-path (vec)
5061 (with-tramp-connection-property
5062 ;; When `tramp-own-remote-path' is in `tramp-remote-path', we
5063 ;; cache the result for the session only. Otherwise, the result
5064 ;; is cached persistently.
5065 (if (memq 'tramp-own-remote-path tramp-remote-path
)
5066 (tramp-get-connection-process vec
)
5069 (let* ((remote-path (copy-tree tramp-remote-path
))
5070 (elt1 (memq 'tramp-default-remote-path remote-path
))
5071 (elt2 (memq 'tramp-own-remote-path remote-path
))
5072 (default-remote-path
5075 (tramp-send-command-and-read
5076 vec
"echo \\\"`getconf PATH 2>/dev/null`\\\"" 'noerror
)
5077 ;; Default if "getconf" is not available.
5081 "`getconf PATH' not successful, using default value \"%s\"."
5085 ;; The login shell could return more than just the $PATH
5086 ;; string. So we use `tramp-end-of-heredoc' as marker.
5088 (tramp-send-command-and-read
5091 "%s -l %s 'echo %s \\\"$PATH\\\"'"
5092 (tramp-get-method-parameter
5093 (tramp-file-name-method vec
) 'tramp-remote-shell
)
5096 (tramp-get-method-parameter
5097 (tramp-file-name-method vec
) 'tramp-remote-shell-args
)
5099 (tramp-shell-quote-argument tramp-end-of-heredoc
))
5100 nil
(regexp-quote tramp-end-of-heredoc
)))))
5102 ;; Replace place holder `tramp-default-remote-path'.
5106 (tramp-compat-split-string (or default-remote-path
"") ":")
5108 (setq remote-path
(delq 'tramp-default-remote-path remote-path
)))
5110 ;; Replace place holder `tramp-own-remote-path'.
5114 (tramp-compat-split-string (or own-remote-path
"") ":")
5116 (setq remote-path
(delq 'tramp-own-remote-path remote-path
)))
5118 ;; Remove double entries.
5119 (setq elt1 remote-path
)
5121 (while (and (car elt1
) (setq elt2
(member (car elt1
) (cdr elt1
))))
5123 (setq elt1
(cdr elt1
)))
5125 ;; Remove non-existing directories.
5133 (tramp-make-tramp-file-name
5134 (tramp-file-name-method vec
)
5135 (tramp-file-name-user vec
)
5136 (tramp-file-name-host vec
)
5141 (defun tramp-get-remote-locale (vec)
5142 (with-tramp-connection-property vec
"locale"
5143 (tramp-send-command vec
"locale -a")
5144 (let ((candidates '("en_US.utf8" "C.utf8"))
5146 (with-current-buffer (tramp-get-connection-buffer vec
)
5148 (goto-char (point-min))
5149 (if (string-match (concat "^" (car candidates
) "$") (buffer-string))
5150 (setq locale
(car candidates
)
5152 (setq candidates
(cdr candidates
)))))
5154 (format "LC_ALL=%s" (or locale
"C")))))
5156 (defun tramp-get-ls-command (vec)
5157 (with-tramp-connection-property vec
"ls"
5158 (tramp-message vec
5 "Finding a suitable `ls' command")
5161 (dolist (cmd '("ls" "gnuls" "gls"))
5162 (let ((dl (tramp-get-remote-path vec
))
5164 (while (and dl
(setq result
(tramp-find-executable vec cmd dl t t
)))
5165 ;; Check parameters. On busybox, "ls" output coloring is
5166 ;; enabled by default sometimes. So we try to disable it
5167 ;; when possible. $LS_COLORING is not supported there.
5168 ;; Some "ls" versions are sensible wrt the order of
5169 ;; arguments, they fail when "-al" is after the
5170 ;; "--color=never" argument (for example on FreeBSD).
5171 (when (tramp-send-command-and-check
5172 vec
(format "%s -lnd /" result
))
5173 (when (tramp-send-command-and-check
5175 "%s --color=never -al /dev/null" result
))
5176 (setq result
(concat result
" --color=never")))
5177 (throw 'ls-found result
))
5178 (setq dl
(cdr dl
))))))
5179 (tramp-error vec
'file-error
"Couldn't find a proper `ls' command"))))
5181 (defun tramp-get-ls-command-with-dired (vec)
5183 (with-tramp-connection-property vec
"ls-dired"
5184 (tramp-message vec
5 "Checking, whether `ls --dired' works")
5185 ;; Some "ls" versions are sensible wrt the order of arguments,
5186 ;; they fail when "-al" is after the "--dired" argument (for
5187 ;; example on FreeBSD).
5188 (tramp-send-command-and-check
5189 vec
(format "%s --dired -al /dev/null" (tramp-get-ls-command vec
))))))
5191 (defun tramp-get-test-command (vec)
5192 (with-tramp-connection-property vec
"test"
5193 (tramp-message vec
5 "Finding a suitable `test' command")
5194 (if (tramp-send-command-and-check vec
"test 0")
5196 (tramp-find-executable vec
"test" (tramp-get-remote-path vec
)))))
5198 (defun tramp-get-test-nt-command (vec)
5199 ;; Does `test A -nt B' work? Use abominable `find' construct if it
5200 ;; doesn't. BSD/OS 4.0 wants the parentheses around the command,
5201 ;; for otherwise the shell crashes.
5202 (with-tramp-connection-property vec
"test-nt"
5206 vec
(format "( %s / -nt / )" (tramp-get-test-command vec
)))
5207 (with-current-buffer (tramp-get-buffer vec
)
5208 (goto-char (point-min))
5209 (when (looking-at (regexp-quote tramp-end-of-output
))
5210 (format "%s %%s -nt %%s" (tramp-get-test-command vec
)))))
5215 "tramp_test_nt () {\n%s -n \"`find $1 -prune -newer $2 -print`\"\n}"
5216 (tramp-get-test-command vec
)))
5217 "tramp_test_nt %s %s"))))
5219 (defun tramp-get-file-exists-command (vec)
5220 (with-tramp-connection-property vec
"file-exists"
5221 (tramp-message vec
5 "Finding command to check if file exists")
5222 (tramp-find-file-exists-command vec
)))
5224 (defun tramp-get-remote-ln (vec)
5225 (with-tramp-connection-property vec
"ln"
5226 (tramp-message vec
5 "Finding a suitable `ln' command")
5227 (tramp-find-executable vec
"ln" (tramp-get-remote-path vec
))))
5229 (defun tramp-get-remote-perl (vec)
5230 (with-tramp-connection-property vec
"perl"
5231 (tramp-message vec
5 "Finding a suitable `perl' command")
5233 (or (tramp-find-executable vec
"perl5" (tramp-get-remote-path vec
))
5234 (tramp-find-executable
5235 vec
"perl" (tramp-get-remote-path vec
)))))
5236 ;; We must check also for some Perl modules.
5238 (with-tramp-connection-property vec
"perl-file-spec"
5239 (tramp-send-command-and-check
5240 vec
(format "%s -e 'use File::Spec;'" result
)))
5241 (with-tramp-connection-property vec
"perl-cwd-realpath"
5242 (tramp-send-command-and-check
5243 vec
(format "%s -e 'use Cwd \"realpath\";'" result
))))
5246 (defun tramp-get-remote-stat (vec)
5247 (with-tramp-connection-property vec
"stat"
5248 (tramp-message vec
5 "Finding a suitable `stat' command")
5249 (let ((result (tramp-find-executable
5250 vec
"stat" (tramp-get-remote-path vec
)))
5252 ;; Check whether stat(1) returns usable syntax. "%s" does not
5253 ;; work on older AIX systems.
5256 (tramp-send-command-and-read
5257 vec
(format "%s -c '(\"%%N\" %%s)' /" result
) 'noerror
))
5258 (unless (and (listp tmp
) (stringp (car tmp
))
5259 (string-match "^./.$" (car tmp
))
5260 (integerp (cadr tmp
)))
5264 (defun tramp-get-remote-readlink (vec)
5265 (with-tramp-connection-property vec
"readlink"
5266 (tramp-message vec
5 "Finding a suitable `readlink' command")
5267 (let ((result (tramp-find-executable
5268 vec
"readlink" (tramp-get-remote-path vec
))))
5270 (tramp-send-command-and-check
5271 vec
(format "%s --canonicalize-missing /" result
)))
5274 (defun tramp-get-remote-trash (vec)
5275 (with-tramp-connection-property vec
"trash"
5276 (tramp-message vec
5 "Finding a suitable `trash' command")
5277 (tramp-find-executable vec
"trash" (tramp-get-remote-path vec
))))
5279 (defun tramp-get-remote-touch (vec)
5280 (with-tramp-connection-property vec
"touch"
5281 (tramp-message vec
5 "Finding a suitable `touch' command")
5282 (let ((result (tramp-find-executable
5283 vec
"touch" (tramp-get-remote-path vec
)))
5287 tramp-temp-name-prefix
(tramp-get-remote-tmpdir vec
)))))
5288 ;; Busyboxes do support the "-t" option only when they have been
5289 ;; built with the DESKTOP config option. Let's check it.
5291 (tramp-set-connection-property
5293 (tramp-send-command-and-check
5298 (format-time-string "%Y%m%d%H%M.%S")
5299 (tramp-file-name-handler 'file-remote-p tmpfile
'localname
))))
5300 (delete-file tmpfile
))
5303 (defun tramp-get-remote-gvfs-monitor-dir (vec)
5304 (with-tramp-connection-property vec
"gvfs-monitor-dir"
5305 (tramp-message vec
5 "Finding a suitable `gvfs-monitor-dir' command")
5306 (tramp-find-executable
5307 vec
"gvfs-monitor-dir" (tramp-get-remote-path vec
) t t
)))
5309 (defun tramp-get-remote-inotifywait (vec)
5310 (with-tramp-connection-property vec
"inotifywait"
5311 (tramp-message vec
5 "Finding a suitable `inotifywait' command")
5312 (tramp-find-executable vec
"inotifywait" (tramp-get-remote-path vec
) t t
)))
5314 (defun tramp-get-remote-id (vec)
5315 (with-tramp-connection-property vec
"id"
5316 (tramp-message vec
5 "Finding POSIX `id' command")
5318 (dolist (cmd '("id" "gid"))
5319 (let ((dl (tramp-get-remote-path vec
))
5321 (while (and dl
(setq result
(tramp-find-executable vec cmd dl t t
)))
5322 ;; Check POSIX parameter.
5323 (when (tramp-send-command-and-check vec
(format "%s -u" result
))
5324 (throw 'id-found result
))
5325 (setq dl
(cdr dl
))))))))
5327 (defun tramp-get-remote-uid-with-id (vec id-format
)
5328 (tramp-send-command-and-read
5330 (format "%s -u%s %s"
5331 (tramp-get-remote-id vec
)
5332 (if (equal id-format
'integer
) "" "n")
5333 (if (equal id-format
'integer
)
5334 "" "| sed -e s/^/\\\"/ -e s/\$/\\\"/"))))
5336 (defun tramp-get-remote-uid-with-perl (vec id-format
)
5337 (tramp-send-command-and-read
5339 (format "%s -le '%s'"
5340 (tramp-get-remote-perl vec
)
5341 (if (equal id-format
'integer
)
5343 "print \"\\\"\", scalar getpwuid($>), \"\\\"\""))))
5345 (defun tramp-get-remote-python (vec)
5346 (with-tramp-connection-property vec
"python"
5347 (tramp-message vec
5 "Finding a suitable `python' command")
5348 (or (tramp-find-executable vec
"python" (tramp-get-remote-path vec
))
5349 (tramp-find-executable vec
"python2" (tramp-get-remote-path vec
))
5350 (tramp-find-executable vec
"python3" (tramp-get-remote-path vec
)))))
5352 (defun tramp-get-remote-uid-with-python (vec id-format
)
5353 (tramp-send-command-and-read
5355 (format "%s -c \"%s\""
5356 (tramp-get-remote-python vec
)
5357 (if (equal id-format
'integer
)
5358 "import os; print (os.getuid())"
5359 "import os, pwd; print ('\\\"' + pwd.getpwuid(os.getuid())[0] + '\\\"')"))))
5361 (defun tramp-get-remote-uid (vec id-format
)
5362 (with-tramp-connection-property vec
(format "uid-%s" id-format
)
5366 ((tramp-get-remote-id vec
)
5367 (tramp-get-remote-uid-with-id vec id-format
))
5368 ((tramp-get-remote-perl vec
)
5369 (tramp-get-remote-uid-with-perl vec id-format
))
5370 ((tramp-get-remote-python vec
)
5371 (tramp-get-remote-uid-with-python vec id-format
))))))
5372 ;; Ensure there is a valid result.
5374 ((and (equal id-format
'integer
) (not (integerp res
))) -
1)
5375 ((and (equal id-format
'string
) (not (stringp res
))) "UNKNOWN")
5378 (defun tramp-get-remote-gid-with-id (vec id-format
)
5379 (tramp-send-command-and-read
5381 (format "%s -g%s %s"
5382 (tramp-get-remote-id vec
)
5383 (if (equal id-format
'integer
) "" "n")
5384 (if (equal id-format
'integer
)
5385 "" "| sed -e s/^/\\\"/ -e s/\$/\\\"/"))))
5387 (defun tramp-get-remote-gid-with-perl (vec id-format
)
5388 (tramp-send-command-and-read
5390 (format "%s -le '%s'"
5391 (tramp-get-remote-perl vec
)
5392 (if (equal id-format
'integer
)
5393 "print ($)=~/(\\d+)/)"
5394 "print \"\\\"\", scalar getgrgid($)), \"\\\"\""))))
5396 (defun tramp-get-remote-gid-with-python (vec id-format
)
5397 (tramp-send-command-and-read
5399 (format "%s -c \"%s\""
5400 (tramp-get-remote-python vec
)
5401 (if (equal id-format
'integer
)
5402 "import os; print (os.getgid())"
5403 "import os, grp; print ('\\\"' + grp.getgrgid(os.getgid())[0] + '\\\"')"))))
5405 (defun tramp-get-remote-gid (vec id-format
)
5406 (with-tramp-connection-property vec
(format "gid-%s" id-format
)
5410 ((tramp-get-remote-id vec
)
5411 (tramp-get-remote-gid-with-id vec id-format
))
5412 ((tramp-get-remote-perl vec
)
5413 (tramp-get-remote-gid-with-perl vec id-format
))
5414 ((tramp-get-remote-python vec
)
5415 (tramp-get-remote-gid-with-python vec id-format
))))))
5416 ;; Ensure there is a valid result.
5418 ((and (equal id-format
'integer
) (not (integerp res
))) -
1)
5419 ((and (equal id-format
'string
) (not (stringp res
))) "UNKNOWN")
5422 ;; Some predefined connection properties.
5423 (defun tramp-get-inline-compress (vec prop size
)
5424 "Return the compress command related to PROP.
5425 PROP is either `inline-compress' or `inline-decompress'. SIZE is
5426 the length of the file to be compressed.
5428 If no corresponding command is found, nil is returned."
5429 (when (and (integerp tramp-inline-compress-start-size
)
5430 (> size tramp-inline-compress-start-size
))
5431 (with-tramp-connection-property (tramp-get-connection-process vec
) prop
5432 (tramp-find-inline-compress vec
)
5433 (tramp-get-connection-property
5434 (tramp-get-connection-process vec
) prop nil
))))
5436 (defun tramp-get-inline-coding (vec prop size
)
5437 "Return the coding command related to PROP.
5438 PROP is either `remote-encoding', `remote-decoding',
5439 `local-encoding' or `local-decoding'.
5441 SIZE is the length of the file to be coded. Depending on SIZE,
5442 compression might be applied.
5444 If no corresponding command is found, nil is returned.
5445 Otherwise, either a string is returned which contains a `%s' mark
5446 to be used for the respective input or output file; or a Lisp
5447 function cell is returned to be applied on a buffer."
5448 ;; We must catch the errors, because we want to return `nil', when
5449 ;; no inline coding is found.
5452 (with-tramp-connection-property
5453 (tramp-get-connection-process vec
) prop
5454 (tramp-find-inline-encoding vec
)
5455 (tramp-get-connection-property
5456 (tramp-get-connection-process vec
) prop nil
)))
5457 (prop1 (if (string-match "encoding" prop
)
5458 "inline-compress" "inline-decompress"))
5460 ;; The connection property might have been cached. So we must
5461 ;; send the script to the remote side - maybe.
5462 (when (and coding
(symbolp coding
) (string-match "remote" prop
))
5463 (let ((name (symbol-name coding
)))
5464 (while (string-match (regexp-quote "-") name
)
5465 (setq name
(replace-match "_" nil t name
)))
5466 (tramp-maybe-send-script vec
(symbol-value coding
) name
)
5467 (setq coding name
)))
5469 ;; Check for the `compress' command.
5470 (setq compress
(tramp-get-inline-compress vec prop1 size
))
5471 ;; Return the value.
5473 ((and compress
(symbolp coding
))
5474 (if (string-match "decompress" prop1
)
5477 (let ((coding-system-for-write 'binary
)
5478 (coding-system-for-read 'binary
))
5480 'call-process-region
(point-min) (point-max)
5481 (car (split-string ,compress
)) t t nil
5482 (cdr (split-string ,compress
)))))
5484 (let ((coding-system-for-write 'binary
)
5485 (coding-system-for-read 'binary
))
5487 'call-process-region beg end
5488 (car (split-string ,compress
)) t t nil
5489 (cdr (split-string ,compress
))))
5490 (,coding
(point-min) (point-max)))))
5493 ((and compress
(string-match "decoding" prop
))
5495 ;; Windows shells need the program file name after
5496 ;; the pipe symbol be quoted if they use forward
5497 ;; slashes as directory separators.
5499 ((and (string-match "local" prop
)
5500 (memq system-type
'(windows-nt)))
5502 ((string-match "local" prop
) "(%s | %s)")
5503 (t "(%s | %s >%%s)"))
5507 ;; Windows shells need the program file name after
5508 ;; the pipe symbol be quoted if they use forward
5509 ;; slashes as directory separators.
5510 (if (and (string-match "local" prop
)
5511 (memq system-type
'(windows-nt)))
5512 "(%s <%%s | \"%s\")"
5515 ((string-match "decoding" prop
)
5517 ((string-match "local" prop
) (format "%s" coding
))
5518 (t (format "%s >%%s" coding
))))
5520 (format "%s <%%s" coding
)))))))
5522 (add-hook 'tramp-unload-hook
5524 (unload-feature 'tramp-sh
'force
)))
5530 ;; * Don't use globbing for directories with many files, as this is
5531 ;; likely to produce long command lines, and some shells choke on
5532 ;; long command lines.
5533 ;; * Make it work for different encodings, and for different file name
5534 ;; encodings, too. (Daniel Pittman)
5535 ;; * Don't search for perl5 and perl. Instead, only search for perl and
5536 ;; then look if it's the right version (with `perl -v').
5537 ;; * When editing a remote CVS controlled file as a different user, VC
5538 ;; gets confused about the file locking status. Try to find out why
5539 ;; the workaround doesn't work.
5540 ;; * Allow out-of-band methods as _last_ multi-hop. Open a connection
5541 ;; until the last but one hop via `start-file-process'. Apply it
5542 ;; also for ftp and smb.
5543 ;; * WIBNI if we had a command "trampclient"? If I was editing in
5544 ;; some shell with root privileges, it would be nice if I could
5546 ;; trampclient filename.c
5547 ;; as an editor, and the _current_ shell would connect to an Emacs
5548 ;; server and would be used in an existing non-privileged Emacs
5549 ;; session for doing the editing in question.
5550 ;; That way, I need not tell Emacs my password again and be afraid
5551 ;; that it makes it into core dumps or other ugly stuff (I had Emacs
5552 ;; once display a just typed password in the context of a keyboard
5553 ;; sequence prompt for a question immediately following in a shell
5554 ;; script run within Emacs -- nasty).
5555 ;; And if I have some ssh session running to a different computer,
5556 ;; having the possibility of passing a local file there to a local
5557 ;; Emacs session (in case I can arrange for a connection back) would
5559 ;; Likely the corresponding Tramp server should not allow the
5560 ;; equivalent of the emacsclient -eval option in order to make this
5561 ;; reasonably unproblematic. And maybe trampclient should have some
5562 ;; way of passing credentials, like by using an SSL socket or
5563 ;; something. (David Kastrup)
5564 ;; * Reconnect directly to a compliant shell without first going
5565 ;; through the user's default shell. (Pete Forman)
5566 ;; * How can I interrupt the remote process with a signal
5567 ;; (interrupt-process seems not to work)? (Markus Triska)
5568 ;; * Avoid the local shell entirely for starting remote processes. If
5569 ;; so, I think even a signal, when delivered directly to the local
5570 ;; SSH instance, would correctly be propagated to the remote process
5571 ;; automatically; possibly SSH would have to be started with
5572 ;; "-t". (Markus Triska)
5573 ;; * It makes me wonder if tramp couldn't fall back to ssh when scp
5574 ;; isn't on the remote host. (Mark A. Hershberger)
5575 ;; * Use lsh instead of ssh. (Alfred M. Szmidt)
5576 ;; * Optimize out-of-band copying when both methods are scp-like (not
5578 ;; * Keep a second connection open for out-of-band methods like scp or
5581 ;;; tramp-sh.el ends here