]> code.delx.au - gnu-emacs/blob - lisp/net/tramp.el
(zone-mode): Use write-file-functions, not write-file-hooks.
[gnu-emacs] / lisp / net / tramp.el
1 ;;; -*- mode: Emacs-Lisp; coding: iso-2022-7bit; -*-
2 ;;; tramp.el --- Transparent Remote Access, Multiple Protocol
3
4 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5
6 ;; Author: kai.grossjohann@gmx.net
7 ;; Keywords: comm, processes
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; This package provides remote file editing, similar to ange-ftp.
29 ;; The difference is that ange-ftp uses FTP to transfer files between
30 ;; the local and the remote host, whereas tramp.el uses a combination
31 ;; of rsh and rcp or other work-alike programs, such as ssh/scp.
32 ;;
33 ;; For more detailed instructions, please see the info file.
34 ;;
35 ;; Notes:
36 ;; -----
37 ;;
38 ;; This package only works for Emacs 20 and higher, and for XEmacs 21
39 ;; and higher. (XEmacs 20 is missing the `with-timeout' macro. Emacs
40 ;; 19 is reported to have other problems. For XEmacs 21, you need the
41 ;; package `fsf-compat' for the `with-timeout' macro.)
42 ;;
43 ;; This version might not work with pre-Emacs 21 VC unless VC is
44 ;; loaded before tramp.el. Could you please test this and tell me about
45 ;; the result? Thanks.
46 ;;
47 ;; Also see the todo list at the bottom of this file.
48 ;;
49 ;; The current version of Tramp can be retrieved from the following URL:
50 ;; http://savannah.nongnu.org/download/tramp/
51 ;;
52 ;; There's a mailing list for this, as well. Its name is:
53 ;; tramp-devel@mail.freesoftware.fsf.org
54 ;; Send a mail with `help' in the subject (!) to the administration
55 ;; address for instructions on joining the list. The administration
56 ;; address is:
57 ;; tramp-devel-request@mail.freesoftware.fsf.org
58 ;; You can also use the Web to subscribe, under the following URL:
59 ;; http://mail.freesoftware.fsf.org/mailman/listinfo/tramp-devel
60 ;;
61 ;; For the adventurous, the current development sources are available
62 ;; via CVS. You can find instructions about this at the following URL:
63 ;; http://savannah.gnu.org/projects/tramp/
64 ;; Click on "CVS" in the navigation bar near the top.
65 ;;
66 ;; Don't forget to put on your asbestos longjohns, first!
67
68 ;;; Code:
69
70 ;; The Tramp version number and bug report address, as prepared by configure.
71 (require 'trampver)
72
73 (require 'timer)
74 (require 'format-spec) ;from Gnus 5.8, also in tar ball
75 ;; The explicit check is not necessary in Emacs, which provides the
76 ;; feature even if implemented in C, but it appears to be necessary
77 ;; in XEmacs.
78 (unless (and (fboundp 'base64-encode-region)
79 (fboundp 'base64-decode-region))
80 (require 'base64)) ;for the mimencode methods
81 (require 'shell)
82 (require 'advice)
83
84 (autoload 'tramp-uuencode-region "tramp-uu"
85 "Implementation of `uuencode' in Lisp.")
86
87 (unless (fboundp 'uudecode-decode-region)
88 (autoload 'uudecode-decode-region "uudecode"))
89
90 ;; XEmacs is distributed with few Lisp packages. Further packages are
91 ;; installed using EFS. If we use a unified filename format, then
92 ;; Tramp is required in addition to EFS. (But why can't Tramp just
93 ;; disable EFS when Tramp is loaded? Then XEmacs can ship with EFS
94 ;; just like before.) Another reason for using a separate filename
95 ;; syntax on XEmacs is that EFS hooks into XEmacs in many places, but
96 ;; Tramp only knows how to deal with `file-name-handler-alist', not
97 ;; the other places.
98 ;;;###autoload
99 (defvar tramp-unified-filenames (not (featurep 'xemacs))
100 "Non-nil means to use unified Ange-FTP/Tramp filename syntax.
101 Nil means to use a separate filename syntax for Tramp.")
102
103 ;; Load foreign methods. Because they do require Tramp internally, this
104 ;; must be done with the `eval-after-load' trick.
105
106 ;; tramp-ftp supports Ange-FTP only. Not suited for XEmacs therefore.
107 (unless (featurep 'xemacs)
108 (eval-after-load "tramp"
109 '(require 'tramp-ftp)))
110 (when (and tramp-unified-filenames (featurep 'xemacs))
111 (eval-after-load "tramp"
112 '(require 'tramp-efs)))
113
114 ;; tramp-smb uses "smbclient" from Samba.
115 ;; Not available under Cygwin and Windows, because they don't offer
116 ;; "smbclient". And even not necessary there, because Emacs supports
117 ;; UNC file names like "//host/share/localname".
118 (unless (memq system-type '(cygwin windows-nt))
119 (eval-after-load "tramp"
120 '(require 'tramp-smb)))
121
122 (eval-when-compile
123 (require 'cl)
124 (require 'custom)
125 ;; Emacs 19.34 compatibility hack -- is this needed?
126 (or (>= emacs-major-version 20)
127 (load "cl-seq")))
128
129 (unless (boundp 'custom-print-functions)
130 (defvar custom-print-functions nil)) ; not autoloaded before Emacs 20.4
131
132 ;; Avoid bytecompiler warnings if the byte-compiler supports this.
133 ;; Currently, XEmacs supports this.
134 (eval-when-compile
135 (when (fboundp 'byte-compiler-options)
136 (byte-compiler-options (warnings (- unused-vars)))))
137
138 ;;; User Customizable Internal Variables:
139
140 (defgroup tramp nil
141 "Edit remote files with a combination of rsh and rcp or similar programs."
142 :group 'files)
143
144 (defcustom tramp-verbose 9
145 "*Verbosity level for tramp.el. 0 means be silent, 10 is most verbose."
146 :group 'tramp
147 :type 'integer)
148
149 (defcustom tramp-debug-buffer nil
150 "*Whether to send all commands and responses to a debug buffer."
151 :group 'tramp
152 :type 'boolean)
153
154 (defcustom tramp-auto-save-directory nil
155 "*Put auto-save files in this directory, if set.
156 The idea is to use a local directory so that auto-saving is faster."
157 :group 'tramp
158 :type '(choice (const nil)
159 string))
160
161 (defcustom tramp-encoding-shell
162 (if (memq system-type '(windows-nt))
163 (getenv "COMSPEC")
164 "/bin/sh")
165 "*Use this program for encoding and decoding commands on the local host.
166 This shell is used to execute the encoding and decoding command on the
167 local host, so if you want to use `~' in those commands, you should
168 choose a shell here which groks tilde expansion. `/bin/sh' normally
169 does not understand tilde expansion.
170
171 For encoding and deocding, commands like the following are executed:
172
173 /bin/sh -c COMMAND < INPUT > OUTPUT
174
175 This variable can be used to change the \"/bin/sh\" part. See the
176 variable `tramp-encoding-command-switch' for the \"-c\" part. Also, see the
177 variable `tramp-encoding-reads-stdin' to specify whether the commands read
178 standard input or a file.
179
180 Note that this variable is not used for remote commands. There are
181 mechanisms in tramp.el which automatically determine the right shell to
182 use for the remote host."
183 :group 'tramp
184 :type '(file :must-match t))
185
186 (defcustom tramp-encoding-command-switch
187 (if (string-match "cmd\\.exe" tramp-encoding-shell)
188 "/c"
189 "-c")
190 "*Use this switch together with `tramp-encoding-shell' for local commands.
191 See the variable `tramp-encoding-shell' for more information."
192 :group 'tramp
193 :type 'string)
194
195 (defcustom tramp-encoding-reads-stdin t
196 "*If non-nil, encoding commands read from standard input.
197 If nil, the filename is the last argument.
198
199 Note that the commands always must write to standard output."
200 :group 'tramp
201 :type 'boolean)
202
203 (defcustom tramp-multi-sh-program
204 tramp-encoding-shell
205 "*Use this program for bootstrapping multi-hop connections.
206 This variable is similar to `tramp-encoding-shell', but it is only used
207 when initializing a multi-hop connection. Therefore, the set of
208 commands sent to this shell is quite restricted, and if you are
209 careful it works to use CMD.EXE under Windows (instead of a Bourne-ish
210 shell which does not normally exist on Windows anyway).
211
212 To use multi-hop methods from Windows, you also need suitable entries
213 in `tramp-multi-connection-function-alist' for the first hop.
214
215 This variable defaults to the value of `tramp-encoding-shell'."
216 :group 'tramp
217 :type '(file :must-match t))
218
219 ;; CCC I have changed all occurrences of comint-quote-filename with
220 ;; tramp-shell-quote-argument, except in tramp-handle-expand-many-files.
221 ;; There, comint-quote-filename was removed altogether. If it turns
222 ;; out to be necessary there, something will need to be done.
223 ;;-(defcustom tramp-file-name-quote-list
224 ;;- '(?] ?[ ?\| ?& ?< ?> ?\( ?\) ?\; ?\ ?\* ?\? ?\! ?\" ?\' ?\` ?# ?\@ ?\+ )
225 ;;- "*Protect these characters from the remote shell.
226 ;;-Any character in this list is quoted (preceded with a backslash)
227 ;;-because it means something special to the shell. This takes effect
228 ;;-when sending file and directory names to the remote shell.
229 ;;-
230 ;;-See `comint-file-name-quote-list' for details."
231 ;;- :group 'tramp
232 ;;- :type '(repeat character))
233
234 (defcustom tramp-methods
235 '( ("rcp" (tramp-connection-function tramp-open-connection-rsh)
236 (tramp-login-program "rsh")
237 (tramp-copy-program "rcp")
238 (tramp-remote-sh "/bin/sh")
239 (tramp-login-args nil)
240 (tramp-copy-args nil)
241 (tramp-copy-keep-date-arg "-p")
242 (tramp-password-end-of-line nil))
243 ("scp" (tramp-connection-function tramp-open-connection-rsh)
244 (tramp-login-program "ssh")
245 (tramp-copy-program "scp")
246 (tramp-remote-sh "/bin/sh")
247 (tramp-login-args ("-e" "none"))
248 (tramp-copy-args nil)
249 (tramp-copy-keep-date-arg "-p")
250 (tramp-password-end-of-line nil))
251 ("scp1" (tramp-connection-function tramp-open-connection-rsh)
252 (tramp-login-program "ssh")
253 (tramp-copy-program "scp")
254 (tramp-remote-sh "/bin/sh")
255 (tramp-login-args ("-1" "-e" "none"))
256 (tramp-copy-args ("-1"))
257 (tramp-copy-keep-date-arg "-p")
258 (tramp-password-end-of-line nil))
259 ("scp2" (tramp-connection-function tramp-open-connection-rsh)
260 (tramp-login-program "ssh")
261 (tramp-copy-program "scp")
262 (tramp-remote-sh "/bin/sh")
263 (tramp-login-args ("-2" "-e" "none"))
264 (tramp-copy-args ("-2"))
265 (tramp-copy-keep-date-arg "-p")
266 (tramp-password-end-of-line nil))
267 ("scp1_old"
268 (tramp-connection-function tramp-open-connection-rsh)
269 (tramp-login-program "ssh1")
270 (tramp-copy-program "scp1")
271 (tramp-remote-sh "/bin/sh")
272 (tramp-login-args ("-e" "none"))
273 (tramp-copy-args nil)
274 (tramp-copy-keep-date-arg "-p")
275 (tramp-password-end-of-line nil))
276 ("scp2_old"
277 (tramp-connection-function tramp-open-connection-rsh)
278 (tramp-login-program "ssh2")
279 (tramp-copy-program "scp2")
280 (tramp-remote-sh "/bin/sh")
281 (tramp-login-args ("-e" "none"))
282 (tramp-copy-args nil)
283 (tramp-copy-keep-date-arg "-p")
284 (tramp-password-end-of-line nil))
285 ("rsync" (tramp-connection-function tramp-open-connection-rsh)
286 (tramp-login-program "ssh")
287 (tramp-copy-program "rsync")
288 (tramp-remote-sh "/bin/sh")
289 (tramp-login-args ("-e" "none"))
290 (tramp-copy-args ("-e" "ssh"))
291 (tramp-copy-keep-date-arg "-t")
292 (tramp-password-end-of-line nil))
293 ("remcp" (tramp-connection-function tramp-open-connection-rsh)
294 (tramp-login-program "remsh")
295 (tramp-copy-program "rcp")
296 (tramp-remote-sh "/bin/sh")
297 (tramp-login-args nil)
298 (tramp-copy-args nil)
299 (tramp-copy-keep-date-arg "-p")
300 (tramp-password-end-of-line nil))
301 ("rsh" (tramp-connection-function tramp-open-connection-rsh)
302 (tramp-login-program "rsh")
303 (tramp-copy-program nil)
304 (tramp-remote-sh "/bin/sh")
305 (tramp-login-args nil)
306 (tramp-copy-args nil)
307 (tramp-copy-keep-date-arg nil)
308 (tramp-password-end-of-line nil))
309 ("ssh" (tramp-connection-function tramp-open-connection-rsh)
310 (tramp-login-program "ssh")
311 (tramp-copy-program nil)
312 (tramp-remote-sh "/bin/sh")
313 (tramp-login-args ("-e" "none"))
314 (tramp-copy-args nil)
315 (tramp-copy-keep-date-arg nil)
316 (tramp-password-end-of-line nil))
317 ("ssh1" (tramp-connection-function tramp-open-connection-rsh)
318 (tramp-login-program "ssh")
319 (tramp-copy-program nil)
320 (tramp-remote-sh "/bin/sh")
321 (tramp-login-args ("-1" "-e" "none"))
322 (tramp-copy-args ("-1"))
323 (tramp-copy-keep-date-arg nil)
324 (tramp-password-end-of-line nil))
325 ("ssh2" (tramp-connection-function tramp-open-connection-rsh)
326 (tramp-login-program "ssh")
327 (tramp-copy-program nil)
328 (tramp-remote-sh "/bin/sh")
329 (tramp-login-args ("-2" "-e" "none"))
330 (tramp-copy-args ("-2"))
331 (tramp-copy-keep-date-arg nil)
332 (tramp-password-end-of-line nil))
333 ("ssh1_old"
334 (tramp-connection-function tramp-open-connection-rsh)
335 (tramp-login-program "ssh1")
336 (tramp-copy-program nil)
337 (tramp-remote-sh "/bin/sh")
338 (tramp-login-args ("-e" "none"))
339 (tramp-copy-args nil)
340 (tramp-copy-keep-date-arg nil)
341 (tramp-password-end-of-line nil))
342 ("ssh2_old"
343 (tramp-connection-function tramp-open-connection-rsh)
344 (tramp-login-program "ssh2")
345 (tramp-copy-program nil)
346 (tramp-remote-sh "/bin/sh")
347 (tramp-login-args ("-e" "none"))
348 (tramp-copy-args nil)
349 (tramp-copy-keep-date-arg nil)
350 (tramp-password-end-of-line nil))
351 ("remsh" (tramp-connection-function tramp-open-connection-rsh)
352 (tramp-login-program "remsh")
353 (tramp-copy-program nil)
354 (tramp-remote-sh "/bin/sh")
355 (tramp-login-args nil)
356 (tramp-copy-args nil)
357 (tramp-copy-keep-date-arg nil)
358 (tramp-password-end-of-line nil))
359 ("telnet"
360 (tramp-connection-function tramp-open-connection-telnet)
361 (tramp-login-program "telnet")
362 (tramp-copy-program nil)
363 (tramp-remote-sh "/bin/sh")
364 (tramp-login-args nil)
365 (tramp-copy-args nil)
366 (tramp-copy-keep-date-arg nil)
367 (tramp-password-end-of-line nil))
368 ("su" (tramp-connection-function tramp-open-connection-su)
369 (tramp-login-program "su")
370 (tramp-copy-program nil)
371 (tramp-remote-sh "/bin/sh")
372 (tramp-login-args ("-" "%u"))
373 (tramp-copy-args nil)
374 (tramp-copy-keep-date-arg nil)
375 (tramp-password-end-of-line nil))
376 ("sudo" (tramp-connection-function tramp-open-connection-su)
377 (tramp-login-program "sudo")
378 (tramp-copy-program nil)
379 (tramp-remote-sh "/bin/sh")
380 (tramp-login-args ("-u" "%u" "-s"
381 "-p" "Password:"))
382 (tramp-copy-args nil)
383 (tramp-copy-keep-date-arg nil)
384 (tramp-password-end-of-line nil))
385 ("multi" (tramp-connection-function tramp-open-connection-multi)
386 (tramp-login-program nil)
387 (tramp-copy-program nil)
388 (tramp-remote-sh "/bin/sh")
389 (tramp-login-args nil)
390 (tramp-copy-args nil)
391 (tramp-copy-keep-date-arg nil)
392 (tramp-password-end-of-line nil))
393 ("scpx" (tramp-connection-function tramp-open-connection-rsh)
394 (tramp-login-program "ssh")
395 (tramp-copy-program "scp")
396 (tramp-remote-sh "/bin/sh")
397 (tramp-login-args ("-e" "none" "-t" "-t" "/bin/sh"))
398 (tramp-copy-args nil)
399 (tramp-copy-keep-date-arg "-p")
400 (tramp-password-end-of-line nil))
401 ("sshx" (tramp-connection-function tramp-open-connection-rsh)
402 (tramp-login-program "ssh")
403 (tramp-copy-program nil)
404 (tramp-remote-sh "/bin/sh")
405 (tramp-login-args ("-e" "none" "-t" "-t" "/bin/sh"))
406 (tramp-copy-args nil)
407 (tramp-copy-keep-date-arg nil)
408 (tramp-password-end-of-line nil))
409 ("krlogin"
410 (tramp-connection-function tramp-open-connection-rsh)
411 (tramp-login-program "krlogin")
412 (tramp-copy-program nil)
413 (tramp-remote-sh "/bin/sh")
414 (tramp-login-args ("-x"))
415 (tramp-copy-args nil)
416 (tramp-copy-keep-date-arg nil)
417 (tramp-password-end-of-line nil))
418 ("plink"
419 (tramp-connection-function tramp-open-connection-rsh)
420 (tramp-login-program "plink")
421 (tramp-copy-program nil)
422 (tramp-remote-sh "/bin/sh")
423 (tramp-login-args ("-ssh")) ;optionally add "-v"
424 (tramp-copy-args nil)
425 (tramp-copy-keep-date-arg nil)
426 (tramp-password-end-of-line "xy")) ;see docstring for "xy"
427 ("plink1"
428 (tramp-connection-function tramp-open-connection-rsh)
429 (tramp-login-program "plink")
430 (tramp-copy-program nil)
431 (tramp-remote-sh "/bin/sh")
432 (tramp-login-args ("-1" "-ssh")) ;optionally add "-v"
433 (tramp-copy-args nil)
434 (tramp-copy-keep-date-arg nil)
435 (tramp-password-end-of-line "xy")) ;see docstring for "xy"
436 ("pscp"
437 (tramp-connection-function tramp-open-connection-rsh)
438 (tramp-login-program "plink")
439 (tramp-copy-program "pscp")
440 (tramp-remote-sh "/bin/sh")
441 (tramp-login-args ("-ssh"))
442 (tramp-copy-args nil)
443 (tramp-copy-keep-date-arg "-p")
444 (tramp-password-end-of-line "xy")) ;see docstring for "xy"
445 ("fcp"
446 (tramp-connection-function tramp-open-connection-rsh)
447 (tramp-login-program "fsh")
448 (tramp-copy-program "fcp")
449 (tramp-remote-sh "/bin/sh -i")
450 (tramp-login-args ("sh" "-i"))
451 (tramp-copy-args nil)
452 (tramp-copy-keep-date-arg "-p")
453 (tramp-password-end-of-line nil))
454 )
455 "*Alist of methods for remote files.
456 This is a list of entries of the form (NAME PARAM1 PARAM2 ...).
457 Each NAME stands for a remote access method. Each PARAM is a
458 pair of the form (KEY VALUE). The following KEYs are defined:
459 * `tramp-connection-function'
460 This specifies the function to use to connect to the remote host.
461 Currently, `tramp-open-connection-rsh', `tramp-open-connection-telnet'
462 and `tramp-open-connection-su' are defined. See the documentation
463 of these functions for more details.
464 * `tramp-remote-sh'
465 This specifies the Bourne shell to use on the remote host. This
466 MUST be a Bourne-like shell. It is normally not necessary to set
467 this to any value other than \"/bin/sh\": tramp wants to use a shell
468 which groks tilde expansion, but it can search for it. Also note
469 that \"/bin/sh\" exists on all Unixen, this might not be true for
470 the value that you decide to use. You Have Been Warned.
471 * `tramp-login-program'
472 This specifies the name of the program to use for logging in to the
473 remote host. Depending on `tramp-connection-function', this may be
474 the name of rsh or a workalike program (when
475 `tramp-connection-function' is `tramp-open-connection-rsh'), or the
476 name of telnet or a workalike (for `tramp-open-connection-telnet'),
477 or the name of su or a workalike (for `tramp-open-connection-su').
478 * `tramp-login-args'
479 This specifies the list of arguments to pass to the above
480 mentioned program. Please note that this is a list of arguments,
481 that is, normally you don't want to put \"-a -b\" or \"-f foo\"
482 here. Instead, you want two list elements, one for \"-a\" and one
483 for \"-b\", or one for \"-f\" and one for \"foo\".
484 If `tramp-connection-function' is `tramp-open-connection-su', then
485 \"%u\" in this list is replaced by the user name, and \"%%\" can
486 be used to obtain a literal percent character.
487 * `tramp-copy-program'
488 This specifies the name of the program to use for remotely copying
489 the file; this might be the absolute filename of rcp or the name of
490 a workalike program.
491 * `tramp-copy-args'
492 This specifies the list of parameters to pass to the above mentioned
493 program, the hints for `tramp-login-args' also apply here.
494 * `tramp-copy-keep-date-arg'
495 This specifies the parameter to use for the copying program when the
496 timestamp of the original file should be kept. For `rcp', use `-p', for
497 `rsync', use `-t'.
498 * `tramp-password-end-of-line'
499 This specifies the string to use for terminating the line after
500 submitting the password. If this method parameter is nil, then the
501 value of the normal variable `tramp-default-password-end-of-line'
502 is used. This parameter is necessary because the \"plink\" program
503 requires any two characters after sending the password. These do
504 not have to be newline or carriage return characters. Other login
505 programs are happy with just one character, the newline character.
506 We use \"xy\" as the value for methods using \"plink\".
507
508 What does all this mean? Well, you should specify `tramp-login-program'
509 for all methods; this program is used to log in to the remote site. Then,
510 there are two ways to actually transfer the files between the local and the
511 remote side. One way is using an additional rcp-like program. If you want
512 to do this, set `tramp-copy-program' in the method.
513
514 Another possibility for file transfer is inline transfer, i.e. the
515 file is passed through the same buffer used by `tramp-login-program'. In
516 this case, the file contents need to be protected since the
517 `tramp-login-program' might use escape codes or the connection might not
518 be eight-bit clean. Therefore, file contents are encoded for transit.
519 See the variable `tramp-coding-commands' for details.
520
521 So, to summarize: if the method is an out-of-band method, then you
522 must specify `tramp-copy-program' and `tramp-copy-args'. If it is an
523 inline method, then these two parameters should be nil. Every method,
524 inline or out of band, must specify `tramp-connection-function' plus
525 the associated arguments (for example, the login program if you chose
526 `tramp-open-connection-telnet').
527
528 Notes:
529
530 When using `tramp-open-connection-su' the phrase `open connection to a
531 remote host' sounds strange, but it is used nevertheless, for
532 consistency. No connection is opened to a remote host, but `su' is
533 started on the local host. You are not allowed to specify a remote
534 host other than `localhost' or the name of the local host."
535 :group 'tramp
536 :type '(repeat
537 (cons string
538 (set (list (const tramp-connection-function) function)
539 (list (const tramp-login-program)
540 (choice (const nil) string))
541 (list (const tramp-copy-program)
542 (choice (const nil) string))
543 (list (const tramp-remote-sh)
544 (choice (const nil) string))
545 (list (const tramp-login-args) (repeat string))
546 (list (const tramp-copy-args) (repeat string))
547 (list (const tramp-copy-keep-date-arg)
548 (choice (const nil) string))
549 (list (const tramp-encoding-command)
550 (choice (const nil) string))
551 (list (const tramp-decoding-command)
552 (choice (const nil) string))
553 (list (const tramp-encoding-function)
554 (choice (const nil) function))
555 (list (const tramp-decoding-function)
556 (choice (const nil) function))
557 (list (const tramp-password-end-of-line)
558 (choice (const nil) string))))))
559
560 (defcustom tramp-multi-methods '("multi" "multiu")
561 "*List of multi-hop methods.
562 Each entry in this list should be a method name as mentioned in the
563 variable `tramp-methods'."
564 :group 'tramp
565 :type '(repeat string))
566
567 (defcustom tramp-multi-connection-function-alist
568 '(("telnet" tramp-multi-connect-telnet "telnet %h%n")
569 ("rsh" tramp-multi-connect-rlogin "rsh %h -l %u%n")
570 ("remsh" tramp-multi-connect-rlogin "remsh %h -l %u%n")
571 ("ssh" tramp-multi-connect-rlogin "ssh %h -l %u%n")
572 ("ssht" tramp-multi-connect-rlogin "ssh %h -e none -t -t -l %u%n")
573 ("su" tramp-multi-connect-su "su - %u%n")
574 ("sudo" tramp-multi-connect-su "sudo -u %u -s -p Password:%n"))
575 "*List of connection functions for multi-hop methods.
576 Each list item is a list of three items (METHOD FUNCTION COMMAND),
577 where METHOD is the name as used in the file name, FUNCTION is the
578 function to be executed, and COMMAND is the shell command used for
579 connecting.
580
581 COMMAND may contain percent escapes. `%u' will be replaced with the
582 user name, `%h' will be replaced with the host name, and `%n' will be
583 replaced with an end-of-line character, as specified in the variable
584 `tramp-rsh-end-of-line'. Use `%%' for a literal percent character.
585 Note that the interpretation of the percent escapes also depends on
586 the FUNCTION. For example, the `%u' escape is forbidden with the
587 function `tramp-multi-connect-telnet'. See the documentation of the
588 various functions for details."
589 :group 'tramp
590 :type '(repeat (list string function string)))
591
592 (defcustom tramp-default-method
593 (if (and (fboundp 'executable-find)
594 (executable-find "plink"))
595 "plink"
596 "ssh")
597 "*Default method to use for transferring files.
598 See `tramp-methods' for possibilities.
599 Also see `tramp-default-method-alist'."
600 :group 'tramp
601 :type 'string)
602
603 (defcustom tramp-default-method-alist
604 '(("\\`localhost\\'" "\\`root\\'" "su"))
605 "*Default method to use for specific user/host pairs.
606 This is an alist of items (HOST USER METHOD). The first matching item
607 specifies the method to use for a file name which does not specify a
608 method. HOST and USER are regular expressions or nil, which is
609 interpreted as a regular expression which always matches. If no entry
610 matches, the variable `tramp-default-method' takes effect.
611
612 If the file name does not specify the user, lookup is done using the
613 empty string for the user name.
614
615 See `tramp-methods' for a list of possibilities for METHOD."
616 :group 'tramp
617 :type '(repeat (list (regexp :tag "Host regexp")
618 (regexp :tag "User regexp")
619 (string :tag "Method"))))
620
621 ;; Default values for non-Unices seeked
622 (defconst tramp-completion-function-alist-rsh
623 (unless (memq system-type '(windows-nt))
624 '((tramp-parse-rhosts "/etc/hosts.equiv")
625 (tramp-parse-rhosts "~/.rhosts")))
626 "Default list of (FUNCTION FILE) pairs to be examined for rsh methods.")
627
628 ;; Default values for non-Unices seeked
629 (defconst tramp-completion-function-alist-ssh
630 (unless (memq system-type '(windows-nt))
631 '((tramp-parse-rhosts "/etc/hosts.equiv")
632 (tramp-parse-rhosts "/etc/shosts.equiv")
633 (tramp-parse-shosts "/etc/ssh_known_hosts")
634 (tramp-parse-sconfig "/etc/ssh_config")
635 (tramp-parse-rhosts "~/.rhosts")
636 (tramp-parse-rhosts "~/.shosts")
637 (tramp-parse-shosts "~/.ssh/known_hosts")
638 (tramp-parse-sconfig "~/.ssh/config")))
639 "Default list of (FUNCTION FILE) pairs to be examined for ssh methods.")
640
641 ;; Default values for non-Unices seeked
642 (defconst tramp-completion-function-alist-telnet
643 (unless (memq system-type '(windows-nt))
644 '((tramp-parse-hosts "/etc/hosts")))
645 "Default list of (FUNCTION FILE) pairs to be examined for telnet methods.")
646
647 ;; Default values for non-Unices seeked
648 (defconst tramp-completion-function-alist-su
649 (unless (memq system-type '(windows-nt))
650 '((tramp-parse-passwd "/etc/passwd")))
651 "Default list of (FUNCTION FILE) pairs to be examined for su methods.")
652
653 (defcustom tramp-completion-function-alist
654 (list (cons "rcp" tramp-completion-function-alist-rsh)
655 (cons "scp" tramp-completion-function-alist-ssh)
656 (cons "scp1" tramp-completion-function-alist-ssh)
657 (cons "scp2" tramp-completion-function-alist-ssh)
658 (cons "scp1_old" tramp-completion-function-alist-ssh)
659 (cons "scp2_old" tramp-completion-function-alist-ssh)
660 (cons "rsync" tramp-completion-function-alist-rsh)
661 (cons "remcp" tramp-completion-function-alist-rsh)
662 (cons "rsh" tramp-completion-function-alist-rsh)
663 (cons "ssh" tramp-completion-function-alist-ssh)
664 (cons "ssh1" tramp-completion-function-alist-ssh)
665 (cons "ssh2" tramp-completion-function-alist-ssh)
666 (cons "ssh1_old" tramp-completion-function-alist-ssh)
667 (cons "ssh2_old" tramp-completion-function-alist-ssh)
668 (cons "remsh" tramp-completion-function-alist-rsh)
669 (cons "telnet" tramp-completion-function-alist-telnet)
670 (cons "su" tramp-completion-function-alist-su)
671 (cons "sudo" tramp-completion-function-alist-su)
672 (cons "multi" nil)
673 (cons "scpx" tramp-completion-function-alist-ssh)
674 (cons "sshx" tramp-completion-function-alist-ssh)
675 (cons "krlogin" tramp-completion-function-alist-rsh)
676 (cons "plink" tramp-completion-function-alist-ssh)
677 (cons "plink1" tramp-completion-function-alist-ssh)
678 (cons "pscp" tramp-completion-function-alist-ssh)
679 (cons "fcp" tramp-completion-function-alist-ssh)
680 )
681 "*Alist of methods for remote files.
682 This is a list of entries of the form (NAME PAIR1 PAIR2 ...).
683 Each NAME stands for a remote access method. Each PAIR is of the form
684 \(FUNCTION FILE). FUNCTION is responsible to extract user names and host
685 names from FILE for completion. The following predefined FUNCTIONs exists:
686
687 * `tramp-parse-rhosts' for \"~/.rhosts\" like files,
688 * `tramp-parse-shosts' for \"~/.ssh/known_hosts\" like files,
689 * `tramp-parse-sconfig' for \"~/.ssh/config\" like files,
690 * `tramp-parse-hosts' for \"/etc/hosts\" like files, and
691 * `tramp-parse-passwd' for \"/etc/passwd\" like files.
692 * `tramp-parse-netrc' for \"~/.netrc\" like files.
693
694 FUNCTION can also see a customer defined function. For more details see
695 the info pages."
696 :group 'tramp
697 :type '(repeat
698 (cons string
699 (choice (const nil) (repeat (list function file))))))
700
701 (defcustom tramp-rsh-end-of-line "\n"
702 "*String used for end of line in rsh connections.
703 I don't think this ever needs to be changed, so please tell me about it
704 if you need to change this.
705 Also see the method parameter `tramp-password-end-of-line' and the normal
706 variable `tramp-default-password-end-of-line'."
707 :group 'tramp
708 :type 'string)
709
710 (defcustom tramp-default-password-end-of-line
711 tramp-rsh-end-of-line
712 "*String used for end of line after sending a password.
713 This variable provides the default value for the method parameter
714 `tramp-password-end-of-line', see `tramp-methods' for more details.
715
716 It seems that people using plink under Windows need to send
717 \"\\r\\n\" (carriage-return, then newline) after a password, but just
718 \"\\n\" after all other lines. This variable can be used for the
719 password, see `tramp-rsh-end-of-line' for the other cases.
720
721 The default value is to use the same value as `tramp-rsh-end-of-line'."
722 :group 'tramp
723 :type 'string)
724
725 (defcustom tramp-remote-path
726 '("/bin" "/usr/bin" "/usr/sbin" "/usr/local/bin" "/usr/ccs/bin"
727 "/local/bin" "/local/freeware/bin" "/local/gnu/bin"
728 "/usr/freeware/bin" "/usr/pkg/bin" "/usr/contrib/bin")
729 "*List of directories to search for executables on remote host.
730 Please notify me about other semi-standard directories to include here.
731
732 You can use `~' in this list, but when searching for a shell which groks
733 tilde expansion, all directory names starting with `~' will be ignored."
734 :group 'tramp
735 :type '(repeat string))
736
737 (defcustom tramp-login-prompt-regexp
738 ".*ogin: *"
739 "*Regexp matching login-like prompts.
740 The regexp should match at end of buffer."
741 :group 'tramp
742 :type 'regexp)
743
744 (defcustom tramp-shell-prompt-pattern
745 "^[^#$%>\n]*[#$%>] *\\(\e\\[[0-9;]*[a-zA-Z] *\\)*"
746 "Regexp to match prompts from remote shell.
747 Normally, Tramp expects you to configure `shell-prompt-pattern'
748 correctly, but sometimes it happens that you are connecting to a
749 remote host which sends a different kind of shell prompt. Therefore,
750 Tramp recognizes things matched by `shell-prompt-pattern' as prompt,
751 and also things matched by this variable. The default value of this
752 variable is similar to the default value of `shell-prompt-pattern',
753 which should work well in many cases."
754 :group 'tramp
755 :type 'regexp)
756
757 (defcustom tramp-password-prompt-regexp
758 "^.*\\([pP]assword\\|passphrase.*\\):\^@? *"
759 "*Regexp matching password-like prompts.
760 The regexp should match at end of buffer.
761
762 The `sudo' program appears to insert a `^@' character into the prompt."
763 :group 'tramp
764 :type 'regexp)
765
766 (defcustom tramp-wrong-passwd-regexp
767 (concat "^.*"
768 ;; These strings should be on the last line
769 (regexp-opt '("Permission denied."
770 "Login incorrect"
771 "Login Incorrect"
772 "Connection refused"
773 "Connection closed"
774 "Sorry, try again."
775 "Name or service not known"
776 "Host key verification failed.") t)
777 ".*"
778 "\\|"
779 "^.*\\("
780 ;; Here comes a list of regexes, separated by \\|
781 "Received signal [0-9]+"
782 "\\).*")
783 "*Regexp matching a `login failed' message.
784 The regexp should match at end of buffer."
785 :group 'tramp
786 :type 'regexp)
787
788 (defcustom tramp-yesno-prompt-regexp
789 (concat
790 (regexp-opt '("Are you sure you want to continue connecting (yes/no)?") t)
791 "\\s-*")
792 "Regular expression matching all yes/no queries which need to be confirmed.
793 The confirmation should be done with yes or no.
794 The regexp should match at end of buffer.
795 See also `tramp-yn-prompt-regexp'."
796 :group 'tramp
797 :type 'regexp)
798
799 (defcustom tramp-yn-prompt-regexp
800 (concat (regexp-opt '("Store key in cache? (y/n)") t)
801 "\\s-*")
802 "Regular expression matching all y/n queries which need to be confirmed.
803 The confirmation should be done with y or n.
804 The regexp should match at end of buffer.
805 See also `tramp-yesno-prompt-regexp'."
806 :group 'tramp
807 :type 'regexp)
808
809 (defcustom tramp-terminal-prompt-regexp
810 (concat "\\("
811 "TERM = (.*)"
812 "\\|"
813 "Terminal type\\? \\[.*\\]"
814 "\\)\\s-*")
815 "Regular expression matching all terminal setting prompts.
816 The regexp should match at end of buffer.
817 The answer will be provided by `tramp-action-terminal', which see."
818 :group 'tramp
819 :type 'regexp)
820
821 (defcustom tramp-temp-name-prefix "tramp."
822 "*Prefix to use for temporary files.
823 If this is a relative file name (such as \"tramp.\"), it is considered
824 relative to the directory name returned by the function
825 `tramp-temporary-file-directory' (which see). It may also be an
826 absolute file name; don't forget to include a prefix for the filename
827 part, though."
828 :group 'tramp
829 :type 'string)
830
831 (defcustom tramp-discard-garbage nil
832 "*If non-nil, try to discard garbage sent by remote shell.
833 Some shells send such garbage upon connection setup."
834 :group 'tramp
835 :type 'boolean)
836
837 (defcustom tramp-sh-extra-args '(("/bash\\'" . "-norc -noprofile"))
838 "*Alist specifying extra arguments to pass to the remote shell.
839 Entries are (REGEXP . ARGS) where REGEXP is a regular expression
840 matching the shell file name and ARGS is a string specifying the
841 arguments.
842
843 This variable is only used when Tramp needs to start up another shell
844 for tilde expansion. The extra arguments should typically prevent the
845 shell from reading its init file."
846 :group 'tramp
847 ;; This might be the wrong way to test whether the widget type
848 ;; `alist' is available. Who knows the right way to test it?
849 :type (if (get 'alist 'widget-type)
850 '(alist :key-type string :value-type string)
851 '(repeat (cons string string))))
852
853 (defcustom tramp-prefix-format
854 (if tramp-unified-filenames "/" "/[")
855 "*String matching the very beginning of tramp file names.
856 Used in `tramp-make-tramp-file-name' and `tramp-make-tramp-multi-file-name'."
857 :group 'tramp
858 :type 'string)
859
860 (defcustom tramp-prefix-regexp
861 (concat "^" (regexp-quote tramp-prefix-format))
862 "*Regexp matching the very beginning of tramp file names.
863 Should always start with \"^\". Derived from `tramp-prefix-format'."
864 :group 'tramp
865 :type 'regexp)
866
867 (defcustom tramp-method-regexp
868 "[a-zA-Z_0-9-]+"
869 "*Regexp matching methods identifiers."
870 :group 'tramp
871 :type 'regexp)
872
873 ;; It is a little bit annoying that in XEmacs case this delimeter is different
874 ;; for single-hop and multi-hop cases.
875 (defcustom tramp-postfix-single-method-format
876 (if tramp-unified-filenames ":" "/")
877 "*String matching delimeter between method and user or host names.
878 Applicable for single-hop methods.
879 Used in `tramp-make-tramp-file-name'."
880 :group 'tramp
881 :type 'string)
882
883 (defcustom tramp-postfix-single-method-regexp
884 (regexp-quote tramp-postfix-single-method-format)
885 "*Regexp matching delimeter between method and user or host names.
886 Applicable for single-hop methods.
887 Derived from `tramp-postfix-single-method-format'."
888 :group 'tramp
889 :type 'regexp)
890
891 (defcustom tramp-postfix-multi-method-format
892 ":"
893 "*String matching delimeter between method and user or host names.
894 Applicable for multi-hop methods.
895 Used in `tramp-make-tramp-multi-file-name'."
896 :group 'tramp
897 :type 'string)
898
899 (defcustom tramp-postfix-multi-method-regexp
900 (regexp-quote tramp-postfix-multi-method-format)
901 "*Regexp matching delimeter between method and user or host names.
902 Applicable for multi-hop methods.
903 Derived from `tramp-postfix-multi-method-format'."
904 :group 'tramp
905 :type 'regexp)
906
907 (defcustom tramp-postfix-multi-hop-format
908 (if tramp-unified-filenames ":" "/")
909 "*String matching delimeter between host and next method.
910 Applicable for multi-hop methods.
911 Used in `tramp-make-tramp-multi-file-name'."
912 :group 'tramp
913 :type 'string)
914
915 (defcustom tramp-postfix-multi-hop-regexp
916 (regexp-quote tramp-postfix-multi-hop-format)
917 "*Regexp matching delimeter between host and next method.
918 Applicable for multi-hop methods.
919 Derived from `tramp-postfix-multi-hop-format'."
920 :group 'tramp
921 :type 'regexp)
922
923 (defcustom tramp-user-regexp
924 "[^:@/ \t]*"
925 "*Regexp matching user names."
926 :group 'tramp
927 :type 'regexp)
928
929 (defcustom tramp-postfix-user-format
930 "@"
931 "*String matching delimeter between user and host names.
932 Used in `tramp-make-tramp-file-name' and `tramp-make-tramp-multi-file-name'."
933 :group 'tramp
934 :type 'string)
935
936 (defcustom tramp-postfix-user-regexp
937 (regexp-quote tramp-postfix-user-format)
938 "*Regexp matching delimeter between user and host names.
939 Derived from `tramp-postfix-user-format'."
940 :group 'tramp
941 :type 'regexp)
942
943 (defcustom tramp-host-regexp
944 "[a-zA-Z0-9_.-]*"
945 "*Regexp matching host names."
946 :group 'tramp
947 :type 'regexp)
948
949 (defcustom tramp-host-with-port-regexp
950 "[a-zA-Z0-9_.#-]*"
951 "*Regexp matching host names."
952 :group 'tramp
953 :type 'regexp)
954
955 (defcustom tramp-postfix-host-format
956 (if tramp-unified-filenames ":" "]")
957 "*String matching delimeter between host names and localnames.
958 Used in `tramp-make-tramp-file-name' and `tramp-make-tramp-multi-file-name'."
959 :group 'tramp
960 :type 'string)
961
962 (defcustom tramp-postfix-host-regexp
963 (regexp-quote tramp-postfix-host-format)
964 "*Regexp matching delimeter between host names and localnames.
965 Derived from `tramp-postfix-host-format'."
966 :group 'tramp
967 :type 'regexp)
968
969 (defcustom tramp-localname-regexp
970 ".*$"
971 "*Regexp matching localnames."
972 :group 'tramp
973 :type 'regexp)
974
975 ;; File name format.
976
977 (defcustom tramp-file-name-structure
978 (list
979 (concat
980 tramp-prefix-regexp
981 "\\(" "\\(" tramp-method-regexp "\\)" tramp-postfix-single-method-regexp "\\)?"
982 "\\(" "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp "\\)?"
983 "\\(" tramp-host-with-port-regexp "\\)" tramp-postfix-host-regexp
984 "\\(" tramp-localname-regexp "\\)")
985 2 4 5 6)
986
987 "*List of five elements (REGEXP METHOD USER HOST FILE), detailing \
988 the tramp file name structure.
989
990 The first element REGEXP is a regular expression matching a tramp file
991 name. The regex should contain parentheses around the method name,
992 the user name, the host name, and the file name parts.
993
994 The second element METHOD is a number, saying which pair of
995 parentheses matches the method name. The third element USER is
996 similar, but for the user name. The fourth element HOST is similar,
997 but for the host name. The fifth element FILE is for the file name.
998 These numbers are passed directly to `match-string', which see. That
999 means the opening parentheses are counted to identify the pair.
1000
1001 See also `tramp-file-name-regexp'."
1002 :group 'tramp
1003 :type '(list (regexp :tag "File name regexp")
1004 (integer :tag "Paren pair for method name")
1005 (integer :tag "Paren pair for user name ")
1006 (integer :tag "Paren pair for host name ")
1007 (integer :tag "Paren pair for file name ")))
1008
1009 ;;;###autoload
1010 (defconst tramp-file-name-regexp-unified
1011 "\\`/[^/:]+:"
1012 "Value for `tramp-file-name-regexp' for unified remoting.
1013 Emacs (not XEmacs) uses a unified filename syntax for Ange-FTP and
1014 Tramp. See `tramp-file-name-structure-unified' for more explanations.")
1015
1016 ;;;###autoload
1017 (defconst tramp-file-name-regexp-separate
1018 "\\`/\\[.*\\]"
1019 "Value for `tramp-file-name-regexp' for separate remoting.
1020 XEmacs uses a separate filename syntax for Tramp and EFS.
1021 See `tramp-file-name-structure-separate' for more explanations.")
1022
1023 ;;;###autoload
1024 (defcustom tramp-file-name-regexp
1025 (if tramp-unified-filenames
1026 tramp-file-name-regexp-unified
1027 tramp-file-name-regexp-separate)
1028 "*Regular expression matching file names handled by tramp.
1029 This regexp should match tramp file names but no other file names.
1030 \(When tramp.el is loaded, this regular expression is prepended to
1031 `file-name-handler-alist', and that is searched sequentially. Thus,
1032 if the tramp entry appears rather early in the `file-name-handler-alist'
1033 and is a bit too general, then some files might be considered tramp
1034 files which are not really tramp files.
1035
1036 Please note that the entry in `file-name-handler-alist' is made when
1037 this file (tramp.el) is loaded. This means that this variable must be set
1038 before loading tramp.el. Alternatively, `file-name-handler-alist' can be
1039 updated after changing this variable.
1040
1041 Also see `tramp-file-name-structure'."
1042 :group 'tramp
1043 :type 'regexp)
1044
1045 ;;;###autoload
1046 (defconst tramp-completion-file-name-regexp-unified
1047 "^/[^/]*$"
1048 "Value for `tramp-completion-file-name-regexp' for unified remoting.
1049 Emacs (not XEmacs) uses a unified filename syntax for Ange-FTP and
1050 Tramp. See `tramp-file-name-structure-unified' for more explanations.")
1051
1052 ;;;###autoload
1053 (defconst tramp-completion-file-name-regexp-separate
1054 "^/\\([[][^]]*\\)?$"
1055 "Value for `tramp-completion-file-name-regexp' for separate remoting.
1056 XEmacs uses a separate filename syntax for Tramp and EFS.
1057 See `tramp-file-name-structure-separate' for more explanations.")
1058
1059 ;;;###autoload
1060 (defcustom tramp-completion-file-name-regexp
1061 (if tramp-unified-filenames
1062 tramp-completion-file-name-regexp-unified
1063 tramp-completion-file-name-regexp-separate)
1064 "*Regular expression matching file names handled by tramp completion.
1065 This regexp should match partial tramp file names only.
1066
1067 Please note that the entry in `file-name-handler-alist' is made when
1068 this file (tramp.el) is loaded. This means that this variable must be set
1069 before loading tramp.el. Alternatively, `file-name-handler-alist' can be
1070 updated after changing this variable.
1071
1072 Also see `tramp-file-name-structure'."
1073 :group 'tramp
1074 :type 'regexp)
1075
1076 (defcustom tramp-multi-file-name-structure
1077 (list
1078 (concat
1079 tramp-prefix-regexp
1080 "\\(" "\\(" tramp-method-regexp "\\)" "\\)?"
1081 "\\(" "\\(" tramp-postfix-multi-hop-regexp "%s" "\\)+" "\\)?"
1082 tramp-postfix-host-regexp "\\(" tramp-localname-regexp "\\)")
1083 2 3 -1)
1084 "*Describes the file name structure of `multi' files.
1085 Multi files allow you to contact a remote host in several hops.
1086 This is a list of four elements (REGEXP METHOD HOP LOCALNAME).
1087
1088 The first element, REGEXP, gives a regular expression to match against
1089 the file name. In this regular expression, `%s' is replaced with the
1090 value of `tramp-multi-file-name-hop-structure'. (Note: in order to
1091 allow multiple hops, you normally want to use something like
1092 \"\\\\(\\\\(%s\\\\)+\\\\)\" in the regular expression. The outer pair
1093 of parentheses is used for the HOP element, see below.)
1094
1095 All remaining elements are numbers. METHOD gives the number of the
1096 paren pair which matches the method name. HOP gives the number of the
1097 paren pair which matches the hop sequence. LOCALNAME gives the number of
1098 the paren pair which matches the localname (pathname) on the remote host.
1099
1100 LOCALNAME can also be negative, which means to count from the end. Ie, a
1101 value of -1 means the last paren pair.
1102
1103 I think it would be good if the regexp matches the whole of the
1104 string, but I haven't actually tried what happens if it doesn't..."
1105 :group 'tramp
1106 :type '(list (regexp :tag "File name regexp")
1107 (integer :tag "Paren pair for method name")
1108 (integer :tag "Paren pair for hops")
1109 (integer :tag "Paren pair to match localname")))
1110
1111 (defcustom tramp-multi-file-name-hop-structure
1112 (list
1113 (concat
1114 "\\(" tramp-method-regexp "\\)" tramp-postfix-multi-method-regexp
1115 "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp
1116 "\\(" tramp-host-with-port-regexp "\\)")
1117 1 2 3)
1118 "*Describes the structure of a hop in multi files.
1119 This is a list of four elements (REGEXP METHOD USER HOST). First
1120 element REGEXP is used to match against the hop. Pair number METHOD
1121 matches the method of one hop, pair number USER matches the user of
1122 one hop, pair number HOST matches the host of one hop.
1123
1124 This regular expression should match exactly all of one hop."
1125 :group 'tramp
1126 :type '(list (regexp :tag "Hop regexp")
1127 (integer :tag "Paren pair for method name")
1128 (integer :tag "Paren pair for user name")
1129 (integer :tag "Paren pair for host name")))
1130
1131 (defcustom tramp-make-multi-tramp-file-format
1132 (list
1133 (concat tramp-prefix-format "%m")
1134 (concat tramp-postfix-multi-hop-format
1135 "%m" tramp-postfix-multi-method-format
1136 "%u" tramp-postfix-user-format
1137 "%h")
1138 (concat tramp-postfix-host-format "%p"))
1139 "*Describes how to construct a `multi' file name.
1140 This is a list of three elements PREFIX, HOP and LOCALNAME.
1141
1142 The first element PREFIX says how to construct the prefix, the second
1143 element HOP specifies what each hop looks like, and the final element
1144 LOCALNAME says how to construct the localname (pathname).
1145
1146 In PREFIX, `%%' means `%' and `%m' means the method name.
1147
1148 In HOP, `%%' means `%' and `%m', `%u', `%h' mean the hop method, hop
1149 user and hop host, respectively.
1150
1151 In LOCALNAME, `%%' means `%' and `%p' means the localname.
1152
1153 The resulting file name always contains one copy of PREFIX and one
1154 copy of LOCALNAME, but there is one copy of HOP for each hop in the file
1155 name.
1156
1157 Note: the current implementation requires the prefix to contain the
1158 method name, followed by all the hops, and the localname must come
1159 last."
1160 :group 'tramp
1161 :type '(list string string string))
1162
1163 (defcustom tramp-terminal-type "dumb"
1164 "*Value of TERM environment variable for logging in to remote host.
1165 Because Tramp wants to parse the output of the remote shell, it is easily
1166 confused by ANSI color escape sequences and suchlike. Often, shell init
1167 files conditionalize this setup based on the TERM environment variable."
1168 :group 'tramp
1169 :type 'string)
1170
1171 (defcustom tramp-completion-without-shell-p nil
1172 "*If nil, use shell wildcards for completion, else rely on Lisp only.
1173 Using shell wildcards for completions has the advantage that it can be
1174 fast even in large directories, but completion is always
1175 case-sensitive. Relying on Lisp only means that case-insensitive
1176 completion is possible (subject to the variable `completion-ignore-case'),
1177 but it might be slow on large directories."
1178 :group 'tramp
1179 :type 'boolean)
1180
1181 (defcustom tramp-actions-before-shell
1182 '((tramp-password-prompt-regexp tramp-action-password)
1183 (tramp-login-prompt-regexp tramp-action-login)
1184 (shell-prompt-pattern tramp-action-succeed)
1185 (tramp-shell-prompt-pattern tramp-action-succeed)
1186 (tramp-wrong-passwd-regexp tramp-action-permission-denied)
1187 (tramp-yesno-prompt-regexp tramp-action-yesno)
1188 (tramp-yn-prompt-regexp tramp-action-yn)
1189 (tramp-terminal-prompt-regexp tramp-action-terminal))
1190 "List of pattern/action pairs.
1191 Whenever a pattern matches, the corresponding action is performed.
1192 Each item looks like (PATTERN ACTION).
1193
1194 The PATTERN should be a symbol, a variable. The value of this
1195 variable gives the regular expression to search for. Note that the
1196 regexp must match at the end of the buffer, \"\\'\" is implicitly
1197 appended to it.
1198
1199 The ACTION should also be a symbol, but a function. When the
1200 corresponding PATTERN matches, the ACTION function is called."
1201 :group 'tramp
1202 :type '(repeat (list variable function)))
1203
1204 (defcustom tramp-multi-actions
1205 '((tramp-password-prompt-regexp tramp-multi-action-password)
1206 (tramp-login-prompt-regexp tramp-multi-action-login)
1207 (shell-prompt-pattern tramp-multi-action-succeed)
1208 (tramp-shell-prompt-pattern tramp-multi-action-succeed)
1209 (tramp-wrong-passwd-regexp tramp-multi-action-permission-denied))
1210 "List of pattern/action pairs.
1211 This list is used for each hop in multi-hop connections.
1212 See `tramp-actions-before-shell' for more info."
1213 :group 'tramp
1214 :type '(repeat (list variable function)))
1215
1216 (defcustom tramp-initial-commands
1217 '("unset correct"
1218 "unset autocorrect")
1219 "List of commands to send to the first remote shell that we see.
1220 These commands will be sent to any shell, and thus they should be
1221 designed to work in such circumstances. Also, restrict the commands
1222 to the bare necessity for getting the remote shell into a state
1223 where it is possible to execute the Bourne-ish shell.
1224
1225 At the moment, the command to execute the Bourne-ish shell uses strange
1226 quoting which `tcsh' tries to correct, so we send the command \"unset
1227 autocorrect\" to the remote host."
1228 :group 'tramp
1229 :type '(repeat string))
1230
1231 ;; Chunked sending kluge. We set this to 500 for black-listed constellations
1232 ;; known to have a bug in `process-send-string'; some ssh connections appear
1233 ;; to drop bytes when data is sent too quickly.
1234 (defcustom tramp-chunksize
1235 (when (and (not (featurep 'xemacs))
1236 (memq system-type '(hpux)))
1237 500)
1238 "*If non-nil, chunksize for sending input to local process.
1239 It is necessary only on systems which have a buggy `process-send-string'
1240 implementation. The necessity, whether this variable must be set, can be
1241 checked via the following code:
1242
1243 (with-temp-buffer
1244 (let ((bytes 1000)
1245 (proc (start-process (buffer-name) (current-buffer) \"wc\" \"-c\")))
1246 (process-send-string proc (make-string bytes ?x))
1247 (process-send-eof proc)
1248 (process-send-eof proc)
1249 (accept-process-output proc 1)
1250 (goto-char (point-min))
1251 (re-search-forward \"\\\\w+\")
1252 (message \"Bytes sent: %s\\tBytes received: %s\" bytes (match-string 0))))
1253
1254 In the Emacs normally running Tramp, evaluate the above code.
1255 You can do this, for example, by pasting it into the `*scratch*'
1256 buffer and then hitting C-j with the cursor after the last
1257 closing parenthesis.
1258
1259 If your Emacs is buggy, the sent and received numbers will be
1260 different. In that case, you'll want to set this variable to
1261 some number. For those people who have needed it, the value 500
1262 seems to have worked well. There is no way to predict what value
1263 you need; maybe you could just experiment a bit.
1264
1265 Please raise a bug report via \"M-x tramp-bug\" if your system needs
1266 this variable to be set as well."
1267 :group 'tramp
1268 :type '(choice (const nil) integer))
1269
1270 ;;; Internal Variables:
1271
1272 (defvar tramp-buffer-file-attributes nil
1273 "Holds the `ls -ild' output for the current buffer.
1274 This variable is local to each buffer. It is not used if the remote
1275 machine groks Perl. If it is used, it's used as an emulation for
1276 the visited file modtime.")
1277 (make-variable-buffer-local 'tramp-buffer-file-attributes)
1278
1279 (defvar tramp-md5-function
1280 (cond ((and (require 'md5) (fboundp 'md5)) 'md5)
1281 ((fboundp 'md5-encode)
1282 (lambda (x) (base64-encode-string (md5-encode x))))
1283 (t (error "Coulnd't find an `md5' function")))
1284 "Function to call for running the MD5 algorithm.")
1285
1286 (defvar tramp-end-of-output
1287 (concat "///"
1288 (funcall tramp-md5-function
1289 (concat
1290 (prin1-to-string process-environment)
1291 (current-time-string)
1292 ;; (prin1-to-string
1293 ;; (if (fboundp 'directory-files-and-attributes)
1294 ;; (funcall 'directory-files-and-attributes
1295 ;; (or (getenv "HOME")
1296 ;; (tramp-temporary-file-directory)))
1297 ;; (mapcar
1298 ;; (lambda (x)
1299 ;; (cons x (file-attributes x)))
1300 ;; (directory-files (or (getenv "HOME")
1301 ;; (tramp-temporary-file-directory))
1302 ;; t))))
1303 )))
1304 "String used to recognize end of output.")
1305
1306 (defvar tramp-connection-function nil
1307 "This internal variable holds a parameter for `tramp-methods'.
1308 In the connection buffer, this variable has the value of the like-named
1309 method parameter, as specified in `tramp-methods' (which see).")
1310
1311 (defvar tramp-remote-sh nil
1312 "This internal variable holds a parameter for `tramp-methods'.
1313 In the connection buffer, this variable has the value of the like-named
1314 method parameter, as specified in `tramp-methods' (which see).")
1315
1316 (defvar tramp-login-program nil
1317 "This internal variable holds a parameter for `tramp-methods'.
1318 In the connection buffer, this variable has the value of the like-named
1319 method parameter, as specified in `tramp-methods' (which see).")
1320
1321 (defvar tramp-login-args nil
1322 "This internal variable holds a parameter for `tramp-methods'.
1323 In the connection buffer, this variable has the value of the like-named
1324 method parameter, as specified in `tramp-methods' (which see).")
1325
1326 (defvar tramp-copy-program nil
1327 "This internal variable holds a parameter for `tramp-methods'.
1328 In the connection buffer, this variable has the value of the like-named
1329 method parameter, as specified in `tramp-methods' (which see).")
1330
1331 (defvar tramp-copy-args nil
1332 "This internal variable holds a parameter for `tramp-methods'.
1333 In the connection buffer, this variable has the value of the like-named
1334 method parameter, as specified in `tramp-methods' (which see).")
1335
1336 (defvar tramp-copy-keep-date-arg nil
1337 "This internal variable holds a parameter for `tramp-methods'.
1338 In the connection buffer, this variable has the value of the like-named
1339 method parameter, as specified in `tramp-methods' (which see).")
1340
1341 (defvar tramp-encoding-command nil
1342 "This internal variable holds a parameter for `tramp-methods'.
1343 In the connection buffer, this variable has the value of the like-named
1344 method parameter, as specified in `tramp-methods' (which see).")
1345
1346 (defvar tramp-decoding-command nil
1347 "This internal variable holds a parameter for `tramp-methods'.
1348 In the connection buffer, this variable has the value of the like-named
1349 method parameter, as specified in `tramp-methods' (which see).")
1350
1351 (defvar tramp-encoding-function nil
1352 "This internal variable holds a parameter for `tramp-methods'.
1353 In the connection buffer, this variable has the value of the like-named
1354 method parameter, as specified in `tramp-methods' (which see).")
1355
1356 (defvar tramp-decoding-function nil
1357 "This internal variable holds a parameter for `tramp-methods'.
1358 In the connection buffer, this variable has the value of the like-named
1359 method parameter, as specified in `tramp-methods' (which see).")
1360
1361 (defvar tramp-password-end-of-line nil
1362 "This internal variable holds a parameter for `tramp-methods'.
1363 In the connection buffer, this variable has the value of the like-named
1364 method parameter, as specified in `tramp-methods' (which see).")
1365
1366 ;; CCC `local in each buffer'?
1367 (defvar tramp-ls-command nil
1368 "This command is used to get a long listing with numeric user and group ids.
1369 This variable is automatically made buffer-local to each rsh process buffer
1370 upon opening the connection.")
1371
1372 (defvar tramp-current-multi-method nil
1373 "Name of `multi' connection method for this *tramp* buffer, or nil if not multi.
1374 This variable is automatically made buffer-local to each rsh process buffer
1375 upon opening the connection.")
1376
1377 (defvar tramp-current-method nil
1378 "Connection method for this *tramp* buffer.
1379 This variable is automatically made buffer-local to each rsh process buffer
1380 upon opening the connection.")
1381
1382 (defvar tramp-current-user nil
1383 "Remote login name for this *tramp* buffer.
1384 This variable is automatically made buffer-local to each rsh process buffer
1385 upon opening the connection.")
1386
1387 (defvar tramp-current-host nil
1388 "Remote host for this *tramp* buffer.
1389 This variable is automatically made buffer-local to each rsh process buffer
1390 upon opening the connection.")
1391
1392 (defvar tramp-test-groks-nt nil
1393 "Whether the `test' command groks the `-nt' switch.
1394 \(`test A -nt B' tests if file A is newer than file B.)
1395 This variable is automatically made buffer-local to each rsh process buffer
1396 upon opening the connection.")
1397
1398 (defvar tramp-file-exists-command nil
1399 "Command to use for checking if a file exists.
1400 This variable is automatically made buffer-local to each rsh process buffer
1401 upon opening the connection.")
1402
1403 (defconst tramp-uudecode "\
1404 tramp_uudecode () {
1405 \(echo begin 600 /tmp/tramp.$$; tail +2) | uudecode
1406 cat /tmp/tramp.$$
1407 rm -f /tmp/tramp.$$
1408 }"
1409 "Shell function to implement `uudecode' to standard output.
1410 Many systems support `uudecode -o -' for this or `uudecode -p', but
1411 some systems don't, and for them we have this shell function.")
1412
1413 ;; Perl script to implement `file-attributes' in a Lisp `read'able
1414 ;; output. If you are hacking on this, note that you get *no* output
1415 ;; unless this spits out a complete line, including the '\n' at the
1416 ;; end.
1417 ;; The device number is returned as "-1", because there will be a virtual
1418 ;; device number set in `tramp-handle-file-attributes'
1419 (defconst tramp-perl-file-attributes "\
1420 ($f, $n) = @ARGV;
1421 @s = lstat($f);
1422 if (($s[2] & 0170000) == 0120000) { $l = readlink($f); $l = \"\\\"$l\\\"\"; }
1423 elsif (($s[2] & 0170000) == 040000) { $l = \"t\"; }
1424 else { $l = \"nil\" };
1425 $u = ($n eq \"nil\") ? $s[4] : getpwuid($s[4]);
1426 $g = ($n eq \"nil\") ? $s[5] : getgrgid($s[5]);
1427 printf(\"(%s %u %s %s (%u %u) (%u %u) (%u %u) %u %u t (%u . %u) -1)\\n\",
1428 $l, $s[3], $u, $g, $s[8] >> 16 & 0xffff, $s[8] & 0xffff,
1429 $s[9] >> 16 & 0xffff, $s[9] & 0xffff, $s[10] >> 16 & 0xffff, $s[10] & 0xffff,
1430 $s[7], $s[2], $s[1] >> 16 & 0xffff, $s[1] & 0xffff);"
1431 "Perl script to produce output suitable for use with `file-attributes'
1432 on the remote file system.")
1433
1434 ;; ;; These two use uu encoding.
1435 ;; (defvar tramp-perl-encode "%s -e'\
1436 ;; print qq(begin 644 xxx\n);
1437 ;; my $s = q();
1438 ;; my $res = q();
1439 ;; while (read(STDIN, $s, 45)) {
1440 ;; print pack(q(u), $s);
1441 ;; }
1442 ;; print qq(`\n);
1443 ;; print qq(end\n);
1444 ;; '"
1445 ;; "Perl program to use for encoding a file.
1446 ;; Escape sequence %s is replaced with name of Perl binary.")
1447
1448 ;; (defvar tramp-perl-decode "%s -ne '
1449 ;; print unpack q(u), $_;
1450 ;; '"
1451 ;; "Perl program to use for decoding a file.
1452 ;; Escape sequence %s is replaced with name of Perl binary.")
1453
1454 ;; These two use base64 encoding.
1455 (defvar tramp-perl-encode-with-module
1456 "perl -MMIME::Base64 -0777 -ne 'print encode_base64($_)'"
1457 "Perl program to use for encoding a file.
1458 Escape sequence %s is replaced with name of Perl binary.
1459 This string is passed to `format', so percent characters need to be doubled.
1460 This implementation requires the MIME::Base64 Perl module to be installed
1461 on the remote host.")
1462
1463 (defvar tramp-perl-decode-with-module
1464 "perl -MMIME::Base64 -0777 -ne 'print decode_base64($_)'"
1465 "Perl program to use for decoding a file.
1466 Escape sequence %s is replaced with name of Perl binary.
1467 This string is passed to `format', so percent characters need to be doubled.
1468 This implementation requires the MIME::Base64 Perl module to be installed
1469 on the remote host.")
1470
1471 (defvar tramp-perl-encode
1472 "%s -e '
1473 # This script contributed by Juanma Barranquero <lektu@terra.es>.
1474 # Copyright (C) 2002 Free Software Foundation, Inc.
1475 use strict;
1476
1477 my %%trans = do {
1478 my $i = 0;
1479 map {(substr(unpack(q(B8), chr $i++), 2, 6), $_)}
1480 split //, q(ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/);
1481 };
1482
1483 binmode(\\*STDIN);
1484
1485 # We read in chunks of 54 bytes, to generate output lines
1486 # of 72 chars (plus end of line)
1487 $/ = \\54;
1488
1489 while (my $data = <STDIN>) {
1490 my $pad = q();
1491
1492 # Only for the last chunk, and only if did not fill the last three-byte packet
1493 if (eof) {
1494 my $mod = length($data) %% 3;
1495 $pad = q(=) x (3 - $mod) if $mod;
1496 }
1497
1498 # Not the fastest method, but it is simple: unpack to binary string, split
1499 # by groups of 6 bits and convert back from binary to byte; then map into
1500 # the translation table
1501 print
1502 join q(),
1503 map($trans{$_},
1504 (substr(unpack(q(B*), $data) . q(00000), 0, 432) =~ /....../g)),
1505 $pad,
1506 qq(\\n);
1507 }
1508 '"
1509 "Perl program to use for encoding a file.
1510 Escape sequence %s is replaced with name of Perl binary.
1511 This string is passed to `format', so percent characters need to be doubled.")
1512
1513 (defvar tramp-perl-decode
1514 "%s -e '
1515 # This script contributed by Juanma Barranquero <lektu@terra.es>.
1516 # Copyright (C) 2002 Free Software Foundation, Inc.
1517 use strict;
1518
1519 my %%trans = do {
1520 my $i = 0;
1521 map {($_, substr(unpack(q(B8), chr $i++), 2, 6))}
1522 split //, q(ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/)
1523 };
1524
1525 my %%bytes = map {(unpack(q(B8), chr $_), chr $_)} 0 .. 255;
1526
1527 binmode(\\*STDOUT);
1528
1529 # We are going to accumulate into $pending to accept any line length
1530 # (we do not check they are <= 76 chars as the RFC says)
1531 my $pending = q();
1532
1533 while (my $data = <STDIN>) {
1534 chomp $data;
1535
1536 # If we find one or two =, we have reached the end and
1537 # any following data is to be discarded
1538 my $finished = $data =~ s/(==?).*/$1/;
1539 $pending .= $data;
1540
1541 my $len = length($pending);
1542 my $chunk = substr($pending, 0, $len & ~3);
1543
1544 # Easy method: translate from chars to (pregenerated) six-bit packets, join,
1545 # split in 8-bit chunks and convert back to char.
1546 print join q(),
1547 map $bytes{$_},
1548 ((join q(), map {$trans{$_} || q()} split //, $chunk) =~ /......../g);
1549
1550 last if $finished;
1551 }
1552 '"
1553 "Perl program to use for decoding a file.
1554 Escape sequence %s is replaced with name of Perl binary.
1555 This string is passed to `format', so percent characters need to be doubled.")
1556
1557 ; These values conform to `file-attributes' from XEmacs 21.2.
1558 ; GNU Emacs and other tools not checked.
1559 (defconst tramp-file-mode-type-map '((0 . "-") ; Normal file (SVID-v2 and XPG2)
1560 (1 . "p") ; fifo
1561 (2 . "c") ; character device
1562 (3 . "m") ; multiplexed character device (v7)
1563 (4 . "d") ; directory
1564 (5 . "?") ; Named special file (XENIX)
1565 (6 . "b") ; block device
1566 (7 . "?") ; multiplexed block device (v7)
1567 (8 . "-") ; regular file
1568 (9 . "n") ; network special file (HP-UX)
1569 (10 . "l") ; symlink
1570 (11 . "?") ; ACL shadow inode (Solaris, not userspace)
1571 (12 . "s") ; socket
1572 (13 . "D") ; door special (Solaris)
1573 (14 . "w")) ; whiteout (BSD)
1574 "A list of file types returned from the `stat' system call.
1575 This is used to map a mode number to a permission string.")
1576
1577 (defvar tramp-dos-coding-system
1578 (if (and (fboundp 'coding-system-p)
1579 (funcall 'coding-system-p '(dos)))
1580 'dos
1581 'undecided-dos)
1582 "Some Emacsen know the `dos' coding system, others need `undecided-dos'.")
1583
1584 (defvar tramp-last-cmd-time nil
1585 "Internal Tramp variable recording the time when the last cmd was sent.
1586 This variable is buffer-local in every buffer.")
1587 (make-variable-buffer-local 'tramp-last-cmd-time)
1588
1589 ;; This variable does not have the right value in XEmacs. What should
1590 ;; I use instead of find-operation-coding-system in XEmacs?
1591 (defvar tramp-feature-write-region-fix
1592 (when (fboundp 'find-operation-coding-system)
1593 (let ((file-coding-system-alist '(("test" emacs-mule))))
1594 (find-operation-coding-system 'write-region 0 0 "" nil "test")))
1595 "Internal variable to say if `write-region' chooses the right coding.
1596 Older versions of Emacs chose the coding system for `write-region' based
1597 on the FILENAME argument, even if VISIT was a string.")
1598
1599 ;; New handlers should be added here. The following operations can be
1600 ;; handled using the normal primitives: file-name-as-directory,
1601 ;; file-name-directory, file-name-nondirectory,
1602 ;; file-name-sans-versions, get-file-buffer.
1603 (defconst tramp-file-name-handler-alist
1604 '(
1605 (load . tramp-handle-load)
1606 (make-symbolic-link . tramp-handle-make-symbolic-link)
1607 (file-name-directory . tramp-handle-file-name-directory)
1608 (file-name-nondirectory . tramp-handle-file-name-nondirectory)
1609 (file-truename . tramp-handle-file-truename)
1610 (file-exists-p . tramp-handle-file-exists-p)
1611 (file-directory-p . tramp-handle-file-directory-p)
1612 (file-executable-p . tramp-handle-file-executable-p)
1613 (file-accessible-directory-p . tramp-handle-file-accessible-directory-p)
1614 (file-readable-p . tramp-handle-file-readable-p)
1615 (file-regular-p . tramp-handle-file-regular-p)
1616 (file-symlink-p . tramp-handle-file-symlink-p)
1617 (file-writable-p . tramp-handle-file-writable-p)
1618 (file-ownership-preserved-p . tramp-handle-file-ownership-preserved-p)
1619 (file-newer-than-file-p . tramp-handle-file-newer-than-file-p)
1620 (file-attributes . tramp-handle-file-attributes)
1621 (file-modes . tramp-handle-file-modes)
1622 (file-directory-files . tramp-handle-file-directory-files)
1623 (directory-files . tramp-handle-directory-files)
1624 (file-name-all-completions . tramp-handle-file-name-all-completions)
1625 (file-name-completion . tramp-handle-file-name-completion)
1626 (add-name-to-file . tramp-handle-add-name-to-file)
1627 (copy-file . tramp-handle-copy-file)
1628 (rename-file . tramp-handle-rename-file)
1629 (set-file-modes . tramp-handle-set-file-modes)
1630 (make-directory . tramp-handle-make-directory)
1631 (delete-directory . tramp-handle-delete-directory)
1632 (delete-file . tramp-handle-delete-file)
1633 (directory-file-name . tramp-handle-directory-file-name)
1634 (shell-command . tramp-handle-shell-command)
1635 (insert-directory . tramp-handle-insert-directory)
1636 (expand-file-name . tramp-handle-expand-file-name)
1637 (file-local-copy . tramp-handle-file-local-copy)
1638 (insert-file-contents . tramp-handle-insert-file-contents)
1639 (write-region . tramp-handle-write-region)
1640 (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory)
1641 (dired-call-process . tramp-handle-dired-call-process)
1642 (dired-recursive-delete-directory
1643 . tramp-handle-dired-recursive-delete-directory)
1644 (set-visited-file-modtime . tramp-handle-set-visited-file-modtime)
1645 (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime))
1646 "Alist of handler functions.
1647 Operations not mentioned here will be handled by the normal Emacs functions.")
1648
1649 ;; Handlers for partial tramp file names. For GNU Emacs just
1650 ;; `file-name-all-completions' is needed. The other ones are necessary
1651 ;; for XEmacs.
1652 (defconst tramp-completion-file-name-handler-alist
1653 '(
1654 (file-name-directory . tramp-completion-handle-file-name-directory)
1655 (file-name-nondirectory . tramp-completion-handle-file-name-nondirectory)
1656 (file-exists-p . tramp-completion-handle-file-exists-p)
1657 (file-name-all-completions . tramp-completion-handle-file-name-all-completions)
1658 (file-name-completion . tramp-completion-handle-file-name-completion)
1659 (expand-file-name . tramp-completion-handle-expand-file-name))
1660 "Alist of completion handler functions.
1661 Used for file names matching `tramp-file-name-regexp'. Operations not
1662 mentioned here will be handled by `tramp-file-name-handler-alist' or the
1663 normal Emacs functions.")
1664
1665 ;; Handlers for foreign methods, like FTP or SMB, shall be plugged here.
1666 (defvar tramp-foreign-file-name-handler-alist
1667 ;; (identity . tramp-sh-file-name-handler) should always be the last
1668 ;; entry, since `identity' always matches.
1669 '((identity . tramp-sh-file-name-handler))
1670 "Alist of elements (FUNCTION . HANDLER) for foreign methods handled specially.
1671 If (FUNCTION FILENAME) returns non-nil, then all I/O on that file is done by
1672 calling HANDLER.")
1673
1674 ;;; Internal functions which must come first.
1675
1676 (defsubst tramp-message (level fmt-string &rest args)
1677 "Emit a message depending on verbosity level.
1678 First arg LEVEL says to be quiet if `tramp-verbose' is less than LEVEL. The
1679 message is emitted only if `tramp-verbose' is greater than or equal to LEVEL.
1680 Calls function `message' with FMT-STRING as control string and the remaining
1681 ARGS to actually emit the message (if applicable).
1682
1683 This function expects to be called from the tramp buffer only!"
1684 (when (<= level tramp-verbose)
1685 (apply #'message (concat "tramp: " fmt-string) args)
1686 (when tramp-debug-buffer
1687 (save-excursion
1688 (set-buffer
1689 (tramp-get-debug-buffer
1690 tramp-current-multi-method tramp-current-method
1691 tramp-current-user tramp-current-host))
1692 (goto-char (point-max))
1693 (tramp-insert-with-face
1694 'italic
1695 (concat "# " (apply #'format fmt-string args) "\n"))))))
1696
1697 (defun tramp-message-for-buffer
1698 (multi-method method user host level fmt-string &rest args)
1699 "Like `tramp-message' but temporarily switches to the tramp buffer.
1700 First three args METHOD, USER, and HOST identify the tramp buffer to use,
1701 remaining args passed to `tramp-message'."
1702 (save-excursion
1703 (set-buffer (tramp-get-buffer multi-method method user host))
1704 (apply 'tramp-message level fmt-string args)))
1705
1706 (defsubst tramp-line-end-position nil
1707 "Return point at end of line.
1708 Calls `line-end-position' or `point-at-eol' if defined, else
1709 own implementation."
1710 (cond
1711 ((fboundp 'line-end-position) (funcall 'line-end-position))
1712 ((fboundp 'point-at-eol) (funcall 'point-at-eol))
1713 (t (save-excursion (end-of-line) (point)))))
1714
1715 (defmacro with-parsed-tramp-file-name (filename var &rest body)
1716 "Parse a Tramp filename and make components available in the body.
1717
1718 First arg FILENAME is evaluated and dissected into its components.
1719 Second arg VAR is a symbol. It is used as a variable name to hold
1720 the filename structure. It is also used as a prefix for the variables
1721 holding the components. For example, if VAR is the symbol `foo', then
1722 `foo' will be bound to the whole structure, `foo-multi-method' will
1723 be bound to the multi-method component, and so on for `foo-method',
1724 `foo-user', `foo-host', `foo-localname'.
1725
1726 Remaining args are Lisp expressions to be evaluated (inside an implicit
1727 `progn').
1728
1729 If VAR is nil, then we bind `v' to the structure and `multi-method',
1730 `method', `user', `host', `localname' to the components."
1731 `(let* ((,(or var 'v) (tramp-dissect-file-name ,filename))
1732 (,(if var (intern (concat (symbol-name var) "-multi-method")) 'multi-method)
1733 (tramp-file-name-multi-method ,(or var 'v)))
1734 (,(if var (intern (concat (symbol-name var) "-method")) 'method)
1735 (tramp-file-name-method ,(or var 'v)))
1736 (,(if var (intern (concat (symbol-name var) "-user")) 'user)
1737 (tramp-file-name-user ,(or var 'v)))
1738 (,(if var (intern (concat (symbol-name var) "-host")) 'host)
1739 (tramp-file-name-host ,(or var 'v)))
1740 (,(if var (intern (concat (symbol-name var) "-localname")) 'localname)
1741 (tramp-file-name-localname ,(or var 'v))))
1742 ,@body))
1743
1744 (put 'with-parsed-tramp-file-name 'lisp-indent-function 2)
1745
1746 ;;; Config Manipulation Functions:
1747
1748 (defun tramp-set-completion-function (method function-list)
1749 "Sets the list of completion functions for METHOD.
1750 FUNCTION-LIST is a list of entries of the form (FUNCTION FILE).
1751 The FUNCTION is intended to parse FILE according its syntax.
1752 It might be a predefined FUNCTION, or a user defined FUNCTION.
1753 Predefined FUNCTIONs are `tramp-parse-rhosts', `tramp-parse-shosts',
1754 `tramp-parse-sconfig',`tramp-parse-hosts', `tramp-parse-passwd',
1755 and `tramp-parse-netrc'.
1756
1757 Example:
1758
1759 (tramp-set-completion-function
1760 \"ssh\"
1761 '((tramp-parse-sconfig \"/etc/ssh_config\")
1762 (tramp-parse-sconfig \"~/.ssh/config\")))"
1763
1764 (let ((v (cdr (assoc method tramp-completion-function-alist))))
1765 (if v (setcdr v function-list)
1766 (add-to-list 'tramp-completion-function-alist
1767 (cons method function-list)))))
1768
1769 (defun tramp-get-completion-function (method)
1770 "Returns list of completion functions for METHOD.
1771 For definition of that list see `tramp-set-completion-function'."
1772 (cdr (assoc method tramp-completion-function-alist)))
1773
1774 ;;; File Name Handler Functions:
1775
1776 (defun tramp-handle-make-symbolic-link
1777 (filename linkname &optional ok-if-already-exists)
1778 "Like `make-symbolic-link' for tramp files.
1779 If LINKNAME is a non-Tramp file, it is used verbatim as the target of
1780 the symlink. If LINKNAME is a Tramp file, only the localname component is
1781 used as the target of the symlink.
1782
1783 If LINKNAME is a Tramp file and the localname component is relative, then
1784 it is expanded first, before the localname component is taken. Note that
1785 this can give surprising results if the user/host for the source and
1786 target of the symlink differ."
1787 (with-parsed-tramp-file-name linkname l
1788 (let ((ln (tramp-get-remote-ln l-multi-method l-method l-user l-host))
1789 (cwd (file-name-directory l-localname)))
1790 (unless ln
1791 (signal 'file-error
1792 (list "Making a symbolic link."
1793 "ln(1) does not exist on the remote host.")))
1794
1795 ;; Do the 'confirm if exists' thing.
1796 (when (file-exists-p linkname)
1797 ;; What to do?
1798 (if (or (null ok-if-already-exists) ; not allowed to exist
1799 (and (numberp ok-if-already-exists)
1800 (not (yes-or-no-p
1801 (format
1802 "File %s already exists; make it a link anyway? "
1803 l-localname)))))
1804 (signal 'file-already-exists (list "File already exists" l-localname))
1805 (delete-file linkname)))
1806
1807 ;; If FILENAME is a Tramp name, use just the localname component.
1808 (when (tramp-tramp-file-p filename)
1809 (setq filename (tramp-file-name-localname
1810 (tramp-dissect-file-name
1811 (expand-file-name filename)))))
1812
1813 ;; Right, they are on the same host, regardless of user, method, etc.
1814 ;; We now make the link on the remote machine. This will occur as the user
1815 ;; that FILENAME belongs to.
1816 (zerop
1817 (tramp-send-command-and-check
1818 l-multi-method l-method l-user l-host
1819 (format "cd %s && %s -sf %s %s"
1820 cwd ln
1821 filename
1822 l-localname)
1823 t)))))
1824
1825
1826 (defun tramp-handle-load (file &optional noerror nomessage nosuffix must-suffix)
1827 "Like `load' for tramp files. Not implemented!"
1828 (unless (file-name-absolute-p file)
1829 (error "Tramp cannot `load' files without absolute file name"))
1830 (with-parsed-tramp-file-name file nil
1831 (unless nosuffix
1832 (cond ((file-exists-p (concat file ".elc"))
1833 (setq file (concat file ".elc")))
1834 ((file-exists-p (concat file ".el"))
1835 (setq file (concat file ".el")))))
1836 (when must-suffix
1837 ;; The first condition is always true for absolute file names.
1838 ;; Included for safety's sake.
1839 (unless (or (file-name-directory file)
1840 (string-match "\\.elc?\\'" file))
1841 (error "File `%s' does not include a `.el' or `.elc' suffix"
1842 file)))
1843 (unless noerror
1844 (when (not (file-exists-p file))
1845 (error "Cannot load nonexistant file `%s'" file)))
1846 (if (not (file-exists-p file))
1847 nil
1848 (unless nomessage
1849 (message "Loading %s..." file))
1850 (let ((local-copy (file-local-copy file)))
1851 ;; MUST-SUFFIX doesn't exist on XEmacs, so let it default to nil.
1852 (load local-copy noerror t t)
1853 (delete-file local-copy))
1854 (unless nomessage
1855 (message "Loading %s...done" file))
1856 t)))
1857
1858 ;; Localname manipulation functions that grok TRAMP localnames...
1859 (defun tramp-handle-file-name-directory (file)
1860 "Like `file-name-directory' but aware of TRAMP files."
1861 ;; everything except the last filename thing is the directory
1862 (with-parsed-tramp-file-name file nil
1863 ;; For the following condition, two possibilities should be tried:
1864 ;; (1) (string= localname "")
1865 ;; (2) (or (string= localname "") (string= localname "/"))
1866 ;; The second variant fails when completing a "/" directory on
1867 ;; the remote host, that is a filename which looks like
1868 ;; "/user@host:/". But maybe wildcards fail with the first variant.
1869 ;; We should do some investigation.
1870 (if (string= localname "")
1871 ;; For a filename like "/[foo]", we return "/". The `else'
1872 ;; case would return "/[foo]" unchanged. But if we do that,
1873 ;; then `file-expand-wildcards' ceases to work. It's not
1874 ;; quite clear to me what's the intuition that tells that this
1875 ;; behavior is the right behavior, but oh, well.
1876 "/"
1877 ;; run the command on the localname portion only
1878 ;; CCC: This should take into account the remote machine type, no?
1879 ;; --daniel <daniel@danann.net>
1880 (tramp-make-tramp-file-name multi-method method user host
1881 ;; This will not recurse...
1882 (or (file-name-directory localname) "")))))
1883
1884 (defun tramp-handle-file-name-nondirectory (file)
1885 "Like `file-name-nondirectory' but aware of TRAMP files."
1886 (with-parsed-tramp-file-name file nil
1887 (file-name-nondirectory localname)))
1888
1889 (defun tramp-handle-file-truename (filename &optional counter prev-dirs)
1890 "Like `file-truename' for tramp files."
1891 (with-parsed-tramp-file-name filename nil
1892 (let* ((steps (tramp-split-string localname "/"))
1893 (localnamedir (let ((directory-sep-char ?/))
1894 (file-name-as-directory localname)))
1895 (is-dir (string= localname localnamedir))
1896 (thisstep nil)
1897 (numchase 0)
1898 ;; Don't make the following value larger than necessary.
1899 ;; People expect an error message in a timely fashion when
1900 ;; something is wrong; otherwise they might think that Emacs
1901 ;; is hung. Of course, correctness has to come first.
1902 (numchase-limit 20)
1903 (result nil) ;result steps in reverse order
1904 symlink-target)
1905 (tramp-message-for-buffer
1906 multi-method method user host
1907 10 "Finding true name for `%s'" filename)
1908 (while (and steps (< numchase numchase-limit))
1909 (setq thisstep (pop steps))
1910 (tramp-message-for-buffer
1911 multi-method method user host
1912 10 "Check %s"
1913 (mapconcat 'identity
1914 (append '("") (reverse result) (list thisstep))
1915 "/"))
1916 (setq symlink-target
1917 (nth 0 (file-attributes
1918 (tramp-make-tramp-file-name
1919 multi-method method user host
1920 (mapconcat 'identity
1921 (append '("")
1922 (reverse result)
1923 (list thisstep))
1924 "/")))))
1925 (cond ((string= "." thisstep)
1926 (tramp-message-for-buffer multi-method method user host
1927 10 "Ignoring step `.'"))
1928 ((string= ".." thisstep)
1929 (tramp-message-for-buffer multi-method method user host
1930 10 "Processing step `..'")
1931 (pop result))
1932 ((stringp symlink-target)
1933 ;; It's a symlink, follow it.
1934 (tramp-message-for-buffer
1935 multi-method method user host
1936 10 "Follow symlink to %s" symlink-target)
1937 (setq numchase (1+ numchase))
1938 (when (file-name-absolute-p symlink-target)
1939 (setq result nil))
1940 ;; If the symlink was absolute, we'll get a string like
1941 ;; "/user@host:/some/target"; extract the
1942 ;; "/some/target" part from it.
1943 (when (tramp-tramp-file-p symlink-target)
1944 (with-parsed-tramp-file-name symlink-target sym
1945 (unless (equal (list multi-method method user host)
1946 (list sym-multi-method sym-method
1947 sym-user sym-host))
1948 (error "Symlink target `%s' on wrong host"
1949 symlink-target))
1950 (setq symlink-target localname)))
1951 (setq steps
1952 (append (tramp-split-string symlink-target "/") steps)))
1953 (t
1954 ;; It's a file.
1955 (setq result (cons thisstep result)))))
1956 (when (>= numchase numchase-limit)
1957 (error "Maximum number (%d) of symlinks exceeded" numchase-limit))
1958 (setq result (reverse result))
1959 ;; Combine list to form string.
1960 (setq result
1961 (if result
1962 (mapconcat 'identity (cons "" result) "/")
1963 "/"))
1964 (when (and is-dir (or (string= "" result)
1965 (not (string= (substring result -1) "/"))))
1966 (setq result (concat result "/")))
1967 (tramp-message-for-buffer
1968 multi-method method user host
1969 10 "True name of `%s' is `%s'" filename result)
1970 (tramp-make-tramp-file-name
1971 multi-method method user host result))))
1972
1973 ;; Basic functions.
1974
1975 (defun tramp-handle-file-exists-p (filename)
1976 "Like `file-exists-p' for tramp files."
1977 (with-parsed-tramp-file-name filename nil
1978 (save-excursion
1979 (zerop (tramp-send-command-and-check
1980 multi-method method user host
1981 (format
1982 (tramp-get-file-exists-command multi-method method user host)
1983 (tramp-shell-quote-argument localname)))))))
1984
1985 ;; Devices must distinguish physical file systems. The device numbers
1986 ;; provided by "lstat" aren't unique, because we operate on different hosts.
1987 ;; So we use virtual device numbers, generated by Tramp. Both Ange-FTP and
1988 ;; EFS use device number "-1". In order to be different, we use device number
1989 ;; (-1 x), whereby "x" is unique for a given (multi-method method user host).
1990 (defvar tramp-devices nil
1991 "Keeps virtual device numbers.")
1992
1993 ;; CCC: This should check for an error condition and signal failure
1994 ;; when something goes wrong.
1995 ;; Daniel Pittman <daniel@danann.net>
1996 (defun tramp-handle-file-attributes (filename &optional id-format)
1997 "Like `file-attributes' for tramp files."
1998 (let ((nonnumeric (and id-format (equal id-format 'string)))
1999 result)
2000 (with-parsed-tramp-file-name filename nil
2001 (when (tramp-handle-file-exists-p filename)
2002 ;; file exists, find out stuff
2003 (save-excursion
2004 (if (tramp-get-remote-perl multi-method method user host)
2005 (setq result
2006 (tramp-handle-file-attributes-with-perl
2007 multi-method method user host localname nonnumeric))
2008 (setq result
2009 (tramp-handle-file-attributes-with-ls
2010 multi-method method user host localname nonnumeric)))
2011 ;; set virtual device number
2012 (setcar (nthcdr 11 result)
2013 (tramp-get-device multi-method method user host)))))
2014 result))
2015
2016 (defun tramp-handle-file-attributes-with-ls
2017 (multi-method method user host localname &optional nonnumeric)
2018 "Implement `file-attributes' for tramp files using the ls(1) command."
2019 (let (symlinkp dirp
2020 res-inode res-filemodes res-numlinks
2021 res-uid res-gid res-size res-symlink-target)
2022 (tramp-message-for-buffer multi-method method user host 10
2023 "file attributes with ls: %s"
2024 (tramp-make-tramp-file-name
2025 multi-method method user host localname))
2026 (tramp-send-command
2027 multi-method method user host
2028 (format "%s %s %s"
2029 (tramp-get-ls-command multi-method method user host)
2030 (if nonnumeric "-ild" "-ildn")
2031 (tramp-shell-quote-argument localname)))
2032 (tramp-wait-for-output)
2033 ;; parse `ls -l' output ...
2034 ;; ... inode
2035 (setq res-inode
2036 (condition-case err
2037 (read (current-buffer))
2038 (invalid-read-syntax
2039 (when (and (equal (cadr err)
2040 "Integer constant overflow in reader")
2041 (string-match
2042 "^[0-9]+\\([0-9][0-9][0-9][0-9][0-9]\\)\\'"
2043 (caddr err)))
2044 (let* ((big (read (substring (caddr err) 0
2045 (match-beginning 1))))
2046 (small (read (match-string 1 (caddr err))))
2047 (twiddle (/ small 65536)))
2048 (cons (+ big twiddle)
2049 (- small (* twiddle 65536))))))))
2050 ;; ... file mode flags
2051 (setq res-filemodes (symbol-name (read (current-buffer))))
2052 ;; ... number links
2053 (setq res-numlinks (read (current-buffer)))
2054 ;; ... uid and gid
2055 (setq res-uid (read (current-buffer)))
2056 (setq res-gid (read (current-buffer)))
2057 (unless nonnumeric
2058 (unless (numberp res-uid) (setq res-uid -1))
2059 (unless (numberp res-gid) (setq res-gid -1)))
2060 ;; ... size
2061 (setq res-size (read (current-buffer)))
2062 ;; From the file modes, figure out other stuff.
2063 (setq symlinkp (eq ?l (aref res-filemodes 0)))
2064 (setq dirp (eq ?d (aref res-filemodes 0)))
2065 ;; if symlink, find out file name pointed to
2066 (when symlinkp
2067 (search-forward "-> ")
2068 (setq res-symlink-target
2069 (buffer-substring (point)
2070 (tramp-line-end-position))))
2071 ;; return data gathered
2072 (list
2073 ;; 0. t for directory, string (name linked to) for symbolic
2074 ;; link, or nil.
2075 (or dirp res-symlink-target nil)
2076 ;; 1. Number of links to file.
2077 res-numlinks
2078 ;; 2. File uid.
2079 res-uid
2080 ;; 3. File gid.
2081 res-gid
2082 ;; 4. Last access time, as a list of two integers. First
2083 ;; integer has high-order 16 bits of time, second has low 16
2084 ;; bits.
2085 ;; 5. Last modification time, likewise.
2086 ;; 6. Last status change time, likewise.
2087 '(0 0) '(0 0) '(0 0) ;CCC how to find out?
2088 ;; 7. Size in bytes (-1, if number is out of range).
2089 res-size
2090 ;; 8. File modes, as a string of ten letters or dashes as in ls -l.
2091 res-filemodes
2092 ;; 9. t iff file's gid would change if file were deleted and
2093 ;; recreated.
2094 nil ;hm?
2095 ;; 10. inode number.
2096 res-inode
2097 ;; 11. Device number. Will be replaced by a virtual device number.
2098 -1
2099 )))
2100
2101 (defun tramp-handle-file-attributes-with-perl
2102 (multi-method method user host localname &optional nonnumeric)
2103 "Implement `file-attributes' for tramp files using a Perl script.
2104
2105 The Perl command is sent to the remote machine when the connection
2106 is initially created and is kept cached by the remote shell."
2107 (tramp-message-for-buffer multi-method method user host 10
2108 "file attributes with perl: %s"
2109 (tramp-make-tramp-file-name
2110 multi-method method user host localname))
2111 (tramp-send-command
2112 multi-method method user host
2113 (format "tramp_file_attributes %s %s"
2114 (tramp-shell-quote-argument localname) nonnumeric))
2115 (tramp-wait-for-output)
2116 (let ((result (read (current-buffer))))
2117 (setcar (nthcdr 8 result)
2118 (tramp-file-mode-from-int (nth 8 result)))
2119 result))
2120
2121 (defun tramp-get-device (multi-method method user host)
2122 "Returns the virtual device number.
2123 If it doesn't exist, generate a new one."
2124 (let ((string (tramp-make-tramp-file-name multi-method method user host "")))
2125 (unless (assoc string tramp-devices)
2126 (add-to-list 'tramp-devices
2127 (list string (length tramp-devices))))
2128 (list -1 (nth 1 (assoc string tramp-devices)))))
2129
2130 (defun tramp-handle-set-visited-file-modtime (&optional time-list)
2131 "Like `set-visited-file-modtime' for tramp files."
2132 (unless (buffer-file-name)
2133 (error "Can't set-visited-file-modtime: buffer `%s' not visiting a file"
2134 (buffer-name)))
2135 (when time-list
2136 (tramp-run-real-handler 'set-visited-file-modtime (list time-list)))
2137 (let ((f (buffer-file-name))
2138 (coding-system-used nil))
2139 (with-parsed-tramp-file-name f nil
2140 (let* ((attr (file-attributes f))
2141 (modtime (nth 5 attr)))
2142 ;; We use '(0 0) as a don't-know value. See also
2143 ;; `tramp-handle-file-attributes-with-ls'.
2144 (when (boundp 'last-coding-system-used)
2145 (setq coding-system-used last-coding-system-used))
2146 (if (not (equal modtime '(0 0)))
2147 (tramp-run-real-handler 'set-visited-file-modtime (list modtime))
2148 (save-excursion
2149 (tramp-send-command
2150 multi-method method user host
2151 (format "%s -ild %s"
2152 (tramp-get-ls-command multi-method method user host)
2153 (tramp-shell-quote-argument localname)))
2154 (tramp-wait-for-output)
2155 (setq attr (buffer-substring (point)
2156 (progn (end-of-line) (point)))))
2157 (setq tramp-buffer-file-attributes attr))
2158 (when (boundp 'last-coding-system-used)
2159 (setq last-coding-system-used coding-system-used))
2160 nil))))
2161
2162 ;; CCC continue here
2163
2164 ;; This function makes the same assumption as
2165 ;; `tramp-handle-set-visited-file-modtime'.
2166 (defun tramp-handle-verify-visited-file-modtime (buf)
2167 "Like `verify-visited-file-modtime' for tramp files."
2168 (with-current-buffer buf
2169 (let ((f (buffer-file-name)))
2170 (with-parsed-tramp-file-name f nil
2171 (let* ((attr (file-attributes f))
2172 (modtime (nth 5 attr)))
2173 (cond ((and attr (not (equal modtime '(0 0))))
2174 ;; Why does `file-attributes' return a list (HIGH
2175 ;; LOW), but `visited-file-modtime' returns a cons
2176 ;; (HIGH . LOW)?
2177 (let ((mt (visited-file-modtime)))
2178 (< (abs (tramp-time-diff
2179 modtime (list (car mt) (cdr mt)))) 2)))
2180 (attr
2181 (save-excursion
2182 (tramp-send-command
2183 multi-method method user host
2184 (format "%s -ild %s"
2185 (tramp-get-ls-command multi-method method
2186 user host)
2187 (tramp-shell-quote-argument localname)))
2188 (tramp-wait-for-output)
2189 (setq attr (buffer-substring
2190 (point) (progn (end-of-line) (point)))))
2191 (equal tramp-buffer-file-attributes attr))
2192 ;; If file does not exist, say it is not modified.
2193 (t nil)))))))
2194
2195 (defadvice clear-visited-file-modtime (after tramp activate)
2196 "Set `tramp-buffer-file-attributes' back to nil.
2197 Tramp uses this variable as an emulation for the actual modtime of the file,
2198 if the remote host can't provide the modtime."
2199 (setq tramp-buffer-file-attributes nil))
2200
2201 (defun tramp-handle-set-file-modes (filename mode)
2202 "Like `set-file-modes' for tramp files."
2203 (with-parsed-tramp-file-name filename nil
2204 (save-excursion
2205 (unless (zerop (tramp-send-command-and-check
2206 multi-method method user host
2207 (format "chmod %s %s"
2208 (tramp-decimal-to-octal mode)
2209 (tramp-shell-quote-argument localname))))
2210 (signal 'file-error
2211 (list "Doing chmod"
2212 ;; FIXME: extract the proper text from chmod's stderr.
2213 "error while changing file's mode"
2214 filename))))))
2215
2216 ;; Simple functions using the `test' command.
2217
2218 (defun tramp-handle-file-executable-p (filename)
2219 "Like `file-executable-p' for tramp files."
2220 (with-parsed-tramp-file-name filename nil
2221 (zerop (tramp-run-test "-x" filename))))
2222
2223 (defun tramp-handle-file-readable-p (filename)
2224 "Like `file-readable-p' for tramp files."
2225 (with-parsed-tramp-file-name filename nil
2226 (zerop (tramp-run-test "-r" filename))))
2227
2228 (defun tramp-handle-file-accessible-directory-p (filename)
2229 "Like `file-accessible-directory-p' for tramp files."
2230 (with-parsed-tramp-file-name filename nil
2231 (and (zerop (tramp-run-test "-d" filename))
2232 (zerop (tramp-run-test "-r" filename))
2233 (zerop (tramp-run-test "-x" filename)))))
2234
2235 ;; When the remote shell is started, it looks for a shell which groks
2236 ;; tilde expansion. Here, we assume that all shells which grok tilde
2237 ;; expansion will also provide a `test' command which groks `-nt' (for
2238 ;; newer than). If this breaks, tell me about it and I'll try to do
2239 ;; something smarter about it.
2240 (defun tramp-handle-file-newer-than-file-p (file1 file2)
2241 "Like `file-newer-than-file-p' for tramp files."
2242 (cond ((not (file-exists-p file1))
2243 nil)
2244 ((not (file-exists-p file2))
2245 t)
2246 ;; We are sure both files exist at this point.
2247 (t
2248 (save-excursion
2249 ;; We try to get the mtime of both files. If they are not
2250 ;; equal to the "dont-know" value, then we subtract the times
2251 ;; and obtain the result.
2252 (let ((fa1 (file-attributes file1))
2253 (fa2 (file-attributes file2)))
2254 (if (and (not (equal (nth 5 fa1) '(0 0)))
2255 (not (equal (nth 5 fa2) '(0 0))))
2256 (> 0 (tramp-time-diff (nth 5 fa1) (nth 5 fa2)))
2257 ;; If one of them is the dont-know value, then we can
2258 ;; still try to run a shell command on the remote host.
2259 ;; However, this only works if both files are Tramp
2260 ;; files and both have the same method, same user, same
2261 ;; host.
2262 (unless (and (tramp-tramp-file-p file1)
2263 (tramp-tramp-file-p file2))
2264 (signal
2265 'file-error
2266 (list
2267 "Cannot check if Tramp file is newer than non-Tramp file"
2268 file1 file2)))
2269 (with-parsed-tramp-file-name file1 v1
2270 (with-parsed-tramp-file-name file2 v2
2271 (unless (and (equal v1-multi-method v2-multi-method)
2272 (equal v1-method v2-method)
2273 (equal v1-user v2-user)
2274 (equal v1-host v2-host))
2275 (signal 'file-error
2276 (list "Files must have same method, user, host"
2277 file1 file2)))
2278 (unless (and (tramp-tramp-file-p file1)
2279 (tramp-tramp-file-p file2))
2280 (signal 'file-error
2281 (list "Files must be tramp files on same host"
2282 file1 file2)))
2283 (if (tramp-get-test-groks-nt
2284 v1-multi-method v1-method v1-user v1-host)
2285 (zerop (tramp-run-test2 "test" file1 file2 "-nt"))
2286 (zerop (tramp-run-test2
2287 "tramp_test_nt" file1 file2)))))))))))
2288
2289 ;; Functions implemented using the basic functions above.
2290
2291 (defun tramp-handle-file-modes (filename)
2292 "Like `file-modes' for tramp files."
2293 (with-parsed-tramp-file-name filename nil
2294 (when (file-exists-p filename)
2295 (tramp-mode-string-to-int
2296 (nth 8 (file-attributes filename))))))
2297
2298 (defun tramp-handle-file-directory-p (filename)
2299 "Like `file-directory-p' for tramp files."
2300 ;; Care must be taken that this function returns `t' for symlinks
2301 ;; pointing to directories. Surely the most obvious implementation
2302 ;; would be `test -d', but that returns false for such symlinks.
2303 ;; CCC: Stefan Monnier says that `test -d' follows symlinks. And
2304 ;; I now think he's right. So we could be using `test -d', couldn't
2305 ;; we?
2306 ;;
2307 ;; Alternatives: `cd %s', `test -d %s'
2308 (with-parsed-tramp-file-name filename nil
2309 (save-excursion
2310 (zerop
2311 (tramp-send-command-and-check
2312 multi-method method user host
2313 (format "test -d %s"
2314 (tramp-shell-quote-argument localname))
2315 t))))) ;run command in subshell
2316
2317 (defun tramp-handle-file-regular-p (filename)
2318 "Like `file-regular-p' for tramp files."
2319 (with-parsed-tramp-file-name filename nil
2320 (and (file-exists-p filename)
2321 (eq ?- (aref (nth 8 (file-attributes filename)) 0)))))
2322
2323 (defun tramp-handle-file-symlink-p (filename)
2324 "Like `file-symlink-p' for tramp files."
2325 (with-parsed-tramp-file-name filename nil
2326 (let ((x (car (file-attributes filename))))
2327 (when (stringp x)
2328 ;; When Tramp is running on VMS, then `file-name-absolute-p'
2329 ;; might do weird things.
2330 (if (file-name-absolute-p x)
2331 (tramp-make-tramp-file-name
2332 multi-method method user host x)
2333 x)))))
2334
2335 (defun tramp-handle-file-writable-p (filename)
2336 "Like `file-writable-p' for tramp files."
2337 (with-parsed-tramp-file-name filename nil
2338 (if (tramp-handle-file-exists-p filename)
2339 ;; Existing files must be writable.
2340 (zerop (tramp-run-test "-w" filename))
2341 ;; If file doesn't exist, check if directory is writable.
2342 (and (zerop (tramp-run-test
2343 "-d" (tramp-handle-file-name-directory filename)))
2344 (zerop (tramp-run-test
2345 "-w" (tramp-handle-file-name-directory filename)))))))
2346
2347 (defun tramp-handle-file-ownership-preserved-p (filename)
2348 "Like `file-ownership-preserved-p' for tramp files."
2349 (with-parsed-tramp-file-name filename nil
2350 (or (not (tramp-handle-file-exists-p filename))
2351 ;; Existing files must be writable.
2352 (zerop (tramp-run-test "-O" filename)))))
2353
2354 ;; Other file name ops.
2355
2356 ;; ;; Matthias K\e,Av\e(Bppe <mkoeppe@mail.math.uni-magdeburg.de>
2357 ;; (defun tramp-handle-directory-file-name (directory)
2358 ;; "Like `directory-file-name' for tramp files."
2359 ;; (if (and (eq (aref directory (- (length directory) 1)) ?/)
2360 ;; (not (eq (aref directory (- (length directory) 2)) ?:)))
2361 ;; (substring directory 0 (- (length directory) 1))
2362 ;; directory))
2363
2364 ;; ;; Philippe Troin <phil@fifi.org>
2365 ;; (defun tramp-handle-directory-file-name (directory)
2366 ;; "Like `directory-file-name' for tramp files."
2367 ;; (with-parsed-tramp-file-name directory nil
2368 ;; (let ((directory-length-1 (1- (length directory))))
2369 ;; (save-match-data
2370 ;; (if (and (eq (aref directory directory-length-1) ?/)
2371 ;; (eq (string-match tramp-file-name-regexp directory) 0)
2372 ;; (/= (match-end 0) directory-length-1))
2373 ;; (substring directory 0 directory-length-1)
2374 ;; directory)))))
2375
2376 (defun tramp-handle-directory-file-name (directory)
2377 "Like `directory-file-name' for tramp files."
2378 ;; If localname component of filename is "/", leave it unchanged.
2379 ;; Otherwise, remove any trailing slash from localname component.
2380 ;; Method, host, etc, are unchanged. Does it make sense to try
2381 ;; to avoid parsing the filename?
2382 (with-parsed-tramp-file-name directory nil
2383 (if (and (not (zerop (length localname)))
2384 (eq (aref localname (1- (length localname))) ?/)
2385 (not (string= localname "/")))
2386 (substring directory 0 -1)
2387 directory)))
2388
2389 ;; Directory listings.
2390
2391 (defun tramp-handle-directory-files (directory
2392 &optional full match nosort files-only)
2393 "Like `directory-files' for tramp files."
2394 (with-parsed-tramp-file-name directory nil
2395 (let (result x)
2396 (save-excursion
2397 (tramp-barf-unless-okay
2398 multi-method method user host
2399 (concat "cd " (tramp-shell-quote-argument localname))
2400 nil
2401 'file-error
2402 "tramp-handle-directory-files: couldn't `cd %s'"
2403 (tramp-shell-quote-argument localname))
2404 (tramp-send-command
2405 multi-method method user host
2406 (concat (tramp-get-ls-command multi-method method user host)
2407 " -a | cat"))
2408 (tramp-wait-for-output)
2409 (goto-char (point-max))
2410 (while (zerop (forward-line -1))
2411 (setq x (buffer-substring (point)
2412 (tramp-line-end-position)))
2413 (when (or (not match) (string-match match x))
2414 (if full
2415 (push (concat (file-name-as-directory directory)
2416 x)
2417 result)
2418 (push x result))))
2419 (tramp-send-command multi-method method user host "cd")
2420 (tramp-wait-for-output)
2421 ;; Remove non-files or non-directories if necessary. Using
2422 ;; the remote shell for this would probably be way faster.
2423 ;; Maybe something could be adapted from
2424 ;; tramp-handle-file-name-all-completions.
2425 (when files-only
2426 (let ((temp (nreverse result))
2427 item)
2428 (setq result nil)
2429 (if (equal files-only t)
2430 ;; files only
2431 (while temp
2432 (setq item (pop temp))
2433 (when (file-regular-p item)
2434 (push item result)))
2435 ;; directories only
2436 (while temp
2437 (setq item (pop temp))
2438 (when (file-directory-p item)
2439 (push item result)))))))
2440 result)))
2441
2442 ;; This function should return "foo/" for directories and "bar" for
2443 ;; files. We use `ls -ad' to get a list of files (including
2444 ;; directories), and `find . -type d \! -name . -prune' to get a list
2445 ;; of directories.
2446 (defun tramp-handle-file-name-all-completions (filename directory)
2447 "Like `file-name-all-completions' for tramp files."
2448 (with-parsed-tramp-file-name directory nil
2449 (unless (save-match-data (string-match "/" filename))
2450 (let* ((nowild tramp-completion-without-shell-p)
2451 result)
2452 (save-excursion
2453 (tramp-barf-unless-okay
2454 multi-method method user host
2455 (format "cd %s" (tramp-shell-quote-argument localname))
2456 nil 'file-error
2457 "tramp-handle-file-name-all-completions: Couldn't `cd %s'"
2458 (tramp-shell-quote-argument localname))
2459
2460 ;; Get a list of directories and files, including reliably
2461 ;; tagging the directories with a trailing '/'. Because I
2462 ;; rock. --daniel@danann.net
2463 (tramp-send-command
2464 multi-method method user host
2465 (format (concat "%s -a %s 2>/dev/null | while read f; do "
2466 "if test -d \"$f\" 2>/dev/null; "
2467 "then echo \"$f/\"; else echo \"$f\"; fi; done")
2468 (tramp-get-ls-command multi-method method user host)
2469 (if (or nowild (zerop (length filename)))
2470 ""
2471 (format "-d %s*"
2472 (tramp-shell-quote-argument filename)))))
2473
2474 ;; Now grab the output.
2475 (tramp-wait-for-output)
2476 (goto-char (point-max))
2477 (while (zerop (forward-line -1))
2478 (push (buffer-substring (point)
2479 (tramp-line-end-position))
2480 result))
2481
2482 (tramp-send-command multi-method method user host "cd")
2483 (tramp-wait-for-output)
2484
2485 ;; Return the list.
2486 (if nowild
2487 (all-completions filename (mapcar 'list result))
2488 result))))))
2489
2490
2491 ;; The following isn't needed for Emacs 20 but for 19.34?
2492 (defun tramp-handle-file-name-completion (filename directory)
2493 "Like `file-name-completion' for tramp files."
2494 (unless (tramp-tramp-file-p directory)
2495 (error
2496 "tramp-handle-file-name-completion invoked on non-tramp directory `%s'"
2497 directory))
2498 (with-parsed-tramp-file-name directory nil
2499 (try-completion
2500 filename
2501 (mapcar (lambda (x) (cons x nil))
2502 (file-name-all-completions filename directory)))))
2503
2504 ;; cp, mv and ln
2505
2506 (defun tramp-handle-add-name-to-file
2507 (filename newname &optional ok-if-already-exists)
2508 "Like `add-name-to-file' for tramp files."
2509 (with-parsed-tramp-file-name filename v1
2510 (with-parsed-tramp-file-name newname v2
2511 (let ((ln (when v1 (tramp-get-remote-ln
2512 v1-multi-method v1-method v1-user v1-host))))
2513 (unless (and v1-method v2-method v1-user v2-user v1-host v2-host
2514 (equal v1-multi-method v2-multi-method)
2515 (equal v1-method v2-method)
2516 (equal v1-user v2-user)
2517 (equal v1-host v2-host))
2518 (error "add-name-to-file: %s"
2519 "only implemented for same method, same user, same host"))
2520 (when (and (not ok-if-already-exists)
2521 (file-exists-p newname)
2522 (not (numberp ok-if-already-exists))
2523 (y-or-n-p
2524 (format
2525 "File %s already exists; make it a new name anyway? "
2526 newname)))
2527 (error "add-name-to-file: file %s already exists" newname))
2528 (tramp-barf-unless-okay
2529 v1-multi-method v1-method v1-user v1-host
2530 (format "%s %s %s" ln (tramp-shell-quote-argument v1-localname)
2531 (tramp-shell-quote-argument v2-localname))
2532 nil 'file-error
2533 "error with add-name-to-file, see buffer `%s' for details"
2534 (buffer-name))))))
2535
2536 (defun tramp-handle-copy-file
2537 (filename newname &optional ok-if-already-exists keep-date)
2538 "Like `copy-file' for tramp files."
2539 ;; Check if both files are local -- invoke normal copy-file.
2540 ;; Otherwise, use tramp from local system.
2541 (setq filename (expand-file-name filename))
2542 (setq newname (expand-file-name newname))
2543 ;; At least one file a tramp file?
2544 (if (or (tramp-tramp-file-p filename)
2545 (tramp-tramp-file-p newname))
2546 (let ((modes (file-modes filename)))
2547 (tramp-do-copy-or-rename-file
2548 'copy filename newname ok-if-already-exists keep-date)
2549 (set-file-modes newname modes))
2550 (tramp-run-real-handler
2551 'copy-file
2552 (list filename newname ok-if-already-exists keep-date))))
2553
2554 (defun tramp-handle-rename-file
2555 (filename newname &optional ok-if-already-exists)
2556 "Like `rename-file' for tramp files."
2557 ;; Check if both files are local -- invoke normal rename-file.
2558 ;; Otherwise, use tramp from local system.
2559 (setq filename (expand-file-name filename))
2560 (setq newname (expand-file-name newname))
2561 ;; At least one file a tramp file?
2562 (if (or (tramp-tramp-file-p filename)
2563 (tramp-tramp-file-p newname))
2564 (tramp-do-copy-or-rename-file
2565 'rename filename newname ok-if-already-exists)
2566 (tramp-run-real-handler 'rename-file
2567 (list filename newname ok-if-already-exists))))
2568
2569 (defun tramp-do-copy-or-rename-file
2570 (op filename newname &optional ok-if-already-exists keep-date)
2571 "Copy or rename a remote file.
2572 OP must be `copy' or `rename' and indicates the operation to perform.
2573 FILENAME specifies the file to copy or rename, NEWNAME is the name of
2574 the new file (for copy) or the new name of the file (for rename).
2575 OK-IF-ALREADY-EXISTS means don't barf if NEWNAME exists already.
2576 KEEP-DATE means to make sure that NEWNAME has the same timestamp
2577 as FILENAME.
2578
2579 This function is invoked by `tramp-handle-copy-file' and
2580 `tramp-handle-rename-file'. It is an error if OP is neither of `copy'
2581 and `rename'. FILENAME and NEWNAME must be absolute file names."
2582 (unless (memq op '(copy rename))
2583 (error "Unknown operation `%s', must be `copy' or `rename'" op))
2584 (unless ok-if-already-exists
2585 (when (file-exists-p newname)
2586 (signal 'file-already-exists
2587 (list newname))))
2588 (let ((t1 (tramp-tramp-file-p filename))
2589 (t2 (tramp-tramp-file-p newname)))
2590 ;; Check which ones of source and target are Tramp files.
2591 (cond
2592 ((and t1 t2)
2593 ;; Both are Tramp files.
2594 (with-parsed-tramp-file-name filename v1
2595 (with-parsed-tramp-file-name newname v2
2596 ;; Check if we can use a shortcut.
2597 (if (and (equal v1-multi-method v2-multi-method)
2598 (equal v1-method v2-method)
2599 (equal v1-host v2-host)
2600 (equal v1-user v2-user))
2601 ;; Shortcut: if method, host, user are the same for both
2602 ;; files, we invoke `cp' or `mv' on the remote host
2603 ;; directly.
2604 (tramp-do-copy-or-rename-file-directly
2605 op v1-multi-method v1-method v1-user v1-host
2606 v1-localname v2-localname keep-date)
2607 ;; The shortcut was not possible. So we copy the
2608 ;; file first. If the operation was `rename', we go
2609 ;; back and delete the original file (if the copy was
2610 ;; successful). The approach is simple-minded: we
2611 ;; create a new buffer, insert the contents of the
2612 ;; source file into it, then write out the buffer to
2613 ;; the target file. The advantage is that it doesn't
2614 ;; matter which filename handlers are used for the
2615 ;; source and target file.
2616
2617 ;; CCC: If both source and target are Tramp files,
2618 ;; and both are using the same copy-program, then we
2619 ;; can invoke rcp directly. Note that
2620 ;; default-directory should point to a local
2621 ;; directory if we want to invoke rcp.
2622 (tramp-do-copy-or-rename-via-buffer
2623 op filename newname keep-date)))))
2624 ((or t1 t2)
2625 ;; Use the generic method via a Tramp buffer.
2626 (tramp-do-copy-or-rename-via-buffer op filename newname keep-date))
2627 (t
2628 ;; One of them must be a Tramp file.
2629 (error "Tramp implementation says this cannot happen")))))
2630
2631 ;; CCC: implement keep-date if possible -- via touch?
2632 (defun tramp-do-copy-or-rename-via-buffer (op filename newname keep-date)
2633 "Use an Emacs buffer to copy or rename a file.
2634 First arg OP is either `copy' or `rename' and indicates the operation.
2635 FILENAME is the source file, NEWNAME the target file.
2636 KEEP-DATE is non-nil if NEWNAME should have the same timestamp as FILENAME."
2637 (let ((trampbuf (get-buffer-create "*tramp output*")))
2638 (when keep-date
2639 (tramp-message
2640 1 (concat "Warning: cannot preserve file time stamp"
2641 " with inline copying across machines")))
2642 (save-excursion
2643 (set-buffer trampbuf) (erase-buffer)
2644 (insert-file-contents-literally filename)
2645 ;; We don't want the target file to be compressed, so we let-bind
2646 ;; `jka-compr-inhibit' to t.
2647 (let ((coding-system-for-write 'binary)
2648 (jka-compr-inhibit t))
2649 (write-region (point-min) (point-max) newname)))
2650 ;; If the operation was `rename', delete the original file.
2651 (unless (eq op 'copy)
2652 (delete-file filename))))
2653
2654 (defun tramp-do-copy-or-rename-file-directly
2655 (op multi-method method user host localname1 localname2 keep-date)
2656 "Invokes `cp' or `mv' on the remote system.
2657 OP must be one of `copy' or `rename', indicating `cp' or `mv',
2658 respectively. METHOD, USER, and HOST specify the connection.
2659 LOCALNAME1 and LOCALNAME2 specify the two arguments of `cp' or `mv'.
2660 If KEEP-DATE is non-nil, preserve the time stamp when copying."
2661 ;; CCC: What happens to the timestamp when renaming?
2662 (let ((cmd (cond ((and (eq op 'copy) keep-date) "cp -f -p")
2663 ((eq op 'copy) "cp -f")
2664 ((eq op 'rename) "mv -f")
2665 (t (error
2666 "Unknown operation `%s', must be `copy' or `rename'"
2667 op)))))
2668 (save-excursion
2669 (tramp-barf-unless-okay
2670 multi-method method user host
2671 (format "%s %s %s"
2672 cmd
2673 (tramp-shell-quote-argument localname1)
2674 (tramp-shell-quote-argument localname2))
2675 nil 'file-error
2676 "Copying directly failed, see buffer `%s' for details."
2677 (buffer-name)))))
2678
2679 (defun tramp-do-copy-or-rename-file-one-local
2680 (op filename newname keep-date)
2681 "Invoke rcp program to copy.
2682 One of FILENAME and NEWNAME must be a Tramp name, the other must
2683 be a local filename. The method used must be an out-of-band method."
2684 ;; CCC
2685 )
2686
2687 ;; mkdir
2688 (defun tramp-handle-make-directory (dir &optional parents)
2689 "Like `make-directory' for tramp files."
2690 (setq dir (expand-file-name dir))
2691 (with-parsed-tramp-file-name dir nil
2692 (save-excursion
2693 (tramp-barf-unless-okay
2694 multi-method method user host
2695 (format " %s %s"
2696 (if parents "mkdir -p" "mkdir")
2697 (tramp-shell-quote-argument localname))
2698 nil 'file-error
2699 "Couldn't make directory %s" dir))))
2700
2701 ;; CCC error checking?
2702 (defun tramp-handle-delete-directory (directory)
2703 "Like `delete-directory' for tramp files."
2704 (setq directory (expand-file-name directory))
2705 (with-parsed-tramp-file-name directory nil
2706 (save-excursion
2707 (tramp-send-command
2708 multi-method method user host
2709 (format "rmdir %s ; echo ok"
2710 (tramp-shell-quote-argument localname)))
2711 (tramp-wait-for-output))))
2712
2713 (defun tramp-handle-delete-file (filename)
2714 "Like `delete-file' for tramp files."
2715 (setq filename (expand-file-name filename))
2716 (with-parsed-tramp-file-name filename nil
2717 (save-excursion
2718 (unless (zerop (tramp-send-command-and-check
2719 multi-method method user host
2720 (format "rm -f %s"
2721 (tramp-shell-quote-argument localname))))
2722 (signal 'file-error "Couldn't delete Tramp file")))))
2723
2724 ;; Dired.
2725
2726 ;; CCC: This does not seem to be enough. Something dies when
2727 ;; we try and delete two directories under TRAMP :/
2728 (defun tramp-handle-dired-recursive-delete-directory (filename)
2729 "Recursively delete the directory given.
2730 This is like `dired-recursive-delete-directory' for tramp files."
2731 (with-parsed-tramp-file-name filename nil
2732 ;; run a shell command 'rm -r <localname>'
2733 ;; Code shamelessly stolen for the dired implementation and, um, hacked :)
2734 (or (tramp-handle-file-exists-p filename)
2735 (signal
2736 'file-error
2737 (list "Removing old file name" "no such directory" filename)))
2738 ;; Which is better, -r or -R? (-r works for me <daniel@danann.net>)
2739 (tramp-send-command multi-method method user host
2740 (format "rm -r %s" (tramp-shell-quote-argument localname)))
2741 ;; Wait for the remote system to return to us...
2742 ;; This might take a while, allow it plenty of time.
2743 (tramp-wait-for-output 120)
2744 ;; Make sure that it worked...
2745 (and (tramp-handle-file-exists-p filename)
2746 (error "Failed to recusively delete %s" filename))))
2747
2748
2749 (defun tramp-handle-dired-call-process (program discard &rest arguments)
2750 "Like `dired-call-process' for tramp files."
2751 (with-parsed-tramp-file-name default-directory nil
2752 (save-excursion
2753 (tramp-barf-unless-okay
2754 multi-method method user host
2755 (format "cd %s" (tramp-shell-quote-argument localname))
2756 nil 'file-error
2757 "tramp-handle-dired-call-process: Couldn't `cd %s'"
2758 (tramp-shell-quote-argument localname))
2759 (tramp-send-command
2760 multi-method method user host
2761 (mapconcat #'tramp-shell-quote-argument (cons program arguments) " "))
2762 (tramp-wait-for-output))
2763 (unless discard
2764 (insert-buffer (tramp-get-buffer multi-method method user host)))
2765 (save-excursion
2766 (prog1
2767 (tramp-send-command-and-check multi-method method user host nil)
2768 (tramp-send-command multi-method method user host "cd")
2769 (tramp-wait-for-output)))))
2770
2771 ;; Pacify byte-compiler. The function is needed on XEmacs only. I'm
2772 ;; not sure at all that this is the right way to do it, but let's hope
2773 ;; it works for now, and wait for a guru to point out the Right Way to
2774 ;; achieve this.
2775 ;;(eval-when-compile
2776 ;; (unless (fboundp 'dired-insert-set-properties)
2777 ;; (fset 'dired-insert-set-properties 'ignore)))
2778 ;; Gerd suggests this:
2779 (eval-when-compile (require 'dired))
2780 ;; Note that dired is required at run-time, too, when it is needed.
2781 ;; It is only needed on XEmacs for the function
2782 ;; `dired-insert-set-properties'.
2783
2784 (defun tramp-handle-insert-directory
2785 (filename switches &optional wildcard full-directory-p)
2786 "Like `insert-directory' for tramp files."
2787 ;; For the moment, we assume that the remote "ls" program does not
2788 ;; grok "--dired". In the future, we should detect this on
2789 ;; connection setup.
2790 (when (string-match "^--dired\\s-+" switches)
2791 (setq switches (replace-match "" nil t switches)))
2792 (setq filename (expand-file-name filename))
2793 (with-parsed-tramp-file-name filename nil
2794 (tramp-message-for-buffer
2795 multi-method method user host 10
2796 "Inserting directory `ls %s %s', wildcard %s, fulldir %s"
2797 switches filename (if wildcard "yes" "no")
2798 (if full-directory-p "yes" "no"))
2799 (when wildcard
2800 (setq wildcard (file-name-nondirectory localname))
2801 (setq localname (file-name-directory localname)))
2802 (when (listp switches)
2803 (setq switches (mapconcat 'identity switches " ")))
2804 (unless full-directory-p
2805 (setq switches (concat "-d " switches)))
2806 (when wildcard
2807 (setq switches (concat switches " " wildcard)))
2808 (save-excursion
2809 ;; If `full-directory-p', we just say `ls -l FILENAME'.
2810 ;; Else we chdir to the parent directory, then say `ls -ld BASENAME'.
2811 (if full-directory-p
2812 (tramp-send-command
2813 multi-method method user host
2814 (format "%s %s %s"
2815 (tramp-get-ls-command multi-method method user host)
2816 switches
2817 (if wildcard
2818 localname
2819 (tramp-shell-quote-argument (concat localname ".")))))
2820 (tramp-barf-unless-okay
2821 multi-method method user host
2822 (format "cd %s" (tramp-shell-quote-argument
2823 (file-name-directory localname)))
2824 nil 'file-error
2825 "Couldn't `cd %s'"
2826 (tramp-shell-quote-argument (file-name-directory localname)))
2827 (tramp-send-command
2828 multi-method method user host
2829 (format "%s %s %s"
2830 (tramp-get-ls-command multi-method method user host)
2831 switches
2832 (if full-directory-p
2833 ;; Add "/." to make sure we got complete dir
2834 ;; listing for symlinks, too.
2835 (concat (file-name-as-directory
2836 (file-name-nondirectory localname)) ".")
2837 (file-name-nondirectory localname)))))
2838 (sit-for 1) ;needed for rsh but not ssh?
2839 (tramp-wait-for-output))
2840 ;; The following let-binding is used by code that's commented
2841 ;; out. Let's leave the let-binding in for a while to see
2842 ;; that the commented-out code is really not needed. Commenting-out
2843 ;; happened on 2003-03-13.
2844 (let ((old-pos (point)))
2845 (insert-buffer-substring
2846 (tramp-get-buffer multi-method method user host))
2847 ;; On XEmacs, we want to call (exchange-point-and-mark t), but
2848 ;; that doesn't exist on Emacs, so we use this workaround instead.
2849 ;; Since zmacs-region-stays doesn't exist in Emacs, this ought to
2850 ;; be safe. Thanks to Daniel Pittman <daniel@danann.net>.
2851 ;; (let ((zmacs-region-stays t))
2852 ;; (exchange-point-and-mark))
2853 (save-excursion
2854 (tramp-send-command multi-method method user host "cd")
2855 (tramp-wait-for-output))
2856 ;; For the time being, the XEmacs kludge is commented out.
2857 ;; Please test it on various XEmacs versions to see if it works.
2858 ;; ;; Another XEmacs specialty follows. What's the right way to do
2859 ;; ;; it?
2860 ;; (when (and (featurep 'xemacs)
2861 ;; (eq major-mode 'dired-mode))
2862 ;; (save-excursion
2863 ;; (require 'dired)
2864 ;; (dired-insert-set-properties old-pos (point))))
2865 )))
2866
2867 ;; Continuation of kluge to pacify byte-compiler.
2868 ;;(eval-when-compile
2869 ;; (when (eq (symbol-function 'dired-insert-set-properties) 'ignore)
2870 ;; (fmakunbound 'dired-insert-set-properties)))
2871
2872 ;; CCC is this the right thing to do?
2873 (defun tramp-handle-unhandled-file-name-directory (filename)
2874 "Like `unhandled-file-name-directory' for tramp files."
2875 (with-parsed-tramp-file-name filename nil
2876 (expand-file-name "~/")))
2877
2878 ;; Canonicalization of file names.
2879
2880 (defun tramp-drop-volume-letter (name)
2881 "Cut off unnecessary drive letter from file NAME.
2882 The function `tramp-handle-expand-file-name' calls `expand-file-name'
2883 locally on a remote file name. When the local system is a W32 system
2884 but the remote system is Unix, this introduces a superfluous drive
2885 letter into the file name. This function removes it.
2886
2887 Doesn't do anything if the NAME does not start with a drive letter."
2888 (if (and (> (length name) 1)
2889 (char-equal (aref name 1) ?:)
2890 (let ((c1 (aref name 0)))
2891 (or (and (>= c1 ?A) (<= c1 ?Z))
2892 (and (>= c1 ?a) (<= c1 ?z)))))
2893 (substring name 2)
2894 name))
2895
2896 (defun tramp-handle-expand-file-name (name &optional dir)
2897 "Like `expand-file-name' for tramp files.
2898 If the localname part of the given filename starts with \"/../\" then
2899 the result will be a local, non-Tramp, filename."
2900 ;; If DIR is not given, use DEFAULT-DIRECTORY or "/".
2901 (setq dir (or dir default-directory "/"))
2902 ;; Unless NAME is absolute, concat DIR and NAME.
2903 (unless (file-name-absolute-p name)
2904 (setq name (concat (file-name-as-directory dir) name)))
2905 ;; If NAME is not a tramp file, run the real handler
2906 (if (not (tramp-tramp-file-p name))
2907 (tramp-run-real-handler 'expand-file-name
2908 (list name nil))
2909 ;; Dissect NAME.
2910 (with-parsed-tramp-file-name name nil
2911 (unless (file-name-absolute-p localname)
2912 (setq localname (concat "~/" localname)))
2913 (save-excursion
2914 ;; Tilde expansion if necessary. This needs a shell which
2915 ;; groks tilde expansion! The function `tramp-find-shell' is
2916 ;; supposed to find such a shell on the remote host. Please
2917 ;; tell me about it when this doesn't work on your system.
2918 (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname)
2919 (let ((uname (match-string 1 localname))
2920 (fname (match-string 2 localname)))
2921 ;; CCC fanatic error checking?
2922 (set-buffer (tramp-get-buffer multi-method method user host))
2923 (erase-buffer)
2924 (tramp-send-command
2925 multi-method method user host
2926 (format "cd %s; pwd" uname)
2927 t)
2928 (tramp-wait-for-output)
2929 (goto-char (point-min))
2930 (setq uname (buffer-substring (point) (tramp-line-end-position)))
2931 (setq localname (concat uname fname))
2932 (erase-buffer)))
2933 ;; No tilde characters in file name, do normal
2934 ;; expand-file-name (this does "/./" and "/../"). We bind
2935 ;; directory-sep-char here for XEmacs on Windows, which
2936 ;; would otherwise use backslash.
2937 (let ((directory-sep-char ?/))
2938 (tramp-make-tramp-file-name
2939 multi-method (or method (tramp-find-default-method user host))
2940 user host
2941 (tramp-drop-volume-letter
2942 (tramp-run-real-handler 'expand-file-name
2943 (list localname)))))))))
2944
2945 ;; old version follows. it uses ".." to cross file handler
2946 ;; boundaries.
2947 ;; ;; Look if localname starts with "/../" construct. If this is
2948 ;; ;; the case, then we return a local name instead of a remote name.
2949 ;; (if (string-match "^/\\.\\./" localname)
2950 ;; (expand-file-name (substring localname 3))
2951 ;; ;; No tilde characters in file name, do normal
2952 ;; ;; expand-file-name (this does "/./" and "/../"). We bind
2953 ;; ;; directory-sep-char here for XEmacs on Windows, which
2954 ;; ;; would otherwise use backslash.
2955 ;; (let ((directory-sep-char ?/))
2956 ;; (tramp-make-tramp-file-name
2957 ;; multi-method method user host
2958 ;; (tramp-drop-volume-letter
2959 ;; (tramp-run-real-handler 'expand-file-name
2960 ;; (list localname))))))))))
2961
2962 ;; Remote commands.
2963
2964 (defun tramp-handle-shell-command (command &optional output-buffer error-buffer)
2965 "Like `shell-command' for tramp files.
2966 This will break if COMMAND prints a newline, followed by the value of
2967 `tramp-end-of-output', followed by another newline."
2968 (if (tramp-tramp-file-p default-directory)
2969 (with-parsed-tramp-file-name default-directory nil
2970 (let (status)
2971 (when (string-match "&[ \t]*\\'" command)
2972 (error "Tramp doesn't grok asynchronous shell commands, yet"))
2973 ;; (when error-buffer
2974 ;; (error "Tramp doesn't grok optional third arg ERROR-BUFFER, yet"))
2975 (save-excursion
2976 (tramp-barf-unless-okay
2977 multi-method method user host
2978 (format "cd %s" (tramp-shell-quote-argument localname))
2979 nil 'file-error
2980 "tramp-handle-shell-command: Couldn't `cd %s'"
2981 (tramp-shell-quote-argument localname))
2982 (tramp-send-command
2983 multi-method method user host
2984 (if error-buffer
2985 (format "( %s ) 2>/tmp/tramp.$$.err; tramp_old_status=$?"
2986 command)
2987 (format "%s ;tramp_old_status=$?" command)))
2988 ;; This will break if the shell command prints "/////"
2989 ;; somewhere. Let's just hope for the best...
2990 (tramp-wait-for-output))
2991 (unless output-buffer
2992 (setq output-buffer (get-buffer-create "*Shell Command Output*"))
2993 (set-buffer output-buffer)
2994 (erase-buffer))
2995 (unless (bufferp output-buffer)
2996 (setq output-buffer (current-buffer)))
2997 (set-buffer output-buffer)
2998 (insert-buffer (tramp-get-buffer multi-method method user host))
2999 (when error-buffer
3000 (save-excursion
3001 (unless (bufferp error-buffer)
3002 (setq error-buffer (get-buffer-create error-buffer)))
3003 (tramp-send-command
3004 multi-method method user host
3005 "cat /tmp/tramp.$$.err")
3006 (tramp-wait-for-output)
3007 (set-buffer error-buffer)
3008 (insert-buffer (tramp-get-buffer multi-method method user host))
3009 (tramp-send-command-and-check
3010 multi-method method user host "rm -f /tmp/tramp.$$.err")))
3011 (save-excursion
3012 (tramp-send-command multi-method method user host "cd")
3013 (tramp-wait-for-output)
3014 (tramp-send-command
3015 multi-method method user host
3016 (concat "tramp_set_exit_status $tramp_old_status;"
3017 " echo tramp_exit_status $?"))
3018 (tramp-wait-for-output)
3019 (goto-char (point-max))
3020 (unless (search-backward "tramp_exit_status " nil t)
3021 (error "Couldn't find exit status of `%s'" command))
3022 (skip-chars-forward "^ ")
3023 (setq status (read (current-buffer))))
3024 (unless (zerop (buffer-size))
3025 (display-buffer output-buffer))
3026 status))
3027 ;; The following is only executed if something strange was
3028 ;; happening. Emit a helpful message and do it anyway.
3029 (message "tramp-handle-shell-command called with non-tramp directory: `%s'"
3030 default-directory)
3031 (tramp-run-real-handler 'shell-command
3032 (list command output-buffer error-buffer))))
3033
3034 ;; File Editing.
3035
3036 (defsubst tramp-make-temp-file ()
3037 (funcall (if (fboundp 'make-temp-file) 'make-temp-file 'make-temp-name)
3038 (expand-file-name tramp-temp-name-prefix
3039 (tramp-temporary-file-directory))))
3040
3041 (defun tramp-handle-file-local-copy (filename)
3042 "Like `file-local-copy' for tramp files."
3043 (with-parsed-tramp-file-name filename nil
3044 (let ((output-buf (get-buffer-create "*tramp output*"))
3045 (tramp-buf (tramp-get-buffer multi-method method user host))
3046 (copy-program (tramp-get-method-parameter
3047 multi-method
3048 (tramp-find-method multi-method method user host)
3049 user host 'tramp-copy-program))
3050 (copy-args (tramp-get-method-parameter
3051 multi-method
3052 (tramp-find-method multi-method method user host)
3053 user host 'tramp-copy-args))
3054 ;; We used to bind the following as late as possible.
3055 ;; loc-enc and loc-dec were bound directly before the if
3056 ;; statement that checks them. But the functions
3057 ;; tramp-get-* might invoke the "are you awake" check in
3058 ;; tramp-maybe-open-connection, which is an unfortunate time
3059 ;; since we rely on the buffer contents at that spot.
3060 (rem-enc (tramp-get-remote-encoding multi-method method user host))
3061 (rem-dec (tramp-get-remote-decoding multi-method method user host))
3062 (loc-enc (tramp-get-local-encoding multi-method method user host))
3063 (loc-dec (tramp-get-local-decoding multi-method method user host))
3064 tmpfil)
3065 (unless (file-exists-p filename)
3066 (error "Cannot make local copy of non-existing file `%s'"
3067 filename))
3068 (setq tmpfil (tramp-make-temp-file))
3069 (cond (copy-program
3070 ;; The following should be changed. We need a more general
3071 ;; mechanism to parse extra host args.
3072 (when (string-match "\\([^#]*\\)#\\(.*\\)" host)
3073 (setq copy-args (cons "-p" (cons (match-string 2 host)
3074 rsh-args)))
3075 (setq host (match-string 1 host)))
3076 ;; Use rcp-like program for file transfer.
3077 (tramp-message-for-buffer
3078 multi-method method user host
3079 5 "Fetching %s to tmp file %s..." filename tmpfil)
3080 (save-excursion (set-buffer output-buf) (erase-buffer))
3081 (unless (equal
3082 0
3083 (apply #'call-process
3084 copy-program
3085 nil output-buf nil
3086 (append copy-args
3087 (list
3088 (tramp-make-copy-program-file-name
3089 user host
3090 (tramp-shell-quote-argument localname))
3091 tmpfil))))
3092 (pop-to-buffer output-buf)
3093 (error
3094 (concat "tramp-handle-file-local-copy: `%s' didn't work, "
3095 "see buffer `%s' for details")
3096 copy-program output-buf))
3097 (tramp-message-for-buffer
3098 multi-method method user host
3099 5 "Fetching %s to tmp file %s...done" filename tmpfil))
3100 ((and rem-enc rem-dec)
3101 ;; Use inline encoding for file transfer.
3102 (save-excursion
3103 ;; Following line for setting tramp-current-method,
3104 ;; tramp-current-user, tramp-current-host.
3105 (set-buffer tramp-buf)
3106 (tramp-message 5 "Encoding remote file %s..." filename)
3107 (tramp-barf-unless-okay
3108 multi-method method user host
3109 (concat rem-enc " < " (tramp-shell-quote-argument localname))
3110 nil 'file-error
3111 "Encoding remote file failed, see buffer `%s' for details"
3112 tramp-buf)
3113 ;; Remove trailing status code
3114 (goto-char (point-max))
3115 (delete-region (point) (progn (forward-line -1) (point)))
3116
3117 (tramp-message 5 "Decoding remote file %s..." filename)
3118
3119 ;; Here is where loc-enc and loc-dec used to be let-bound.
3120 (if (and (symbolp loc-dec) (fboundp loc-dec))
3121 ;; If local decoding is a function, we call it.
3122 (let ((tmpbuf (get-buffer-create " *tramp tmp*")))
3123 (set-buffer tmpbuf)
3124 (erase-buffer)
3125 (insert-buffer tramp-buf)
3126 (tramp-message-for-buffer
3127 multi-method method user host
3128 6 "Decoding remote file %s with function %s..."
3129 filename loc-dec)
3130 (set-buffer tmpbuf)
3131 ;; Douglas Gray Stephens <DGrayStephens@slb.com>
3132 ;; says that we need to strip tramp_exit_status
3133 ;; line from the output here. Go to point-max,
3134 ;; search backward for tramp_exit_status, delete
3135 ;; between point and point-max if found.
3136 (let ((coding-system-for-write 'binary))
3137 (funcall loc-dec (point-min) (point-max))
3138 (write-region (point-min) (point-max) tmpfil))
3139 (kill-buffer tmpbuf))
3140 ;; If tramp-decoding-function is not defined for this
3141 ;; method, we invoke tramp-decoding-command instead.
3142 (let ((tmpfil2 (tramp-make-temp-file)))
3143 (write-region (point-min) (point-max) tmpfil2)
3144 (tramp-message
3145 6 "Decoding remote file %s with command %s..."
3146 filename loc-dec)
3147 (tramp-call-local-coding-command
3148 loc-dec tmpfil2 tmpfil)
3149 (delete-file tmpfil2)))
3150 (tramp-message-for-buffer
3151 multi-method method user host
3152 5 "Decoding remote file %s...done" filename)))
3153
3154 (t (error "Wrong method specification for `%s'" method)))
3155 tmpfil)))
3156
3157
3158 (defun tramp-handle-insert-file-contents
3159 (filename &optional visit beg end replace)
3160 "Like `insert-file-contents' for tramp files."
3161 (barf-if-buffer-read-only)
3162 (setq filename (expand-file-name filename))
3163 (with-parsed-tramp-file-name filename nil
3164 (if (not (file-exists-p filename))
3165 (progn
3166 (when visit
3167 (setq buffer-file-name filename)
3168 (set-visited-file-modtime)
3169 (set-buffer-modified-p nil))
3170 (signal 'file-error
3171 (format "File `%s' not found on remote host" filename))
3172 (list (expand-file-name filename) 0))
3173 ;; `insert-file-contents-literally' takes care to avoid calling
3174 ;; jka-compr. By let-binding inhibit-file-name-operation, we
3175 ;; propagate that care to the file-local-copy operation.
3176 (let ((local-copy
3177 (let ((inhibit-file-name-operation
3178 (when (eq inhibit-file-name-operation
3179 'insert-file-contents)
3180 'file-local-copy)))
3181 (file-local-copy filename)))
3182 (coding-system-used nil)
3183 (result nil))
3184 (when visit
3185 (setq buffer-file-name filename)
3186 (set-visited-file-modtime)
3187 (set-buffer-modified-p nil))
3188 (tramp-message-for-buffer
3189 multi-method method user host
3190 9 "Inserting local temp file `%s'..." local-copy)
3191 (setq result (insert-file-contents local-copy nil beg end replace))
3192 ;; Now `last-coding-system-used' has right value. Remember it.
3193 (when (boundp 'last-coding-system-used)
3194 (setq coding-system-used last-coding-system-used))
3195 (tramp-message-for-buffer
3196 multi-method method user host
3197 9 "Inserting local temp file `%s'...done" local-copy)
3198 (delete-file local-copy)
3199 (when (boundp 'last-coding-system-used)
3200 (setq last-coding-system-used coding-system-used))
3201 (list (expand-file-name filename)
3202 (second result))))))
3203
3204 ;; CCC grok APPEND, LOCKNAME, CONFIRM
3205 (defun tramp-handle-write-region
3206 (start end filename &optional append visit lockname confirm)
3207 "Like `write-region' for tramp files."
3208 (unless (eq append nil)
3209 (error "Cannot append to file using tramp (`%s')" filename))
3210 (setq filename (expand-file-name filename))
3211 ;; Following part commented out because we don't know what to do about
3212 ;; file locking, and it does not appear to be a problem to ignore it.
3213 ;; Ange-ftp ignores it, too.
3214 ;; (when (and lockname (stringp lockname))
3215 ;; (setq lockname (expand-file-name lockname)))
3216 ;; (unless (or (eq lockname nil)
3217 ;; (string= lockname filename))
3218 ;; (error
3219 ;; "tramp-handle-write-region: LOCKNAME must be nil or equal FILENAME"))
3220 ;; XEmacs takes a coding system as the sevent argument, not `confirm'
3221 (when (and (not (featurep 'xemacs))
3222 confirm (file-exists-p filename))
3223 (unless (y-or-n-p (format "File %s exists; overwrite anyway? "
3224 filename))
3225 (error "File not overwritten")))
3226 (with-parsed-tramp-file-name filename nil
3227 (let ((curbuf (current-buffer))
3228 (copy-program (tramp-get-method-parameter
3229 multi-method
3230 (tramp-find-method multi-method method user host)
3231 user host 'tramp-copy-program))
3232 (copy-args (tramp-get-method-parameter
3233 multi-method
3234 (tramp-find-method multi-method method user host)
3235 user host 'tramp-copy-args))
3236 (rem-enc (tramp-get-remote-encoding multi-method method user host))
3237 (rem-dec (tramp-get-remote-decoding multi-method method user host))
3238 (loc-enc (tramp-get-local-encoding multi-method method user host))
3239 (loc-dec (tramp-get-local-decoding multi-method method user host))
3240 (trampbuf (get-buffer-create "*tramp output*"))
3241 ;; We use this to save the value of `last-coding-system-used'
3242 ;; after writing the tmp file. At the end of the function,
3243 ;; we set `last-coding-system-used' to this saved value.
3244 ;; This way, any intermediary coding systems used while
3245 ;; talking to the remote shell or suchlike won't hose this
3246 ;; variable. This approach was snarfed from ange-ftp.el.
3247 coding-system-used
3248 tmpfil)
3249 ;; Write region into a tmp file. This isn't really needed if we
3250 ;; use an encoding function, but currently we use it always
3251 ;; because this makes the logic simpler.
3252 (setq tmpfil (tramp-make-temp-file))
3253 ;; We say `no-message' here because we don't want the visited file
3254 ;; modtime data to be clobbered from the temp file. We call
3255 ;; `set-visited-file-modtime' ourselves later on.
3256 (tramp-run-real-handler
3257 'write-region
3258 (if confirm ; don't pass this arg unless defined for backward compat.
3259 (list start end tmpfil append 'no-message lockname confirm)
3260 (list start end tmpfil append 'no-message lockname)))
3261 ;; Now, `last-coding-system-used' has the right value. Remember it.
3262 (when (boundp 'last-coding-system-used)
3263 (setq coding-system-used last-coding-system-used))
3264 ;; This is a bit lengthy due to the different methods possible for
3265 ;; file transfer. First, we check whether the method uses an rcp
3266 ;; program. If so, we call it. Otherwise, both encoding and
3267 ;; decoding command must be specified. However, if the method
3268 ;; _also_ specifies an encoding function, then that is used for
3269 ;; encoding the contents of the tmp file.
3270 (cond (copy-program
3271 ;; The following should be changed. We need a more general
3272 ;; mechanism to parse extra host args.
3273 (when (string-match "\\([^#]*\\)#\\(.*\\)" host)
3274 (setq copy-args (cons "-p" (cons (match-string 2 host)
3275 rsh-args)))
3276 (setq host (match-string 1 host)))
3277
3278 ;; use rcp-like program for file transfer
3279 (let ((argl (append copy-args
3280 (list
3281 tmpfil
3282 (tramp-make-copy-program-file-name
3283 user host
3284 (tramp-shell-quote-argument localname))))))
3285 (tramp-message-for-buffer
3286 multi-method method user host
3287 6 "Writing tmp file using `%s'..." copy-program)
3288 (save-excursion (set-buffer trampbuf) (erase-buffer))
3289 (when tramp-debug-buffer
3290 (save-excursion
3291 (set-buffer (tramp-get-debug-buffer multi-method
3292 method user host))
3293 (goto-char (point-max))
3294 (tramp-insert-with-face
3295 'bold (format "$ %s %s\n" copy-program
3296 (mapconcat 'identity argl " ")))))
3297 (unless (equal 0
3298 (apply #'call-process
3299 copy-program nil trampbuf nil argl))
3300 (pop-to-buffer trampbuf)
3301 (error
3302 "Cannot write region to file `%s', command `%s' failed"
3303 filename copy-program))
3304 (tramp-message-for-buffer
3305 multi-method method user host
3306 6 "Transferring file using `%s'...done"
3307 copy-program)))
3308 ((and rem-enc rem-dec)
3309 ;; Use inline file transfer
3310 (let ((tmpbuf (get-buffer-create " *tramp file transfer*")))
3311 (save-excursion
3312 ;; Encode tmpfil into tmpbuf
3313 (tramp-message-for-buffer multi-method method user host
3314 5 "Encoding region...")
3315 (set-buffer tmpbuf)
3316 (erase-buffer)
3317 ;; Use encoding function or command.
3318 (if (and (symbolp loc-enc) (fboundp loc-enc))
3319 (progn
3320 (tramp-message-for-buffer
3321 multi-method method user host
3322 6 "Encoding region using function...")
3323 (insert-file-contents-literally tmpfil)
3324 ;; CCC. The following `let' is a workaround for
3325 ;; the base64.el that comes with pgnus-0.84. If
3326 ;; both of the following conditions are
3327 ;; satisfied, it tries to write to a local file
3328 ;; in default-directory, but at this point,
3329 ;; default-directory is remote.
3330 ;; (CALL-PROCESS-REGION can't write to remote
3331 ;; files, it seems.) The file in question is a
3332 ;; tmp file anyway.
3333 (let ((default-directory
3334 (tramp-temporary-file-directory)))
3335 (funcall loc-enc (point-min) (point-max)))
3336 (goto-char (point-max))
3337 (unless (bolp)
3338 (newline)))
3339 (tramp-message-for-buffer
3340 multi-method method user host
3341 6 "Encoding region using command `%s'..." loc-enc)
3342 (unless (equal 0 (tramp-call-local-coding-command
3343 loc-enc tmpfil t))
3344 (pop-to-buffer trampbuf)
3345 (error (concat "Cannot write to `%s', local encoding"
3346 " command `%s' failed")
3347 filename loc-enc)))
3348 ;; Send tmpbuf into remote decoding command which
3349 ;; writes to remote file. Because this happens on the
3350 ;; remote host, we cannot use the function.
3351 (tramp-message-for-buffer
3352 multi-method method user host
3353 5 "Decoding region into remote file %s..." filename)
3354 (tramp-send-command
3355 multi-method method user host
3356 (format "%s >%s <<'EOF'"
3357 rem-dec
3358 (tramp-shell-quote-argument localname)))
3359 (set-buffer tmpbuf)
3360 (tramp-message-for-buffer
3361 multi-method method user host
3362 6 "Sending data to remote host...")
3363 (tramp-send-string multi-method method user host
3364 (buffer-string))
3365 ;; wait for remote decoding to complete
3366 (tramp-message-for-buffer
3367 multi-method method user host
3368 6 "Sending end of data token...")
3369 (tramp-send-command
3370 multi-method method user host "EOF" nil t)
3371 (tramp-message-for-buffer
3372 multi-method method user host 6
3373 "Waiting for remote host to process data...")
3374 (set-buffer (tramp-get-buffer multi-method method user host))
3375 (tramp-wait-for-output)
3376 (tramp-barf-unless-okay
3377 multi-method method user host nil nil 'file-error
3378 (concat "Couldn't write region to `%s',"
3379 " decode using `%s' failed")
3380 filename rem-dec)
3381 (tramp-message 5 "Decoding region into remote file %s...done"
3382 filename)
3383 (kill-buffer tmpbuf))))
3384 (t
3385 (error
3386 (concat "Method `%s' should specify both encoding and "
3387 "decoding command or an rcp program")
3388 method)))
3389 (delete-file tmpfil)
3390 (unless (equal curbuf (current-buffer))
3391 (error "Buffer has changed from `%s' to `%s'"
3392 curbuf (current-buffer)))
3393 (when (eq visit t)
3394 (set-visited-file-modtime))
3395 ;; Make `last-coding-system-used' have the right value.
3396 (when (boundp 'last-coding-system-used)
3397 (setq last-coding-system-used coding-system-used))
3398 (when (or (eq visit t)
3399 (eq visit nil)
3400 (stringp visit))
3401 (message "Wrote %s" filename)))))
3402
3403 ;; Call down to the real handler.
3404 ;; Because EFS does not play nicely with TRAMP (both systems match a
3405 ;; TRAMP file name) it is needed to disable efs as well as tramp for the
3406 ;; operation.
3407 ;;
3408 ;; Other than that, this is the canon file-handler code that the doco
3409 ;; says should be used here. Which is nice.
3410 ;;
3411 ;; Under XEmacs current, EFS also hooks in as
3412 ;; efs-sifn-handler-function to handle any filename with environment
3413 ;; variables. This has two implications:
3414 ;; 1) That EFS may not be completely dead (yet) for TRAMP filenames
3415 ;; 2) That TRAMP might want to do the same thing.
3416 ;; Details as they come in.
3417 ;;
3418 ;; Daniel Pittman <daniel@danann.net>
3419
3420 ;; (defun tramp-run-real-handler (operation args)
3421 ;; "Invoke normal file name handler for OPERATION.
3422 ;; This inhibits EFS and Ange-FTP, too, because they conflict with tramp.
3423 ;; First arg specifies the OPERATION, remaining ARGS are passed to the
3424 ;; OPERATION."
3425 ;; (let ((inhibit-file-name-handlers
3426 ;; (list 'tramp-file-name-handler
3427 ;; 'efs-file-handler-function
3428 ;; 'ange-ftp-hook-function
3429 ;; (and (eq inhibit-file-name-operation operation)
3430 ;; inhibit-file-name-handlers)))
3431 ;; (inhibit-file-name-operation operation))
3432 ;; (apply operation args)))
3433
3434 (defun tramp-run-real-handler (operation args)
3435 "Invoke normal file name handler for OPERATION.
3436 First arg specifies the OPERATION, second arg is a list of arguments to
3437 pass to the OPERATION."
3438 (let* ((inhibit-file-name-handlers
3439 `(tramp-file-name-handler
3440 tramp-completion-file-name-handler
3441 cygwin-mount-name-hook-function
3442 cygwin-mount-map-drive-hook-function
3443 .
3444 ,(and (eq inhibit-file-name-operation operation)
3445 inhibit-file-name-handlers)))
3446 (inhibit-file-name-operation operation))
3447 (apply operation args)))
3448
3449 ;; This function is used from `tramp-completion-file-name-handler' functions
3450 ;; only, if `tramp-completion-mode' is true. But this cannot be checked here
3451 ;; because the check is based on a full filename, not available for all
3452 ;; basic I/O operations.
3453 (defun tramp-completion-run-real-handler (operation args)
3454 "Invoke `tramp-file-name-handler' for OPERATION.
3455 First arg specifies the OPERATION, second arg is a list of arguments to
3456 pass to the OPERATION."
3457 (let* ((inhibit-file-name-handlers
3458 `(tramp-completion-file-name-handler
3459 cygwin-mount-name-hook-function
3460 cygwin-mount-map-drive-hook-function
3461 .
3462 ,(and (eq inhibit-file-name-operation operation)
3463 inhibit-file-name-handlers)))
3464 (inhibit-file-name-operation operation))
3465 (apply operation args)))
3466
3467 ;; We handle here all file primitives. Most of them have the file
3468 ;; name as first parameter; nevertheless we check for them explicitly
3469 ;; in order to be be signalled if a new primitive appears. This
3470 ;; scenario is needed because there isn't a way to decide by
3471 ;; syntactical means whether a foreign method must be called. It would
3472 ;; ease the live if `file-name-handler-alist' would support a decision
3473 ;; function as well but regexp only.
3474 (defun tramp-file-name-for-operation (operation &rest args)
3475 "Return file name related to OPERATION file primitive.
3476 ARGS are the arguments OPERATION has been called with."
3477 (cond
3478 ; FILE resp DIRECTORY
3479 ((member operation
3480 (list 'access-file 'byte-compiler-base-file-name 'delete-directory
3481 'delete-file 'diff-latest-backup-file 'directory-file-name
3482 'directory-files 'directory-files-and-attributes
3483 'dired-compress-file 'dired-uncache
3484 'file-accessible-directory-p 'file-attributes
3485 'file-directory-p 'file-executable-p 'file-exists-p
3486 'file-local-copy 'file-modes 'file-name-as-directory
3487 'file-name-directory 'file-name-nondirectory
3488 'file-name-sans-versions 'file-ownership-preserved-p
3489 'file-readable-p 'file-regular-p 'file-symlink-p
3490 'file-truename 'file-writable-p 'find-backup-file-name
3491 'find-file-noselect 'get-file-buffer 'insert-directory
3492 'insert-file-contents 'load 'make-directory
3493 'make-directory-internal 'set-file-modes
3494 'substitute-in-file-name 'unhandled-file-name-directory
3495 'vc-registered
3496 ; XEmacs only
3497 'abbreviate-file-name 'create-file-buffer
3498 'dired-file-modtime 'dired-make-compressed-filename
3499 'dired-recursive-delete-directory 'dired-set-file-modtime
3500 'dired-shell-unhandle-file-name 'dired-uucode-file
3501 'insert-file-contents-literally 'recover-file
3502 'vm-imap-check-mail 'vm-pop-check-mail 'vm-spool-check-mail))
3503 (if (file-name-absolute-p (nth 0 args))
3504 (nth 0 args)
3505 (expand-file-name (nth 0 args))))
3506 ; FILE DIRECTORY resp FILE1 FILE2
3507 ((member operation
3508 (list 'add-name-to-file 'copy-file 'expand-file-name
3509 'file-name-all-completions 'file-name-completion
3510 'file-newer-than-file-p 'make-symbolic-link 'rename-file
3511 ; XEmacs only
3512 'dired-make-relative-symlink
3513 'vm-imap-move-mail 'vm-pop-move-mail 'vm-spool-move-mail))
3514 (save-match-data
3515 (cond
3516 ((string-match tramp-file-name-regexp (nth 0 args)) (nth 0 args))
3517 ((string-match tramp-file-name-regexp (nth 1 args)) (nth 1 args))
3518 (t (buffer-file-name (current-buffer))))))
3519 ; START END FILE
3520 ((eq operation 'write-region)
3521 (nth 2 args))
3522 ; BUF
3523 ((member operation
3524 (list 'set-visited-file-modtime 'verify-visited-file-modtime
3525 ; XEmacs only
3526 'backup-buffer))
3527 (buffer-file-name
3528 (if (bufferp (nth 0 args)) (nth 0 args) (current-buffer))))
3529 ; COMMAND
3530 ((member operation
3531 (list 'dired-call-process 'shell-command
3532 ; XEmacs only
3533 'dired-print-file 'dired-shell-call-process))
3534 default-directory)
3535 ; unknown file primitive
3536 (t (error "unknown file I/O primitive: %s" operation))))
3537
3538 (defun tramp-find-foreign-file-name-handler (filename)
3539 "Return foreign file name handler if exists."
3540 (when (tramp-tramp-file-p filename)
3541 (let (elt
3542 res
3543 (handler-alist tramp-foreign-file-name-handler-alist))
3544 (while handler-alist
3545 (setq elt (car handler-alist)
3546 handler-alist (cdr handler-alist))
3547 (when (funcall (car elt) filename)
3548 (setq handler-alist nil)
3549 (setq res (cdr elt))))
3550 res)))
3551
3552 ;; Main function.
3553 ;;;###autoload
3554 (defun tramp-file-name-handler (operation &rest args)
3555 "Invoke Tramp file name handler.
3556 Falls back to normal file name handler if no tramp file name handler exists."
3557 (save-match-data
3558 (let* ((filename (apply 'tramp-file-name-for-operation operation args))
3559 (foreign (tramp-find-foreign-file-name-handler filename)))
3560 (cond
3561 (foreign (apply foreign operation args))
3562 (t (tramp-run-real-handler operation args))))))
3563
3564 ;;;###autoload
3565 (put 'tramp-file-name-handler 'file-remote-p t) ;for file-remote-p
3566
3567 (defun tramp-sh-file-name-handler (operation &rest args)
3568 "Invoke remote-shell Tramp file name handler.
3569 Fall back to normal file name handler if no Tramp handler exists."
3570 (save-match-data
3571 (let ((fn (assoc operation tramp-file-name-handler-alist)))
3572 (if fn
3573 (apply (cdr fn) args)
3574 (tramp-run-real-handler operation args)))))
3575
3576 ;;;###autoload
3577 (defun tramp-completion-file-name-handler (operation &rest args)
3578 "Invoke tramp file name completion handler.
3579 Falls back to normal file name handler if no tramp file name handler exists."
3580 ;; (setq tramp-debug-buffer t)
3581 ;; (tramp-message 1 "%s %s" operation args)
3582 ;; (tramp-message 1 "%s %s\n%s"
3583 ;; operation args (with-output-to-string (backtrace)))
3584 (let ((fn (assoc operation tramp-completion-file-name-handler-alist)))
3585 (if fn
3586 (save-match-data (apply (cdr fn) args))
3587 (tramp-completion-run-real-handler operation args))))
3588
3589 ;;;###autoload
3590 (put 'tramp-completion-file-name-handler 'safe-magic t)
3591
3592 ;; Register in file name handler alist
3593 ;;;###autoload
3594 (add-to-list 'file-name-handler-alist
3595 (cons tramp-file-name-regexp 'tramp-file-name-handler))
3596 (add-to-list 'file-name-handler-alist
3597 (cons tramp-completion-file-name-regexp
3598 'tramp-completion-file-name-handler))
3599
3600 (defun tramp-repair-jka-compr ()
3601 "If jka-compr is already loaded, move it to the front of
3602 `file-name-handler-alist'. On Emacs 21.4 or so this will not be
3603 necessary anymore."
3604 (let ((jka (rassoc 'jka-compr-handler file-name-handler-alist)))
3605 (when jka
3606 (setq file-name-handler-alist
3607 (cons jka (delete jka file-name-handler-alist))))))
3608 (tramp-repair-jka-compr)
3609
3610
3611 ;;; Interactions with other packages:
3612
3613 ;; -- complete.el --
3614
3615 ;; This function contributed by Ed Sabol
3616 (defun tramp-handle-expand-many-files (name)
3617 "Like `PC-expand-many-files' for tramp files."
3618 (with-parsed-tramp-file-name name nil
3619 (save-match-data
3620 (if (or (string-match "\\*" name)
3621 (string-match "\\?" name)
3622 (string-match "\\[.*\\]" name))
3623 (save-excursion
3624 (let (bufstr)
3625 ;; CCC: To do it right, we should quote certain characters
3626 ;; in the file name, but since the echo command is going to
3627 ;; break anyway when there are spaces in the file names, we
3628 ;; don't bother.
3629 ;;-(let ((comint-file-name-quote-list
3630 ;;- (set-difference tramp-file-name-quote-list
3631 ;;- '(?\* ?\? ?[ ?]))))
3632 ;;- (tramp-send-command
3633 ;;- multi-method method user host
3634 ;;- (format "echo %s" (comint-quote-filename localname)))
3635 ;;- (tramp-wait-for-output))
3636 (tramp-send-command multi-method method user host
3637 (format "echo %s" localname))
3638 (tramp-wait-for-output)
3639 (setq bufstr (buffer-substring (point-min)
3640 (tramp-line-end-position)))
3641 (goto-char (point-min))
3642 (if (string-equal localname bufstr)
3643 nil
3644 (insert "(\"")
3645 (while (search-forward " " nil t)
3646 (delete-backward-char 1)
3647 (insert "\" \""))
3648 (goto-char (point-max))
3649 (delete-backward-char 1)
3650 (insert "\")")
3651 (goto-char (point-min))
3652 (mapcar
3653 (function (lambda (x)
3654 (tramp-make-tramp-file-name multi-method method
3655 user host x)))
3656 (read (current-buffer))))))
3657 (list (tramp-handle-expand-file-name name))))))
3658
3659 ;; Check for complete.el and override PC-expand-many-files if appropriate.
3660 (eval-when-compile
3661 (defun tramp-save-PC-expand-many-files (name))); avoid compiler warning
3662
3663 (defun tramp-setup-complete ()
3664 (fset 'tramp-save-PC-expand-many-files
3665 (symbol-function 'PC-expand-many-files))
3666 (defun PC-expand-many-files (name)
3667 (if (tramp-tramp-file-p name)
3668 (tramp-handle-expand-many-files name)
3669 (tramp-save-PC-expand-many-files name))))
3670
3671 ;; Why isn't eval-after-load sufficient?
3672 (if (fboundp 'PC-expand-many-files)
3673 (tramp-setup-complete)
3674 (eval-after-load "complete" '(tramp-setup-complete)))
3675
3676 ;;; File name handler functions for completion mode
3677
3678 ;; Necessary because `tramp-file-name-regexp-unified' and
3679 ;; `tramp-completion-file-name-regexp-unified' aren't different.
3680 ;; If nil, `tramp-completion-run-real-handler' is called (i.e. forwarding to
3681 ;; `tramp-file-name-handler'). Otherwise, it takes `tramp-run-real-handler'.
3682 ;; Using `last-input-event' is a little bit risky, because completing a file
3683 ;; might require loading other files, like "~/.netrc", and for them it
3684 ;; shouldn't be decided based on that variable. On the other hand, those files
3685 ;; shouldn't have partial tramp file name syntax. Maybe another variable should
3686 ;; be introduced overwriting this check in such cases. Or we change tramp
3687 ;; file name syntax in order to avoid ambiguities, like in XEmacs ...
3688 ;; In case of XEmacs it can be always true (and wouldn't be necessary).
3689 (defun tramp-completion-mode (file)
3690 "Checks whether method / user name / host name completion is active."
3691 (cond
3692 ((featurep 'xemacs) t)
3693 ((string-match "^/.*:.*:$" file) nil)
3694 ((string-match
3695 (concat tramp-prefix-regexp
3696 "\\(" tramp-method-regexp "\\)" tramp-postfix-single-method-regexp "$")
3697 file)
3698 (member (match-string 1 file) (mapcar 'car tramp-methods)))
3699 ((or (equal last-input-event 'tab)
3700 (and (integerp last-input-event)
3701 (not (event-modifiers last-input-event))
3702 (or (char-equal last-input-event ?\?)
3703 (char-equal last-input-event ?\t) ; handled by 'tab already?
3704 (char-equal last-input-event ?\ ))))
3705 t)))
3706
3707 (defun tramp-completion-handle-file-exists-p (filename)
3708 "Like `file-exists-p' for tramp files."
3709 (if (tramp-completion-mode filename)
3710 (tramp-run-real-handler
3711 'file-exists-p (list filename))
3712 (tramp-completion-run-real-handler
3713 'file-exists-p (list filename))))
3714
3715 ;; Localname manipulation in case of partial TRAMP file names.
3716 (defun tramp-completion-handle-file-name-directory (file)
3717 "Like `file-name-directory' but aware of TRAMP files."
3718 (if (tramp-completion-mode file)
3719 "/"
3720 (tramp-completion-run-real-handler
3721 'file-name-directory (list file))))
3722
3723 ;; Localname manipulation in case of partial TRAMP file names.
3724 (defun tramp-completion-handle-file-name-nondirectory (file)
3725 "Like `file-name-nondirectory' but aware of TRAMP files."
3726 (substring
3727 file (length (tramp-completion-handle-file-name-directory file))))
3728
3729 ;; Method, host name and user name completion.
3730 ;; `tramp-completion-dissect-file-name' returns a list of
3731 ;; tramp-file-name structures. For all of them we return possible completions.
3732 (defun tramp-completion-handle-file-name-all-completions (filename directory)
3733 "Like `file-name-all-completions' for partial tramp files."
3734
3735 (let*
3736 ((fullname (concat directory filename))
3737 ;; local files
3738 (result
3739 (if (tramp-completion-mode fullname)
3740 (tramp-run-real-handler
3741 'file-name-all-completions (list filename directory))
3742 (tramp-completion-run-real-handler
3743 'file-name-all-completions (list filename directory))))
3744 ;; possible completion structures
3745 (v (tramp-completion-dissect-file-name fullname)))
3746
3747 (while v
3748 (let* ((car (car v))
3749 (multi-method (tramp-file-name-multi-method car))
3750 (method (tramp-file-name-method car))
3751 (user (tramp-file-name-user car))
3752 (host (tramp-file-name-host car))
3753 (localname (tramp-file-name-localname car))
3754 (m (tramp-find-method multi-method method user host))
3755 (tramp-current-user user) ; see `tramp-parse-passwd'
3756 all-user-hosts)
3757
3758 (unless (or multi-method ;; Not handled (yet).
3759 localname) ;; Nothing to complete
3760
3761 (if (or user host)
3762
3763 ;; Method dependent user / host combinations
3764 (progn
3765 (mapcar
3766 (lambda (x)
3767 (setq all-user-hosts
3768 (append all-user-hosts
3769 (funcall (nth 0 x) (nth 1 x)))))
3770 (tramp-get-completion-function m))
3771
3772 (setq result (append result
3773 (mapcar
3774 (lambda (x)
3775 (tramp-get-completion-user-host
3776 method user host (nth 0 x) (nth 1 x)))
3777 (delq nil all-user-hosts)))))
3778
3779 ;; Possible methods
3780 (setq result
3781 (append result (tramp-get-completion-methods m)))))
3782
3783 (setq v (delq car v))))
3784
3785 ;;; unify list, remove nil elements
3786 (let (result1)
3787 (while result
3788 (let ((car (car result)))
3789 (when car (add-to-list 'result1 car))
3790 (setq result (delq car result))))
3791
3792 result1)))
3793
3794 ;; Method, host name and user name completion for a file.
3795 (defun tramp-completion-handle-file-name-completion (filename directory)
3796 "Like `file-name-completion' for tramp files."
3797 (try-completion filename
3798 (mapcar 'list (file-name-all-completions filename directory))))
3799
3800 ;; I misuse a little bit the tramp-file-name structure in order to handle
3801 ;; completion possibilities for partial methods / user names / host names.
3802 ;; Return value is a list of tramp-file-name structures according to possible
3803 ;; completions. If "multi-method" or "localname" is non-nil it means there
3804 ;; shouldn't be a completion anymore.
3805
3806 ;; Expected results:
3807
3808 ;; "/x" "/[x" "/x@" "/[x@" "/x@y" "/[x@y"
3809 ;; [nil nil nil "x" nil] [nil nil "x" nil nil] [nil nil "x" "y" nil]
3810 ;; [nil nil "x" nil nil]
3811 ;; [nil "x" nil nil nil]
3812
3813 ;; "/x:" "/x:y" "/x:y:"
3814 ;; [nil nil nil "x" ""] [nil nil nil "x" "y"] [nil "x" nil "y" ""]
3815 ;; "/[x/" "/[x/y"
3816 ;; [nil "x" nil "" nil] [nil "x" nil "y" nil]
3817 ;; [nil "x" "" nil nil] [nil "x" "y" nil nil]
3818
3819 ;; "/x:y@" "/x:y@z" "/x:y@z:"
3820 ;; [nil nil nil "x" "y@"] [nil nil nil "x" "y@z"] [nil "x" "y" "z" ""]
3821 ;; "/[x/y@" "/[x/y@z"
3822 ;; [nil "x" nil "y" nil] [nil "x" "y" "z" nil]
3823 (defun tramp-completion-dissect-file-name (name)
3824 "Returns a list of `tramp-file-name' structures.
3825 They are collected by `tramp-completion-dissect-file-name1'."
3826
3827 (let* ((result)
3828 (x-nil "\\|\\(\\)")
3829 ;; "/method" "/[method"
3830 (tramp-completion-file-name-structure1
3831 (list (concat tramp-prefix-regexp "\\(" tramp-method-regexp x-nil "\\)$")
3832 1 nil nil nil))
3833 ;; "/user" "/[user"
3834 (tramp-completion-file-name-structure2
3835 (list (concat tramp-prefix-regexp "\\(" tramp-user-regexp x-nil "\\)$")
3836 nil 1 nil nil))
3837 ;; "/host" "/[host"
3838 (tramp-completion-file-name-structure3
3839 (list (concat tramp-prefix-regexp "\\(" tramp-host-regexp x-nil "\\)$")
3840 nil nil 1 nil))
3841 ;; "/user@host" "/[user@host"
3842 (tramp-completion-file-name-structure4
3843 (list (concat tramp-prefix-regexp
3844 "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp
3845 "\\(" tramp-host-regexp x-nil "\\)$")
3846 nil 1 2 nil))
3847 ;; "/method:user" "/[method/user"
3848 (tramp-completion-file-name-structure5
3849 (list (concat tramp-prefix-regexp
3850 "\\(" tramp-method-regexp "\\)" tramp-postfix-single-method-regexp
3851 "\\(" tramp-user-regexp x-nil "\\)$")
3852 1 2 nil nil))
3853 ;; "/method:host" "/[method/host"
3854 (tramp-completion-file-name-structure6
3855 (list (concat tramp-prefix-regexp
3856 "\\(" tramp-method-regexp "\\)" tramp-postfix-single-method-regexp
3857 "\\(" tramp-host-regexp x-nil "\\)$")
3858 1 nil 2 nil))
3859 ;; "/method:user@host" "/[method/user@host"
3860 (tramp-completion-file-name-structure7
3861 (list (concat tramp-prefix-regexp
3862 "\\(" tramp-method-regexp "\\)" tramp-postfix-single-method-regexp
3863 "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp
3864 "\\(" tramp-host-regexp x-nil "\\)$")
3865 1 2 3 nil)))
3866
3867 (mapcar (lambda (regexp)
3868 (add-to-list 'result
3869 (tramp-completion-dissect-file-name1 regexp name)))
3870 (list
3871 tramp-completion-file-name-structure1
3872 tramp-completion-file-name-structure2
3873 tramp-completion-file-name-structure3
3874 tramp-completion-file-name-structure4
3875 tramp-completion-file-name-structure5
3876 tramp-completion-file-name-structure6
3877 tramp-completion-file-name-structure7
3878 tramp-file-name-structure))
3879
3880 (delq nil result)))
3881
3882 (defun tramp-completion-dissect-file-name1 (structure name)
3883 "Returns a `tramp-file-name' structure matching STRUCTURE.
3884 The structure consists of multi-method, remote method, remote user,
3885 remote host and localname (filename on remote host)."
3886
3887 (let (method)
3888 (save-match-data
3889 (when (string-match (nth 0 structure) name)
3890 (setq method (and (nth 1 structure)
3891 (match-string (nth 1 structure) name)))
3892 (if (and method (member method tramp-multi-methods))
3893 ;; Not handled (yet).
3894 (make-tramp-file-name
3895 :multi-method method
3896 :method nil
3897 :user nil
3898 :host nil
3899 :localname nil)
3900 (let ((user (and (nth 2 structure)
3901 (match-string (nth 2 structure) name)))
3902 (host (and (nth 3 structure)
3903 (match-string (nth 3 structure) name)))
3904 (localname (and (nth 4 structure)
3905 (match-string (nth 4 structure) name))))
3906 (make-tramp-file-name
3907 :multi-method nil
3908 :method method
3909 :user user
3910 :host host
3911 :localname localname)))))))
3912
3913 ;; This function returns all possible method completions, adding the
3914 ;; trailing method delimeter.
3915 (defun tramp-get-completion-methods (partial-method)
3916 "Returns all method completions for PARTIAL-METHOD."
3917 (mapcar
3918 (lambda (method)
3919 (and method
3920 (string-match (concat "^" (regexp-quote partial-method)) method)
3921 ;; we must remove leading "/".
3922 (substring (tramp-make-tramp-file-name nil method nil nil nil) 1)))
3923 (delete "multi" (mapcar 'car tramp-methods))))
3924
3925 ;; Compares partial user and host names with possible completions.
3926 (defun tramp-get-completion-user-host (method partial-user partial-host user host)
3927 "Returns the most expanded string for user and host name completion.
3928 PARTIAL-USER must match USER, PARTIAL-HOST must match HOST."
3929 (cond
3930
3931 ((and partial-user partial-host)
3932 (if (and host
3933 (string-match (concat "^" (regexp-quote partial-host)) host)
3934 (string-equal partial-user (or user partial-user)))
3935 (setq user partial-user)
3936 (setq user nil
3937 host nil)))
3938
3939 (partial-user
3940 (setq host nil)
3941 (unless
3942 (and user (string-match (concat "^" (regexp-quote partial-user)) user))
3943 (setq user nil)))
3944
3945 (partial-host
3946 (setq user nil)
3947 (unless
3948 (and host (string-match (concat "^" (regexp-quote partial-host)) host))
3949 (setq host nil)))
3950
3951 (t (setq user nil
3952 host nil)))
3953
3954 (unless (zerop (+ (length user) (length host)))
3955 ;; we must remove leading "/".
3956 (substring (tramp-make-tramp-file-name nil method user host nil) 1)))
3957
3958 (defun tramp-parse-rhosts (filename)
3959 "Return a list of (user host) tuples allowed to access.
3960 Either user or host may be nil."
3961
3962 (let (res)
3963 (when (file-readable-p filename)
3964 (with-temp-buffer
3965 (insert-file-contents filename)
3966 (goto-char (point-min))
3967 (while (not (eobp))
3968 (push (tramp-parse-rhosts-group) res))))
3969 res))
3970
3971 ;; Taken from gnus/netrc.el
3972 (eval-and-compile
3973 (defalias 'tramp-point-at-eol
3974 (if (fboundp 'point-at-eol)
3975 'point-at-eol
3976 'line-end-position)))
3977
3978 (defun tramp-parse-rhosts-group ()
3979 "Return a (user host) tuple allowed to access.
3980 Either user or host may be nil."
3981
3982 (let ((result)
3983 (regexp
3984 (concat
3985 "^\\(" tramp-host-regexp "\\)"
3986 "\\([ \t]+" "\\(" tramp-user-regexp "\\)" "\\)?")))
3987
3988 (narrow-to-region (point) (tramp-point-at-eol))
3989 (when (re-search-forward regexp nil t)
3990 (setq result (append (list (match-string 3) (match-string 1)))))
3991 (widen)
3992 (forward-line 1)
3993 result))
3994
3995 (defun tramp-parse-shosts (filename)
3996 "Return a list of (user host) tuples allowed to access.
3997 User is always nil."
3998
3999 (let (res)
4000 (when (file-readable-p filename)
4001 (with-temp-buffer
4002 (insert-file-contents filename)
4003 (goto-char (point-min))
4004 (while (not (eobp))
4005 (push (tramp-parse-shosts-group) res))))
4006 res))
4007
4008 (defun tramp-parse-shosts-group ()
4009 "Return a (user host) tuple allowed to access.
4010 User is always nil."
4011
4012 (let ((result)
4013 (regexp (concat "^\\(" tramp-host-regexp "\\)")))
4014
4015 (narrow-to-region (point) (tramp-point-at-eol))
4016 (when (re-search-forward regexp nil t)
4017 (setq result (list nil (match-string 1))))
4018 (widen)
4019 (or
4020 (> (skip-chars-forward ",") 0)
4021 (forward-line 1))
4022 result))
4023
4024 (defun tramp-parse-sconfig (filename)
4025 "Return a list of (user host) tuples allowed to access.
4026 User is always nil."
4027
4028 (let (res)
4029 (when (file-readable-p filename)
4030 (with-temp-buffer
4031 (insert-file-contents filename)
4032 (goto-char (point-min))
4033 (while (not (eobp))
4034 (push (tramp-parse-sconfig-group) res))))
4035 res))
4036
4037 (defun tramp-parse-sconfig-group ()
4038 "Return a (user host) tuple allowed to access.
4039 User is always nil."
4040
4041 (let ((result)
4042 (regexp (concat "^[ \t]*Host[ \t]+" "\\(" tramp-host-regexp "\\)")))
4043
4044 (narrow-to-region (point) (tramp-point-at-eol))
4045 (when (re-search-forward regexp nil t)
4046 (setq result (list nil (match-string 1))))
4047 (widen)
4048 (or
4049 (> (skip-chars-forward ",") 0)
4050 (forward-line 1))
4051 result))
4052
4053 (defun tramp-parse-hosts (filename)
4054 "Return a list of (user host) tuples allowed to access.
4055 User is always nil."
4056
4057 (let (res)
4058 (when (file-readable-p filename)
4059 (with-temp-buffer
4060 (insert-file-contents filename)
4061 (goto-char (point-min))
4062 (while (not (eobp))
4063 (push (tramp-parse-hosts-group) res))))
4064 res))
4065
4066 (defun tramp-parse-hosts-group ()
4067 "Return a (user host) tuple allowed to access.
4068 User is always nil."
4069
4070 (let ((result)
4071 (regexp (concat "^\\(" tramp-host-regexp "\\)")))
4072
4073 (narrow-to-region (point) (tramp-point-at-eol))
4074 (when (re-search-forward regexp nil t)
4075 (unless (char-equal (or (char-after) ?\n) ?:) ; no IPv6
4076 (setq result (list nil (match-string 1)))))
4077 (widen)
4078 (or
4079 (> (skip-chars-forward " \t") 0)
4080 (forward-line 1))
4081 result))
4082
4083 ;; For su-alike methods it would be desirable to return "root@localhost"
4084 ;; as default. Unfortunately, we have no information whether any user name
4085 ;; has been typed already. So we (mis-)use tramp-current-user as indication,
4086 ;; assuming it is set in `tramp-completion-handle-file-name-all-completions'.
4087 (defun tramp-parse-passwd (filename)
4088 "Return a list of (user host) tuples allowed to access.
4089 Host is always \"localhost\"."
4090
4091 (let (res)
4092 (if (zerop (length tramp-current-user))
4093 '(("root" nil))
4094 (when (file-readable-p filename)
4095 (with-temp-buffer
4096 (insert-file-contents filename)
4097 (goto-char (point-min))
4098 (while (not (eobp))
4099 (push (tramp-parse-passwd-group) res))))
4100 res)))
4101
4102 (defun tramp-parse-passwd-group ()
4103 "Return a (user host) tuple allowed to access.
4104 Host is always \"localhost\"."
4105
4106 (let ((result)
4107 (regexp (concat "^\\(" tramp-user-regexp "\\):")))
4108
4109 (narrow-to-region (point) (tramp-point-at-eol))
4110 (when (re-search-forward regexp nil t)
4111 (setq result (list (match-string 1) "localhost")))
4112 (widen)
4113 (forward-line 1)
4114 result))
4115
4116 (defun tramp-parse-netrc (filename)
4117 "Return a list of (user host) tuples allowed to access.
4118 User may be nil."
4119
4120 (let (res)
4121 (when (file-readable-p filename)
4122 (with-temp-buffer
4123 (insert-file-contents filename)
4124 (goto-char (point-min))
4125 (while (not (eobp))
4126 (push (tramp-parse-netrc-group) res))))
4127 res))
4128
4129 (defun tramp-parse-netrc-group ()
4130 "Return a (user host) tuple allowed to access.
4131 User may be nil."
4132
4133 (let ((result)
4134 (regexp
4135 (concat
4136 "^[ \t]*machine[ \t]+" "\\(" tramp-host-regexp "\\)"
4137 "\\([ \t]+login[ \t]+" "\\(" tramp-user-regexp "\\)" "\\)?")))
4138
4139 (narrow-to-region (point) (tramp-point-at-eol))
4140 (when (re-search-forward regexp nil t)
4141 (setq result (list (match-string 3) (match-string 1))))
4142 (widen)
4143 (forward-line 1)
4144 result))
4145
4146 (defun tramp-completion-handle-expand-file-name (name &optional dir)
4147 "Like `expand-file-name' for tramp files."
4148 (let ((fullname (concat (or dir default-directory) name)))
4149 (tramp-drop-volume-letter
4150 (if (tramp-completion-mode fullname)
4151 (tramp-run-real-handler
4152 'expand-file-name (list name dir))
4153 (tramp-completion-run-real-handler
4154 'expand-file-name (list name dir))))))
4155
4156 ;;; Internal Functions:
4157
4158 (defun tramp-set-auto-save ()
4159 (when (and (buffer-file-name)
4160 (tramp-tramp-file-p (buffer-file-name))
4161 auto-save-default)
4162 (auto-save-mode 1)))
4163 (add-hook 'find-file-hooks 'tramp-set-auto-save t)
4164
4165 (defun tramp-run-test (switch filename)
4166 "Run `test' on the remote system, given a SWITCH and a FILENAME.
4167 Returns the exit code of the `test' program."
4168 (let ((v (tramp-dissect-file-name filename)))
4169 (save-excursion
4170 (tramp-send-command-and-check
4171 (tramp-file-name-multi-method v) (tramp-file-name-method v)
4172 (tramp-file-name-user v) (tramp-file-name-host v)
4173 (format "test %s %s" switch
4174 (tramp-shell-quote-argument (tramp-file-name-localname v)))))))
4175
4176 (defun tramp-run-test2 (program file1 file2 &optional switch)
4177 "Run `test'-like PROGRAM on the remote system, given FILE1, FILE2.
4178 The optional SWITCH is inserted between the two files.
4179 Returns the exit code of the `test' PROGRAM. Barfs if the methods,
4180 hosts, or files, disagree."
4181 (let* ((v1 (tramp-dissect-file-name file1))
4182 (v2 (tramp-dissect-file-name file2))
4183 (mmethod1 (tramp-file-name-multi-method v1))
4184 (mmethod2 (tramp-file-name-multi-method v2))
4185 (method1 (tramp-file-name-method v1))
4186 (method2 (tramp-file-name-method v2))
4187 (user1 (tramp-file-name-user v1))
4188 (user2 (tramp-file-name-user v2))
4189 (host1 (tramp-file-name-host v1))
4190 (host2 (tramp-file-name-host v2))
4191 (localname1 (tramp-file-name-localname v1))
4192 (localname2 (tramp-file-name-localname v2)))
4193 (unless (and method1 method2 host1 host2
4194 (equal mmethod1 mmethod2)
4195 (equal method1 method2)
4196 (equal user1 user2)
4197 (equal host1 host2))
4198 (error "tramp-run-test2: %s"
4199 "only implemented for same method, same user, same host"))
4200 (save-excursion
4201 (tramp-send-command-and-check
4202 mmethod1 method1 user1 host1
4203 (format "%s %s %s %s"
4204 program
4205 (tramp-shell-quote-argument localname1)
4206 (or switch "")
4207 (tramp-shell-quote-argument localname2))))))
4208
4209 (defun tramp-buffer-name (multi-method method user host)
4210 "A name for the connection buffer for USER at HOST using METHOD."
4211 (if multi-method
4212 (tramp-buffer-name-multi-method "tramp" multi-method method user host)
4213 (let ((method (tramp-find-method multi-method method user host)))
4214 (if user
4215 (format "*tramp/%s %s@%s*" method user host))
4216 (format "*tramp/%s %s*" method host))))
4217
4218 (defun tramp-buffer-name-multi-method (prefix multi-method method user host)
4219 "A name for the multi method connection buffer.
4220 MULTI-METHOD gives the multi method, METHOD the array of methods,
4221 USER the array of user names, HOST the array of host names."
4222 (unless (and (= (length method) (length user))
4223 (= (length method) (length host)))
4224 (error "Syntax error in multi method (implementation error)"))
4225 (let ((len (length method))
4226 (i 0)
4227 string-list)
4228 (while (< i len)
4229 (setq string-list
4230 (cons (if (aref user i)
4231 (format "%s#%s@%s:" (aref method i)
4232 (aref user i) (aref host i))
4233 (format "%s@%s:" (aref method i) (aref host i)))
4234 string-list))
4235 (incf i))
4236 (format "*%s/%s %s*"
4237 prefix multi-method
4238 (apply 'concat (reverse string-list)))))
4239
4240 (defun tramp-get-buffer (multi-method method user host)
4241 "Get the connection buffer to be used for USER at HOST using METHOD."
4242 (get-buffer-create (tramp-buffer-name multi-method method user host)))
4243
4244 (defun tramp-debug-buffer-name (multi-method method user host)
4245 "A name for the debug buffer for USER at HOST using METHOD."
4246 (if multi-method
4247 (tramp-buffer-name-multi-method "debug tramp"
4248 multi-method method user host)
4249 (let ((method (tramp-find-method multi-method method user host)))
4250 (if user
4251 (format "*debug tramp/%s %s@%s*" method user host)
4252 (format "*debug tramp/%s %s*" method host)))))
4253
4254 (defun tramp-get-debug-buffer (multi-method method user host)
4255 "Get the debug buffer for USER at HOST using METHOD."
4256 (get-buffer-create (tramp-debug-buffer-name multi-method method user host)))
4257
4258 (defun tramp-find-executable (multi-method method user host
4259 progname dirlist ignore-tilde)
4260 "Searches for PROGNAME in all directories mentioned in DIRLIST.
4261 First args METHOD, USER and HOST specify the connection, PROGNAME
4262 is the program to search for, and DIRLIST gives the list of directories
4263 to search. If IGNORE-TILDE is non-nil, directory names starting
4264 with `~' will be ignored.
4265
4266 Returns the absolute file name of PROGNAME, if found, and nil otherwise.
4267
4268 This function expects to be in the right *tramp* buffer."
4269 (let (result)
4270 (when ignore-tilde
4271 ;; Remove all ~/foo directories from dirlist. In Emacs 20,
4272 ;; `remove' is in CL, and we want to avoid CL dependencies.
4273 (let (newdl d)
4274 (while dirlist
4275 (setq d (car dirlist))
4276 (setq dirlist (cdr dirlist))
4277 (unless (char-equal ?~ (aref d 0))
4278 (setq newdl (cons d newdl))))
4279 (setq dirlist (nreverse newdl))))
4280 (tramp-send-command
4281 multi-method method user host
4282 (format (concat "while read d; "
4283 "do if test -x $d/%s -a -f $d/%s; "
4284 "then echo tramp_executable $d/%s; "
4285 "break; fi; done <<'EOF'")
4286 progname progname progname))
4287 (mapcar (lambda (d)
4288 (tramp-send-command multi-method method user host d))
4289 dirlist)
4290 (tramp-send-command multi-method method user host "EOF")
4291 (tramp-wait-for-output)
4292 (goto-char (point-max))
4293 (when (search-backward "tramp_executable " nil t)
4294 (skip-chars-forward "^ ")
4295 (skip-chars-forward " ")
4296 (buffer-substring (point) (tramp-line-end-position)))))
4297
4298 (defun tramp-set-remote-path (multi-method method user host var dirlist)
4299 "Sets the remote environment VAR to existing directories from DIRLIST.
4300 I.e., for each directory in DIRLIST, it is tested whether it exists and if
4301 so, it is added to the environment variable VAR."
4302 (let ((existing-dirs
4303 (mapcar
4304 (lambda (x)
4305 (when (and
4306 (file-exists-p
4307 (tramp-make-tramp-file-name multi-method method user host x))
4308 (file-directory-p
4309 (tramp-make-tramp-file-name multi-method method user host x)))
4310 x))
4311 dirlist)))
4312 (tramp-send-command
4313 multi-method method user host
4314 (concat var "="
4315 (mapconcat 'identity (delq nil existing-dirs) ":")
4316 "; export " var))
4317 (tramp-wait-for-output)))
4318
4319 ;; -- communication with external shell --
4320
4321 (defun tramp-find-file-exists-command (multi-method method user host)
4322 "Find a command on the remote host for checking if a file exists.
4323 Here, we are looking for a command which has zero exit status if the
4324 file exists and nonzero exit status otherwise."
4325 (make-local-variable 'tramp-file-exists-command)
4326 (tramp-message 9 "Finding command to check if file exists")
4327 (let ((existing
4328 (tramp-make-tramp-file-name
4329 multi-method method user host
4330 "/")) ;assume this file always exists
4331 (nonexisting
4332 (tramp-make-tramp-file-name
4333 multi-method method user host
4334 "/ this file does not exist "))) ;assume this never exists
4335 ;; The algorithm is as follows: we try a list of several commands.
4336 ;; For each command, we first run `$cmd /' -- this should return
4337 ;; true, as the root directory always exists. And then we run
4338 ;; `$cmd /this\ file\ does\ not\ exist', hoping that the file indeed
4339 ;; does not exist. This should return false. We use the first
4340 ;; command we find that seems to work.
4341 ;; The list of commands to try is as follows:
4342 ;; `ls -d' This works on most systems, but NetBSD 1.4
4343 ;; has a bug: `ls' always returns zero exit
4344 ;; status, even for files which don't exist.
4345 ;; `test -e' Some Bourne shells have a `test' builtin
4346 ;; which does not know the `-e' option.
4347 ;; `/bin/test -e' For those, the `test' binary on disk normally
4348 ;; provides the option. Alas, the binary
4349 ;; is sometimes `/bin/test' and sometimes it's
4350 ;; `/usr/bin/test'.
4351 ;; `/usr/bin/test -e' In case `/bin/test' does not exist.
4352 (unless (or
4353 (and (setq tramp-file-exists-command "test -e %s")
4354 (tramp-handle-file-exists-p existing)
4355 (not (tramp-handle-file-exists-p nonexisting)))
4356 (and (setq tramp-file-exists-command "/bin/test -e %s")
4357 (tramp-handle-file-exists-p existing)
4358 (not (tramp-handle-file-exists-p nonexisting)))
4359 (and (setq tramp-file-exists-command "/usr/bin/test -e %s")
4360 (tramp-handle-file-exists-p existing)
4361 (not (tramp-handle-file-exists-p nonexisting)))
4362 (and (setq tramp-file-exists-command "ls -d %s")
4363 (tramp-handle-file-exists-p existing)
4364 (not (tramp-handle-file-exists-p nonexisting))))
4365 (error "Couldn't find command to check if file exists."))))
4366
4367
4368 ;; CCC test ksh or bash found for tilde expansion?
4369 (defun tramp-find-shell (multi-method method user host)
4370 "Find a shell on the remote host which groks tilde expansion."
4371 (let ((shell nil))
4372 (tramp-send-command multi-method method user host "echo ~root")
4373 (tramp-wait-for-output)
4374 (cond
4375 ((string-match "^~root$" (buffer-string))
4376 (setq shell
4377 (or (tramp-find-executable multi-method method user host
4378 "bash" tramp-remote-path t)
4379 (tramp-find-executable multi-method method user host
4380 "ksh" tramp-remote-path t)))
4381 (unless shell
4382 (error "Couldn't find a shell which groks tilde expansion"))
4383 ;; Find arguments for this shell.
4384 (let ((alist tramp-sh-extra-args)
4385 item extra-args)
4386 (while (and alist (null extra-args))
4387 (setq item (pop alist))
4388 (when (string-match (car item) shell)
4389 (setq extra-args (cdr item))))
4390 (when extra-args (setq shell (concat shell " " extra-args))))
4391 (tramp-message
4392 5 "Starting remote shell `%s' for tilde expansion..." shell)
4393 (tramp-send-command
4394 multi-method method user host
4395 (concat "PS1='$ ' exec " shell)) ;
4396 (unless (tramp-wait-for-regexp
4397 (get-buffer-process (current-buffer))
4398 60 (format "\\(\\(%s\\)\\|\\(%s\\)\\)\\'"
4399 tramp-shell-prompt-pattern shell-prompt-pattern))
4400 (pop-to-buffer (buffer-name))
4401 (error "Couldn't find remote `%s' prompt." shell))
4402 (tramp-message
4403 9 "Setting remote shell prompt...")
4404 ;; Douglas Gray Stephens <DGrayStephens@slb.com> says that we
4405 ;; must use "\n" here, not tramp-rsh-end-of-line. Kai left the
4406 ;; last tramp-rsh-end-of-line, Douglas wanted to replace that,
4407 ;; as well.
4408 (process-send-string nil (format "PS1='%s%s%s'; PS2=''; PS3=''%s"
4409 tramp-rsh-end-of-line
4410 tramp-end-of-output
4411 tramp-rsh-end-of-line
4412 tramp-rsh-end-of-line))
4413 (tramp-wait-for-output)
4414 (tramp-message
4415 9 "Setting remote shell prompt...done")
4416 )
4417 (t (tramp-message 5 "Remote `%s' groks tilde expansion, good"
4418 (tramp-get-method-parameter
4419 multi-method method user host 'tramp-remote-sh))))))
4420
4421 (defun tramp-check-ls-command (multi-method method user host cmd)
4422 "Checks whether the given `ls' executable groks `-n'.
4423 METHOD, USER and HOST specify the connection, CMD (the absolute file name of)
4424 the `ls' executable. Returns t if CMD supports the `-n' option, nil
4425 otherwise."
4426 (tramp-message 9 "Checking remote `%s' command for `-n' option"
4427 cmd)
4428 (when (tramp-handle-file-executable-p
4429 (tramp-make-tramp-file-name multi-method method user host cmd))
4430 (let ((result nil))
4431 (tramp-message 7 "Testing remote command `%s' for -n..." cmd)
4432 (setq result
4433 (tramp-send-command-and-check
4434 multi-method method user host
4435 (format "%s -lnd / >/dev/null"
4436 cmd)))
4437 (tramp-message 7 "Testing remote command `%s' for -n...%s"
4438 cmd
4439 (if (zerop result) "okay" "failed"))
4440 (zerop result))))
4441
4442 (defun tramp-check-ls-commands (multi-method method user host cmd dirlist)
4443 "Checks whether the given `ls' executable in one of the dirs groks `-n'.
4444 Returns nil if none was found, else the command is returned."
4445 (let ((dl dirlist)
4446 (result nil)
4447 (directory-sep-char ?/)) ;for XEmacs
4448 ;; It would be better to use the CL function `find', but
4449 ;; we don't want run-time dependencies on CL.
4450 (while (and dl (not result))
4451 (let ((x (concat (file-name-as-directory (car dl)) cmd)))
4452 (when (tramp-check-ls-command multi-method method user host x)
4453 (setq result x)))
4454 (setq dl (cdr dl)))
4455 result))
4456
4457 (defun tramp-find-ls-command (multi-method method user host)
4458 "Finds an `ls' command which groks the `-n' option, returning nil if failed.
4459 \(This option prints numeric user and group ids in a long listing.)"
4460 (tramp-message 9 "Finding a suitable `ls' command")
4461 (or
4462 (tramp-check-ls-commands multi-method method user host "ls" tramp-remote-path)
4463 (tramp-check-ls-commands multi-method method user host "gnuls" tramp-remote-path)
4464 (tramp-check-ls-commands multi-method method user host "gls" tramp-remote-path)))
4465
4466 ;; ------------------------------------------------------------
4467 ;; -- Functions for establishing connection --
4468 ;; ------------------------------------------------------------
4469
4470 ;; The following functions are actions to be taken when seeing certain
4471 ;; prompts from the remote host. See the variable
4472 ;; `tramp-actions-before-shell' for usage of these functions.
4473
4474 (defun tramp-action-login (p multi-method method user host)
4475 "Send the login name."
4476 (tramp-message 9 "Sending login name `%s'"
4477 (or user (user-login-name)))
4478 (erase-buffer)
4479 (process-send-string nil (concat (or user (user-login-name))
4480 tramp-rsh-end-of-line)))
4481
4482 (defun tramp-action-password (p multi-method method user host)
4483 "Query the user for a password."
4484 (let ((pw-prompt (match-string 0)))
4485 (when (tramp-method-out-of-band-p multi-method method user host)
4486 (kill-process (get-buffer-process (current-buffer)))
4487 (error (concat "Out of band method `%s' not applicable "
4488 "for remote shell asking for a password")
4489 method))
4490 (tramp-message 9 "Sending password")
4491 (tramp-enter-password p pw-prompt)))
4492
4493 (defun tramp-action-succeed (p multi-method method user host)
4494 "Signal success in finding shell prompt."
4495 (tramp-message 9 "Found remote shell prompt.")
4496 (erase-buffer)
4497 (throw 'tramp-action 'ok))
4498
4499 (defun tramp-action-permission-denied (p multi-method method user host)
4500 "Signal permission denied."
4501 (pop-to-buffer (tramp-get-buffer multi-method method user host))
4502 (tramp-message 9 "Permission denied by remote host.")
4503 (kill-process p)
4504 (throw 'tramp-action 'permission-denied))
4505
4506 (defun tramp-action-yesno (p multi-method method user host)
4507 "Ask the user for confirmation using `yes-or-no-p'.
4508 Send \"yes\" to remote process on confirmation, abort otherwise.
4509 See also `tramp-action-yn'."
4510 (save-window-excursion
4511 (pop-to-buffer (tramp-get-buffer multi-method method user host))
4512 (unless (yes-or-no-p (match-string 0))
4513 (kill-process p)
4514 (erase-buffer)
4515 (throw 'tramp-action 'permission-denied))
4516 (process-send-string p (concat "yes" tramp-rsh-end-of-line))
4517 (erase-buffer)))
4518
4519 (defun tramp-action-yn (p multi-method method user host)
4520 "Ask the user for confirmation using `y-or-n-p'.
4521 Send \"y\" to remote process on confirmation, abort otherwise.
4522 See also `tramp-action-yesno'."
4523 (save-window-excursion
4524 (pop-to-buffer (tramp-get-buffer multi-method method user host))
4525 (unless (y-or-n-p (match-string 0))
4526 (kill-process p)
4527 (throw 'tramp-action 'permission-denied))
4528 (erase-buffer)
4529 (process-send-string p (concat "y" tramp-rsh-end-of-line))))
4530
4531 (defun tramp-action-terminal (p multi-method method user host)
4532 "Tell the remote host which terminal type to use.
4533 The terminal type can be configured with `tramp-terminal-type'."
4534 (tramp-message 9 "Setting `%s' as terminal type."
4535 tramp-terminal-type)
4536 (erase-buffer)
4537 (process-send-string nil (concat tramp-terminal-type
4538 tramp-rsh-end-of-line)))
4539
4540 ;; The following functions are specifically for multi connections.
4541
4542 (defun tramp-multi-action-login (p method user host)
4543 "Send the login name."
4544 (tramp-message 9 "Sending login name `%s'" user)
4545 (erase-buffer)
4546 (process-send-string p (concat user tramp-rsh-end-of-line)))
4547
4548 (defun tramp-multi-action-password (p method user host)
4549 "Query the user for a password."
4550 (tramp-message 9 "Sending password")
4551 (tramp-enter-password p (match-string 0)))
4552
4553 (defun tramp-multi-action-succeed (p method user host)
4554 "Signal success in finding shell prompt."
4555 (tramp-message 9 "Found shell prompt on `%s'" host)
4556 (erase-buffer)
4557 (throw 'tramp-action 'ok))
4558
4559 (defun tramp-multi-action-permission-denied (p method user host)
4560 "Signal permission denied."
4561 (tramp-message 9 "Permission denied by remote host `%s'" host)
4562 (kill-process p)
4563 (erase-buffer)
4564 (throw 'tramp-action 'permission-denied))
4565
4566 ;; Functions for processing the actions.
4567
4568 (defun tramp-process-one-action (p multi-method method user host actions)
4569 "Wait for output from the shell and perform one action."
4570 (let (found item pattern action todo)
4571 (erase-buffer)
4572 (tramp-message 9 "Waiting 60s for prompt from remote shell")
4573 (with-timeout (60 (throw 'tramp-action 'timeout))
4574 (while (not found)
4575 (accept-process-output p 1)
4576 (goto-char (point-min))
4577 (setq todo actions)
4578 (while todo
4579 (goto-char (point-min))
4580 (setq item (pop todo))
4581 (setq pattern (symbol-value (nth 0 item)))
4582 (setq action (nth 1 item))
4583 (tramp-message 10 "Looking for regexp \"%s\" from remote shell"
4584 pattern)
4585 (when (re-search-forward (concat pattern "\\'") nil t)
4586 (setq found (funcall action p multi-method method user host)))))
4587 found)))
4588
4589 (defun tramp-process-actions (p multi-method method user host actions)
4590 "Perform actions until success."
4591 (let (exit)
4592 (while (not exit)
4593 (tramp-message 9 "Waiting for prompts from remote shell")
4594 (setq exit
4595 (catch 'tramp-action
4596 (tramp-process-one-action
4597 p multi-method method user host actions)
4598 nil)))
4599 (unless (eq exit 'ok)
4600 (error "Login failed"))))
4601
4602 ;; For multi-actions.
4603
4604 (defun tramp-process-one-multi-action (p method user host actions)
4605 "Wait for output from the shell and perform one action."
4606 (let (found item pattern action todo)
4607 (erase-buffer)
4608 (tramp-message 9 "Waiting 60s for prompt from remote shell")
4609 (with-timeout (60 (throw 'tramp-action 'timeout))
4610 (while (not found)
4611 (accept-process-output p 1)
4612 (setq todo actions)
4613 (goto-char (point-min))
4614 (while todo
4615 (goto-char (point-min))
4616 (setq item (pop todo))
4617 (setq pattern (symbol-value (nth 0 item)))
4618 (setq action (nth 1 item))
4619 (tramp-message 10 "Looking for regexp \"%s\" from remote shell"
4620 pattern)
4621 (when (re-search-forward (concat pattern "\\'") nil t)
4622 (setq found (funcall action p method user host)))))
4623 found)))
4624
4625 (defun tramp-process-multi-actions (p method user host actions)
4626 "Perform actions until success."
4627 (let (exit)
4628 (while (not exit)
4629 (tramp-message 9 "Waiting for prompts from remote shell")
4630 (setq exit
4631 (catch 'tramp-action
4632 (tramp-process-one-multi-action p method user host actions)
4633 nil)))
4634 (unless (eq exit 'ok)
4635 (error "Login failed"))))
4636
4637 ;; Functions to execute when we have seen the remote shell prompt but
4638 ;; before we exec the Bourne-ish shell. Note that these commands
4639 ;; might be sent to any shell, not just a Bourne-ish shell. This
4640 ;; means that the commands need to work in all shells. (It is also
4641 ;; okay for some commands to just fail with an error message, but
4642 ;; please make sure that they at least don't crash the odd shell people
4643 ;; might be running...)
4644 (defun tramp-process-initial-commands (p
4645 multi-method method user host
4646 commands)
4647 "Send list of commands to remote host, in order."
4648 (let (cmd)
4649 (while commands
4650 (setq cmd (pop commands))
4651 (erase-buffer)
4652 (tramp-message 10 "Sending command to remote shell: %s"
4653 cmd)
4654 (tramp-send-command multi-method method user host cmd)
4655 (tramp-barf-if-no-shell-prompt
4656 p 60 "Remote shell command failed: %s" cmd))
4657 (erase-buffer)))
4658
4659 ;; The actual functions for opening connections.
4660
4661 (defun tramp-open-connection-telnet (multi-method method user host)
4662 "Open a connection using a telnet METHOD.
4663 This starts the command `telnet HOST ARGS'[*], then waits for a remote
4664 login prompt, then sends the user name USER, then waits for a remote
4665 password prompt. It queries the user for the password, then sends the
4666 password to the remote host.
4667
4668 If USER is nil, uses value returned by `(user-login-name)' instead.
4669
4670 Recognition of the remote shell prompt is based on the variables
4671 `shell-prompt-pattern' and `tramp-shell-prompt-pattern' which must be
4672 set up correctly.
4673
4674 Please note that it is NOT possible to use this connection method
4675 together with an out-of-band transfer method! You must use an inline
4676 transfer method.
4677
4678 Maybe the different regular expressions need to be tuned.
4679
4680 * Actually, the telnet program as well as the args to be used can be
4681 specified in the method parameters, see the variable `tramp-methods'."
4682 (save-match-data
4683 (when (tramp-method-out-of-band-p multi-method method user host)
4684 (error "Cannot use out-of-band method `%s' with telnet connection method"
4685 method))
4686 (when multi-method
4687 (error "Cannot multi-connect using telnet connection method"))
4688 (tramp-pre-connection multi-method method user host)
4689 (tramp-message 7 "Opening connection for %s@%s using %s..."
4690 (or user (user-login-name)) host method)
4691 (let ((process-environment (copy-sequence process-environment)))
4692 (setenv "TERM" tramp-terminal-type)
4693 (let* ((default-directory (tramp-temporary-file-directory))
4694 ;; If we omit the conditional here, then we would use
4695 ;; `undecided-dos' in some cases. With the conditional,
4696 ;; we use nil in these cases. Which one is right?
4697 (coding-system-for-read (unless (and (not (featurep 'xemacs))
4698 (> emacs-major-version 20))
4699 tramp-dos-coding-system))
4700 (p (apply 'start-process
4701 (tramp-buffer-name multi-method method user host)
4702 (tramp-get-buffer multi-method method user host)
4703 (tramp-get-method-parameter
4704 multi-method
4705 (tramp-find-method multi-method method user host)
4706 user host 'tramp-login-program)
4707 host
4708 (tramp-get-method-parameter
4709 multi-method
4710 (tramp-find-method multi-method method user host)
4711 user host 'tramp-login-args)))
4712 (found nil)
4713 (pw nil))
4714 (process-kill-without-query p)
4715 (set-buffer (tramp-get-buffer multi-method method user host))
4716 (erase-buffer)
4717 (tramp-process-actions p multi-method method user host
4718 tramp-actions-before-shell)
4719 (tramp-open-connection-setup-interactive-shell
4720 p multi-method method user host)
4721 (tramp-post-connection multi-method method user host)))))
4722
4723
4724 (defun tramp-open-connection-rsh (multi-method method user host)
4725 "Open a connection using an rsh METHOD.
4726 This starts the command `rsh HOST -l USER'[*], then waits for a remote
4727 password or shell prompt. If a password prompt is seen, the user is
4728 queried for a password, this function sends the password to the remote
4729 host and waits for a shell prompt.
4730
4731 If USER is nil, start the command `rsh HOST'[*] instead
4732
4733 Recognition of the remote shell prompt is based on the variables
4734 `shell-prompt-pattern' and `tramp-shell-prompt-pattern' which must be
4735 set up correctly.
4736
4737 Please note that it is NOT possible to use this connection method with
4738 an out-of-band transfer method if this function asks the user for a
4739 password! You must use an inline transfer method in this case.
4740 Sadly, the transfer method cannot be switched on the fly, instead you
4741 must specify the right method in the file name.
4742
4743 Kludgy feature: if HOST has the form \"xx#yy\", then yy is assumed to
4744 be a port number for ssh, and \"-p yy\" will be added to the list of
4745 arguments, and xx will be used as the host name to connect to.
4746
4747 * Actually, the rsh program to be used can be specified in the
4748 method parameters, see the variable `tramp-methods'."
4749 (save-match-data
4750 (when multi-method
4751 (error "Cannot multi-connect using rsh connection method"))
4752 (tramp-pre-connection multi-method method user host)
4753 (if (and user (not (string= user "")))
4754 (tramp-message 7 "Opening connection for %s@%s using %s..."
4755 user host method)
4756 (tramp-message 7 "Opening connection at %s using %s..." host method))
4757 (let ((process-environment (copy-sequence process-environment))
4758 (bufnam (tramp-buffer-name multi-method method user host))
4759 (buf (tramp-get-buffer multi-method method user host))
4760 (login-program (tramp-get-method-parameter
4761 multi-method
4762 (tramp-find-method multi-method method user host)
4763 user host 'tramp-login-program))
4764 (login-args (tramp-get-method-parameter
4765 multi-method
4766 (tramp-find-method multi-method method user host)
4767 user host 'tramp-login-args)))
4768 ;; The following should be changed. We need a more general
4769 ;; mechanism to parse extra host args.
4770 (when (string-match "\\([^#]*\\)#\\(.*\\)" host)
4771 (setq login-args (cons "-p" (cons (match-string 2 host) rsh-args)))
4772 (setq host (match-string 1 host)))
4773 (setenv "TERM" tramp-terminal-type)
4774 (let* ((default-directory (tramp-temporary-file-directory))
4775 ;; If we omit the conditional, we would use
4776 ;; `undecided-dos' in some cases. With the conditional,
4777 ;; we use nil in these cases. Which one is right?
4778 (coding-system-for-read (unless (and (not (featurep 'xemacs))
4779 (> emacs-major-version 20))
4780 tramp-dos-coding-system))
4781 (p (if (and user (not (string= user "")))
4782 (apply #'start-process bufnam buf login-program
4783 host "-l" user login-args)
4784 (apply #'start-process bufnam buf login-program
4785 host login-args)))
4786 (found nil))
4787 (process-kill-without-query p)
4788
4789 (set-buffer buf)
4790 (tramp-process-actions p multi-method method user host
4791 tramp-actions-before-shell)
4792 (tramp-message 7 "Initializing remote shell")
4793 (tramp-open-connection-setup-interactive-shell
4794 p multi-method method user host)
4795 (tramp-post-connection multi-method method user host)))))
4796
4797 (defun tramp-open-connection-su (multi-method method user host)
4798 "Open a connection using the `su' program with METHOD.
4799 This starts `su - USER', then waits for a password prompt. The HOST
4800 name must be equal to the local host name or to `localhost'.
4801
4802 If USER is nil, uses value returned by user-login-name instead.
4803
4804 Recognition of the remote shell prompt is based on the variables
4805 `shell-prompt-pattern' and `tramp-shell-prompt-pattern' which must be
4806 set up correctly. Note that the other user may have a different shell
4807 prompt than you do, so it is not at all unlikely that the variable
4808 `shell-prompt-pattern' is set up wrongly!"
4809 (save-match-data
4810 (when (tramp-method-out-of-band-p multi-method method user host)
4811 (error "Cannot use out-of-band method `%s' with `su' connection method"
4812 method))
4813 (unless (or (string-match (concat "^" (regexp-quote host))
4814 (system-name))
4815 (string= "localhost" host)
4816 (string= "" host))
4817 (error
4818 "Cannot connect to different host `%s' with `su' connection method"
4819 host))
4820 (tramp-pre-connection multi-method method user host)
4821 (tramp-message 7 "Opening connection for `%s' using `%s'..."
4822 (or user "<root>") method)
4823 (let ((process-environment (copy-sequence process-environment)))
4824 (setenv "TERM" tramp-terminal-type)
4825 (let* ((default-directory (tramp-temporary-file-directory))
4826 ;; If we omit the conditional, we use `undecided-dos' in
4827 ;; some cases. With the conditional, we use nil in these
4828 ;; cases. What's the difference? Which one is right?
4829 (coding-system-for-read (unless (and (not (featurep 'xemacs))
4830 (> emacs-major-version 20))
4831 tramp-dos-coding-system))
4832 (p (apply 'start-process
4833 (tramp-buffer-name multi-method method user host)
4834 (tramp-get-buffer multi-method method user host)
4835 (tramp-get-method-parameter
4836 multi-method
4837 (tramp-find-method multi-method method user host)
4838 user host 'tramp-login-program)
4839 (mapcar
4840 (lambda (x)
4841 (format-spec x `((?u . ,(or user "root")))))
4842 (tramp-get-method-parameter
4843 multi-method
4844 (tramp-find-method multi-method method user host)
4845 user host 'tramp-login-args))))
4846 (found nil)
4847 (pw nil))
4848 (process-kill-without-query p)
4849 (set-buffer (tramp-get-buffer multi-method method user host))
4850 (tramp-process-actions p multi-method method user host
4851 tramp-actions-before-shell)
4852 (tramp-open-connection-setup-interactive-shell
4853 p multi-method method user host)
4854 (tramp-post-connection multi-method method
4855 user host)))))
4856
4857 ;; HHH: Not Changed. Multi method. It is not clear to me how this can
4858 ;; handle not giving a user name in the "file name".
4859 ;;
4860 ;; This is more difficult than for the single-hop method. In the
4861 ;; multi-hop-method, the desired behaviour should be that the
4862 ;; user must specify names for the telnet hops of which the user
4863 ;; name is different than the "original" name (or different from
4864 ;; the previous hop.
4865 (defun tramp-open-connection-multi (multi-method method user host)
4866 "Open a multi-hop connection using METHOD.
4867 This uses a slightly changed file name syntax. The idea is to say
4868 [multi/telnet:u1@h1/rsh:u2@h2]/path/to/file
4869 This will use telnet to log in as u1 to h1, then use rsh from there to
4870 log in as u2 to h2."
4871 (save-match-data
4872 (unless multi-method
4873 (error "Multi-hop open connection function called on non-multi method"))
4874 (when (tramp-method-out-of-band-p multi-method method user host)
4875 (error "No out of band multi-hop connections"))
4876 (unless (and (arrayp method) (not (stringp method)))
4877 (error "METHOD must be an array of strings for multi methods"))
4878 (unless (and (arrayp user) (not (stringp user)))
4879 (error "USER must be an array of strings for multi methods"))
4880 (unless (and (arrayp host) (not (stringp host)))
4881 (error "HOST must be an array of strings for multi methods"))
4882 (unless (and (= (length method) (length user))
4883 (= (length method) (length host)))
4884 (error "Arrays METHOD, USER, HOST must have equal length"))
4885 (tramp-pre-connection multi-method method user host)
4886 (tramp-message 7 "Opening `%s' connection..." multi-method)
4887 (let ((process-environment (copy-sequence process-environment)))
4888 (setenv "TERM" tramp-terminal-type)
4889 (let* ((default-directory (tramp-temporary-file-directory))
4890 ;; If we omit the conditional, we use `undecided-dos' in
4891 ;; some cases. With the conditional, we use nil in these
4892 ;; cases. What's the difference? Which one is right?
4893 (coding-system-for-read (unless (and (not (featurep 'xemacs))
4894 (> emacs-major-version 20))
4895 tramp-dos-coding-system))
4896 (p (start-process (tramp-buffer-name multi-method method user host)
4897 (tramp-get-buffer multi-method method user host)
4898 tramp-multi-sh-program))
4899 (num-hops (length method))
4900 (i 0))
4901 (process-kill-without-query p)
4902 (tramp-message 9 "Waiting 60s for local shell to come up...")
4903 (unless (tramp-wait-for-regexp
4904 p 60 (format "\\(%s\\)\\'\\|\\(%s\\)\\'"
4905 shell-prompt-pattern tramp-shell-prompt-pattern))
4906 (pop-to-buffer (buffer-name))
4907 (kill-process p)
4908 (error "Couldn't find local shell prompt"))
4909 ;; Now do all the connections as specified.
4910 (while (< i num-hops)
4911 (let* ((m (aref method i))
4912 (u (aref user i))
4913 (h (aref host i))
4914 (entry (assoc m tramp-multi-connection-function-alist))
4915 (multi-func (nth 1 entry))
4916 (command (nth 2 entry)))
4917 ;; The multi-funcs don't need to do save-match-data, as that
4918 ;; is done here.
4919 (funcall multi-func p m u h command)
4920 (erase-buffer)
4921 (incf i)))
4922 (tramp-open-connection-setup-interactive-shell
4923 p multi-method method user host)
4924 (tramp-post-connection multi-method method user host)))))
4925
4926 ;; HHH: Changed. Multi method. Don't know how to handle this in the case
4927 ;; of no user name provided. Hack to make it work as it did before:
4928 ;; changed `user' to `(or user (user-login-name))' in the places where
4929 ;; the value is actually used.
4930 (defun tramp-multi-connect-telnet (p method user host command)
4931 "Issue `telnet' command.
4932 Uses shell COMMAND to issue a `telnet' command to log in as USER to
4933 HOST. You can use percent escapes in COMMAND: `%h' is replaced with
4934 the host name, and `%n' is replaced with an end of line character, as
4935 set in `tramp-rsh-end-of-line'. Use `%%' if you want a literal percent
4936 character.
4937
4938 If USER is nil, uses the return value of (user-login-name) instead."
4939 (let ((cmd (format-spec command
4940 `((?h . ,host) (?n . ,tramp-rsh-end-of-line))))
4941 (cmd1 (format-spec command `((?h . ,host) (?n . ""))))
4942 found pw)
4943 (erase-buffer)
4944 (tramp-message 9 "Sending telnet command `%s'" cmd1)
4945 (process-send-string p cmd)
4946 (tramp-process-multi-actions p method user host
4947 tramp-multi-actions)))
4948
4949 ;; HHH: Changed. Multi method. Don't know how to handle this in the case
4950 ;; of no user name provided. Hack to make it work as it did before:
4951 ;; changed `user' to `(or user (user-login-name))' in the places where
4952 ;; the value is actually used.
4953 (defun tramp-multi-connect-rlogin (p method user host command)
4954 "Issue `rlogin' command.
4955 Uses shell COMMAND to issue an `rlogin' command to log in as USER to
4956 HOST. You can use percent escapes in COMMAND. `%u' will be replaced
4957 with the user name, `%h' will be replaced with the host name, and `%n'
4958 will be replaced with the value of `tramp-rsh-end-of-line'. You can use
4959 `%%' if you want to use a literal percent character.
4960
4961 If USER is nil, uses the return value of (user-login-name) instead."
4962 (let ((cmd (format-spec command `((?h . ,host)
4963 (?u . ,(or user (user-login-name)))
4964 (?n . ,tramp-rsh-end-of-line))))
4965 (cmd1 (format-spec command `((?h . ,host)
4966 (?u . ,(or user (user-login-name)))
4967 (?n . ""))))
4968 found)
4969 (erase-buffer)
4970 (tramp-message 9 "Sending rlogin command `%s'" cmd1)
4971 (process-send-string p cmd)
4972 (tramp-process-multi-actions p method user host
4973 tramp-multi-actions)))
4974
4975 ;; HHH: Changed. Multi method. Don't know how to handle this in the case
4976 ;; of no user name provided. Hack to make it work as it did before:
4977 ;; changed `user' to `(or user (user-login-name))' in the places where
4978 ;; the value is actually used.
4979 (defun tramp-multi-connect-su (p method user host command)
4980 "Issue `su' command.
4981 Uses shell COMMAND to issue a `su' command to log in as USER on
4982 HOST. The HOST name is ignored, this just changes the user id on the
4983 host currently logged in to.
4984
4985 If USER is nil, uses the return value of (user-login-name) instead.
4986
4987 You can use percent escapes in the COMMAND. `%u' is replaced with the
4988 user name, and `%n' is replaced with the value of
4989 `tramp-rsh-end-of-line'. Use `%%' if you want a literal percent
4990 character."
4991 (let ((cmd (format-spec command `((?u . ,(or user (user-login-name)))
4992 (?n . ,tramp-rsh-end-of-line))))
4993 (cmd1 (format-spec command `((?u . ,(or user (user-login-name)))
4994 (?n . ""))))
4995 found)
4996 (erase-buffer)
4997 (tramp-message 9 "Sending su command `%s'" cmd1)
4998 (process-send-string p cmd)
4999 (tramp-process-multi-actions p method user host
5000 tramp-multi-actions)))
5001
5002 ;; Utility functions.
5003
5004 (defun tramp-wait-for-regexp (proc timeout regexp)
5005 "Wait for a REGEXP to appear from process PROC within TIMEOUT seconds.
5006 Expects the output of PROC to be sent to the current buffer. Returns
5007 the string that matched, or nil. Waits indefinitely if TIMEOUT is
5008 nil."
5009 (let ((found nil)
5010 (start-time (current-time)))
5011 (cond (timeout
5012 ;; Work around a bug in XEmacs 21, where the timeout
5013 ;; expires faster than it should. This degenerates
5014 ;; to polling for buggy XEmacsen, but oh, well.
5015 (while (and (not found)
5016 (< (tramp-time-diff (current-time) start-time)
5017 timeout))
5018 (with-timeout (timeout)
5019 (while (not found)
5020 (accept-process-output proc 1)
5021 (goto-char (point-min))
5022 (setq found (when (re-search-forward regexp nil t)
5023 (tramp-match-string-list)))))))
5024 (t
5025 (while (not found)
5026 (accept-process-output proc 1)
5027 (goto-char (point-min))
5028 (setq found (when (re-search-forward regexp nil t)
5029 (tramp-match-string-list))))))
5030 (when tramp-debug-buffer
5031 (append-to-buffer
5032 (tramp-get-debug-buffer tramp-current-multi-method tramp-current-method
5033 tramp-current-user tramp-current-host)
5034 (point-min) (point-max))
5035 (when (not found)
5036 (save-excursion
5037 (set-buffer
5038 (tramp-get-debug-buffer tramp-current-multi-method tramp-current-method
5039 tramp-current-user tramp-current-host))
5040 (goto-char (point-max))
5041 (insert "[[Regexp `" regexp "' not found"
5042 (if timeout (format " in %d secs" timeout) "")
5043 "]]"))))
5044 found))
5045
5046 (defun tramp-wait-for-shell-prompt (proc timeout)
5047 "Wait for the shell prompt to appear from process PROC within TIMEOUT seconds.
5048 See `tramp-wait-for-regexp' for more details.
5049 Shell prompt pattern is determined by variables `shell-prompt-pattern'
5050 and `tramp-shell-prompt-pattern'."
5051 (tramp-wait-for-regexp
5052 proc timeout
5053 (format "\\(%s\\|%s\\)\\'"
5054 shell-prompt-pattern tramp-shell-prompt-pattern)))
5055
5056 (defun tramp-barf-if-no-shell-prompt (proc timeout &rest error-args)
5057 "Wait for shell prompt and barf if none appears.
5058 Looks at process PROC to see if a shell prompt appears in TIMEOUT
5059 seconds. If not, it produces an error message with the given ERROR-ARGS."
5060 (unless (tramp-wait-for-shell-prompt proc timeout)
5061 (pop-to-buffer (buffer-name))
5062 (apply 'error error-args)))
5063
5064 (defun tramp-enter-password (p prompt)
5065 "Prompt for a password and send it to the remote end.
5066 Uses PROMPT as a prompt and sends the password to process P."
5067 (let ((pw (tramp-read-passwd prompt)))
5068 (erase-buffer)
5069 (process-send-string
5070 p (concat pw
5071 (or (tramp-get-method-parameter
5072 tramp-current-multi-method
5073 tramp-current-method
5074 tramp-current-user
5075 tramp-current-host
5076 'tramp-password-end-of-line)
5077 tramp-default-password-end-of-line)))))
5078
5079 ;; HHH: Not Changed. This might handle the case where USER is not
5080 ;; given in the "File name" very poorly. Then, the local
5081 ;; variable tramp-current user will be set to nil.
5082 (defun tramp-pre-connection (multi-method method user host)
5083 "Do some setup before actually logging in.
5084 METHOD, USER and HOST specify the connection."
5085 (set-buffer (tramp-get-buffer multi-method method user host))
5086 (set (make-local-variable 'tramp-current-multi-method) multi-method)
5087 (set (make-local-variable 'tramp-current-method) method)
5088 (set (make-local-variable 'tramp-current-user) user)
5089 (set (make-local-variable 'tramp-current-host) host)
5090 (set (make-local-variable 'inhibit-eol-conversion) nil)
5091 (erase-buffer))
5092
5093 (defun tramp-open-connection-setup-interactive-shell
5094 (p multi-method method user host)
5095 "Set up an interactive shell.
5096 Mainly sets the prompt and the echo correctly. P is the shell process
5097 to set up. METHOD, USER and HOST specify the connection."
5098 ;; Wait a bit in case the remote end feels like sending a little
5099 ;; junk first. It seems that fencepost.gnu.org does this when doing
5100 ;; a Kerberos login.
5101 (sit-for 1)
5102 (tramp-discard-garbage-erase-buffer p multi-method method user host)
5103 (tramp-process-initial-commands p multi-method method user host
5104 tramp-initial-commands)
5105 ;; It is useful to set the prompt in the following command because
5106 ;; some people have a setting for $PS1 which /bin/sh doesn't know
5107 ;; about and thus /bin/sh will display a strange prompt. For
5108 ;; example, if $PS1 has "${CWD}" in the value, then ksh will display
5109 ;; the current working directory but /bin/sh will display a dollar
5110 ;; sign. The following command line sets $PS1 to a sane value, and
5111 ;; works under Bourne-ish shells as well as csh-like shells. Daniel
5112 ;; Pittman reports that the unusual positioning of the single quotes
5113 ;; makes it work under `rc', too. We also unset the variable $ENV
5114 ;; because that is read by some sh implementations (eg, bash when
5115 ;; called as sh) on startup; this way, we avoid the startup file
5116 ;; clobbering $PS1.
5117 (tramp-send-command-internal
5118 multi-method method user host
5119 (format "exec env 'ENV=' 'PS1=$ ' %s"
5120 (tramp-get-method-parameter
5121 multi-method method user host 'tramp-remote-sh))
5122 (format "remote `%s' to come up"
5123 (tramp-get-method-parameter
5124 multi-method method user host 'tramp-remote-sh)))
5125 (tramp-barf-if-no-shell-prompt
5126 p 30
5127 "Remote `%s' didn't come up. See buffer `%s' for details"
5128 (tramp-get-method-parameter multi-method method user host 'tramp-remote-sh)
5129 (buffer-name))
5130 (tramp-message 8 "Setting up remote shell environment")
5131 (tramp-discard-garbage-erase-buffer p multi-method method user host)
5132 (tramp-send-command-internal multi-method method user host
5133 "stty -inlcr -echo kill '^U'")
5134 (erase-buffer)
5135 (tramp-send-command-internal multi-method method user host
5136 "TERM=dumb; export TERM")
5137 ;; Try to set up the coding system correctly.
5138 ;; CCC this can't be the right way to do it. Hm.
5139 (save-excursion
5140 (erase-buffer)
5141 (tramp-message 9 "Determining coding system")
5142 (tramp-send-command-internal multi-method method user host
5143 "echo foo ; echo bar")
5144 (goto-char (point-min))
5145 (if (featurep 'mule)
5146 ;; Use MULE to select the right EOL convention for communicating
5147 ;; with the process.
5148 (let* ((cs (or (process-coding-system p) (cons 'undecided 'undecided)))
5149 cs-decode cs-encode)
5150 (when (symbolp cs) (setq cs (cons cs cs)))
5151 (setq cs-decode (car cs))
5152 (setq cs-encode (cdr cs))
5153 (unless cs-decode (setq cs-decode 'undecided))
5154 (unless cs-encode (setq cs-encode 'undecided))
5155 (setq cs-encode (tramp-coding-system-change-eol-conversion
5156 cs-encode 'unix))
5157 (when (search-forward "\r" nil t)
5158 (setq cs-decode (tramp-coding-system-change-eol-conversion
5159 cs-decode 'dos)))
5160 (set-buffer-process-coding-system cs-decode cs-encode))
5161 ;; Look for ^M and do something useful if found.
5162 (when (search-forward "\r" nil t)
5163 ;; We have found a ^M but cannot frob the process coding system
5164 ;; because we're running on a non-MULE Emacs. Let's try
5165 ;; stty, instead.
5166 (erase-buffer)
5167 (tramp-message 9 "Trying `stty -onlcr'")
5168 (tramp-send-command-internal multi-method method user host
5169 "stty -onlcr"))))
5170 (erase-buffer)
5171 (tramp-message
5172 9 "Waiting 30s for `HISTFILE=$HOME/.tramp_history; HISTSIZE=1'")
5173 (tramp-send-command-internal multi-method method user host
5174 "HISTFILE=$HOME/.tramp_history; HISTSIZE=1")
5175 (erase-buffer)
5176 (tramp-message 9 "Waiting 30s for `set +o vi +o emacs'")
5177 (tramp-send-command-internal multi-method method user host
5178 "set +o vi +o emacs")
5179 (erase-buffer)
5180 (tramp-message 9 "Waiting 30s for `unset MAIL MAILCHECK MAILPATH'")
5181 (tramp-send-command-internal
5182 multi-method method user host
5183 "unset MAIL MAILCHECK MAILPATH 1>/dev/null 2>/dev/null")
5184 (erase-buffer)
5185 (tramp-message 9 "Waiting 30s for `unset CDPATH'")
5186 (tramp-send-command-internal multi-method method user host
5187 "unset CDPATH")
5188 (erase-buffer)
5189 (tramp-message 9 "Setting shell prompt")
5190 ;; Douglas Gray Stephens <DGrayStephens@slb.com> says that we must
5191 ;; use "\n" here, not tramp-rsh-end-of-line. We also manually frob
5192 ;; the last time we sent a command, to avoid tramp-send-command to send
5193 ;; "echo are you awake".
5194 (setq tramp-last-cmd-time (current-time))
5195 (tramp-send-command
5196 multi-method method user host
5197 (format "PS1='%s%s%s'; PS2=''; PS3=''"
5198 tramp-rsh-end-of-line
5199 tramp-end-of-output
5200 tramp-rsh-end-of-line))
5201 (tramp-wait-for-output))
5202
5203 (defun tramp-post-connection (multi-method method user host)
5204 "Prepare a remote shell before being able to work on it.
5205 METHOD, USER and HOST specify the connection.
5206 Among other things, this finds a shell which groks tilde expansion,
5207 tries to find an `ls' command which groks the `-n' option, sets the
5208 locale to C and sets up the remote shell search path."
5209 ;; Search for a good shell before searching for a command which
5210 ;; checks if a file exists. This is done because Tramp wants to use
5211 ;; "test foo; echo $?" to check if various conditions hold, and
5212 ;; there are buggy /bin/sh implementations which don't execute the
5213 ;; "echo $?" part if the "test" part has an error. In particular,
5214 ;; the Solaris /bin/sh is a problem. I'm betting that all systems
5215 ;; with buggy /bin/sh implementations will have a working bash or
5216 ;; ksh. Whee...
5217 (tramp-find-shell multi-method method user host)
5218 ;; Without (sit-for 0.1) at least, my machine will almost always blow
5219 ;; up on 'not numberp /root' - a race that causes the 'echo ~root'
5220 ;; output of (tramp-find-shell) to show up along with the output of
5221 ;; (tramp-find-ls-command) testing.
5222 ;;
5223 ;; I can't work out why this is a problem though. The (tramp-wait-for-output)
5224 ;; call in (tramp-find-shell) *should* make this not happen, I thought.
5225 ;;
5226 ;; After much debugging I couldn't find any problem with the implementation
5227 ;; of that function though. The workaround stays for me at least. :/
5228 ;;
5229 ;; Daniel Pittman <daniel@danann.net>
5230 (sleep-for 1)
5231 (erase-buffer)
5232 (tramp-find-file-exists-command multi-method method user host)
5233 (make-local-variable 'tramp-ls-command)
5234 (setq tramp-ls-command (tramp-find-ls-command multi-method method user host))
5235 (unless tramp-ls-command
5236 (tramp-message
5237 1
5238 "Danger! Couldn't find ls which groks -n. Muddling through anyway")
5239 (setq tramp-ls-command
5240 (tramp-find-executable multi-method method user host
5241 "ls" tramp-remote-path nil)))
5242 (unless tramp-ls-command
5243 (error "Fatal error: Couldn't find remote executable `ls'"))
5244 (tramp-message 5 "Using remote command `%s' for getting directory listings"
5245 tramp-ls-command)
5246 (tramp-send-command multi-method method user host
5247 (concat "tramp_set_exit_status () {" tramp-rsh-end-of-line
5248 "return $1" tramp-rsh-end-of-line
5249 "}"))
5250 (tramp-wait-for-output)
5251 ;; Set remote PATH variable.
5252 (tramp-set-remote-path multi-method method user host "PATH" tramp-remote-path)
5253 ;; Tell remote shell to use standard time format, needed for
5254 ;; parsing `ls -l' output.
5255 (tramp-send-command multi-method method user host
5256 "LC_TIME=C; export LC_TIME; echo huhu")
5257 (tramp-wait-for-output)
5258 (tramp-send-command multi-method method user host
5259 "mesg n; echo huhu")
5260 (tramp-wait-for-output)
5261 (tramp-send-command multi-method method user host
5262 "biff n ; echo huhu")
5263 (tramp-wait-for-output)
5264 ;; Unalias ls(1) to work around issues with those silly people who make it
5265 ;; spit out ANSI escapes or whatever.
5266 (tramp-send-command multi-method method user host
5267 "unalias ls; echo huhu")
5268 (tramp-wait-for-output)
5269 ;; Does `test A -nt B' work? Use abominable `find' construct if it
5270 ;; doesn't. BSD/OS 4.0 wants the parentheses around the command,
5271 ;; for otherwise the shell crashes.
5272 (erase-buffer)
5273 (make-local-variable 'tramp-test-groks-nt)
5274 (tramp-send-command multi-method method user host
5275 "( test / -nt / )")
5276 (tramp-wait-for-output)
5277 (goto-char (point-min))
5278 (setq tramp-test-groks-nt
5279 (looking-at (format "\n%s\r?\n" (regexp-quote tramp-end-of-output))))
5280 (unless tramp-test-groks-nt
5281 (tramp-send-command
5282 multi-method method user host
5283 (concat "tramp_test_nt () {" tramp-rsh-end-of-line
5284 "test -n \"`find $1 -prune -newer $2 -print`\"" tramp-rsh-end-of-line
5285 "}")))
5286 (tramp-wait-for-output)
5287 ;; Send the fallback `uudecode' script.
5288 (erase-buffer)
5289 (tramp-send-string multi-method method user host tramp-uudecode)
5290 (tramp-wait-for-output)
5291 ;; Find a `perl'.
5292 (erase-buffer)
5293 (let ((tramp-remote-perl
5294 (or (tramp-find-executable multi-method method user host
5295 "perl5" tramp-remote-path nil)
5296 (tramp-find-executable multi-method method user host
5297 "perl" tramp-remote-path nil))))
5298 (when tramp-remote-perl
5299 (tramp-set-connection-property "perl" tramp-remote-perl
5300 multi-method method user host)
5301 ;; Set up stat in Perl if we can.
5302 (when tramp-remote-perl
5303 (tramp-message 5 "Sending the Perl `file-attributes' implementation.")
5304 (tramp-send-string
5305 multi-method method user host
5306 (concat "tramp_file_attributes () {\n"
5307 tramp-remote-perl
5308 " -e '" tramp-perl-file-attributes "' $1 $2 2>/dev/null\n"
5309 "}"))
5310 (tramp-wait-for-output)
5311 (unless (tramp-get-method-parameter
5312 multi-method
5313 (tramp-find-method multi-method method user host)
5314 user host 'tramp-copy-program)
5315 (tramp-message 5 "Sending the Perl `mime-encode' implementations.")
5316 (tramp-send-string
5317 multi-method method user host
5318 (concat "tramp_encode () {\n"
5319 (format tramp-perl-encode tramp-remote-perl)
5320 " 2>/dev/null"
5321 "\n}"))
5322 (tramp-wait-for-output)
5323 (tramp-send-string
5324 multi-method method user host
5325 (concat "tramp_encode_with_module () {\n"
5326 (format tramp-perl-encode-with-module tramp-remote-perl)
5327 " 2>/dev/null"
5328 "\n}"))
5329 (tramp-wait-for-output)
5330 (tramp-message 5 "Sending the Perl `mime-decode' implementations.")
5331 (tramp-send-string
5332 multi-method method user host
5333 (concat "tramp_decode () {\n"
5334 (format tramp-perl-decode tramp-remote-perl)
5335 " 2>/dev/null"
5336 "\n}"))
5337 (tramp-wait-for-output)
5338 (tramp-send-string
5339 multi-method method user host
5340 (concat "tramp_decode_with_module () {\n"
5341 (format tramp-perl-decode-with-module tramp-remote-perl)
5342 " 2>/dev/null"
5343 "\n}"))
5344 (tramp-wait-for-output)))))
5345 ;; Find ln(1)
5346 (erase-buffer)
5347 (let ((ln (tramp-find-executable multi-method method user host
5348 "ln" tramp-remote-path nil)))
5349 (when ln
5350 (tramp-set-connection-property "ln" ln multi-method method user host)))
5351 (erase-buffer)
5352 ;; Find the right encoding/decoding commands to use.
5353 (unless (tramp-get-method-parameter
5354 multi-method
5355 (tramp-find-method multi-method method user host)
5356 user host 'tramp-copy-program)
5357 (tramp-find-inline-encoding multi-method method user host))
5358 ;; If encoding/decoding command are given, test to see if they work.
5359 ;; CCC: Maybe it would be useful to run the encoder both locally and
5360 ;; remotely to see if they produce the same result.
5361 (let ((rem-enc (tramp-get-remote-encoding multi-method method user host))
5362 (rem-dec (tramp-get-remote-decoding multi-method method user host))
5363 (magic-string "xyzzy"))
5364 (when (and (or rem-dec rem-enc) (not (and rem-dec rem-enc)))
5365 (tramp-kill-process multi-method method user host)
5366 ;; Improve error message and/or error check.
5367 (error
5368 "Must give both decoding and encoding command in method definition"))
5369 (when (and rem-enc rem-dec)
5370 (tramp-message
5371 5
5372 "Checking to see if encoding/decoding commands work on remote host...")
5373 (tramp-send-command
5374 multi-method method user host
5375 (format "echo %s | %s | %s"
5376 (tramp-shell-quote-argument magic-string) rem-enc rem-dec))
5377 (tramp-wait-for-output)
5378 (unless (looking-at (regexp-quote magic-string))
5379 (tramp-kill-process multi-method method user host)
5380 (error "Remote host cannot execute de/encoding commands. See buffer `%s' for details"
5381 (buffer-name)))
5382 (erase-buffer)
5383 (tramp-message
5384 5 "Checking to see if encoding/decoding commands work on remote host...done"))))
5385
5386 ;; CCC: We should either implement a Perl version of base64 encoding
5387 ;; and decoding. Then we just use that in the last item. The other
5388 ;; alternative is to use the Perl version of UU encoding. But then
5389 ;; we need a Lisp version of uuencode.
5390 ;;
5391 ;; Old text from documentation of tramp-methods:
5392 ;; Using a uuencode/uudecode inline method is discouraged, please use one
5393 ;; of the base64 methods instead since base64 encoding is much more
5394 ;; reliable and the commands are more standardized between the different
5395 ;; Unix versions. But if you can't use base64 for some reason, please
5396 ;; note that the default uudecode command does not work well for some
5397 ;; Unices, in particular AIX and Irix. For AIX, you might want to use
5398 ;; the following command for uudecode:
5399 ;;
5400 ;; sed '/^begin/d;/^[` ]$/d;/^end/d' | iconv -f uucode -t ISO8859-1
5401 ;;
5402 ;; For Irix, no solution is known yet.
5403
5404 (defvar tramp-coding-commands
5405 '(("mimencode -b" "mimencode -u -b"
5406 base64-encode-region base64-decode-region)
5407 ("mmencode -b" "mmencode -u -b"
5408 base64-encode-region base64-decode-region)
5409 ("recode data..base64" "recode base64..data"
5410 base64-encode-region base64-decode-region)
5411 ("uuencode xxx" "uudecode -o -"
5412 tramp-uuencode-region uudecode-decode-region)
5413 ("uuencode xxx" "uudecode -p"
5414 tramp-uuencode-region uudecode-decode-region)
5415 ("uuencode xxx" "tramp_uudecode"
5416 tramp-uuencode-region uudecode-decode-region)
5417 ("tramp_encode_with_module" "tramp_decode_with_module"
5418 base64-encode-region base64-decode-region)
5419 ("tramp_encode" "tramp_decode"
5420 base64-encode-region base64-decode-region))
5421 "List of coding commands for inline transfer.
5422 Each item is a list that looks like this:
5423
5424 \(REMOTE-ENCODING REMOTE-DECODING LOCAL-ENCODING LOCAL-DECODING)
5425
5426 The REMOTE-ENCODING should be a string, giving a command accepting a
5427 plain file on standard input and writing the encoded file to standard
5428 output. The REMOTE-DECODING should also be a string, giving a command
5429 accepting an encoded file on standard input and writing the decoded
5430 file to standard output.
5431
5432 LOCAL-ENCODING and LOCAL-DECODING can be strings, giving commands, or
5433 symbols, giving functions. If they are strings, then they can contain
5434 the \"%s\" format specifier. If that specifier is present, the input
5435 filename will be put into the command line at that spot. If the
5436 specifier is not present, the input should be read from standard
5437 input.
5438
5439 If they are functions, they will be called with two arguments, start
5440 and end of region, and are expected to replace the region contents
5441 with the encoded or decoded results, respectively.")
5442
5443 (defun tramp-find-inline-encoding (multi-method method user host)
5444 "Find an inline transfer encoding that works.
5445 Goes through the list `tramp-coding-commands'."
5446 (let ((commands tramp-coding-commands)
5447 (magic "xyzzy")
5448 item found)
5449 (while (and commands (null found))
5450 (setq item (pop commands))
5451 (catch 'wont-work
5452 (let ((rem-enc (nth 0 item))
5453 (rem-dec (nth 1 item))
5454 (loc-enc (nth 2 item))
5455 (loc-dec (nth 3 item)))
5456 ;; Check if remote encoding and decoding commands can be
5457 ;; called remotely with null input and output. This makes
5458 ;; sure there are no syntax errors and the command is really
5459 ;; found. Note that we do not redirect stdout to /dev/null,
5460 ;; for two reaons: when checking the decoding command, we
5461 ;; actually check the output it gives. And also, when
5462 ;; redirecting "mimencode" output to /dev/null, then as root
5463 ;; it might change the permissions of /dev/null!
5464 (tramp-message-for-buffer
5465 multi-method method user host 9
5466 "Checking remote encoding command `%s' for sanity" rem-enc)
5467 (unless (zerop (tramp-send-command-and-check
5468 multi-method method user host
5469 (format "%s </dev/null" rem-enc) t))
5470 (throw 'wont-work nil))
5471 (tramp-message-for-buffer
5472 multi-method method user host 9
5473 "Checking remote decoding command `%s' for sanity" rem-dec)
5474 (unless (zerop (tramp-send-command-and-check
5475 multi-method method user host
5476 (format "echo %s | %s | %s"
5477 magic rem-enc rem-dec) t))
5478 (throw 'wont-work nil))
5479 (save-excursion
5480 (goto-char (point-min))
5481 (unless (looking-at (regexp-quote magic))
5482 (throw 'wont-work nil)))
5483 ;; If the local encoder or decoder is a string, the
5484 ;; corresponding command has to work locally.
5485 (when (stringp loc-enc)
5486 (tramp-message-for-buffer
5487 multi-method method user host 9
5488 "Checking local encoding command `%s' for sanity" loc-enc)
5489 (unless (zerop (tramp-call-local-coding-command
5490 loc-enc nil nil))
5491 (throw 'wont-work nil)))
5492 (when (stringp loc-dec)
5493 (tramp-message-for-buffer
5494 multi-method method user host 9
5495 "Checking local decoding command `%s' for sanity" loc-dec)
5496 (unless (zerop (tramp-call-local-coding-command
5497 loc-dec nil nil))
5498 (throw 'wont-work nil)))
5499 ;; CCC: At this point, maybe we should check that the output
5500 ;; of the commands is correct. But for the moment we will
5501 ;; assume that commands working on empty input will also
5502 ;; work in practice.
5503 (setq found item))))
5504 ;; Did we find something? If not, issue error. If so,
5505 ;; set connection properties.
5506 (unless found
5507 (error "Couldn't find an inline transfer encoding"))
5508 (let ((rem-enc (nth 0 found))
5509 (rem-dec (nth 1 found))
5510 (loc-enc (nth 2 found))
5511 (loc-dec (nth 3 found)))
5512 (tramp-message 10 "Using remote encoding %s" rem-enc)
5513 (tramp-set-remote-encoding multi-method method user host rem-enc)
5514 (tramp-message 10 "Using remote decoding %s" rem-dec)
5515 (tramp-set-remote-decoding multi-method method user host rem-dec)
5516 (tramp-message 10 "Using local encoding %s" loc-enc)
5517 (tramp-set-local-encoding multi-method method user host loc-enc)
5518 (tramp-message 10 "Using local decoding %s" loc-dec)
5519 (tramp-set-local-decoding multi-method method user host loc-dec))))
5520
5521 (defun tramp-call-local-coding-command (cmd input output)
5522 "Call the local encoding or decoding command.
5523 If CMD contains \"%s\", provide input file INPUT there in command.
5524 Otherwise, INPUT is passed via standard input.
5525 INPUT can also be nil which means `/dev/null'.
5526 OUTPUT can be a string (which specifies a filename), or t (which
5527 means standard output and thus the current buffer), or nil (which
5528 means discard it)."
5529 (call-process
5530 tramp-encoding-shell ;program
5531 (when (and input (not (string-match "%s" cmd)))
5532 input) ;input
5533 (if (eq output t) t nil) ;output
5534 nil ;redisplay
5535 tramp-encoding-command-switch
5536 ;; actual shell command
5537 (concat
5538 (if (string-match "%s" cmd) (format cmd input) cmd)
5539 (if (stringp output) (concat "> " output) ""))))
5540
5541 (defun tramp-maybe-open-connection (multi-method method user host)
5542 "Maybe open a connection to HOST, logging in as USER, using METHOD.
5543 Does not do anything if a connection is already open, but re-opens the
5544 connection if a previous connection has died for some reason."
5545 (let ((p (get-buffer-process
5546 (tramp-get-buffer multi-method method user host)))
5547 last-cmd-time)
5548 ;; If too much time has passed since last command was sent, look
5549 ;; whether process is still alive. If it isn't, kill it. When
5550 ;; using ssh, it can sometimes happen that the remote end has hung
5551 ;; up but the local ssh client doesn't recognize this until it
5552 ;; tries to send some data to the remote end. So that's why we
5553 ;; try to send a command from time to time, then look again
5554 ;; whether the process is really alive.
5555 (save-excursion
5556 (set-buffer (tramp-get-buffer multi-method method user host))
5557 (when (and tramp-last-cmd-time
5558 (> (tramp-time-diff (current-time) tramp-last-cmd-time) 60)
5559 p (processp p) (memq (process-status p) '(run open)))
5560 (tramp-send-command
5561 multi-method method user host "echo are you awake" nil t)
5562 (unless (tramp-wait-for-output 10)
5563 (delete-process p)
5564 (setq p nil))
5565 (erase-buffer)))
5566 (unless (and p (processp p) (memq (process-status p) '(run open)))
5567 (when (and p (processp p))
5568 (delete-process p))
5569 (funcall (tramp-get-method-parameter
5570 multi-method
5571 (tramp-find-method multi-method method user host)
5572 user host 'tramp-connection-function)
5573 multi-method method user host))))
5574
5575 (defun tramp-send-command
5576 (multi-method method user host command &optional noerase neveropen)
5577 "Send the COMMAND to USER at HOST (logged in using METHOD).
5578 Erases temporary buffer before sending the command (unless NOERASE
5579 is true).
5580 If optional seventh arg NEVEROPEN is non-nil, never try to open the
5581 connection. This is meant to be used from
5582 `tramp-maybe-open-connection' only."
5583 (or neveropen
5584 (tramp-maybe-open-connection multi-method method user host))
5585 (setq tramp-last-cmd-time (current-time))
5586 (when tramp-debug-buffer
5587 (save-excursion
5588 (set-buffer (tramp-get-debug-buffer multi-method method user host))
5589 (goto-char (point-max))
5590 (tramp-insert-with-face 'bold (format "$ %s\n" command))))
5591 (let ((proc nil))
5592 (set-buffer (tramp-get-buffer multi-method method user host))
5593 (unless noerase (erase-buffer))
5594 (setq proc (get-buffer-process (current-buffer)))
5595 (process-send-string proc
5596 (concat command tramp-rsh-end-of-line))))
5597
5598 (defun tramp-send-command-internal
5599 (multi-method method user host command &optional msg)
5600 "Send command to remote host and wait for success.
5601 Sends COMMAND, then waits 30 seconds for shell prompt."
5602 (tramp-send-command multi-method method user host command t t)
5603 (when msg
5604 (tramp-message 9 "Waiting 30s for %s..." msg))
5605 (tramp-barf-if-no-shell-prompt
5606 nil 30
5607 "Couldn't `%s', see buffer `%s'" command (buffer-name)))
5608
5609 (defun tramp-wait-for-output (&optional timeout)
5610 "Wait for output from remote rsh command."
5611 (let ((proc (get-buffer-process (current-buffer)))
5612 (found nil)
5613 (start-time (current-time))
5614 (end-of-output (concat "^"
5615 (regexp-quote tramp-end-of-output)
5616 "\r?$")))
5617 ;; Algorithm: get waiting output. See if last line contains
5618 ;; end-of-output sentinel. If not, wait a bit and again get
5619 ;; waiting output. Repeat until timeout expires or end-of-output
5620 ;; sentinel is seen. Will hang if timeout is nil and
5621 ;; end-of-output sentinel never appears.
5622 (save-match-data
5623 (cond (timeout
5624 ;; Work around an XEmacs bug, where the timeout expires
5625 ;; faster than it should. This degenerates into polling
5626 ;; for buggy XEmacsen, but oh, well.
5627 (while (and (not found)
5628 (< (tramp-time-diff (current-time) start-time)
5629 timeout))
5630 (with-timeout (timeout)
5631 (while (not found)
5632 (accept-process-output proc 1)
5633 (goto-char (point-max))
5634 (forward-line -1)
5635 (setq found (looking-at end-of-output))))))
5636 (t
5637 (while (not found)
5638 (accept-process-output proc 1)
5639 (goto-char (point-max))
5640 (forward-line -1)
5641 (setq found (looking-at end-of-output))))))
5642 ;; At this point, either the timeout has expired or we have found
5643 ;; the end-of-output sentinel.
5644 (when found
5645 (goto-char (point-max))
5646 (forward-line -2)
5647 (delete-region (point) (point-max)))
5648 ;; Add output to debug buffer if appropriate.
5649 (when tramp-debug-buffer
5650 (append-to-buffer
5651 (tramp-get-debug-buffer tramp-current-multi-method tramp-current-method
5652 tramp-current-user tramp-current-host)
5653 (point-min) (point-max))
5654 (when (not found)
5655 (save-excursion
5656 (set-buffer
5657 (tramp-get-debug-buffer tramp-current-multi-method tramp-current-method
5658 tramp-current-user tramp-current-host))
5659 (goto-char (point-max))
5660 (insert "[[Remote prompt `" end-of-output "' not found"
5661 (if timeout (format " in %d secs" timeout) "")
5662 "]]"))))
5663 (goto-char (point-min))
5664 ;; Return value is whether end-of-output sentinel was found.
5665 found))
5666
5667 (defun tramp-match-string-list (&optional string)
5668 "Returns list of all match strings.
5669 That is, (list (match-string 0) (match-string 1) ...), according to the
5670 number of matches."
5671 (let* ((nmatches (/ (length (match-data)) 2))
5672 (i (- nmatches 1))
5673 (res nil))
5674 (while (>= i 0)
5675 (setq res (cons (match-string i string) res))
5676 (setq i (- i 1)))
5677 res))
5678
5679 (defun tramp-send-command-and-check (multi-method method user host command
5680 &optional subshell)
5681 "Run COMMAND and check its exit status.
5682 MULTI-METHOD and METHOD specify how to log in (as USER) to the remote HOST.
5683 Sends `echo $?' along with the COMMAND for checking the exit status. If
5684 COMMAND is nil, just sends `echo $?'. Returns the exit status found.
5685
5686 If the optional argument SUBSHELL is non-nil, the command is executed in
5687 a subshell, ie surrounded by parentheses."
5688 (tramp-send-command multi-method method user host
5689 (concat (if subshell "( " "")
5690 command
5691 (if command " 2>/dev/null; " "")
5692 "echo tramp_exit_status $?"
5693 (if subshell " )" " ")))
5694 (tramp-wait-for-output)
5695 (goto-char (point-max))
5696 (unless (search-backward "tramp_exit_status " nil t)
5697 (error "Couldn't find exit status of `%s'" command))
5698 (skip-chars-forward "^ ")
5699 (read (current-buffer)))
5700
5701 (defun tramp-barf-unless-okay (multi-method method user host command subshell
5702 signal fmt &rest args)
5703 "Run COMMAND, check exit status, throw error if exit status not okay.
5704 Similar to `tramp-send-command-and-check' but accepts two more arguments
5705 FMT and ARGS which are passed to `error'."
5706 (unless (zerop (tramp-send-command-and-check
5707 multi-method method user host command subshell))
5708 ;; CCC: really pop-to-buffer? Maybe it's appropriate to be more
5709 ;; silent.
5710 (pop-to-buffer (current-buffer))
5711 (funcall 'signal signal (apply 'format fmt args))))
5712
5713 ;; It seems that Tru64 Unix does not like it if long strings are sent
5714 ;; to it in one go. (This happens when sending the Perl
5715 ;; `file-attributes' implementation, for instance.) Therefore, we
5716 ;; have this function which waits a bit at each line.
5717 (defun tramp-send-string
5718 (multi-method method user host string)
5719 "Send the STRING to USER at HOST using METHOD.
5720
5721 The STRING is expected to use Unix line-endings, but the lines sent to
5722 the remote host use line-endings as defined in the variable
5723 `tramp-rsh-end-of-line'."
5724 (let ((proc (get-buffer-process
5725 (tramp-get-buffer multi-method method user host))))
5726 (unless proc
5727 (error "Can't send string to remote host -- not logged in"))
5728 ;; debug message
5729 (when tramp-debug-buffer
5730 (save-excursion
5731 (set-buffer (tramp-get-debug-buffer multi-method method user host))
5732 (goto-char (point-max))
5733 (tramp-insert-with-face 'bold (format "$ %s\n" string))))
5734 ;; replace "\n" by `tramp-rsh-end-of-line'
5735 (setq string
5736 (mapconcat 'identity
5737 (split-string string "\n")
5738 tramp-rsh-end-of-line))
5739 (unless (or (string= string "")
5740 (string-equal (substring string -1) tramp-rsh-end-of-line))
5741 (setq string (concat string tramp-rsh-end-of-line)))
5742 ;; send the string
5743 (if (and tramp-chunksize (not (zerop tramp-chunksize)))
5744 (let ((pos 0)
5745 (end (length string)))
5746 (while (< pos end)
5747 (tramp-message-for-buffer
5748 multi-method method user host 10
5749 "Sending chunk from %s to %s"
5750 pos (min (+ pos tramp-chunksize) end))
5751 (process-send-string
5752 proc (substring string pos (min (+ pos tramp-chunksize) end)))
5753 (setq pos (+ pos tramp-chunksize))
5754 (sleep-for 0.1)))
5755 (process-send-string proc string))))
5756
5757 (defun tramp-send-eof (multi-method method user host)
5758 "Send EOF to the remote end.
5759 METHOD, HOST and USER specify the connection."
5760 (let ((proc (get-buffer-process
5761 (tramp-get-buffer multi-method method user host))))
5762 (unless proc
5763 (error "Can't send EOF to remote host -- not logged in"))
5764 (process-send-eof proc)))
5765 ; (process-send-string proc "\^D")))
5766
5767 (defun tramp-kill-process (multi-method method user host)
5768 "Kill the connection process used by Tramp.
5769 MULTI-METHOD, METHOD, USER, and HOST specify the connection."
5770 (let ((proc (get-buffer-process
5771 (tramp-get-buffer multi-method method user host))))
5772 (kill-process proc)))
5773
5774 (defun tramp-discard-garbage-erase-buffer (p multi-method method user host)
5775 "Erase buffer, then discard subsequent garbage.
5776 If `tramp-discard-garbage' is nil, just erase buffer."
5777 (if (not tramp-discard-garbage)
5778 (erase-buffer)
5779 (while (prog1 (erase-buffer) (accept-process-output p 0.25))
5780 (when tramp-debug-buffer
5781 (save-excursion
5782 (set-buffer (tramp-get-debug-buffer multi-method method user host))
5783 (goto-char (point-max))
5784 (tramp-insert-with-face
5785 'bold (format "Additional characters detected\n")))))))
5786
5787 (defun tramp-mode-string-to-int (mode-string)
5788 "Converts a ten-letter `drwxrwxrwx'-style mode string into mode bits."
5789 (let* ((mode-chars (string-to-vector mode-string))
5790 (owner-read (aref mode-chars 1))
5791 (owner-write (aref mode-chars 2))
5792 (owner-execute-or-setid (aref mode-chars 3))
5793 (group-read (aref mode-chars 4))
5794 (group-write (aref mode-chars 5))
5795 (group-execute-or-setid (aref mode-chars 6))
5796 (other-read (aref mode-chars 7))
5797 (other-write (aref mode-chars 8))
5798 (other-execute-or-sticky (aref mode-chars 9)))
5799 (save-match-data
5800 (logior
5801 (case owner-read
5802 (?r (tramp-octal-to-decimal "00400")) (?- 0)
5803 (t (error "Second char `%c' must be one of `r-'" owner-read)))
5804 (case owner-write
5805 (?w (tramp-octal-to-decimal "00200")) (?- 0)
5806 (t (error "Third char `%c' must be one of `w-'" owner-write)))
5807 (case owner-execute-or-setid
5808 (?x (tramp-octal-to-decimal "00100"))
5809 (?S (tramp-octal-to-decimal "04000"))
5810 (?s (tramp-octal-to-decimal "04100"))
5811 (?- 0)
5812 (t (error "Fourth char `%c' must be one of `xsS-'"
5813 owner-execute-or-setid)))
5814 (case group-read
5815 (?r (tramp-octal-to-decimal "00040")) (?- 0)
5816 (t (error "Fifth char `%c' must be one of `r-'" group-read)))
5817 (case group-write
5818 (?w (tramp-octal-to-decimal "00020")) (?- 0)
5819 (t (error "Sixth char `%c' must be one of `w-'" group-write)))
5820 (case group-execute-or-setid
5821 (?x (tramp-octal-to-decimal "00010"))
5822 (?S (tramp-octal-to-decimal "02000"))
5823 (?s (tramp-octal-to-decimal "02010"))
5824 (?- 0)
5825 (t (error "Seventh char `%c' must be one of `xsS-'"
5826 group-execute-or-setid)))
5827 (case other-read
5828 (?r (tramp-octal-to-decimal "00004")) (?- 0)
5829 (t (error "Eighth char `%c' must be one of `r-'" other-read)))
5830 (case other-write
5831 (?w (tramp-octal-to-decimal "00002")) (?- 0)
5832 (t (error "Nineth char `%c' must be one of `w-'" other-write)))
5833 (case other-execute-or-sticky
5834 (?x (tramp-octal-to-decimal "00001"))
5835 (?T (tramp-octal-to-decimal "01000"))
5836 (?t (tramp-octal-to-decimal "01001"))
5837 (?- 0)
5838 (t (error "Tenth char `%c' must be one of `xtT-'"
5839 other-execute-or-sticky)))))))
5840
5841
5842 (defun tramp-file-mode-from-int (mode)
5843 "Turn an integer representing a file mode into an ls(1)-like string."
5844 (let ((type (cdr (assoc (logand (lsh mode -12) 15) tramp-file-mode-type-map)))
5845 (user (logand (lsh mode -6) 7))
5846 (group (logand (lsh mode -3) 7))
5847 (other (logand (lsh mode -0) 7))
5848 (suid (> (logand (lsh mode -9) 4) 0))
5849 (sgid (> (logand (lsh mode -9) 2) 0))
5850 (sticky (> (logand (lsh mode -9) 1) 0)))
5851 (setq user (tramp-file-mode-permissions user suid "s"))
5852 (setq group (tramp-file-mode-permissions group sgid "s"))
5853 (setq other (tramp-file-mode-permissions other sticky "t"))
5854 (concat type user group other)))
5855
5856
5857 (defun tramp-file-mode-permissions (perm suid suid-text)
5858 "Convert a permission bitset into a string.
5859 This is used internally by `tramp-file-mode-from-int'."
5860 (let ((r (> (logand perm 4) 0))
5861 (w (> (logand perm 2) 0))
5862 (x (> (logand perm 1) 0)))
5863 (concat (or (and r "r") "-")
5864 (or (and w "w") "-")
5865 (or (and suid x suid-text) ; suid, execute
5866 (and suid (upcase suid-text)) ; suid, !execute
5867 (and x "x") "-")))) ; !suid
5868
5869
5870 (defun tramp-decimal-to-octal (i)
5871 "Return a string consisting of the octal digits of I.
5872 Not actually used. Use `(format \"%o\" i)' instead?"
5873 (cond ((< i 0) (error "Cannot convert negative number to octal"))
5874 ((not (integerp i)) (error "Cannot convert non-integer to octal"))
5875 ((zerop i) "0")
5876 (t (concat (tramp-decimal-to-octal (/ i 8))
5877 (number-to-string (% i 8))))))
5878
5879
5880 ;;(defun tramp-octal-to-decimal (ostr)
5881 ;; "Given a string of octal digits, return a decimal number."
5882 ;; (cond ((null ostr) 0)
5883 ;; ((string= "" ostr) 0)
5884 ;; (t (let ((last (aref ostr (1- (length ostr))))
5885 ;; (rest (substring ostr 0 (1- (length ostr)))))
5886 ;; (unless (and (>= last ?0)
5887 ;; (<= last ?7))
5888 ;; (error "Not an octal digit: %c" last))
5889 ;; (+ (- last ?0) (* 8 (tramp-octal-to-decimal rest)))))))
5890 ;; Kudos to Gerd Moellmann for this suggestion.
5891 (defun tramp-octal-to-decimal (ostr)
5892 "Given a string of octal digits, return a decimal number."
5893 (let ((x (or ostr "")))
5894 ;; `save-match' is in `tramp-mode-string-to-int' which calls this.
5895 (unless (string-match "\\`[0-7]*\\'" x)
5896 (error "Non-octal junk in string `%s'" x))
5897 (string-to-number ostr 8)))
5898
5899 (defun tramp-shell-case-fold (string)
5900 "Converts STRING to shell glob pattern which ignores case."
5901 (mapconcat
5902 (lambda (c)
5903 (if (equal (downcase c) (upcase c))
5904 (vector c)
5905 (format "[%c%c]" (downcase c) (upcase c))))
5906 string
5907 ""))
5908
5909
5910 ;; ------------------------------------------------------------
5911 ;; -- TRAMP file names --
5912 ;; ------------------------------------------------------------
5913 ;; Conversion functions between external representation and
5914 ;; internal data structure. Convenience functions for internal
5915 ;; data structure.
5916
5917 (defstruct tramp-file-name multi-method method user host localname)
5918
5919 (defun tramp-tramp-file-p (name)
5920 "Return t iff NAME is a tramp file."
5921 (save-match-data
5922 (string-match tramp-file-name-regexp name)))
5923
5924 ;; HHH: Changed. Used to assign the return value of (user-login-name)
5925 ;; to the `user' part of the structure if a user name was not
5926 ;; provided, now it assigns nil.
5927 (defun tramp-dissect-file-name (name)
5928 "Return an `tramp-file-name' structure.
5929 The structure consists of remote method, remote user, remote host and
5930 localname (file name on remote host)."
5931 (save-match-data
5932 (let* ((match (string-match (nth 0 tramp-file-name-structure) name))
5933 (method
5934 ; single-hop
5935 (if match (match-string (nth 1 tramp-file-name-structure) name)
5936 ; maybe multi-hop
5937 (string-match
5938 (format (nth 0 tramp-multi-file-name-structure)
5939 (nth 0 tramp-multi-file-name-hop-structure)) name)
5940 (match-string (nth 1 tramp-multi-file-name-structure) name))))
5941 (if (and method (member method tramp-multi-methods))
5942 ;; If it's a multi method, the file name structure contains
5943 ;; arrays of method, user and host.
5944 (tramp-dissect-multi-file-name name)
5945 ;; Normal method. First, find out default method.
5946 (unless match (error "Not a tramp file name: %s" name))
5947 (let ((user (match-string (nth 2 tramp-file-name-structure) name))
5948 (host (match-string (nth 3 tramp-file-name-structure) name))
5949 (localname (match-string (nth 4 tramp-file-name-structure) name)))
5950 (make-tramp-file-name
5951 :multi-method nil
5952 :method method
5953 :user (or user nil)
5954 :host host
5955 :localname localname))))))
5956
5957 (defun tramp-find-default-method (user host)
5958 "Look up the right method to use in `tramp-default-method-alist'."
5959 (let ((choices tramp-default-method-alist)
5960 (method tramp-default-method)
5961 item)
5962 (while choices
5963 (setq item (pop choices))
5964 (when (and (string-match (nth 0 item) (or host ""))
5965 (string-match (nth 1 item) (or user "")))
5966 (setq method (nth 2 item))
5967 (setq choices nil)))
5968 method))
5969
5970 (defun tramp-find-method (multi-method method user host)
5971 "Return the right method string to use.
5972 This is MULTI-METHOD, if non-nil. Otherwise, it is METHOD, if non-nil.
5973 If both MULTI-METHOD and METHOD are nil, do a lookup in
5974 `tramp-default-method-alist'."
5975 (or multi-method method (tramp-find-default-method user host)))
5976
5977 ;; HHH: Not Changed. Multi method. Will probably not handle the case where
5978 ;; a user name is not provided in the "file name" very well.
5979 (defun tramp-dissect-multi-file-name (name)
5980 "Not implemented yet."
5981 (let ((regexp (nth 0 tramp-multi-file-name-structure))
5982 (method-index (nth 1 tramp-multi-file-name-structure))
5983 (hops-index (nth 2 tramp-multi-file-name-structure))
5984 (localname-index (nth 3 tramp-multi-file-name-structure))
5985 (hop-regexp (nth 0 tramp-multi-file-name-hop-structure))
5986 (hop-method-index (nth 1 tramp-multi-file-name-hop-structure))
5987 (hop-user-index (nth 2 tramp-multi-file-name-hop-structure))
5988 (hop-host-index (nth 3 tramp-multi-file-name-hop-structure))
5989 method hops len hop-methods hop-users hop-hosts localname)
5990 (unless (string-match (format regexp hop-regexp) name)
5991 (error "Not a multi tramp file name: %s" name))
5992 (setq method (match-string method-index name))
5993 (setq hops (match-string hops-index name))
5994 (setq len (/ (length (match-data t)) 2))
5995 (when (< localname-index 0) (incf localname-index len))
5996 (setq localname (match-string localname-index name))
5997 (let ((index 0))
5998 (while (string-match hop-regexp hops index)
5999 (setq index (match-end 0))
6000 (setq hop-methods
6001 (cons (match-string hop-method-index hops) hop-methods))
6002 (setq hop-users
6003 (cons (match-string hop-user-index hops) hop-users))
6004 (setq hop-hosts
6005 (cons (match-string hop-host-index hops) hop-hosts))))
6006 (make-tramp-file-name
6007 :multi-method method
6008 :method (apply 'vector (reverse hop-methods))
6009 :user (apply 'vector (reverse hop-users))
6010 :host (apply 'vector (reverse hop-hosts))
6011 :localname localname)))
6012
6013 (defun tramp-make-tramp-file-name (multi-method method user host localname)
6014 "Constructs a tramp file name from METHOD, USER, HOST and LOCALNAME."
6015 (if multi-method
6016 (tramp-make-tramp-multi-file-name multi-method method user host localname)
6017 (format-spec
6018 (concat tramp-prefix-format
6019 (when method (concat "%m" tramp-postfix-single-method-format))
6020 (when user (concat "%u" tramp-postfix-user-format))
6021 (when host (concat "%h" tramp-postfix-host-format))
6022 (when localname (concat "%p")))
6023 `((?m . ,method) (?u . ,user) (?h . ,host) (?p . ,localname)))))
6024
6025 ;; CCC: Henrik Holm: Not Changed. Multi Method. What should be done
6026 ;; with this when USER is nil?
6027 (defun tramp-make-tramp-multi-file-name (multi-method method user host localname)
6028 "Constructs a tramp file name for a multi-hop method."
6029 (unless tramp-make-multi-tramp-file-format
6030 (error "`tramp-make-multi-tramp-file-format' is nil"))
6031 (let* ((prefix-format (nth 0 tramp-make-multi-tramp-file-format))
6032 (hop-format (nth 1 tramp-make-multi-tramp-file-format))
6033 (localname-format (nth 2 tramp-make-multi-tramp-file-format))
6034 (prefix (format-spec prefix-format `((?m . ,multi-method))))
6035 (hops "")
6036 (localname (format-spec localname-format `((?p . ,localname))))
6037 (i 0)
6038 (len (length method)))
6039 (while (< i len)
6040 (let ((m (aref method i)) (u (aref user i)) (h (aref host i)))
6041 (setq hops (concat hops (format-spec hop-format
6042 `((?m . ,m) (?u . ,u) (?h . ,h)))))
6043 (incf i)))
6044 (concat prefix hops localname)))
6045
6046 (defun tramp-make-copy-program-file-name (user host localname)
6047 "Create a file name suitable to be passed to `rcp' and workalikes."
6048 (if user
6049 (format "%s@%s:%s" user host localname)
6050 (format "%s:%s" host localname)))
6051
6052 (defun tramp-method-out-of-band-p (multi-method method user host)
6053 "Return t if this is an out-of-band method, nil otherwise.
6054 It is important to check for this condition, since it is not possible
6055 to enter a password for the `tramp-copy-program'."
6056 (tramp-get-method-parameter
6057 multi-method
6058 (tramp-find-method multi-method method user host)
6059 user host 'tramp-copy-program))
6060
6061 ;; Variables local to connection.
6062
6063 (defun tramp-get-ls-command (multi-method method user host)
6064 (save-excursion
6065 (tramp-maybe-open-connection multi-method method user host)
6066 (set-buffer (tramp-get-buffer multi-method method user host))
6067 tramp-ls-command))
6068
6069 (defun tramp-get-test-groks-nt (multi-method method user host)
6070 (save-excursion
6071 (tramp-maybe-open-connection multi-method method user host)
6072 (set-buffer (tramp-get-buffer multi-method method user host))
6073 tramp-test-groks-nt))
6074
6075 (defun tramp-get-file-exists-command (multi-method method user host)
6076 (save-excursion
6077 (tramp-maybe-open-connection multi-method method user host)
6078 (set-buffer (tramp-get-buffer multi-method method user host))
6079 tramp-file-exists-command))
6080
6081 (defun tramp-get-remote-perl (multi-method method user host)
6082 (tramp-get-connection-property "perl" nil multi-method method user host))
6083
6084 (defun tramp-get-remote-ln (multi-method method user host)
6085 (tramp-get-connection-property "ln" nil multi-method method user host))
6086
6087 ;; Get a property of a TRAMP connection.
6088 (defun tramp-get-connection-property
6089 (property default multi-method method user host)
6090 "Get the named property for the connection.
6091 If the value is not set for the connection, return `default'"
6092 (tramp-maybe-open-connection multi-method method user host)
6093 (with-current-buffer (tramp-get-buffer multi-method method user host)
6094 (let (error)
6095 (condition-case nil
6096 (symbol-value (intern (concat "tramp-connection-property-" property)))
6097 (error default)))))
6098
6099 ;; Set a property of a TRAMP connection.
6100 (defun tramp-set-connection-property
6101 (property value multi-method method user host)
6102 "Set the named property of a TRAMP connection."
6103 (tramp-maybe-open-connection multi-method method user host)
6104 (with-current-buffer (tramp-get-buffer multi-method method user host)
6105 (set (make-local-variable
6106 (intern (concat "tramp-connection-property-" property)))
6107 value)))
6108
6109 ;; Some predefined connection properties.
6110 (defun tramp-set-remote-encoding (multi-method method user host rem-enc)
6111 (tramp-set-connection-property "remote-encoding" rem-enc
6112 multi-method method user host))
6113 (defun tramp-get-remote-encoding (multi-method method user host)
6114 (tramp-get-connection-property "remote-encoding" nil
6115 multi-method method user host))
6116
6117 (defun tramp-set-remote-decoding (multi-method method user host rem-dec)
6118 (tramp-set-connection-property "remote-decoding" rem-dec
6119 multi-method method user host))
6120 (defun tramp-get-remote-decoding (multi-method method user host)
6121 (tramp-get-connection-property "remote-decoding" nil
6122 multi-method method user host))
6123
6124 (defun tramp-set-local-encoding (multi-method method user host loc-enc)
6125 (tramp-set-connection-property "local-encoding" loc-enc
6126 multi-method method user host))
6127 (defun tramp-get-local-encoding (multi-method method user host)
6128 (tramp-get-connection-property "local-encoding" nil
6129 multi-method method user host))
6130
6131 (defun tramp-set-local-decoding (multi-method method user host loc-dec)
6132 (tramp-set-connection-property "local-decoding" loc-dec
6133 multi-method method user host))
6134 (defun tramp-get-local-decoding (multi-method method user host)
6135 (tramp-get-connection-property "local-decoding" nil
6136 multi-method method user host))
6137
6138 (defun tramp-get-method-parameter (multi-method method user host param)
6139 "Return the method parameter PARAM.
6140 If the `tramp-methods' entry does not exist, use the variable PARAM
6141 as default."
6142 (unless (boundp param)
6143 (error "Non-existing method parameter `%s'" param))
6144 (let ((entry (assoc param
6145 (assoc (tramp-find-method multi-method method user host)
6146 tramp-methods))))
6147 (if entry
6148 (second entry)
6149 (symbol-value param))))
6150
6151
6152 ;; Auto saving to a special directory.
6153
6154 (defun tramp-make-auto-save-file-name (fn)
6155 "Returns a file name in `tramp-auto-save-directory' for autosaving this file."
6156 (when tramp-auto-save-directory
6157 (unless (file-exists-p tramp-auto-save-directory)
6158 (make-directory tramp-auto-save-directory t)))
6159 ;; jka-compr doesn't like auto-saving, so by appending "~" to the
6160 ;; file name we make sure that jka-compr isn't used for the
6161 ;; auto-save file.
6162 (let ((buffer-file-name (expand-file-name
6163 (tramp-subst-strs-in-string '(("_" . "|")
6164 ("/" . "_a")
6165 (":" . "_b")
6166 ("|" . "__")
6167 ("[" . "_l")
6168 ("]" . "_r"))
6169 fn)
6170 tramp-auto-save-directory)))
6171 (make-auto-save-file-name)))
6172
6173 (defadvice make-auto-save-file-name
6174 (around tramp-advice-make-auto-save-file-name () activate)
6175 "Invoke `tramp-make-auto-save-file-name' for tramp files."
6176 (if (and (buffer-file-name) (tramp-tramp-file-p (buffer-file-name))
6177 tramp-auto-save-directory)
6178 (setq ad-return-value
6179 (tramp-make-auto-save-file-name (buffer-file-name)))
6180 ad-do-it))
6181
6182 (defun tramp-subst-strs-in-string (alist string)
6183 "Replace all occurrences of the string FROM with TO in STRING.
6184 ALIST is of the form ((FROM . TO) ...)."
6185 (save-match-data
6186 (while alist
6187 (let* ((pr (car alist))
6188 (from (car pr))
6189 (to (cdr pr)))
6190 (while (string-match (regexp-quote from) string)
6191 (setq string (replace-match to t t string)))
6192 (setq alist (cdr alist))))
6193 string))
6194
6195 (defun tramp-insert-with-face (face string)
6196 "Insert text with a specific face."
6197 (let ((start (point)))
6198 (insert string)
6199 (add-text-properties start (point) (list 'face face))))
6200
6201 ;; ------------------------------------------------------------
6202 ;; -- Compatibility functions section --
6203 ;; ------------------------------------------------------------
6204
6205 (defun tramp-temporary-file-directory ()
6206 "Return name of directory for temporary files (compat function).
6207 For Emacs, this is the variable `temporary-file-directory', for XEmacs
6208 this is the function `temp-directory'."
6209 (cond ((boundp 'temporary-file-directory)
6210 (symbol-value 'temporary-file-directory))
6211 ((fboundp 'temp-directory)
6212 (funcall (symbol-function 'temp-directory))) ;pacify byte-compiler
6213 ((let ((d (getenv "TEMP"))) (and d (file-directory-p d)))
6214 (file-name-as-directory (getenv "TEMP")))
6215 ((let ((d (getenv "TMP"))) (and d (file-directory-p d)))
6216 (file-name-as-directory (getenv "TMP")))
6217 ((let ((d (getenv "TMPDIR"))) (and d (file-directory-p d)))
6218 (file-name-as-directory (getenv "TMPDIR")))
6219 ((file-exists-p "c:/temp") (file-name-as-directory "c:/temp"))
6220 (t (message (concat "Neither `temporary-file-directory' nor "
6221 "`temp-directory' is defined -- using /tmp."))
6222 (file-name-as-directory "/tmp"))))
6223
6224 (defun tramp-read-passwd (prompt)
6225 "Read a password from user (compat function).
6226 Invokes `read-passwd' if that is defined, else `ange-ftp-read-passwd'."
6227 (apply
6228 (if (fboundp 'read-passwd) #'read-passwd #'ange-ftp-read-passwd)
6229 (list prompt)))
6230
6231 (defun tramp-time-diff (t1 t2)
6232 "Return the difference between the two times, in seconds.
6233 T1 and T2 are time values (as returned by `current-time' for example).
6234
6235 NOTE: This function will fail if the time difference is too large to
6236 fit in an integer."
6237 ;; Pacify byte-compiler with `symbol-function'.
6238 (cond ((and (fboundp 'subtract-time)
6239 (fboundp 'float-time))
6240 (funcall (symbol-function 'float-time)
6241 (funcall (symbol-function 'subtract-time) t1 t2)))
6242 ((and (fboundp 'subtract-time)
6243 (fboundp 'time-to-seconds))
6244 (funcall (symbol-function 'time-to-seconds)
6245 (funcall (symbol-function 'subtract-time) t1 t2)))
6246 ((fboundp 'itimer-time-difference)
6247 (floor (funcall
6248 (symbol-function 'itimer-time-difference)
6249 (if (< (length t1) 3) (append t1 '(0)) t1)
6250 (if (< (length t2) 3) (append t2 '(0)) t2))))
6251 (t
6252 ;; snarfed from Emacs 21 time-date.el; combining
6253 ;; time-to-seconds and subtract-time
6254 (let ((time (let ((borrow (< (cadr t1) (cadr t2))))
6255 (list (- (car t1) (car t2) (if borrow 1 0))
6256 (- (+ (if borrow 65536 0) (cadr t1)) (cadr t2))))))
6257 (+ (* (car time) 65536.0)
6258 (cadr time)
6259 (/ (or (nth 2 time) 0) 1000000.0))))))
6260
6261 (defun tramp-coding-system-change-eol-conversion (coding-system eol-type)
6262 "Return a coding system like CODING-SYSTEM but with given EOL-TYPE.
6263 EOL-TYPE can be one of `dos', `unix', or `mac'."
6264 (cond ((fboundp 'coding-system-change-eol-conversion)
6265 (apply #'coding-system-change-eol-conversion
6266 (list coding-system eol-type)))
6267 ((fboundp 'subsidiary-coding-system)
6268 (apply
6269 #'subsidiary-coding-system
6270 (list coding-system
6271 (cond ((eq eol-type 'dos) 'crlf)
6272 ((eq eol-type 'unix) 'lf)
6273 ((eq eol-type 'mac) 'cr)
6274 (t
6275 (error "Unknown EOL-TYPE `%s', must be %s"
6276 eol-type
6277 "`dos', `unix', or `mac'"))))))
6278 (t (error "Can't change EOL conversion -- is MULE missing?"))))
6279
6280 (defun tramp-split-string (string pattern)
6281 "Like `split-string' but omit empty strings.
6282 In Emacs, (split-string \"/foo/bar\" \"/\") returns (\"foo\" \"bar\").
6283 This is, the first, empty, element is omitted. In XEmacs, the first
6284 element is not omitted.
6285
6286 Note: this function has been written for `tramp-handle-file-truename'.
6287 If you want to use it for something else, you'll have to check whether
6288 it does the right thing."
6289 (delete "" (split-string string pattern)))
6290
6291 ;; ------------------------------------------------------------
6292 ;; -- Kludges section --
6293 ;; ------------------------------------------------------------
6294
6295 ;; Currently (as of Emacs 20.5), the function `shell-quote-argument'
6296 ;; does not deal well with newline characters. Newline is replaced by
6297 ;; backslash newline. But if, say, the string `a backslash newline b'
6298 ;; is passed to a shell, the shell will expand this into "ab",
6299 ;; completely omitting the newline. This is not what was intended.
6300 ;; It does not appear to be possible to make the function
6301 ;; `shell-quote-argument' work with newlines without making it
6302 ;; dependent on the shell used. But within this package, we know that
6303 ;; we will always use a Bourne-like shell, so we use an approach which
6304 ;; groks newlines.
6305 ;;
6306 ;; The approach is simple: we call `shell-quote-argument', then
6307 ;; massage the newline part of the result.
6308 ;;
6309 ;; This function should produce a string which is grokked by a Unix
6310 ;; shell, even if the Emacs is running on Windows. Since this is the
6311 ;; kludges section, we bind `system-type' in such a way that
6312 ;; `shell-quote-arguments' behaves as if on Unix.
6313 ;;
6314 ;; Thanks to Mario DeWeerd for the hint that it is sufficient for this
6315 ;; function to work with Bourne-like shells.
6316 ;;
6317 ;; CCC: This function should be rewritten so that
6318 ;; `shell-quote-argument' is not used. This way, we are safe from
6319 ;; changes in `shell-quote-argument'.
6320 (defun tramp-shell-quote-argument (s)
6321 "Similar to `shell-quote-argument', but groks newlines.
6322 Only works for Bourne-like shells."
6323 (let ((system-type 'not-windows))
6324 (save-match-data
6325 (let ((result (shell-quote-argument s))
6326 (nl (regexp-quote (format "\\%s" tramp-rsh-end-of-line))))
6327 (when (and (>= (length result) 2)
6328 (string= (substring result 0 2) "\\~"))
6329 (setq result (substring result 1)))
6330 (while (string-match nl result)
6331 (setq result (replace-match (format "'%s'" tramp-rsh-end-of-line)
6332 t t result)))
6333 result))))
6334
6335 ;; ;; EFS hooks itself into the file name handling stuff in more places
6336 ;; ;; than just `file-name-handler-alist'. The following tells EFS to stay
6337 ;; ;; away from tramp.el file names.
6338 ;; ;;
6339 ;; ;; This is needed because EFS installs (efs-dired-before-readin) into
6340 ;; ;; 'dired-before-readin-hook'. This prevents EFS from opening an FTP
6341 ;; ;; connection to help it's dired process. Not that I have any real
6342 ;; ;; idea *why* this is helpful to dired.
6343 ;; ;;
6344 ;; ;; Anyway, this advice fixes the problem (with a sledgehammer :)
6345 ;; ;;
6346 ;; ;; Daniel Pittman <daniel@danann.net>
6347 ;; ;;
6348 ;; ;; CCC: when the other defadvice calls have disappeared, make sure
6349 ;; ;; not to call defadvice unless it's necessary. How do we find out whether
6350 ;; ;; it is necessary? (featurep 'efs) is surely the wrong way --
6351 ;; ;; EFS might nicht be loaded yet.
6352 ;; (defadvice efs-ftp-path (around dont-match-tramp-localname activate protect)
6353 ;; "Cause efs-ftp-path to fail when the path is a TRAMP localname."
6354 ;; (if (tramp-tramp-file-p (ad-get-arg 0))
6355 ;; nil
6356 ;; ad-do-it))
6357
6358 ;; We currently (sometimes) use "[" and "]" in the filename format.
6359 ;; This means that Emacs wants to expand wildcards if
6360 ;; `find-file-wildcards' is non-nil, and then barfs because no
6361 ;; expansion could be found. We detect this situation and do
6362 ;; something really awful: we have `file-expand-wildcards' return the
6363 ;; original filename if it can't expand anything. Let's just hope
6364 ;; that this doesn't break anything else.
6365 ;; CCC: This check is now also really awful; we should search all
6366 ;; of the filename format, not just the prefix.
6367 (when (string-match "\\[" tramp-prefix-format)
6368 (defadvice file-expand-wildcards (around tramp-fix activate)
6369 (let ((name (ad-get-arg 0)))
6370 (if (tramp-tramp-file-p name)
6371 ;; If it's a Tramp file, dissect it and look if wildcards
6372 ;; need to be expanded at all.
6373 (let ((v (tramp-dissect-file-name name)))
6374 (if (string-match "[[*?]" (tramp-file-name-localname v))
6375 (let ((res ad-do-it))
6376 (setq ad-return-value (or res (list name))))
6377 (setq ad-return-value (list name))))
6378 ;; If it is not a Tramp file, just run the original function.
6379 (let ((res ad-do-it))
6380 (setq ad-return-value (or res (list name)))))))
6381 )
6382
6383 ;; Tramp version is useful in a number of situations.
6384
6385 (defun tramp-version (arg)
6386 "Print version number of tramp.el in minibuffer or current buffer."
6387 (interactive "P")
6388 (if arg (insert tramp-version) (message tramp-version)))
6389
6390 ;; Make the `reporter` functionality available for making bug reports about
6391 ;; the package. A most useful piece of code.
6392
6393 (unless (fboundp 'reporter-submit-bug-report)
6394 (autoload 'reporter-submit-bug-report "reporter"))
6395
6396 (defun tramp-bug ()
6397 "Submit a bug report to the TRAMP developers."
6398 (interactive)
6399 (require 'reporter)
6400 (let ((reporter-prompt-for-summary-p t))
6401 (reporter-submit-bug-report
6402 tramp-bug-report-address ; to-address
6403 (format "tramp (%s)" tramp-version) ; package name and version
6404 `(;; Current state
6405 tramp-ls-command
6406 tramp-test-groks-nt
6407 tramp-file-exists-command
6408 tramp-current-multi-method
6409 tramp-current-method
6410 tramp-current-user
6411 tramp-current-host
6412
6413 ;; System defaults
6414 tramp-auto-save-directory ; vars to dump
6415 tramp-default-method
6416 tramp-rsh-end-of-line
6417 tramp-default-password-end-of-line
6418 tramp-remote-path
6419 tramp-login-prompt-regexp
6420 tramp-password-prompt-regexp
6421 tramp-wrong-passwd-regexp
6422 tramp-yesno-prompt-regexp
6423 tramp-yn-prompt-regexp
6424 tramp-temp-name-prefix
6425 tramp-file-name-structure
6426 tramp-file-name-regexp
6427 tramp-multi-file-name-structure
6428 tramp-multi-file-name-hop-structure
6429 tramp-multi-methods
6430 tramp-multi-connection-function-alist
6431 tramp-methods
6432 tramp-end-of-output
6433 tramp-coding-commands
6434 tramp-actions-before-shell
6435 tramp-multi-actions
6436 tramp-terminal-type
6437 tramp-shell-prompt-pattern
6438 tramp-chunksize
6439
6440 ;; Non-tramp variables of interest
6441 shell-prompt-pattern
6442 backup-by-copying
6443 backup-by-copying-when-linked
6444 backup-by-copying-when-mismatch
6445 ,(when (boundp 'backup-by-copying-when-privileged-mismatch)
6446 'backup-by-copying-when-privileged-mismatch)
6447 file-name-handler-alist)
6448 nil ; pre-hook
6449 nil ; post-hook
6450 "\
6451 Enter your bug report in this message, including as much detail as you
6452 possibly can about the problem, what you did to cause it and what the
6453 local and remote machines are.
6454
6455 If you can give a simple set of instructions to make this bug happen
6456 reliably, please include those. Thank you for helping kill bugs in
6457 TRAMP.
6458
6459 Another useful thing to do is to put (setq tramp-debug-buffer t) in
6460 the ~/.emacs file and to repeat the bug. Then, include the contents
6461 of the *tramp/foo* buffer and the *debug tramp/foo* buffer in your bug
6462 report.
6463
6464 --bug report follows this line--
6465 ")))
6466
6467 (defalias 'tramp-submit-bug 'tramp-bug)
6468
6469 (provide 'tramp)
6470
6471 ;; Make sure that we get integration with the VC package.
6472 ;; When it is loaded, we need to pull in the integration module.
6473 ;; This must come after (provide 'tramp) because tramp-vc.el
6474 ;; requires tramp.
6475 (eval-after-load "vc"
6476 '(require 'tramp-vc))
6477
6478 ;;; TODO:
6479
6480 ;; * tramp-copy-keep-date-arg is not used!
6481 ;; * Allow putting passwords in the filename.
6482 ;; This should be implemented via a general mechanism to add
6483 ;; parameters in filenames. There is currently a kludge for
6484 ;; putting the port number into the filename for ssh and ftp
6485 ;; files. This could be subsumed by the new mechanism as well.
6486 ;; Another approach is to read a netrc file like ~/.authinfo
6487 ;; from Gnus.
6488 ;; * Handle nonlocal exits such as C-g.
6489 ;; * Autodetect if remote `ls' groks the "--dired" switch.
6490 ;; * Add fallback for inline encodings. This should be used
6491 ;; if the remote end doesn't support mimencode or a similar program.
6492 ;; For reading files from the remote host, we can just parse the output
6493 ;; of `od -b'. For writing files to the remote host, we construct
6494 ;; a shell program which contains only "safe" ascii characters
6495 ;; and which writes the right bytes to the file. We can use printf(1)
6496 ;; or "echo -e" or the printf function in awk and use octal escapes
6497 ;; for the "dangerous" characters. The null byte might be a problem.
6498 ;; On some systems, the octal escape doesn't work. So we try the following
6499 ;; two commands to write a null byte:
6500 ;; dd if=/dev/zero bs=1 count=1
6501 ;; echo | tr '\n' '\000'
6502 ;; * Separate local `tramp-coding-commands' from remote ones. Connect
6503 ;; the two via a format which can be `uu' or `b64'. Then we can search
6504 ;; for the right local commands and the right remote commands separately.
6505 ;; * Cooperate with PCL-CVS. It uses start-process, which doesn't
6506 ;; work for remote files.
6507 ;; * Rewrite `tramp-shell-quote-argument' to abstain from using
6508 ;; `shell-quote-argument'.
6509 ;; * Completion gets confused when you leave out the method name.
6510 ;; * Support `dired-compress-file' filename handler.
6511 ;; * In Emacs 21, `insert-directory' shows total number of bytes used
6512 ;; by the files in that directory. Add this here.
6513 ;; * Avoid screen blanking when hitting `g' in dired. (Eli Tziperman)
6514 ;; * Make ffap.el grok Tramp filenames. (Eli Tziperman)
6515 ;; * When logging in, keep looking for questions according to an alist
6516 ;; and then invoke the right function.
6517 ;; * Case-insensitive filename completion. (Norbert Goevert.)
6518 ;; * Running CVS remotely doesn't appear to work right. It thinks
6519 ;; files are locked by somebody else even if I'm the locking user.
6520 ;; Sometimes, one gets `No CVSROOT specified' errors from CVS.
6521 ;; (Skip Montanaro)
6522 ;; * Don't use globbing for directories with many files, as this is
6523 ;; likely to produce long command lines, and some shells choke on
6524 ;; long command lines.
6525 ;; * Find out about the new auto-save mechanism in Emacs 21 and
6526 ;; do the right thing.
6527 ;; * `vc-directory' does not work. It never displays any files, even
6528 ;; if it does show files when run locally.
6529 ;; * Allow correction of passwords, if the remote end allows this.
6530 ;; (Mark Hershberger)
6531 ;; * Make sure permissions of tmp file are good.
6532 ;; (Nelson Minar <nelson@media.mit.edu>)
6533 ;; * Grok passwd prompts with scp? (David Winter
6534 ;; <winter@nevis1.nevis.columbia.edu>). Maybe just do `ssh -l user
6535 ;; host', then wait a while for the passwd or passphrase prompt. If
6536 ;; there is one, remember the passwd/phrase.
6537 ;; * How to deal with MULE in `insert-file-contents' and `write-region'?
6538 ;; * Do asynchronous `shell-command's.
6539 ;; * Grok `append' parameter for `write-region'.
6540 ;; * Test remote ksh or bash for tilde expansion in `tramp-find-shell'?
6541 ;; * abbreviate-file-name
6542 ;; * grok ~ in tramp-remote-path (Henrik Holm <henrikh@tele.ntnu.no>)
6543 ;; * `C' in dired gives error `not tramp file name'.
6544 ;; * Also allow to omit user names when doing multi-hop. Not sure yet
6545 ;; what the user names should default to, though.
6546 ;; * better error checking. At least whenever we see something
6547 ;; strange when doing zerop, we should kill the process and start
6548 ;; again. (Greg Stark)
6549 ;; * Add caching for filename completion. (Greg Stark)
6550 ;; Of course, this has issues with usability (stale cache bites)
6551 ;; -- <daniel@danann.net>
6552 ;; * Provide a local cache of old versions of remote files for the rsync
6553 ;; transfer method to use. (Greg Stark)
6554 ;; * Remove unneeded parameters from methods.
6555 ;; * Invoke rsync once for copying a whole directory hierarchy.
6556 ;; (Francesco Potort\e,Al\e(B)
6557 ;; * Should we set PATH ourselves or should we rely on the remote end
6558 ;; to do it?
6559 ;; * Do the autoconf thing.
6560 ;; * Make it work for XEmacs 20, which is missing `with-timeout'.
6561 ;; * Allow non-Unix remote systems. (More a long-term thing.)
6562 ;; * Make it work for different encodings, and for different file name
6563 ;; encodings, too. (Daniel Pittman)
6564 ;; * Change applicable functions to pass a struct tramp-file-name rather
6565 ;; than the individual items MULTI-METHOD, METHOD, USER, HOST, LOCALNAME.
6566 ;; * Implement asynchronous shell commands.
6567 ;; * Clean up unused *tramp/foo* buffers after a while. (Pete Forman)
6568 ;; * Progress reports while copying files. (Michael Kifer)
6569 ;; * `Smart' connection method that uses inline for small and out of
6570 ;; band for large files. (Michael Kifer)
6571 ;; * Don't search for perl5 and perl. Instead, only search for perl and
6572 ;; then look if it's the right version (with `perl -v').
6573 ;; * When editing a remote CVS controlled file as a different user, VC
6574 ;; gets confused about the file locking status. Try to find out why
6575 ;; the workaround doesn't work.
6576 ;; * When user is running ssh-agent, it would be useful to add the
6577 ;; passwords typed by the user to that agent. This way, the next time
6578 ;; round, the users don't have to type all this in again.
6579 ;; This would be especially useful for start-process, I think.
6580 ;; An easy way to implement start-process is to open a second shell
6581 ;; connection which is inconvenient if the user has to reenter
6582 ;; passwords.
6583 ;; * Change `copy-file' to grok the case where the filename handler
6584 ;; for the source and the target file are different. Right now,
6585 ;; it looks at the source file and then calls that handler, if
6586 ;; there is one. But since ange-ftp, for instance, does not know
6587 ;; about Tramp, it does not do the right thing if the target file
6588 ;; name is a Tramp name.
6589 ;; * Username and hostname completion.
6590 ;; ** If `partial-completion-mode' isn't loaded, "/foo:bla" tries to
6591 ;; connect to host "blabla" already if that host is unique. No idea
6592 ;; how to suppress. Maybe not an essential problem.
6593 ;; ** Try to avoid usage of `last-input-event' in `tramp-completion-mode'.
6594 ;; ** Extend `tramp-get-completion-su' for NIS and shadow passwords.
6595 ;; ** Unify `tramp-parse-{rhosts,shosts,sconfig,hosts,passwd,netrc}'.
6596 ;; Code is nearly identical.
6597 ;; ** Decide whiche files to take for searching user/host names depending on
6598 ;; operating system (windows-nt) in `tramp-completion-function-alist'.
6599 ;; ** Enhance variables for debug.
6600 ;; ** Implement "/multi:" completion.
6601 ;; ** Add a learning mode for completion. Make results persistent.
6602 ;; * Allow out-of-band methods as _last_ multi-hop.
6603
6604 ;; Functions for file-name-handler-alist:
6605 ;; diff-latest-backup-file -- in diff.el
6606 ;; dired-compress-file
6607 ;; dired-uncache -- this will be needed when we do insert-directory caching
6608 ;; file-name-as-directory -- use primitive?
6609 ;; file-name-directory -- use primitive?
6610 ;; file-name-nondirectory -- use primitive?
6611 ;; file-name-sans-versions -- use primitive?
6612 ;; file-newer-than-file-p
6613 ;; find-backup-file-name
6614 ;; get-file-buffer -- use primitive
6615 ;; load
6616 ;; unhandled-file-name-directory
6617 ;; vc-registered
6618
6619 ;;; arch-tag: 3a21a994-182b-48fa-b0cd-c1d9fede424a
6620 ;;; tramp.el ends here