1 ;;; tramp.el --- Transparent Remote Access, Multiple Protocol -*- coding: iso-8859-1; -*-
3 ;; Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
5 ;; Author: Kai.Grossjohann@CS.Uni-Dortmund.DE
6 ;; Keywords: comm, processes
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This package provides remote file editing, similar to ange-ftp.
28 ;; The difference is that ange-ftp uses FTP to transfer files between
29 ;; the local and the remote host, whereas tramp.el uses a combination
30 ;; of rsh and rcp or other work-alike programs, such as ssh/scp.
32 ;; For more detailed instructions, please see the info file, which is
33 ;; included in the file `tramp.tar.gz' mentioned below.
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.)
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.
47 ;; Also see the todo list at the bottom of this file.
49 ;; The current version of tramp.el can be retrieved from the following
50 ;; URL: ftp://ls6-ftp.cs.uni-dortmund.de/pub/src/emacs/tramp.tar.gz
51 ;; For your convenience, the *.el file is available separately from
52 ;; the same directory.
54 ;; There's a mailing list for this, as well. Its name is:
55 ;; tramp-devel@mail.freesoftware.fsf.org
56 ;; Send a mail with `help' in the subject (!) to the administration
57 ;; address for instructions on joining the list. The administration
59 ;; tramp-devel-request@mail.freesoftware.fsf.org
60 ;; You can also use the Web to subscribe, under the following URL:
61 ;; http://mail.freesoftware.fsf.org/mailman/listinfo/tramp-devel
63 ;; For the adventurous, the current development sources are available
64 ;; via CVS. You can find instructions about this at the following URL:
65 ;; http://savannah.gnu.org/projects/tramp/
66 ;; Click on "CVS" in the navigation bar near the top.
68 ;; Don't forget to put on your asbestos longjohns, first!
72 (defconst tramp-version
"2.0.5"
73 "This version of tramp.")
75 (defconst tramp-bug-report-address
"tramp-devel@mail.freesoftware.fsf.org"
76 "Email address to send bug reports to.")
79 (require 'format-spec
) ;from Gnus 5.8, also in tar ball
80 (require 'base64
) ;for the mimencode methods
84 ;; ;; It does not work to load EFS after loading TRAMP.
85 ;; (when (fboundp 'efs-file-handler-function)
91 ;; Emacs 19.34 compatibility hack -- is this needed?
92 (or (>= emacs-major-version
20)
95 (unless (boundp 'custom-print-functions
)
96 (defvar custom-print-functions nil
)) ; not autoloaded before Emacs 20.4
98 ;;; User Customizable Internal Variables:
101 "Edit remote files with a combination of rsh and rcp or similar programs."
104 (defcustom tramp-verbose
10
105 "*Verbosity level for tramp.el. 0 means be silent, 10 is most verbose."
109 (defcustom tramp-debug-buffer nil
110 "*Whether to send all commands and responses to a debug buffer."
114 (defcustom tramp-auto-save-directory nil
115 "*Put auto-save files in this directory, if set.
116 The idea is to use a local directory so that auto-saving is faster."
118 :type
'(choice (const nil
)
121 (defcustom tramp-sh-program
"/bin/sh"
122 "*Use this program for shell commands on the local host.
123 This MUST be a Bourne-like shell. This shell is used to execute
124 the encoding and decoding command on the local host, so if you
125 want to use `~' in those commands, you should choose a shell here
126 which groks tilde expansion. `/bin/sh' normally does not
127 understand tilde expansion.
129 Note that this variable is not used for remote commands. There are
130 mechanisms in tramp.el which automatically determine the right shell to
131 use for the remote host."
133 :type
'(file :must-match t
))
135 (defcustom tramp-multi-sh-program
136 (if (memq system-type
'(windows-nt))
139 "*Use this program for bootstrapping multi-hop connections.
140 This variable is similar to `tramp-sh-program', but it is only used
141 when initializing a multi-hop connection. Therefore, the set of
142 commands sent to this shell is quite restricted, and if you are
143 careful it works to use CMD.EXE under Windows (instead of a Bourne-ish
144 shell which does not normally exist on Windows anyway).
146 To use multi-hop methods from Windows, you also need suitable entries
147 in `tramp-multi-connection-function-alist' for the first hop.
149 This variable defaults to CMD.EXE on Windows NT, and to the value of
150 `tramp-sh-program' on other systems."
152 :type
'(file :must-match t
))
154 ;; CCC I have changed all occurrences of comint-quote-filename with
155 ;; tramp-shell-quote-argument, except in tramp-handle-expand-many-files.
156 ;; There, comint-quote-filename was removed altogether. If it turns
157 ;; out to be necessary there, something will need to be done.
158 ;;-(defcustom tramp-file-name-quote-list
159 ;;- '(?] ?[ ?\| ?& ?< ?> ?\( ?\) ?\; ?\ ?\* ?\? ?\! ?\" ?\' ?\` ?# ?\@ ?\+ )
160 ;;- "*Protect these characters from the remote shell.
161 ;;-Any character in this list is quoted (preceded with a backslash)
162 ;;-because it means something special to the shell. This takes effect
163 ;;-when sending file and directory names to the remote shell.
165 ;;-See `comint-file-name-quote-list' for details."
167 ;;- :type '(repeat character))
169 (defcustom tramp-methods
170 '( ("rcp" (tramp-connection-function tramp-open-connection-rsh
)
171 (tramp-rsh-program "rsh")
172 (tramp-rcp-program "rcp")
173 (tramp-remote-sh "/bin/sh")
176 (tramp-rcp-keep-date-arg "-p")
177 (tramp-su-program nil
)
179 (tramp-telnet-program nil
)
180 (tramp-telnet-args nil
))
181 ("scp" (tramp-connection-function tramp-open-connection-rsh
)
182 (tramp-rsh-program "ssh")
183 (tramp-rcp-program "scp")
184 (tramp-remote-sh "/bin/sh")
185 (tramp-rsh-args ("-e" "none"))
187 (tramp-rcp-keep-date-arg "-p")
188 (tramp-su-program nil
)
190 (tramp-telnet-program nil
)
191 (tramp-telnet-args nil
))
192 ("scp1" (tramp-connection-function tramp-open-connection-rsh
)
193 (tramp-rsh-program "ssh")
194 (tramp-rcp-program "scp")
195 (tramp-remote-sh "/bin/sh")
196 (tramp-rsh-args ("-1" "-e" "none"))
197 (tramp-rcp-args ("-1"))
198 (tramp-rcp-keep-date-arg "-p")
199 (tramp-su-program nil
)
201 (tramp-telnet-program nil
)
202 (tramp-telnet-args nil
))
203 ("scp2" (tramp-connection-function tramp-open-connection-rsh
)
204 (tramp-rsh-program "ssh")
205 (tramp-rcp-program "scp")
206 (tramp-remote-sh "/bin/sh")
207 (tramp-rsh-args ("-2" "-e" "none"))
208 (tramp-rcp-args ("-2"))
209 (tramp-rcp-keep-date-arg "-p")
210 (tramp-su-program nil
)
212 (tramp-telnet-program nil
)
213 (tramp-telnet-args nil
))
215 (tramp-connection-function tramp-open-connection-rsh
)
216 (tramp-rsh-program "ssh1")
217 (tramp-rcp-program "scp1")
218 (tramp-remote-sh "/bin/sh")
219 (tramp-rsh-args ("-e" "none"))
221 (tramp-rcp-keep-date-arg "-p")
222 (tramp-su-program nil
)
224 (tramp-telnet-program nil
)
225 (tramp-telnet-args nil
))
227 (tramp-connection-function tramp-open-connection-rsh
)
228 (tramp-rsh-program "ssh2")
229 (tramp-rcp-program "scp2")
230 (tramp-remote-sh "/bin/sh")
231 (tramp-rsh-args ("-e" "none"))
233 (tramp-rcp-keep-date-arg "-p")
234 (tramp-su-program nil
)
236 (tramp-telnet-program nil
)
237 (tramp-telnet-args nil
))
238 ("rsync" (tramp-connection-function tramp-open-connection-rsh
)
239 (tramp-rsh-program "ssh")
240 (tramp-rcp-program "rsync")
241 (tramp-remote-sh "/bin/sh")
242 (tramp-rsh-args ("-e" "none"))
243 (tramp-rcp-args ("-e" "ssh"))
244 (tramp-rcp-keep-date-arg "-t")
245 (tramp-su-program nil
)
247 (tramp-telnet-program nil
)
248 (tramp-telnet-args nil
))
249 ("rsh" (tramp-connection-function tramp-open-connection-rsh
)
250 (tramp-rsh-program "rsh")
251 (tramp-rcp-program nil
)
252 (tramp-remote-sh "/bin/sh")
255 (tramp-rcp-keep-date-arg nil
)
256 (tramp-su-program nil
)
258 (tramp-telnet-program nil
)
259 (tramp-telnet-args nil
))
260 ("ssh" (tramp-connection-function tramp-open-connection-rsh
)
261 (tramp-rsh-program "ssh")
262 (tramp-rcp-program nil
)
263 (tramp-remote-sh "/bin/sh")
264 (tramp-rsh-args ("-e" "none"))
266 (tramp-rcp-keep-date-arg nil
)
267 (tramp-su-program nil
)
269 (tramp-telnet-program nil
)
270 (tramp-telnet-args nil
))
271 ("ssh1" (tramp-connection-function tramp-open-connection-rsh
)
272 (tramp-rsh-program "ssh")
273 (tramp-rcp-program nil
)
274 (tramp-remote-sh "/bin/sh")
275 (tramp-rsh-args ("-1" "-e" "none"))
276 (tramp-rcp-args ("-1"))
277 (tramp-rcp-keep-date-arg nil
)
278 (tramp-su-program nil
)
280 (tramp-telnet-program nil
)
281 (tramp-telnet-args nil
))
282 ("ssh2" (tramp-connection-function tramp-open-connection-rsh
)
283 (tramp-rsh-program "ssh")
284 (tramp-rcp-program nil
)
285 (tramp-remote-sh "/bin/sh")
286 (tramp-rsh-args ("-2" "-e" "none"))
287 (tramp-rcp-args ("-2"))
288 (tramp-rcp-keep-date-arg nil
)
289 (tramp-su-program nil
)
291 (tramp-telnet-program nil
)
292 (tramp-telnet-args nil
))
294 (tramp-connection-function tramp-open-connection-rsh
)
295 (tramp-rsh-program "ssh1")
296 (tramp-rcp-program nil
)
297 (tramp-remote-sh "/bin/sh")
298 (tramp-rsh-args ("-e" "none"))
300 (tramp-rcp-keep-date-arg nil
)
301 (tramp-su-program nil
)
303 (tramp-telnet-program nil
)
304 (tramp-telnet-args nil
))
306 (tramp-connection-function tramp-open-connection-rsh
)
307 (tramp-rsh-program "ssh2")
308 (tramp-rcp-program nil
)
309 (tramp-remote-sh "/bin/sh")
310 (tramp-rsh-args ("-e" "none"))
312 (tramp-rcp-keep-date-arg nil
)
313 (tramp-su-program nil
)
315 (tramp-telnet-program nil
)
316 (tramp-telnet-args nil
))
318 (tramp-connection-function tramp-open-connection-rsh
)
319 (tramp-rsh-program "ssh1")
320 (tramp-rcp-program nil
)
321 (tramp-remote-sh "/bin/sh")
322 (tramp-rsh-args ("-e" "none"))
324 (tramp-rcp-keep-date-arg nil
)
325 (tramp-su-program nil
)
327 (tramp-telnet-program nil
)
328 (tramp-telnet-args nil
))
330 (tramp-connection-function tramp-open-connection-rsh
)
331 (tramp-rsh-program "ssh2")
332 (tramp-rcp-program nil
)
333 (tramp-remote-sh "/bin/sh")
334 (tramp-rsh-args ("-e" "none"))
336 (tramp-rcp-keep-date-arg nil
)
337 (tramp-su-program nil
)
339 (tramp-telnet-program nil
)
340 (tramp-telnet-args nil
))
342 (tramp-connection-function tramp-open-connection-telnet
)
343 (tramp-rsh-program nil
)
344 (tramp-rcp-program nil
)
345 (tramp-remote-sh "/bin/sh")
348 (tramp-rcp-keep-date-arg nil
)
349 (tramp-su-program nil
)
351 (tramp-telnet-program "telnet")
352 (tramp-telnet-args nil
))
353 ("su" (tramp-connection-function tramp-open-connection-su
)
354 (tramp-rsh-program nil
)
355 (tramp-rcp-program nil
)
356 (tramp-remote-sh "/bin/sh")
359 (tramp-rcp-keep-date-arg nil
)
360 (tramp-su-program "su")
361 (tramp-su-args ("-" "%u"))
362 (tramp-telnet-program nil
)
363 (tramp-telnet-args nil
))
364 ("sudo" (tramp-connection-function tramp-open-connection-su
)
365 (tramp-rsh-program nil
)
366 (tramp-rcp-program nil
)
367 (tramp-remote-sh "/bin/sh")
370 (tramp-rcp-keep-date-arg nil
)
371 (tramp-su-program "sudo")
372 (tramp-su-args ("-u" "%u" "-s"))
373 (tramp-telnet-program nil
)
374 (tramp-telnet-args nil
))
375 ("multi" (tramp-connection-function tramp-open-connection-multi
)
376 (tramp-rsh-program nil
)
377 (tramp-rcp-program nil
)
378 (tramp-remote-sh "/bin/sh")
381 (tramp-rcp-keep-date-arg nil
)
382 (tramp-su-program nil
)
384 (tramp-telnet-program nil
)
385 (tramp-telnet-args nil
))
386 ("scpx" (tramp-connection-function tramp-open-connection-rsh
)
387 (tramp-rsh-program "ssh")
388 (tramp-rcp-program "scp")
389 (tramp-remote-sh "/bin/sh")
390 (tramp-rsh-args ("-e" "none" "-t" "-t" "/bin/sh"))
392 (tramp-rcp-keep-date-arg "-p")
393 (tramp-telnet-program nil
)
394 (tramp-telnet-args nil
))
395 ("sshx" (tramp-connection-function tramp-open-connection-rsh
)
396 (tramp-rsh-program "ssh")
397 (tramp-rcp-program nil
)
398 (tramp-remote-sh "/bin/sh")
399 (tramp-rsh-args ("-e" "none" "-t" "-t" "/bin/sh"))
401 (tramp-rcp-keep-date-arg nil
)
402 (tramp-su-program nil
)
404 (tramp-telnet-program nil
)
405 (tramp-telnet-args nil
))
407 (tramp-connection-function tramp-open-connection-rsh
)
408 (tramp-rsh-program "krlogin")
409 (tramp-rcp-program nil
)
410 (tramp-remote-sh "/bin/sh")
411 (tramp-rsh-args ("-x"))
413 (tramp-rcp-keep-date-arg nil
)
414 (tramp-su-program nil
)
416 (tramp-telnet-program nil
)
417 (tramp-telnet-args nil
))
419 (tramp-connection-function tramp-open-connection-rsh
)
420 (tramp-rsh-program "plink")
421 (tramp-rcp-program nil
)
422 (tramp-remote-sh "/bin/sh")
423 (tramp-rsh-args ("-ssh")) ;optionally add "-v"
425 (tramp-rcp-keep-date-arg nil
)
426 (tramp-su-program nil
)
428 (tramp-telnet-program nil
)
429 (tramp-telnet-args nil
))
431 (tramp-connection-function tramp-open-connection-rsh
)
432 (tramp-rsh-program "plink")
433 (tramp-rcp-program "pscp")
434 (tramp-remote-sh "/bin/sh")
435 (tramp-rsh-args ("-ssh"))
437 (tramp-rcp-keep-date-arg "-p")
438 (tramp-su-program nil
)
440 (tramp-telnet-program nil
)
441 (tramp-telnet-args nil
))
443 (tramp-connection-function tramp-open-connection-rsh
)
444 (tramp-rsh-program "fsh")
445 (tramp-rcp-program "fcp")
446 (tramp-remote-sh "/bin/sh -i")
447 (tramp-rsh-args ("sh" "-i"))
449 (tramp-rcp-keep-date-arg "-p")
450 (tramp-su-program nil
)
452 (tramp-telnet-program nil
)
453 (tramp-telnet-args nil
))
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.
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-rsh-program'
472 This specifies the name of the program to use for rsh; this might be
473 the full path to rsh or the name of a workalike program.
475 This specifies the list of arguments to pass to the above
476 mentioned program. Please note that this is a list of arguments,
477 that is, normally you don't want to put \"-a -b\" or \"-f foo\"
478 here. Instead, you want two list elements, one for \"-a\" and one
479 for \"-b\", or one for \"-f\" and one for \"foo\".
480 * `tramp-rcp-program'
481 This specifies the name of the program to use for rcp; this might be
482 the full path to rcp or the name of a workalike program.
484 This specifies the list of parameters to pass to the above mentioned
485 program, the hints for `tramp-rsh-args' also apply here.
486 * `tramp-rcp-keep-date-arg'
487 This specifies the parameter to use for `rcp' when the timestamp
488 of the original file should be kept. For `rcp', use `-p', for
491 This specifies the name of the program to use for `su'.
493 This specifies the list of arguments to pass to `su'.
494 \"%u\" is replaced by the user name, use \"%%\" for a literal
496 * `tramp-encoding-command'
497 This specifies a command to use to encode the file contents for
498 transfer. The command should read the raw file contents from
499 standard input and write the encoded file contents to standard
500 output. In this string, the percent escape \"%f\" should be used
501 to indicate the file to convert. Use \"%%\" if you need a literal
502 percent character in your command.
503 * `tramp-decoding-command'
504 This specifies a command to use to decode file contents encoded
505 with `tramp-encoding-command'. The command should read from standard
506 input and write to standard output.
507 * `tramp-encoding-function'
508 This specifies a function to be called to encode the file contents
509 on the local side. This function should accept two arguments
510 START and END, the beginning and end of the region to encode. The
511 region should be replaced with the encoded contents.
512 * `tramp-decoding-function'
513 Same for decoding on the local side.
514 * `tramp-telnet-program'
515 Specifies the telnet program to use when using
516 `tramp-open-connection-telnet' to log in.
517 * `tramp-telnet-args'
518 Specifies list of arguments to pass to `telnet'. The hints for
519 `tramp-rsh-args' also apply here.
521 What does all this mean? Well, you should specify `tramp-rsh-program',
522 `tramp-telnet-program' or `tramp-su-program' for all methods; this program
523 is used to log in to the remote site. Then, there are two ways to
524 actually transfer the files between the local and the remote side.
525 One way is using an additional rcp-like program. If you want to do
526 this, set `tramp-rcp-program' in the method.
528 Another possibility for file transfer is inline transfer, i.e. the
529 file is passed through the same buffer used by `tramp-rsh-program'. In
530 this case, the file contents need to be protected since the
531 `tramp-rsh-program' might use escape codes or the connection might not
532 be eight-bit clean. Therefore, file contents are encoded for transit.
534 Two possibilities for encoding are uuencode/uudecode and mimencode.
535 For uuencode/uudecode you want to set `tramp-encoding-command' to
536 something like \"uuencode\" and `tramp-decoding-command' to \"uudecode
537 -p\". For mimencode you want to set `tramp-encoding-command' to
538 something like \"mimencode -b\" and `tramp-decoding-command' to
541 When using inline transfer, you can use a program or a Lisp function
542 on the local side to encode or decode the file contents. Set the
543 `tramp-encoding-function' and `tramp-decoding-function' parameters to nil
544 in order to use the commands or to the function to use. It is
545 possible to specify one function and the other parameter as nil.
547 So, to summarize: if the method is an inline method, you must specify
548 `tramp-encoding-command' and `tramp-decoding-command', and
549 `tramp-rcp-program' must be nil. If the method is out of band, then
550 you must specify `tramp-rcp-program' and `tramp-rcp-args' and
551 `tramp-encoding-command' and `tramp-decoding-command' must be nil.
552 Every method, inline or out of band, must specify
553 `tramp-connection-function' plus the associated arguments (for
554 example, the telnet program if you chose
555 `tramp-open-connection-telnet').
559 When using `tramp-open-connection-su' the phrase `open connection to a
560 remote host' sounds strange, but it is used nevertheless, for
561 consistency. No connection is opened to a remote host, but `su' is
562 started on the local host. You are not allowed to specify a remote
563 host other than `localhost' or the name of the local host.
565 Using a uuencode/uudecode inline method is discouraged, please use one
566 of the base64 methods instead since base64 encoding is much more
567 reliable and the commands are more standardized between the different
568 Unix versions. But if you can't use base64 for some reason, please
569 note that the default uudecode command does not work well for some
570 Unices, in particular AIX and Irix. For AIX, you might want to use
571 the following command for uudecode:
573 sed '/^begin/d;/^[` ]$/d;/^end/d' | iconv -f uucode -t ISO8859-1
575 For Irix, no solution is known yet."
579 (set (list (const tramp-connection-function
) function
)
580 (list (const tramp-rsh-program
)
581 (choice (const nil
) string
))
582 (list (const tramp-rcp-program
)
583 (choice (const nil
) string
))
584 (list (const tramp-remote-sh
)
585 (choice (const nil
) string
))
586 (list (const tramp-rsh-args
) (repeat string
))
587 (list (const tramp-rcp-args
) (repeat string
))
588 (list (const tramp-rcp-keep-date-arg
)
589 (choice (const nil
) string
))
590 (list (const tramp-su-program
)
591 (choice (const nil
) string
))
592 (list (const tramp-su-args
) (repeat string
))
593 (list (const tramp-encoding-command
)
594 (choice (const nil
) string
))
595 (list (const tramp-decoding-command
)
596 (choice (const nil
) string
))
597 (list (const tramp-encoding-function
)
598 (choice (const nil
) function
))
599 (list (const tramp-decoding-function
)
600 (choice (const nil
) function
))
601 (list (const tramp-telnet-program
)
602 (choice (const nil
) string
))
603 (list (const tramp-telnet-args
) (repeat string
))))))
605 (defcustom tramp-multi-methods
'("multi" "multiu")
606 "*List of multi-hop methods.
607 Each entry in this list should be a method name as mentioned in the
608 variable `tramp-methods'."
610 :type
'(repeat string
))
612 (defcustom tramp-multi-connection-function-alist
613 '(("telnet" tramp-multi-connect-telnet
"telnet %h%n")
614 ("rsh" tramp-multi-connect-rlogin
"rsh %h -l %u%n")
615 ("ssh" tramp-multi-connect-rlogin
"ssh %h -l %u%n")
616 ("su" tramp-multi-connect-su
"su - %u%n")
617 ("sudo" tramp-multi-connect-su
"sudo -u %u -s%n"))
618 "*List of connection functions for multi-hop methods.
619 Each list item is a list of three items (METHOD FUNCTION COMMAND),
620 where METHOD is the name as used in the file name, FUNCTION is the
621 function to be executed, and COMMAND is the shell command used for
624 COMMAND may contain percent escapes. `%u' will be replaced with the
625 user name, `%h' will be replaced with the host name, and `%n' will be
626 replaced with an end-of-line character, as specified in the variable
627 `tramp-rsh-end-of-line'. Use `%%' for a literal percent character.
628 Note that the interpretation of the percent escapes also depends on
629 the FUNCTION. For example, the `%u' escape is forbidden with the
630 function `tramp-multi-connect-telnet'. See the documentation of the
631 various functions for details."
633 :type
'(repeat (list string function string
)))
635 (defcustom tramp-default-method
"sm"
636 ;;(if (featurep 'xemacs) "sm" "ftp")
637 "*Default method to use for transferring files.
638 See `tramp-methods' for possibilities.
639 Also see `tramp-default-method-alist'.
641 Emacs uses a unified filename syntax for Tramp and Ange-FTP.
642 For backward compatibility, the default value of this variable
643 is \"ftp\" on Emacs. But XEmacs uses a separate filename syntax
644 for Tramp and EFS, so there the default method is \"sm\"."
648 (defcustom tramp-default-method-alist
649 (if (featurep 'xemacs
)
651 '(("\\`ftp\\." "" "ftp")
652 ("" "\\`\\(anonymous\\|ftp\\)\\'" "ftp")))
653 "*Default method to use for specific user/host pairs.
654 This is an alist of items (HOST USER METHOD). The first matching item
655 specifies the method to use for a file name which does not specify a
656 method. HOST and USER are regular expressions or nil, which is
657 interpreted as a regular expression which always matches. If no entry
658 matches, the variable `tramp-default-method' takes effect.
660 If the file name does not specify the user, lookup is done using the
661 empty string for the user name.
663 See `tramp-methods' for a list of possibilities for METHOD."
665 :type
'(repeat (list (regexp :tag
"Host regexp")
666 (regexp :tag
"User regexp")
667 (string :tag
"Method"))))
669 (defcustom tramp-ftp-method
"ftp"
670 "*When this method name is used, forward all calls to Ange-FTP."
674 (defcustom tramp-rsh-end-of-line
"\n"
675 "*String used for end of line in rsh connections.
676 I don't think this ever needs to be changed, so please tell me about it
677 if you need to change this."
681 (defcustom tramp-remote-path
682 '("/bin" "/usr/bin" "/usr/sbin" "/usr/local/bin" "/usr/ccs/bin"
683 "/local/bin" "/local/freeware/bin" "/local/gnu/bin"
684 "/usr/freeware/bin" "/usr/pkg/bin" "/usr/contrib/bin")
685 "*List of directories to search for executables on remote host.
686 Please notify me about other semi-standard directories to include here.
688 You can use `~' in this list, but when searching for a shell which groks
689 tilde expansion, all directory names starting with `~' will be ignored."
691 :type
'(repeat string
))
693 (defcustom tramp-login-prompt-regexp
695 "*Regexp matching login-like prompts.
696 The regexp should match at end of buffer."
700 (defcustom tramp-password-prompt-regexp
701 "^.*\\([pP]assword\\|passphrase.*\\):\^@? *"
702 "*Regexp matching password-like prompts.
703 The regexp should match at end of buffer.
705 The `sudo' program appears to insert a `^@' character into the prompt."
709 (defcustom tramp-wrong-passwd-regexp
710 (concat "^.*\\(Permission denied.\\|Login [Ii]ncorrect\\|"
711 "Received signal [0-9]+\\|Connection \\(refused\\|closed\\)\\|"
712 "Sorry, try again.\\|Name or service not known\\).*")
713 "*Regexp matching a `login failed' message.
714 The regexp should match at end of buffer."
718 (defcustom tramp-yesno-prompt-regexp
719 "Are you sure you want to continue connecting (yes/no)\\? *"
720 "Regular expression matching all queries which need to be confirmed.
721 The confirmation should be done with yes or no.
722 The regexp should match at end of buffer."
726 (defcustom tramp-temp-name-prefix
"tramp."
727 "*Prefix to use for temporary files.
728 If this is a relative file name (such as \"tramp.\"), it is considered
729 relative to the directory name returned by the function
730 `tramp-temporary-file-directory' (which see). It may also be an
731 absolute file name; don't forget to include a prefix for the filename
736 (defcustom tramp-discard-garbage nil
737 "*If non-nil, try to discard garbage sent by remote shell.
738 Some shells send such garbage upon connection setup."
742 (defcustom tramp-sh-extra-args
'(("/bash\\'" .
"--norc"))
743 "*Alist specifying extra arguments to pass to the remote shell.
744 Entries are (REGEXP . ARGS) where REGEXP is a regular expression
745 matching the shell file name and ARGS is a string specifying the
748 This variable is only used when Tramp needs to start up another shell
749 for tilde expansion. The extra arguments should typically prevent the
750 shell from reading its init file."
752 :type
'(alist :key-type string
:value-type string
))
756 (defconst tramp-file-name-structure-unified
757 (list (concat "\\`/\\(\\([a-zA-Z0-9-]+\\):\\)?" ;method
758 "\\(\\([^:@/]+\\)@\\)?" ;user
759 "\\([^:/]+\\):" ;host
762 "Default value for `tramp-file-name-structure' for unified remoting.
763 On Emacs (not XEmacs), the Tramp and Ange-FTP packages use a unified
764 filename space. This value is used for this unified namespace.")
766 (defconst tramp-file-name-structure-separate
767 (list (concat "\\`/\\[\\(\\([a-zA-Z0-9-]+\\)/\\)?" ;method
768 "\\(\\([-a-zA-Z0-9_#/:]+\\)@\\)?" ;user
769 "\\([-a-zA-Z0-9_#/:@.]+\\)\\]" ;host
772 "Default value for `tramp-file-name-structure' for separate remoting.
773 On XEmacs, the Tramp and EFS packages use a separate namespace for
774 remote filenames. This value is used in that case. It is designed
775 not to clash with the EFS filename syntax.")
777 (defcustom tramp-file-name-structure
778 (if (featurep 'xemacs
)
779 tramp-file-name-structure-separate
780 tramp-file-name-structure-unified
)
781 "*List of five elements (REGEXP METHOD USER HOST FILE), detailing \
782 the tramp file name structure.
784 The first element REGEXP is a regular expression matching a tramp file
785 name. The regex should contain parentheses around the method name,
786 the user name, the host name, and the file name parts.
788 The second element METHOD is a number, saying which pair of
789 parentheses matches the method name. The third element USER is
790 similar, but for the user name. The fourth element HOST is similar,
791 but for the host name. The fifth element FILE is for the file name.
792 These numbers are passed directly to `match-string', which see. That
793 means the opening parentheses are counted to identify the pair.
795 See also `tramp-file-name-regexp' and `tramp-make-tramp-file-format'."
797 :type
'(list (regexp :tag
"File name regexp")
798 (integer :tag
"Paren pair for method name")
799 (integer :tag
"Paren pair for user name ")
800 (integer :tag
"Paren pair for host name ")
801 (integer :tag
"Paren pair for file name ")))
804 (defconst tramp-file-name-regexp-unified
806 "Value for `tramp-file-name-regexp' for unified remoting.
807 Emacs (not XEmacs) uses a unified filename syntax for Ange-FTP and
808 Tramp. See `tramp-file-name-structure-unified' for more explanations.")
811 (defconst tramp-file-name-regexp-separate
813 "Value for `tramp-file-name-regexp' for separate remoting.
814 XEmacs uses a separate filename syntax for Tramp and EFS.
815 See `tramp-file-name-structure-separate' for more explanations.")
818 (defcustom tramp-file-name-regexp
819 (if (featurep 'xemacs
)
820 tramp-file-name-regexp-separate
821 tramp-file-name-regexp-unified
)
822 "*Regular expression matching file names handled by tramp.
823 This regexp should match tramp file names but no other file names.
824 \(When tramp.el is loaded, this regular expression is prepended to
825 `file-name-handler-alist', and that is searched sequentially. Thus,
826 if the tramp entry appears rather early in the `file-name-handler-alist'
827 and is a bit too general, then some files might be considered tramp
828 files which are not really tramp files.
830 Please note that the entry in `file-name-handler-alist' is made when
831 this file (tramp.el) is loaded. This means that this variable must be set
832 before loading tramp.el. Alternatively, `file-name-handler-alist' can be
833 updated after changing this variable.
835 Also see `tramp-file-name-structure' and `tramp-make-tramp-file-format'."
839 (defconst tramp-make-tramp-file-format-unified
841 "Value for `tramp-make-tramp-file-format' for unified remoting.
842 Emacs (not XEmacs) uses a unified filename syntax for Ange-FTP and Tramp.
843 See `tramp-file-name-structure-unified' for more details.")
845 (defconst tramp-make-tramp-file-format-separate
847 "Value for `tramp-make-tramp-file-format' for separate remoting.
848 XEmacs uses a separate filename syntax for EFS and Tramp.
849 See `tramp-file-name-structure-separate' for more details.")
851 (defcustom tramp-make-tramp-file-format
852 (if (featurep 'xemacs
)
853 tramp-make-tramp-file-format-separate
854 tramp-make-tramp-file-format-unified
)
855 "*Format string saying how to construct tramp file name.
856 `%m' is replaced by the method name.
857 `%u' is replaced by the user name.
858 `%h' is replaced by the host name.
859 `%p' is replaced by the file name.
860 `%%' is replaced by %.
862 Also see `tramp-file-name-structure' and `tramp-file-name-regexp'."
866 (defconst tramp-make-tramp-file-user-nil-format-unified
868 "Value of `tramp-make-tramp-file-user-nil-format' for unified remoting.
869 Emacs (not XEmacs) uses a unified filename syntax for Ange-FTP and Tramp.
870 See `tramp-file-name-structure-unified' for details.")
872 (defconst tramp-make-tramp-file-user-nil-format-separate
874 "Value of `tramp-make-tramp-file-user-nil-format' for separate remoting.
875 XEmacs uses a separate filename syntax for EFS and Tramp.
876 See `tramp-file-name-structure-separate' for details.")
878 (defcustom tramp-make-tramp-file-user-nil-format
879 (if (featurep 'xemacs
)
880 tramp-make-tramp-file-user-nil-format-separate
881 tramp-make-tramp-file-user-nil-format-unified
)
882 "*Format string saying how to construct tramp file name when the user name is not known.
883 `%m' is replaced by the method name.
884 `%h' is replaced by the host name.
885 `%p' is replaced by the file name.
886 `%%' is replaced by %.
888 Also see `tramp-make-tramp-file-format', `tramp-file-name-structure', and `tramp-file-name-regexp'."
892 (defconst tramp-multi-file-name-structure-unified
893 (list (concat "\\`/\\(\\([a-zA-Z0-9]+\\)?:\\)" ;method
894 "\\(\\(%s\\)+\\)" ;hops
897 "Value for `tramp-multi-file-name-structure' for unified remoting.
898 Emacs (not XEmacs) uses a unified filename syntax for Ange-FTP and Tramp.
899 See `tramp-file-name-structure-unified' for details.")
901 (defconst tramp-multi-file-name-structure-separate
904 "\\`/\\[\\(\\([a-z0-9]+\\)?\\)"
905 ;; regexp specifying the hops
909 2 ;number of pair to match method
910 3 ;number of pair to match hops
911 -
1) ;number of pair to match path
912 "Value of `tramp-multi-file-name-structure' for separate remoting.
913 XEmacs uses a separate filename syntax for EFS and Tramp.
914 See `tramp-file-name-structure-separate' for details.")
916 (defcustom tramp-multi-file-name-structure
917 (if (featurep 'xemacs
)
918 tramp-multi-file-name-structure-separate
919 tramp-multi-file-name-structure-unified
)
920 "*Describes the file name structure of `multi' files.
921 Multi files allow you to contact a remote host in several hops.
922 This is a list of four elements (REGEXP METHOD HOP PATH).
924 The first element, REGEXP, gives a regular expression to match against
925 the file name. In this regular expression, `%s' is replaced with the
926 value of `tramp-multi-file-name-hop-structure'. (Note: in order to
927 allow multiple hops, you normally want to use something like
928 \"\\\\(\\\\(%s\\\\)+\\\\)\" in the regular expression. The outer pair
929 of parentheses is used for the HOP element, see below.)
931 All remaining elements are numbers. METHOD gives the number of the
932 paren pair which matches the method name. HOP gives the number of the
933 paren pair which matches the hop sequence. PATH gives the number of
934 the paren pair which matches the path name on the remote host.
936 PATH can also be negative, which means to count from the end. Ie, a
937 value of -1 means the last paren pair.
939 I think it would be good if the regexp matches the whole of the
940 string, but I haven't actually tried what happens if it doesn't..."
942 :type
'(list (regexp :tag
"File name regexp")
943 (integer :tag
"Paren pair for method name")
944 (integer :tag
"Paren pair for hops")
945 (integer :tag
"Paren pair to match path")))
947 (defconst tramp-multi-file-name-hop-structure-unified
948 (list (concat "\\([a-zA-z0-9_]+\\):" ;hop method
949 "\\([^@:/]+\\)@" ;user
950 "\\([^:/]+\\):") ;host
952 "Value of `tramp-multi-file-name-hop-structure' for unified remoting.
953 Emacs (not XEmacs) uses a unified filename syntax for Ange-FTP and Tramp.
954 See `tramp-file-name-structure-unified' for details.")
956 (defconst tramp-multi-file-name-hop-structure-separate
957 (list (concat "/\\([a-z0-9_]+\\):" ;hop method
958 "\\([a-z0-9_]+\\)@" ;user
959 "\\([a-z0-9.-]+\\)") ;host
961 "Value of `tramp-multi-file-name-hop-structure' for separate remoting.
962 XEmacs uses a separate filename syntax for EFS and Tramp.
963 See `tramp-file-name-structure-separate' for details.")
965 (defcustom tramp-multi-file-name-hop-structure
966 (if (featurep 'xemacs
)
967 tramp-multi-file-name-hop-structure-separate
968 tramp-multi-file-name-hop-structure-unified
)
969 "*Describes the structure of a hop in multi files.
970 This is a list of four elements (REGEXP METHOD USER HOST). First
971 element REGEXP is used to match against the hop. Pair number METHOD
972 matches the method of one hop, pair number USER matches the user of
973 one hop, pair number HOST matches the host of one hop.
975 This regular expression should match exactly all of one hop."
977 :type
'(list (regexp :tag
"Hop regexp")
978 (integer :tag
"Paren pair for method name")
979 (integer :tag
"Paren pair for user name")
980 (integer :tag
"Paren pair for host name")))
982 (defconst tramp-make-multi-tramp-file-format-unified
983 (list "/%m" ":%m:%u@%h" ":%p")
984 "Value of `tramp-make-multi-tramp-file-format' for unified remoting.
985 Emacs (not XEmacs) uses a unified filename syntax for Ange-FTP and Tramp.
986 See `tramp-file-name-structure-unified' for details.")
988 (defconst tramp-make-multi-tramp-file-format-separate
989 (list "/[%m" "/%m:%u@%h" "]%p")
990 "Value of `tramp-make-multi-tramp-file-format' for separate remoting.
991 XEmacs uses a separate filename syntax for EFS and Tramp.
992 See `tramp-file-name-structure-separate' for details.")
994 (defcustom tramp-make-multi-tramp-file-format
995 (if (featurep 'xemacs
)
996 tramp-make-multi-tramp-file-format-separate
997 tramp-make-multi-tramp-file-format-unified
)
998 "*Describes how to construct a `multi' file name.
999 This is a list of three elements PREFIX, HOP and PATH.
1001 The first element PREFIX says how to construct the prefix, the second
1002 element HOP specifies what each hop looks like, and the final element
1003 PATH says how to construct the path name.
1005 In PREFIX, `%%' means `%' and `%m' means the method name.
1007 In HOP, `%%' means `%' and `%m', `%u', `%h' mean the hop method, hop
1008 user and hop host, respectively.
1010 In PATH, `%%' means `%' and `%p' means the path name.
1012 The resulting file name always contains one copy of PREFIX and one
1013 copy of PATH, but there is one copy of HOP for each hop in the file
1016 Note: the current implementation requires the prefix to contain the
1017 method name, followed by all the hops, and the path name must come
1020 :type
'(list string string string
))
1022 (defcustom tramp-terminal-type
"dumb"
1023 "*Value of TERM environment variable for logging in to remote host.
1024 Because Tramp wants to parse the output of the remote shell, it is easily
1025 confused by ANSI color escape sequences and suchlike. Often, shell init
1026 files conditionalize this setup based on the TERM environment variable."
1030 (defcustom tramp-completion-without-shell-p nil
1031 "*If nil, use shell wildcards for completion, else rely on Lisp only.
1032 Using shell wildcards for completions has the advantage that it can be
1033 fast even in large directories, but completion is always
1034 case-sensitive. Relying on Lisp only means that case-insensitive
1035 completion is possible (subject to the variable `completion-ignore-case'),
1036 but it might be slow on large directories."
1040 (defcustom tramp-actions-before-shell
1041 '((tramp-password-prompt-regexp tramp-action-password
)
1042 (tramp-login-prompt-regexp tramp-action-login
)
1043 (shell-prompt-pattern tramp-action-succeed
)
1044 (tramp-wrong-passwd-regexp tramp-action-permission-denied
)
1045 (tramp-yesno-prompt-regexp tramp-action-yesno
))
1046 "List of pattern/action pairs.
1047 Whenever a pattern matches, the corresponding action is performed.
1048 Each item looks like (PATTERN ACTION).
1050 The PATTERN should be a symbol, a variable. The value of this
1051 variable gives the regular expression to search for. Note that the
1052 regexp must match at the end of the buffer, \"\\'\" is implicitly
1055 The ACTION should also be a symbol, but a function. When the
1056 corresponding PATTERN matches, the ACTION function is called."
1058 :type
'(repeat (list variable function
)))
1060 (defcustom tramp-multi-actions
1061 '((tramp-password-prompt-regexp tramp-multi-action-password
)
1062 (tramp-login-prompt-regexp tramp-multi-action-login
)
1063 (shell-prompt-pattern tramp-multi-action-succeed
)
1064 (tramp-wrong-passwd-regexp tramp-multi-action-permission-denied
))
1065 "List of pattern/action pairs.
1066 This list is used for each hop in multi-hop connections.
1067 See `tramp-actions-before-shell' for more info."
1069 :type
'(repeat (list variable function
)))
1071 ;;; Internal Variables:
1073 (defvar tramp-buffer-file-attributes nil
1074 "Holds the `ls -ild' output for the current buffer.
1075 This variable is local to each buffer. It is not used if the remote
1076 machine groks Perl. If it is used, it's used as an emulation for
1077 the visited file modtime.")
1078 (make-variable-buffer-local 'tramp-buffer-file-attributes
)
1080 (defvar tramp-end-of-output
"/////"
1081 "String used to recognize end of output.")
1083 (defvar tramp-connection-function nil
1084 "This internal variable holds a parameter for `tramp-methods'.
1085 In the connection buffer, this variable has the value of the like-named
1086 method parameter, as specified in `tramp-methods' (which see).")
1088 (defvar tramp-remote-sh nil
1089 "This internal variable holds a parameter for `tramp-methods'.
1090 In the connection buffer, this variable has the value of the like-named
1091 method parameter, as specified in `tramp-methods' (which see).")
1093 (defvar tramp-rsh-program nil
1094 "This internal variable holds a parameter for `tramp-methods'.
1095 In the connection buffer, this variable has the value of the like-named
1096 method parameter, as specified in `tramp-methods' (which see).")
1098 (defvar tramp-rsh-args nil
1099 "This internal variable holds a parameter for `tramp-methods'.
1100 In the connection buffer, this variable has the value of the like-named
1101 method parameter, as specified in `tramp-methods' (which see).")
1103 (defvar tramp-rcp-program nil
1104 "This internal variable holds a parameter for `tramp-methods'.
1105 In the connection buffer, this variable has the value of the like-named
1106 method parameter, as specified in `tramp-methods' (which see).")
1108 (defvar tramp-rcp-args nil
1109 "This internal variable holds a parameter for `tramp-methods'.
1110 In the connection buffer, this variable has the value of the like-named
1111 method parameter, as specified in `tramp-methods' (which see).")
1113 (defvar tramp-rcp-keep-date-arg nil
1114 "This internal variable holds a parameter for `tramp-methods'.
1115 In the connection buffer, this variable has the value of the like-named
1116 method parameter, as specified in `tramp-methods' (which see).")
1118 (defvar tramp-encoding-command nil
1119 "This internal variable holds a parameter for `tramp-methods'.
1120 In the connection buffer, this variable has the value of the like-named
1121 method parameter, as specified in `tramp-methods' (which see).")
1123 (defvar tramp-decoding-command nil
1124 "This internal variable holds a parameter for `tramp-methods'.
1125 In the connection buffer, this variable has the value of the like-named
1126 method parameter, as specified in `tramp-methods' (which see).")
1128 (defvar tramp-encoding-function nil
1129 "This internal variable holds a parameter for `tramp-methods'.
1130 In the connection buffer, this variable has the value of the like-named
1131 method parameter, as specified in `tramp-methods' (which see).")
1133 (defvar tramp-decoding-function nil
1134 "This internal variable holds a parameter for `tramp-methods'.
1135 In the connection buffer, this variable has the value of the like-named
1136 method parameter, as specified in `tramp-methods' (which see).")
1138 (defvar tramp-telnet-program nil
1139 "This internal variable holds a parameter for `tramp-methods'.
1140 In the connection buffer, this variable has the value of the like-named
1141 method parameter, as specified in `tramp-methods' (which see).")
1143 (defvar tramp-telnet-args nil
1144 "This internal variable holds a parameter for `tramp-methods'.
1145 In the connection buffer, this variable has the value of the like-named
1146 method parameter, as specified in `tramp-methods' (which see).")
1148 ;; CCC `local in each buffer'?
1149 (defvar tramp-ls-command nil
1150 "This command is used to get a long listing with numeric user and group ids.
1151 This variable is automatically made buffer-local to each rsh process buffer
1152 upon opening the connection.")
1154 (defvar tramp-current-multi-method nil
1155 "Name of `multi' connection method for this *tramp* buffer, or nil if not multi.
1156 This variable is automatically made buffer-local to each rsh process buffer
1157 upon opening the connection.")
1159 (defvar tramp-current-method nil
1160 "Connection method for this *tramp* buffer.
1161 This variable is automatically made buffer-local to each rsh process buffer
1162 upon opening the connection.")
1164 (defvar tramp-current-user nil
1165 "Remote login name for this *tramp* buffer.
1166 This variable is automatically made buffer-local to each rsh process buffer
1167 upon opening the connection.")
1169 (defvar tramp-current-host nil
1170 "Remote host for this *tramp* buffer.
1171 This variable is automatically made buffer-local to each rsh process buffer
1172 upon opening the connection.")
1174 (defvar tramp-test-groks-nt nil
1175 "Whether the `test' command groks the `-nt' switch.
1176 \(`test A -nt B' tests if file A is newer than file B.)
1177 This variable is automatically made buffer-local to each rsh process buffer
1178 upon opening the connection.")
1180 (defvar tramp-file-exists-command nil
1181 "Command to use for checking if a file exists.
1182 This variable is automatically made buffer-local to each rsh process buffer
1183 upon opening the connection.")
1185 ;; Perl script to implement `file-attributes' in a Lisp `read'able output.
1186 ;; If you are hacking on this, note that you get *no* output unless this
1187 ;; spits out a complete line, including the '\n' at the end.
1188 (defconst tramp-perl-file-attributes
(concat
1191 if (($s[2] & 0170000) == 0120000) { $l = readlink($f); $l = \"\\\"$l\\\"\"; }
1192 elsif (($s[2] & 0170000) == 040000) { $l = \"t\"; }
1193 else { $l = \"nil\" };
1194 printf(\"(%s %u %u %u (%u %u) (%u %u) (%u %u) %u %u t (%u . %u) (%u %u))\\n\",
1195 $l, $s[3], $s[4], $s[5], $s[8] >> 16 & 0xffff, $s[8] & 0xffff,
1196 $s[9] >> 16 & 0xffff, $s[9] & 0xffff, $s[10] >> 16 & 0xffff, $s[10] & 0xffff,
1197 $s[7], $s[2], $s[1] >> 16 & 0xffff, $s[1] & 0xffff, $s[0] >> 16 & 0xffff, $s[0] & 0xffff);"
1199 "Perl script to produce output suitable for use with `file-attributes'
1200 on the remote file system.")
1202 ;; ;; These two use uu encoding.
1203 ;; (defvar tramp-perl-encode "%s -e'\
1204 ;; print qq(begin 644 xxx\n);
1207 ;; while (read(STDIN, $s, 45)) {
1208 ;; print pack(q(u), $s);
1213 ;; "Perl program to use for encoding a file.
1214 ;; Escape sequence %s is replaced with name of Perl binary.")
1216 ;; (defvar tramp-perl-decode "%s -ne '
1217 ;; print unpack q(u), $_;
1219 ;; "Perl program to use for decoding a file.
1220 ;; Escape sequence %s is replaced with name of Perl binary.")
1222 ;; These two use base64 encoding.
1223 (defvar tramp-perl-encode
1224 "perl -MMIME::Base64 -0777 -ne 'print encode_base64($_)'"
1225 "Perl program to use for encoding a file.
1226 Escape sequence %s is replaced with name of Perl binary.")
1228 (defvar tramp-perl-decode
1229 "perl -MMIME::Base64 -0777 -ne 'print decode_base64($_)'"
1230 "Perl program to use for decoding a file.
1231 Escape sequence %s is replaced with name of Perl binary.")
1233 ; These values conform to `file-attributes' from XEmacs 21.2.
1234 ; GNU Emacs and other tools not checked.
1235 (defconst tramp-file-mode-type-map
'((0 .
"-") ; Normal file (SVID-v2 and XPG2)
1237 (2 .
"c") ; character device
1238 (3 .
"m") ; multiplexed character device (v7)
1239 (4 .
"d") ; directory
1240 (5 .
"?") ; Named special file (XENIX)
1241 (6 .
"b") ; block device
1242 (7 .
"?") ; multiplexed block device (v7)
1243 (8 .
"-") ; regular file
1244 (9 .
"n") ; network special file (HP-UX)
1245 (10 .
"l") ; symlink
1246 (11 .
"?") ; ACL shadow inode (Solaris, not userspace)
1248 (13 .
"D") ; door special (Solaris)
1249 (14 .
"w")) ; whiteout (BSD)
1250 "A list of file types returned from the `stat' system call.
1251 This is used to map a mode number to a permission string.")
1253 (defvar tramp-dos-coding-system
1254 (if (and (fboundp 'coding-system-p
)
1255 (funcall 'coding-system-p
'(dos)))
1258 "Some Emacsen know the `dos' coding system, others need `undecided-dos'.")
1260 (defvar tramp-last-cmd-time nil
1261 "Internal Tramp variable recording the time when the last cmd was sent.
1262 This variable is buffer-local in every buffer.")
1263 (make-variable-buffer-local 'tramp-last-cmd-time
)
1265 ;; New handlers should be added here. The following operations can be
1266 ;; handled using the normal primitives: file-name-as-directory,
1267 ;; file-name-directory, file-name-nondirectory,
1268 ;; file-name-sans-versions, get-file-buffer.
1269 (defconst tramp-file-name-handler-alist
1271 (load . tramp-handle-load
)
1272 (make-symbolic-link . tramp-handle-make-symbolic-link
)
1273 (file-name-directory . tramp-handle-file-name-directory
)
1274 (file-name-nondirectory . tramp-handle-file-name-nondirectory
)
1275 (file-truename . tramp-handle-file-truename
)
1276 (file-exists-p . tramp-handle-file-exists-p
)
1277 (file-directory-p . tramp-handle-file-directory-p
)
1278 (file-executable-p . tramp-handle-file-executable-p
)
1279 (file-accessible-directory-p . tramp-handle-file-accessible-directory-p
)
1280 (file-readable-p . tramp-handle-file-readable-p
)
1281 (file-regular-p . tramp-handle-file-regular-p
)
1282 (file-symlink-p . tramp-handle-file-symlink-p
)
1283 (file-writable-p . tramp-handle-file-writable-p
)
1284 (file-ownership-preserved-p . tramp-handle-file-ownership-preserved-p
)
1285 (file-newer-than-file-p . tramp-handle-file-newer-than-file-p
)
1286 (file-attributes . tramp-handle-file-attributes
)
1287 (file-modes . tramp-handle-file-modes
)
1288 (file-directory-files . tramp-handle-file-directory-files
)
1289 (directory-files . tramp-handle-directory-files
)
1290 (file-name-all-completions . tramp-handle-file-name-all-completions
)
1291 (file-name-completion . tramp-handle-file-name-completion
)
1292 (add-name-to-file . tramp-handle-add-name-to-file
)
1293 (copy-file . tramp-handle-copy-file
)
1294 (rename-file . tramp-handle-rename-file
)
1295 (set-file-modes . tramp-handle-set-file-modes
)
1296 (make-directory . tramp-handle-make-directory
)
1297 (delete-directory . tramp-handle-delete-directory
)
1298 (delete-file . tramp-handle-delete-file
)
1299 (directory-file-name . tramp-handle-directory-file-name
)
1300 (shell-command . tramp-handle-shell-command
)
1301 (insert-directory . tramp-handle-insert-directory
)
1302 (expand-file-name . tramp-handle-expand-file-name
)
1303 (file-local-copy . tramp-handle-file-local-copy
)
1304 (insert-file-contents . tramp-handle-insert-file-contents
)
1305 (write-region . tramp-handle-write-region
)
1306 (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory
)
1307 (dired-call-process . tramp-handle-dired-call-process
)
1308 (dired-recursive-delete-directory
1309 . tramp-handle-dired-recursive-delete-directory
)
1310 (set-visited-file-modtime . tramp-handle-set-visited-file-modtime
)
1311 (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime
))
1312 "Alist of handler functions.
1313 Operations not mentioned here will be handled by the normal Emacs functions.")
1315 ;;; Internal functions which must come first.
1317 (defsubst tramp-message
(level fmt-string
&rest args
)
1318 "Emit a message depending on verbosity level.
1319 First arg LEVEL says to be quiet if `tramp-verbose' is less than LEVEL. The
1320 message is emitted only if `tramp-verbose' is greater than or equal to LEVEL.
1321 Calls function `message' with FMT-STRING as control string and the remaining
1322 ARGS to actually emit the message (if applicable).
1324 This function expects to be called from the tramp buffer only!"
1325 (when (<= level tramp-verbose
)
1326 (apply #'message
(concat "tramp: " fmt-string
) args
)
1327 (when tramp-debug-buffer
1330 (tramp-get-debug-buffer
1331 tramp-current-multi-method tramp-current-method
1332 tramp-current-user tramp-current-host
))
1333 (goto-char (point-max))
1334 (tramp-insert-with-face
1336 (concat "# " (apply #'format fmt-string args
) "\n"))))))
1338 (defun tramp-message-for-buffer
1339 (multi-method method user host level fmt-string
&rest args
)
1340 "Like `tramp-message' but temporarily switches to the tramp buffer.
1341 First three args METHOD, USER, and HOST identify the tramp buffer to use,
1342 remaining args passed to `tramp-message'."
1344 (set-buffer (tramp-get-buffer multi-method method user host
))
1345 (apply 'tramp-message level fmt-string args
)))
1347 (defsubst tramp-line-end-position nil
1348 "Return point at end of line.
1349 Calls `line-end-position' or `point-at-eol' if defined, else
1350 own implementation."
1352 ((fboundp 'line-end-position
) (funcall 'line-end-position
))
1353 ((fboundp 'point-at-eol
) (funcall 'point-at-eol
))
1354 (t (save-excursion (end-of-line) (point)))))
1356 (defmacro with-parsed-tramp-file-name
(filename var
&rest body
)
1357 "Parse a Tramp filename and make components available in the body.
1359 First arg FILENAME is evaluated and dissected into its components.
1360 Second arg VAR is a symbol. It is used as a variable name to hold
1361 the filename structure. It is also used as a prefix for the variables
1362 holding the components. For example, if VAR is the symbol `foo', then
1363 `foo' will be bound to the whole structure, `foo-multi-method' will
1364 be bound to the multi-method component, and so on for `foo-method',
1365 `foo-user', `foo-host', `foo-path'.
1367 Remaining args are Lisp expressions to be evaluated (inside an implicit
1370 If VAR is nil, then we bind `v' to the structure and `multi-method',
1371 `method', `user', `host', `path' to the components."
1372 `(let* ((,(or var
'v
) (tramp-dissect-file-name ,filename
))
1373 (,(if var
(intern (concat (symbol-name var
) "-multi-method")) 'multi-method
)
1374 (tramp-file-name-multi-method ,(or var
'v
)))
1375 (,(if var
(intern (concat (symbol-name var
) "-method")) 'method
)
1376 (tramp-file-name-method ,(or var
'v
)))
1377 (,(if var
(intern (concat (symbol-name var
) "-user")) 'user
)
1378 (tramp-file-name-user ,(or var
'v
)))
1379 (,(if var
(intern (concat (symbol-name var
) "-host")) 'host
)
1380 (tramp-file-name-host ,(or var
'v
)))
1381 (,(if var
(intern (concat (symbol-name var
) "-path")) 'path
)
1382 (tramp-file-name-path ,(or var
'v
))))
1385 (put 'with-parsed-tramp-file-name
'lisp-indent-function
2)
1387 ;;; File Name Handler Functions:
1389 (defun tramp-handle-make-symbolic-link
1390 (filename linkname
&optional ok-if-already-exists
)
1391 "Like `make-symbolic-link' for tramp files.
1392 If LINKNAME is a non-Tramp file, it is used verbatim as the target of
1393 the symlink. If LINKNAME is a Tramp file, only the path component is
1394 used as the target of the symlink.
1396 If LINKNAME is a Tramp file and the path component is relative, then
1397 it is expanded first, before the path component is taken. Note that
1398 this can give surprising results if the user/host for the source and
1399 target of the symlink differ."
1400 (with-parsed-tramp-file-name linkname l
1401 (when (tramp-ange-ftp-file-name-p l-multi-method l-method
)
1402 (tramp-invoke-ange-ftp 'make-symbolic-link
1403 filename linkname ok-if-already-exists
))
1404 (let ((ln (tramp-get-remote-ln l-multi-method l-method l-user l-host
))
1405 (cwd (file-name-directory l-path
)))
1408 (list "Making a symbolic link."
1409 "ln(1) does not exist on the remote host.")))
1411 ;; Do the 'confirm if exists' thing.
1412 (when (file-exists-p linkname
)
1414 (if (or (null ok-if-already-exists
) ; not allowed to exist
1415 (and (numberp ok-if-already-exists
)
1418 "File %s already exists; make it a link anyway? "
1420 (signal 'file-already-exists
(list "File already exists" l-path
))
1421 (delete-file linkname
)))
1423 ;; If FILENAME is a Tramp name, use just the path component.
1424 (when (tramp-tramp-file-p filename
)
1425 (setq filename
(tramp-file-name-path
1426 (tramp-dissect-file-name
1427 (expand-file-name filename
)))))
1429 ;; Right, they are on the same host, regardless of user, method, etc.
1430 ;; We now make the link on the remote machine. This will occur as the user
1431 ;; that FILENAME belongs to.
1433 (tramp-send-command-and-check
1434 l-multi-method l-method l-user l-host
1435 (format "cd %s && %s -sf %s %s"
1442 (defun tramp-handle-load (file &optional noerror nomessage nosuffix must-suffix
)
1443 "Like `load' for tramp files. Not implemented!"
1444 (unless (file-name-absolute-p file
)
1445 (error "Tramp cannot `load' files without absolute path name"))
1446 (with-parsed-tramp-file-name file nil
1447 (when (tramp-ange-ftp-file-name-p multi-method method
)
1448 (tramp-invoke-ange-ftp 'load
1449 file noerror nomessage nosuffix must-suffix
))
1451 (cond ((file-exists-p (concat file
".elc"))
1452 (setq file
(concat file
".elc")))
1453 ((file-exists-p (concat file
".el"))
1454 (setq file
(concat file
".el")))))
1456 ;; The first condition is always true for absolute file names.
1457 ;; Included for safety's sake.
1458 (unless (or (file-name-directory file
)
1459 (string-match "\\.elc?\\'" file
))
1460 (error "File `%s' does not include a `.el' or `.elc' suffix"
1463 (when (not (file-exists-p file
))
1464 (error "Cannot load nonexistant file `%s'" file
)))
1465 (if (not (file-exists-p file
))
1468 (message "Loading %s..." file
))
1469 (let ((local-copy (file-local-copy file
)))
1470 ;; MUST-SUFFIX doesn't exist on XEmacs, so let it default to nil.
1471 (load local-copy noerror t t
)
1472 (delete-file local-copy
))
1474 (message "Loading %s...done" file
))
1477 ;; Path manipulation functions that grok TRAMP paths...
1478 (defun tramp-handle-file-name-directory (file)
1479 "Like `file-name-directory' but aware of TRAMP files."
1480 ;; everything except the last filename thing is the directory
1481 (with-parsed-tramp-file-name file nil
1482 (when (tramp-ange-ftp-file-name-p multi-method method
)
1483 (tramp-invoke-ange-ftp 'file-name-directory file
))
1484 ;; For the following condition, two possibilities should be tried:
1485 ;; (1) (string= path "")
1486 ;; (2) (or (string= path "") (string= path "/"))
1487 ;; The second variant fails when completing a "/" directory on
1488 ;; the remote host, that is a filename which looks like
1489 ;; "/user@host:/". But maybe wildcards fail with the first variant.
1490 ;; We should do some investigation.
1491 (if (string= path
"")
1492 ;; For a filename like "/[foo]", we return "/". The `else'
1493 ;; case would return "/[foo]" unchanged. But if we do that,
1494 ;; then `file-expand-wildcards' ceases to work. It's not
1495 ;; quite clear to me what's the intuition that tells that this
1496 ;; behavior is the right behavior, but oh, well.
1498 ;; run the command on the path portion only
1499 ;; CCC: This should take into account the remote machine type, no?
1500 ;; --daniel <daniel@danann.net>
1501 (tramp-make-tramp-file-name multi-method method user host
1502 ;; This will not recurse...
1503 (or (file-name-directory path
) "")))))
1505 (defun tramp-handle-file-name-nondirectory (file)
1506 "Like `file-name-nondirectory' but aware of TRAMP files."
1507 (with-parsed-tramp-file-name file nil
1508 (when (tramp-ange-ftp-file-name-p multi-method method
)
1509 (tramp-invoke-ange-ftp 'file-name-nondirectory file
))
1510 (file-name-nondirectory path
)))
1512 (defun tramp-handle-file-truename (filename &optional counter prev-dirs
)
1513 "Like `file-truename' for tramp files."
1514 (with-parsed-tramp-file-name filename nil
1515 ;; Ange-FTP does not support truename processing. It returns the
1516 ;; file name as-is. So that's what we do, too.
1517 (when (tramp-ange-ftp-file-name-p multi-method method
)
1519 (let* ((steps (tramp-split-string path
"/"))
1520 (pathdir (let ((directory-sep-char ?
/))
1521 (file-name-as-directory path
)))
1522 (is-dir (string= path pathdir
))
1525 ;; Don't make the following value larger than necessary.
1526 ;; People expect an error message in a timely fashion when
1527 ;; something is wrong; otherwise they might think that Emacs
1528 ;; is hung. Of course, correctness has to come first.
1530 (result nil
) ;result steps in reverse order
1533 (tramp-message-for-buffer
1534 multi-method method user host
1535 10 "Finding true name for `%s'" filename
)
1536 (while (and steps
(< numchase numchase-limit
))
1537 (setq thisstep
(pop steps
))
1538 (tramp-message-for-buffer
1539 multi-method method user host
1541 (mapconcat 'identity
1542 (append '("") (reverse result
) (list thisstep
))
1544 (setq symlink-target
1545 (nth 0 (tramp-handle-file-attributes
1546 (tramp-make-tramp-file-name
1547 multi-method method user host
1548 (mapconcat 'identity
1549 (append '("") (reverse result
) (list thisstep
))
1551 (cond ((string= "." thisstep
)
1552 (tramp-message-for-buffer multi-method method user host
1553 10 "Ignoring step `.'"))
1554 ((string= ".." thisstep
)
1555 (tramp-message-for-buffer multi-method method user host
1556 10 "Processing step `..'")
1558 ((stringp symlink-target
)
1559 ;; It's a symlink, follow it.
1560 (tramp-message-for-buffer
1561 multi-method method user host
1562 10 "Follow symlink to %s" symlink-target
)
1563 (setq numchase
(1+ numchase
))
1564 (when (file-name-absolute-p symlink-target
)
1567 (append (tramp-split-string symlink-target
"/") steps
)))
1570 (setq result
(cons thisstep result
)))))
1571 (when (>= numchase numchase-limit
)
1572 (error "Maximum number (%d) of symlinks exceeded" numchase-limit
))
1573 (setq result
(reverse result
))
1574 (tramp-message-for-buffer
1575 multi-method method user host
1576 10 "True name of `%s' is `%s'"
1577 filename
(mapconcat 'identity
(cons "" result
) "/"))
1578 (tramp-make-tramp-file-name
1579 multi-method method user host
1580 (concat (mapconcat 'identity
(cons "" result
) "/")
1581 (if is-dir
"/" ""))))))
1585 (defun tramp-handle-file-exists-p (filename)
1586 "Like `file-exists-p' for tramp files."
1587 (with-parsed-tramp-file-name filename nil
1588 (when (tramp-ange-ftp-file-name-p multi-method method
)
1589 (tramp-invoke-ange-ftp 'file-exists-p filename
))
1591 (zerop (tramp-send-command-and-check
1592 multi-method method user host
1594 (tramp-get-file-exists-command multi-method method user host
)
1595 (tramp-shell-quote-argument path
)))))))
1597 ;; CCC: This should check for an error condition and signal failure
1598 ;; when something goes wrong.
1599 ;; Daniel Pittman <daniel@danann.net>
1600 (defun tramp-handle-file-attributes (filename &optional nonnumeric
)
1601 "Like `file-attributes' for tramp files.
1602 Optional argument NONNUMERIC means return user and group name
1603 rather than as numbers."
1605 (with-parsed-tramp-file-name filename nil
1606 (when (tramp-ange-ftp-file-name-p multi-method method
)
1607 (tramp-invoke-ange-ftp 'file-attributes filename
))
1608 (when (tramp-handle-file-exists-p filename
)
1609 ;; file exists, find out stuff
1611 (if (tramp-get-remote-perl multi-method method user host
)
1613 (tramp-handle-file-attributes-with-perl
1614 multi-method method user host path nonnumeric
))
1616 (tramp-handle-file-attributes-with-ls
1617 multi-method method user host path nonnumeric
))))))
1621 (defun tramp-handle-file-attributes-with-ls
1622 (multi-method method user host path
&optional nonnumeric
)
1623 "Implement `file-attributes' for tramp files using the ls(1) command."
1625 res-inode res-filemodes res-numlinks
1626 res-uid res-gid res-size res-symlink-target
)
1627 (tramp-message-for-buffer multi-method method user host
10
1628 "file attributes with ls: %s"
1629 (tramp-make-tramp-file-name
1630 multi-method method user host path
))
1632 multi-method method user host
1634 (tramp-get-ls-command multi-method method user host
)
1635 (if nonnumeric
"-ild" "-ildn")
1636 (tramp-shell-quote-argument path
)))
1637 (tramp-wait-for-output)
1638 ;; parse `ls -l' output ...
1642 (read (current-buffer))
1643 (invalid-read-syntax
1644 (when (and (equal (cadr err
)
1645 "Integer constant overflow in reader")
1647 "^[0-9]+\\([0-9][0-9][0-9][0-9][0-9]\\)\\'"
1649 (let* ((big (read (substring (caddr err
) 0
1650 (match-beginning 1))))
1651 (small (read (match-string 1 (caddr err
))))
1652 (twiddle (/ small
65536)))
1653 (cons (+ big twiddle
)
1654 (- small
(* twiddle
65536))))))))
1655 ;; ... file mode flags
1656 (setq res-filemodes
(symbol-name (read (current-buffer))))
1658 (setq res-numlinks
(read (current-buffer)))
1660 (setq res-uid
(read (current-buffer)))
1661 (setq res-gid
(read (current-buffer)))
1663 (unless (numberp res-uid
) (setq res-uid -
1))
1664 (unless (numberp res-gid
) (setq res-gid -
1)))
1666 (setq res-size
(read (current-buffer)))
1667 ;; From the file modes, figure out other stuff.
1668 (setq symlinkp
(eq ?l
(aref res-filemodes
0)))
1669 (setq dirp
(eq ?d
(aref res-filemodes
0)))
1670 ;; if symlink, find out file name pointed to
1672 (search-forward "-> ")
1673 (setq res-symlink-target
1674 (buffer-substring (point)
1675 (tramp-line-end-position))))
1676 ;; return data gathered
1678 ;; 0. t for directory, string (name linked to) for symbolic
1680 (or dirp res-symlink-target nil
)
1681 ;; 1. Number of links to file.
1687 ;; 4. Last access time, as a list of two integers. First
1688 ;; integer has high-order 16 bits of time, second has low 16
1690 ;; 5. Last modification time, likewise.
1691 ;; 6. Last status change time, likewise.
1692 '(0 0) '(0 0) '(0 0) ;CCC how to find out?
1693 ;; 7. Size in bytes (-1, if number is out of range).
1695 ;; 8. File modes, as a string of ten letters or dashes as in ls -l.
1697 ;; 9. t iff file's gid would change if file were deleted and
1700 ;; 10. inode number.
1702 ;; 11. Device number.
1706 (defun tramp-handle-file-attributes-with-perl
1707 (multi-method method user host path
&optional nonnumeric
)
1708 "Implement `file-attributes' for tramp files using a Perl script.
1710 The Perl command is sent to the remote machine when the connection
1711 is initially created and is kept cached by the remote shell."
1712 (tramp-message-for-buffer multi-method method user host
10
1713 "file attributes with perl: %s"
1714 (tramp-make-tramp-file-name
1715 multi-method method user host path
))
1717 multi-method method user host
1718 (format "tramp_file_attributes %s"
1719 (tramp-shell-quote-argument path
)))
1720 (tramp-wait-for-output)
1721 (let ((result (read (current-buffer))))
1722 (setcar (nthcdr 8 result
)
1723 (tramp-file-mode-from-int (nth 8 result
)))
1726 (defun tramp-handle-set-visited-file-modtime (&optional time-list
)
1727 "Like `set-visited-file-modtime' for tramp files."
1728 (unless (buffer-file-name)
1729 (error "Can't set-visited-file-modtime: buffer `%s' not visiting a file"
1732 (tramp-run-real-handler 'set-visited-file-modtime
(list time-list
)))
1733 (let ((f (buffer-file-name))
1734 (coding-system-used nil
))
1735 (with-parsed-tramp-file-name f nil
1736 ;; This operation is not handled by Ange-FTP!
1737 (when (tramp-ange-ftp-file-name-p multi-method method
)
1738 (throw 'tramp-forward-to-ange-ftp
1739 (tramp-run-real-handler 'set-visited-file-modtime
1741 (let* ((attr (file-attributes f
))
1742 (modtime (nth 5 attr
)))
1743 ;; We use '(0 0) as a don't-know value. See also
1744 ;; `tramp-handle-file-attributes-with-ls'.
1745 (when (boundp 'last-coding-system-used
)
1746 (setq coding-system-used last-coding-system-used
))
1747 (if (not (equal modtime
'(0 0)))
1748 (tramp-run-real-handler 'set-visited-file-modtime
(list modtime
))
1751 multi-method method user host
1752 (format "%s -ild %s"
1753 (tramp-get-ls-command multi-method method user host
)
1754 (tramp-shell-quote-argument path
)))
1755 (tramp-wait-for-output)
1756 (setq attr
(buffer-substring (point)
1757 (progn (end-of-line) (point)))))
1758 (setq tramp-buffer-file-attributes attr
))
1759 (when (boundp 'last-coding-system-used
)
1760 (setq last-coding-system-used coding-system-used
))
1763 ;; CCC continue here
1765 ;; This function makes the same assumption as
1766 ;; `tramp-handle-set-visited-file-modtime'.
1767 (defun tramp-handle-verify-visited-file-modtime (buf)
1768 "Like `verify-visited-file-modtime' for tramp files."
1769 (with-current-buffer buf
1770 (let ((f (buffer-file-name)))
1771 (with-parsed-tramp-file-name f nil
1772 (when (tramp-ange-ftp-file-name-p multi-method method
)
1773 ;; This one requires a hack since the file name is not passed
1775 (let ((buffer-file-name (tramp-make-ange-ftp-file-name
1777 (tramp-invoke-ange-ftp 'verify-visited-file-modtime buf
)))
1778 (let* ((attr (file-attributes f
))
1779 (modtime (nth 5 attr
)))
1780 (cond ((and attr
(not (equal modtime
'(0 0))))
1781 ;; Why does `file-attributes' return a list (HIGH
1782 ;; LOW), but `visited-file-modtime' returns a cons
1784 (let ((mt (visited-file-modtime)))
1785 (< (abs (tramp-time-diff
1786 modtime
(list (car mt
) (cdr mt
)))) 2)))
1790 multi-method method user host
1791 (format "%s -ild %s"
1792 (tramp-get-ls-command multi-method method
1794 (tramp-shell-quote-argument path
)))
1795 (tramp-wait-for-output)
1796 (setq attr
(buffer-substring
1797 (point) (progn (end-of-line) (point)))))
1798 (equal tramp-buffer-file-attributes attr
))
1799 ;; If file does not exist, say it is not modified.
1802 (defadvice clear-visited-file-modtime
(after tramp activate
)
1803 "Set `tramp-buffer-file-attributes' back to nil.
1804 Tramp uses this variable as an emulation for the actual modtime of the file,
1805 if the remote host can't provide the modtime."
1806 (setq tramp-buffer-file-attributes nil
))
1808 (defun tramp-handle-set-file-modes (filename mode
)
1809 "Like `set-file-modes' for tramp files."
1810 (with-parsed-tramp-file-name filename nil
1811 (when (tramp-ange-ftp-file-name-p multi-method method
)
1812 (tramp-invoke-ange-ftp 'set-file-modes filename mode
))
1814 (unless (zerop (tramp-send-command-and-check
1815 multi-method method user host
1816 (format "chmod %s %s"
1817 (tramp-decimal-to-octal mode
)
1818 (tramp-shell-quote-argument path
))))
1821 ;; FIXME: extract the proper text from chmod's stderr.
1822 "error while changing file's mode"
1825 ;; Simple functions using the `test' command.
1827 (defun tramp-handle-file-executable-p (filename)
1828 "Like `file-executable-p' for tramp files."
1829 (with-parsed-tramp-file-name filename nil
1830 (when (tramp-ange-ftp-file-name-p multi-method method
)
1831 (tramp-invoke-ange-ftp 'file-executable-p filename
))
1832 (zerop (tramp-run-test "-x" filename
))))
1834 (defun tramp-handle-file-readable-p (filename)
1835 "Like `file-readable-p' for tramp files."
1836 (with-parsed-tramp-file-name filename nil
1837 (when (tramp-ange-ftp-file-name-p multi-method method
)
1838 (tramp-invoke-ange-ftp 'file-readable-p filename
))
1839 (zerop (tramp-run-test "-r" filename
))))
1841 (defun tramp-handle-file-accessible-directory-p (filename)
1842 "Like `file-accessible-directory-p' for tramp files."
1843 (with-parsed-tramp-file-name filename nil
1844 (when (tramp-ange-ftp-file-name-p multi-method method
)
1845 (tramp-invoke-ange-ftp 'file-accessible-directory-p filename
))
1846 (and (zerop (tramp-run-test "-d" filename
))
1847 (zerop (tramp-run-test "-r" filename
))
1848 (zerop (tramp-run-test "-x" filename
)))))
1850 ;; When the remote shell is started, it looks for a shell which groks
1851 ;; tilde expansion. Here, we assume that all shells which grok tilde
1852 ;; expansion will also provide a `test' command which groks `-nt' (for
1853 ;; newer than). If this breaks, tell me about it and I'll try to do
1854 ;; something smarter about it.
1855 (defun tramp-handle-file-newer-than-file-p (file1 file2
)
1856 "Like `file-newer-than-file-p' for tramp files."
1857 (cond ((not (file-exists-p file1
))
1859 ((not (file-exists-p file2
))
1861 ;; We are sure both files exist at this point. We assume that
1862 ;; both files are Tramp files, otherwise we issue an error
1863 ;; message. Todo: make a better error message.
1866 (with-parsed-tramp-file-name file1 v1
1867 (with-parsed-tramp-file-name file2 v2
1868 (when (and (tramp-ange-ftp-file-name-p v1-multi-method v1-method
)
1869 (tramp-ange-ftp-file-name-p v2-multi-method v2-method
))
1870 (tramp-invoke-ange-ftp 'file-newer-than-file-p
1872 (unless (and (equal v1-multi-method v2-multi-method
)
1873 (equal v1-method v2-method
)
1874 (equal v1-user v2-user
)
1875 (equal v1-host v2-host
))
1877 (list "Files must have same method, user, host"
1879 (unless (and (tramp-tramp-file-p file1
)
1880 (tramp-tramp-file-p file2
))
1882 (list "Files must be tramp files on same host"
1884 (if (tramp-get-test-groks-nt
1885 v1-multi-method v1-method v1-user v1-host
)
1886 (zerop (tramp-run-test2 "test" file1 file2
"-nt"))
1887 (zerop (tramp-run-test2 "tramp_test_nt" file1 file2
)))))))))
1889 ;; Functions implemented using the basic functions above.
1891 (defun tramp-handle-file-modes (filename)
1892 "Like `file-modes' for tramp files."
1893 (with-parsed-tramp-file-name filename nil
1894 (when (tramp-ange-ftp-file-name-p multi-method method
)
1895 (tramp-invoke-ange-ftp 'file-modes filename
))
1896 (when (file-exists-p filename
)
1897 (tramp-mode-string-to-int
1898 (nth 8 (tramp-handle-file-attributes filename
))))))
1900 (defun tramp-handle-file-directory-p (filename)
1901 "Like `file-directory-p' for tramp files."
1902 ;; Care must be taken that this function returns `t' for symlinks
1903 ;; pointing to directories. Surely the most obvious implementation
1904 ;; would be `test -d', but that returns false for such symlinks.
1905 ;; CCC: Stefan Monnier says that `test -d' follows symlinks. And
1906 ;; I now think he's right. So we could be using `test -d', couldn't
1909 ;; Alternatives: `cd %s', `test -d %s'
1910 (with-parsed-tramp-file-name filename nil
1911 (when (tramp-ange-ftp-file-name-p multi-method method
)
1912 (tramp-invoke-ange-ftp 'file-directory-p filename
))
1915 (tramp-send-command-and-check
1916 multi-method method user host
1917 (format "test -d %s"
1918 (tramp-shell-quote-argument path
))
1919 t
))))) ;run command in subshell
1921 (defun tramp-handle-file-regular-p (filename)
1922 "Like `file-regular-p' for tramp files."
1923 (with-parsed-tramp-file-name filename nil
1924 (when (tramp-ange-ftp-file-name-p multi-method method
)
1925 (tramp-invoke-ange-ftp 'file-regular-p filename
))
1926 (and (tramp-handle-file-exists-p filename
)
1927 (eq ?-
(aref (nth 8 (tramp-handle-file-attributes filename
)) 0)))))
1929 (defun tramp-handle-file-symlink-p (filename)
1930 "Like `file-symlink-p' for tramp files."
1931 (with-parsed-tramp-file-name filename nil
1932 (when (tramp-ange-ftp-file-name-p multi-method method
)
1933 (tramp-invoke-ange-ftp 'file-symlink-p filename
))
1934 (let ((x (car (tramp-handle-file-attributes filename
))))
1935 (when (stringp x
) x
))))
1937 (defun tramp-handle-file-writable-p (filename)
1938 "Like `file-writable-p' for tramp files."
1939 (with-parsed-tramp-file-name filename nil
1940 (when (tramp-ange-ftp-file-name-p multi-method method
)
1941 (tramp-invoke-ange-ftp 'file-writable-p filename
))
1942 (if (tramp-handle-file-exists-p filename
)
1943 ;; Existing files must be writable.
1944 (zerop (tramp-run-test "-w" filename
))
1945 ;; If file doesn't exist, check if directory is writable.
1946 (and (zerop (tramp-run-test
1947 "-d" (tramp-handle-file-name-directory filename
)))
1948 (zerop (tramp-run-test
1949 "-w" (tramp-handle-file-name-directory filename
)))))))
1951 (defun tramp-handle-file-ownership-preserved-p (filename)
1952 "Like `file-ownership-preserved-p' for tramp files."
1953 (with-parsed-tramp-file-name filename nil
1954 (when (tramp-ange-ftp-file-name-p multi-method method
)
1955 (tramp-invoke-ange-ftp 'file-ownership-preserved-p filename
))
1956 (or (not (tramp-handle-file-exists-p filename
))
1957 ;; Existing files must be writable.
1958 (zerop (tramp-run-test "-O" filename
)))))
1960 ;; Other file name ops.
1962 ;; ;; Matthias Köppe <mkoeppe@mail.math.uni-magdeburg.de>
1963 ;; (defun tramp-handle-directory-file-name (directory)
1964 ;; "Like `directory-file-name' for tramp files."
1965 ;; (if (and (eq (aref directory (- (length directory) 1)) ?/)
1966 ;; (not (eq (aref directory (- (length directory) 2)) ?:)))
1967 ;; (substring directory 0 (- (length directory) 1))
1970 ;; Philippe Troin <phil@fifi.org>
1971 (defun tramp-handle-directory-file-name (directory)
1972 "Like `directory-file-name' for tramp files."
1973 (with-parsed-tramp-file-name directory nil
1974 (when (tramp-ange-ftp-file-name-p multi-method method
)
1975 (tramp-invoke-ange-ftp 'directory-file-name directory
))
1976 (let ((directory-length-1 (1- (length directory
))))
1978 (if (and (eq (aref directory directory-length-1
) ?
/)
1979 (eq (string-match tramp-file-name-regexp directory
) 0)
1980 (/= (match-end 0) directory-length-1
))
1981 (substring directory
0 directory-length-1
)
1984 ;; Directory listings.
1986 (defun tramp-handle-directory-files (directory
1987 &optional full match nosort files-only
)
1988 "Like `directory-files' for tramp files."
1989 (with-parsed-tramp-file-name directory nil
1990 (when (tramp-ange-ftp-file-name-p multi-method method
)
1991 (tramp-invoke-ange-ftp 'directory-files
1992 directory full match nosort files-only
))
1995 (tramp-barf-unless-okay
1996 multi-method method user host
1997 (concat "cd " (tramp-shell-quote-argument path
))
2000 "tramp-handle-directory-files: couldn't `cd %s'"
2001 (tramp-shell-quote-argument path
))
2003 multi-method method user host
2004 (concat (tramp-get-ls-command multi-method method user host
)
2006 (tramp-wait-for-output)
2007 (goto-char (point-max))
2008 (while (zerop (forward-line -
1))
2009 (setq x
(buffer-substring (point)
2010 (tramp-line-end-position)))
2011 (when (or (not match
) (string-match match x
))
2013 (push (concat (file-name-as-directory directory
)
2017 (tramp-send-command multi-method method user host
"cd")
2018 (tramp-wait-for-output)
2019 ;; Remove non-files or non-directories if necessary. Using
2020 ;; the remote shell for this would probably be way faster.
2021 ;; Maybe something could be adapted from
2022 ;; tramp-handle-file-name-all-completions.
2024 (let ((temp (nreverse result
))
2027 (if (equal files-only t
)
2030 (setq item
(pop temp
))
2031 (when (file-regular-p item
)
2032 (push item result
)))
2035 (setq item
(pop temp
))
2036 (when (file-directory-p item
)
2037 (push item result
)))))))
2040 ;; This function should return "foo/" for directories and "bar" for
2041 ;; files. We use `ls -ad' to get a list of files (including
2042 ;; directories), and `find . -type d \! -name . -prune' to get a list
2044 (defun tramp-handle-file-name-all-completions (filename directory
)
2045 "Like `file-name-all-completions' for tramp files."
2046 (with-parsed-tramp-file-name directory nil
2047 (when (tramp-ange-ftp-file-name-p multi-method method
)
2048 (tramp-invoke-ange-ftp 'file-name-all-completions
2049 filename directory
))
2050 (unless (save-match-data (string-match "/" filename
))
2051 (let* ((nowild tramp-completion-without-shell-p
)
2054 (tramp-barf-unless-okay
2055 multi-method method user host
2056 (format "cd %s" (tramp-shell-quote-argument path
))
2058 "tramp-handle-file-name-all-completions: Couldn't `cd %s'"
2059 (tramp-shell-quote-argument path
))
2061 ;; Get a list of directories and files, including reliably
2062 ;; tagging the directories with a trailing '/'. Because I
2063 ;; rock. --daniel@danann.net
2065 multi-method method user host
2066 (format (concat "%s -a %s 2>/dev/null | while read f; do "
2067 "if test -d \"$f\" 2>/dev/null; "
2068 "then echo \"$f/\"; else echo \"$f\"; fi; done")
2069 (tramp-get-ls-command multi-method method user host
)
2070 (if (or nowild
(zerop (length filename
)))
2073 (tramp-shell-quote-argument filename
)))))
2075 ;; Now grab the output.
2076 (tramp-wait-for-output)
2077 (goto-char (point-max))
2078 (while (zerop (forward-line -
1))
2079 (push (buffer-substring (point)
2080 (tramp-line-end-position))
2083 (tramp-send-command multi-method method user host
"cd")
2084 (tramp-wait-for-output)
2088 (all-completions filename
(mapcar 'list result
))
2092 ;; The following isn't needed for Emacs 20 but for 19.34?
2093 (defun tramp-handle-file-name-completion (filename directory
)
2094 "Like `file-name-completion' for tramp files."
2095 (unless (tramp-tramp-file-p directory
)
2097 "tramp-handle-file-name-completion invoked on non-tramp directory `%s'"
2099 (with-parsed-tramp-file-name directory nil
2100 (when (tramp-ange-ftp-file-name-p multi-method method
)
2101 (tramp-invoke-ange-ftp 'file-name-completion
2102 filename directory
))
2105 (mapcar (lambda (x) (cons x nil
))
2106 (tramp-handle-file-name-all-completions filename directory
)))))
2110 (defun tramp-handle-add-name-to-file
2111 (filename newname
&optional ok-if-already-exists
)
2112 "Like `add-name-to-file' for tramp files."
2113 (with-parsed-tramp-file-name filename v1
2114 (with-parsed-tramp-file-name newname v2
2115 (let ((ln (when v1
(tramp-get-remote-ln
2116 v1-multi-method v1-method v1-user v1-host
))))
2117 (unless (and v1-method v2-method v1-user v2-user v1-host v2-host
2118 (equal v1-multi-method v2-multi-method
)
2119 (equal v1-method v2-method
)
2120 (equal v1-user v2-user
)
2121 (equal v1-host v2-host
))
2122 (error "add-name-to-file: %s"
2123 "only implemented for same method, same user, same host"))
2124 (when (and (tramp-ange-ftp-file-name-p v1-multi-method v1-method
)
2125 (tramp-ange-ftp-file-name-p v2-multi-method v2-method
))
2126 (tramp-invoke-ange-ftp 'add-name-to-file
2127 filename newname ok-if-already-exists
))
2128 (when (tramp-ange-ftp-file-name-p v1-multi-method v1-method
)
2129 (tramp-invoke-ange-ftp 'add-name-to-file
2130 filename newname ok-if-already-exists
))
2131 (when (tramp-ange-ftp-file-name-p v2-multi-method v2-method
)
2132 (tramp-invoke-ange-ftp 'add-name-to-file
2133 filename newname ok-if-already-exists
))
2134 (when (and (not ok-if-already-exists
)
2135 (file-exists-p newname
)
2136 (not (numberp ok-if-already-exists
))
2139 "File %s already exists; make it a new name anyway? "
2141 (error "add-name-to-file: file %s already exists" newname
))
2142 (tramp-barf-unless-okay
2143 v1-multi-method v1-method v1-user v1-host
2144 (format "%s %s %s" ln
(tramp-shell-quote-argument v1-path
)
2145 (tramp-shell-quote-argument v2-path
))
2147 "error with add-name-to-file, see buffer `%s' for details"
2150 (defun tramp-handle-copy-file
2151 (filename newname
&optional ok-if-already-exists keep-date
)
2152 "Like `copy-file' for tramp files."
2153 ;; Check if both files are local -- invoke normal copy-file.
2154 ;; Otherwise, use tramp from local system.
2155 (setq filename
(expand-file-name filename
))
2156 (setq newname
(expand-file-name newname
))
2157 ;; At least one file a tramp file?
2158 (if (or (tramp-tramp-file-p filename
)
2159 (tramp-tramp-file-p newname
))
2160 (tramp-do-copy-or-rename-file
2161 'copy filename newname ok-if-already-exists keep-date
)
2162 (tramp-run-real-handler
2164 (list filename newname ok-if-already-exists keep-date
))))
2166 (defun tramp-handle-rename-file
2167 (filename newname
&optional ok-if-already-exists
)
2168 "Like `rename-file' for tramp files."
2169 ;; Check if both files are local -- invoke normal rename-file.
2170 ;; Otherwise, use tramp from local system.
2171 (setq filename
(expand-file-name filename
))
2172 (setq newname
(expand-file-name newname
))
2173 ;; At least one file a tramp file?
2174 (if (or (tramp-tramp-file-p filename
)
2175 (tramp-tramp-file-p newname
))
2176 (tramp-do-copy-or-rename-file
2177 'rename filename newname ok-if-already-exists
)
2178 (tramp-run-real-handler 'rename-file
2179 (list filename newname ok-if-already-exists
))))
2181 (defun tramp-do-copy-or-rename-file
2182 (op filename newname
&optional ok-if-already-exists keep-date
)
2183 "Copy or rename a remote file.
2184 OP must be `copy' or `rename' and indicates the operation to perform.
2185 FILENAME specifies the file to copy or rename, NEWNAME is the name of
2186 the new file (for copy) or the new name of the file (for rename).
2187 OK-IF-ALREADY-EXISTS means don't barf if NEWNAME exists already.
2188 KEEP-DATE means to make sure that NEWNAME has the same timestamp
2191 This function is invoked by `tramp-handle-copy-file' and
2192 `tramp-handle-rename-file'. It is an error if OP is neither of `copy'
2193 and `rename'. FILENAME and NEWNAME must be absolute file names."
2194 (unless (memq op
'(copy rename
))
2195 (error "Unknown operation `%s', must be `copy' or `rename'" op
))
2196 (unless ok-if-already-exists
2197 (when (file-exists-p newname
)
2198 (signal 'file-already-exists
2200 (let ((t1 (tramp-tramp-file-p filename
))
2201 (t2 (tramp-tramp-file-p newname
)))
2202 ;; Check which ones of source and target are Tramp files.
2205 ;; Both are Tramp files.
2206 (with-parsed-tramp-file-name filename v1
2207 (with-parsed-tramp-file-name newname v2
2208 ;; Possibly invoke Ange-FTP.
2209 (when (and (tramp-ange-ftp-file-name-p v1-multi-method v1-method
)
2210 (tramp-ange-ftp-file-name-p v2-multi-method v2-method
))
2211 (tramp-invoke-ange-ftp
2212 (if (eq op
'copy
) 'copy-file
'rename-file
)
2213 filename newname ok-if-already-exists keep-date
))
2214 ;; Check if we can use a shortcut.
2215 (if (and (equal v1-multi-method v2-multi-method
)
2216 (equal v1-method v2-method
)
2217 (equal v1-host v2-host
)
2218 (equal v1-user v2-user
))
2219 ;; Shortcut: if method, host, user are the same for both
2220 ;; files, we invoke `cp' or `mv' on the remote host
2222 (tramp-do-copy-or-rename-file-directly
2223 op v1-multi-method v1-method v1-user v1-host
2224 v1-path v2-path keep-date
)
2225 ;; The shortcut was not possible. So we copy the
2226 ;; file first. If the operation was `rename', we go
2227 ;; back and delete the original file (if the copy was
2228 ;; successful). The approach is simple-minded: we
2229 ;; create a new buffer, insert the contents of the
2230 ;; source file into it, then write out the buffer to
2231 ;; the target file. The advantage is that it doesn't
2232 ;; matter which filename handlers are used for the
2233 ;; source and target file.
2235 ;; CCC: If both source and target are Tramp files,
2236 ;; and both are using the same rcp-program, then we
2237 ;; can invoke rcp directly. Note that
2238 ;; default-directory should point to a local
2239 ;; directory if we want to invoke rcp.
2240 (tramp-do-copy-or-rename-via-buffer
2241 op filename newname keep-date
)))))
2243 ;; Use the generic method via a Tramp buffer.
2244 (tramp-do-copy-or-rename-via-buffer op filename newname keep-date
))
2246 ;; One of them must be a Tramp file.
2247 (error "Tramp implementation says this cannot happen")))))
2249 (defun tramp-do-copy-or-rename-via-buffer (op filename newname keep-date
)
2250 "Use an Emacs buffer to copy or rename a file.
2251 First arg OP is either `copy' or `rename' and indicates the operation.
2252 FILENAME is the source file, NEWNAME the target file.
2253 KEEP-DATE is non-nil if NEWNAME should have the same timestamp as FILENAME."
2254 (let ((trampbuf (get-buffer-create "*tramp output*")))
2257 1 (concat "Warning: cannot preserve file time stamp"
2258 " with inline copying across machines")))
2260 (set-buffer trampbuf
) (erase-buffer)
2261 (insert-file-contents-literally filename
)
2262 (let ((coding-system-for-write 'no-conversion
))
2263 (write-region (point-min) (point-max) newname
)))
2264 ;; If the operation was `rename', delete the original file.
2265 (unless (eq op
'copy
)
2266 (delete-file filename
))))
2268 (defun tramp-do-copy-or-rename-file-directly
2269 (op multi-method method user host path1 path2 keep-date
)
2270 "Invokes `cp' or `mv' on the remote system.
2271 OP must be one of `copy' or `rename', indicating `cp' or `mv',
2272 respectively. METHOD, USER, and HOST specify the connection.
2273 PATH1 and PATH2 specify the two arguments of `cp' or `mv'.
2274 If KEEP-DATE is non-nil, preserve the time stamp when copying."
2275 ;; CCC: What happens to the timestamp when renaming?
2276 (let ((cmd (cond ((and (eq op
'copy
) keep-date
) "cp -f -p")
2277 ((eq op
'copy
) "cp -f")
2278 ((eq op
'rename
) "mv -f")
2280 "Unknown operation `%s', must be `copy' or `rename'"
2283 (tramp-barf-unless-okay
2284 multi-method method user host
2287 (tramp-shell-quote-argument path1
)
2288 (tramp-shell-quote-argument path2
))
2290 "Copying directly failed, see buffer `%s' for details."
2294 (defun tramp-handle-make-directory (dir &optional parents
)
2295 "Like `make-directory' for tramp files."
2296 (setq dir
(expand-file-name dir
))
2297 (with-parsed-tramp-file-name dir nil
2298 (when (tramp-ange-ftp-file-name-p multi-method method
)
2299 (tramp-invoke-ange-ftp 'make-directory dir parents
))
2300 (tramp-barf-unless-okay
2301 multi-method method user host
2303 (if parents
"mkdir -p" "mkdir")
2304 (tramp-shell-quote-argument path
))
2306 "Couldn't make directory %s" dir
)))
2308 ;; CCC error checking?
2309 (defun tramp-handle-delete-directory (directory)
2310 "Like `delete-directory' for tramp files."
2311 (setq directory
(expand-file-name directory
))
2312 (with-parsed-tramp-file-name directory nil
2313 (when (tramp-ange-ftp-file-name-p multi-method method
)
2314 (tramp-invoke-ange-ftp 'delete-directory directory
))
2317 multi-method method user host
2318 (format "rmdir %s ; echo ok"
2319 (tramp-shell-quote-argument path
)))
2320 (tramp-wait-for-output))))
2322 (defun tramp-handle-delete-file (filename)
2323 "Like `delete-file' for tramp files."
2324 (setq filename
(expand-file-name filename
))
2325 (with-parsed-tramp-file-name filename nil
2326 (when (tramp-ange-ftp-file-name-p multi-method method
)
2327 (tramp-invoke-ange-ftp 'delete-file filename
))
2329 (unless (zerop (tramp-send-command-and-check
2330 multi-method method user host
2332 (tramp-shell-quote-argument path
))))
2333 (signal 'file-error
"Couldn't delete Tramp file")))))
2337 ;; CCC: This does not seem to be enough. Something dies when
2338 ;; we try and delete two directories under TRAMP :/
2339 (defun tramp-handle-dired-recursive-delete-directory (filename)
2340 "Recursively delete the directory given.
2341 This is like `dired-recursive-delete-directory' for tramp files."
2342 (with-parsed-tramp-file-name filename nil
2343 (when (tramp-ange-ftp-file-name-p multi-method method
)
2344 (tramp-invoke-ange-ftp 'dired-recursive-delete-directory
2346 ;; run a shell command 'rm -r <path>'
2347 ;; Code shamelessly stolen for the dired implementation and, um, hacked :)
2348 (or (tramp-handle-file-exists-p filename
)
2351 (list "Removing old file name" "no such directory" filename
)))
2352 ;; Which is better, -r or -R? (-r works for me <daniel@danann.net>)
2353 (tramp-send-command multi-method method user host
2354 (format "rm -r %s" (tramp-shell-quote-argument path
)))
2355 ;; Wait for the remote system to return to us...
2356 ;; This might take a while, allow it plenty of time.
2357 (tramp-wait-for-output 120)
2358 ;; Make sure that it worked...
2359 (and (tramp-handle-file-exists-p filename
)
2360 (error "Failed to recusively delete %s" filename
))))
2363 (defun tramp-handle-dired-call-process (program discard
&rest arguments
)
2364 "Like `dired-call-process' for tramp files."
2365 (with-parsed-tramp-file-name default-directory nil
2366 (when (tramp-ange-ftp-file-name-p multi-method method
)
2367 (let ((default-directory
2368 (tramp-make-ange-ftp-file-name user host path
)))
2369 (tramp-invoke-ange-ftp 'dired-call-process
2370 program discard arguments
)))
2372 (tramp-barf-unless-okay
2373 multi-method method user host
2374 (format "cd %s" (tramp-shell-quote-argument path
))
2376 "tramp-handle-dired-call-process: Couldn't `cd %s'"
2377 (tramp-shell-quote-argument path
))
2379 multi-method method user host
2380 (mapconcat #'tramp-shell-quote-argument
(cons program arguments
) " "))
2381 (tramp-wait-for-output))
2383 (insert-buffer (tramp-get-buffer multi-method method user host
)))
2386 (tramp-send-command-and-check multi-method method user host nil
)
2387 (tramp-send-command multi-method method user host
"cd")
2388 (tramp-wait-for-output)))))
2390 ;; Pacify byte-compiler. The function is needed on XEmacs only. I'm
2391 ;; not sure at all that this is the right way to do it, but let's hope
2392 ;; it works for now, and wait for a guru to point out the Right Way to
2394 ;;(eval-when-compile
2395 ;; (unless (fboundp 'dired-insert-set-properties)
2396 ;; (fset 'dired-insert-set-properties 'ignore)))
2397 ;; Gerd suggests this:
2398 (eval-when-compile (require 'dired
))
2399 ;; Note that dired is required at run-time, too, when it is needed.
2400 ;; It is only needed on XEmacs for the function
2401 ;; `dired-insert-set-properties'.
2403 (defun tramp-handle-insert-directory
2404 (filename switches
&optional wildcard full-directory-p
)
2405 "Like `insert-directory' for tramp files."
2406 (setq filename
(expand-file-name filename
))
2407 (with-parsed-tramp-file-name filename nil
2408 (when (tramp-ange-ftp-file-name-p multi-method method
)
2409 (tramp-invoke-ange-ftp 'insert-directory
2410 filename switches wildcard full-directory-p
))
2411 (tramp-message-for-buffer
2412 multi-method method user host
10
2413 "Inserting directory `ls %s %s', wildcard %s, fulldir %s"
2414 switches filename
(if wildcard
"yes" "no")
2415 (if full-directory-p
"yes" "no"))
2417 (setq wildcard
(file-name-nondirectory path
))
2418 (setq path
(file-name-directory path
)))
2419 (when (listp switches
)
2420 (setq switches
(mapconcat 'identity switches
" ")))
2421 (unless full-directory-p
2422 (setq switches
(concat "-d " switches
)))
2424 (setq switches
(concat switches
" " wildcard
)))
2426 ;; If `full-directory-p', we just say `ls -l FILENAME'.
2427 ;; Else we chdir to the parent directory, then say `ls -ld BASENAME'.
2428 (if full-directory-p
2430 multi-method method user host
2432 (tramp-get-ls-command multi-method method user host
)
2436 (tramp-shell-quote-argument (concat path
".")))))
2437 (tramp-barf-unless-okay
2438 multi-method method user host
2439 (format "cd %s" (tramp-shell-quote-argument
2440 (file-name-directory path
)))
2443 (tramp-shell-quote-argument (file-name-directory path
)))
2445 multi-method method user host
2447 (tramp-get-ls-command multi-method method user host
)
2449 (if full-directory-p
2450 ;; Add "/." to make sure we got complete dir
2451 ;; listing for symlinks, too.
2452 (concat (file-name-as-directory
2453 (file-name-nondirectory path
)) ".")
2454 (file-name-nondirectory path
)))))
2455 (sit-for 1) ;needed for rsh but not ssh?
2456 (tramp-wait-for-output))
2457 (insert-buffer (tramp-get-buffer multi-method method user host
))
2458 ;; On XEmacs, we want to call (exchange-point-and-mark t), but
2459 ;; that doesn't exist on Emacs, so we use this workaround instead.
2460 ;; Since zmacs-region-stays doesn't exist in Emacs, this ought to
2461 ;; be safe. Thanks to Daniel Pittman <daniel@danann.net>.
2462 (let ((zmacs-region-stays t
))
2463 (exchange-point-and-mark))
2465 (tramp-send-command multi-method method user host
"cd")
2466 (tramp-wait-for-output))
2467 ;; Another XEmacs specialty follows. What's the right way to do
2469 (when (and (featurep 'xemacs
)
2470 (eq major-mode
'dired-mode
))
2473 (dired-insert-set-properties (point) (mark t
))))))
2475 ;; Continuation of kluge to pacify byte-compiler.
2476 ;;(eval-when-compile
2477 ;; (when (eq (symbol-function 'dired-insert-set-properties) 'ignore)
2478 ;; (fmakunbound 'dired-insert-set-properties)))
2480 ;; CCC is this the right thing to do?
2481 (defun tramp-handle-unhandled-file-name-directory (filename)
2482 "Like `unhandled-file-name-directory' for tramp files."
2483 (with-parsed-tramp-file-name filename nil
2484 (when (tramp-ange-ftp-file-name-p multi-method method
)
2485 (tramp-invoke-ange-ftp 'unhandled-file-name-directory
2487 (expand-file-name "~/")))
2489 ;; Canonicalization of file names.
2491 (defun tramp-drop-volume-letter (name)
2492 "Cut off unnecessary drive letter from file NAME.
2493 The function `tramp-handle-expand-file-name' calls `expand-file-name'
2494 locally on a remote file name. When the local system is a W32 system
2495 but the remote system is Unix, this introduces a superfluous drive
2496 letter into the file name. This function removes it.
2498 Doesn't do anything if the NAME does not start with a drive letter."
2499 (if (and (> (length name
) 1)
2500 (char-equal (aref name
1) ?
:)
2501 (let ((c1 (aref name
0)))
2502 (or (and (>= c1 ?A
) (<= c1 ?Z
))
2503 (and (>= c1 ?a
) (<= c1 ?z
)))))
2507 (defun tramp-handle-expand-file-name (name &optional dir
)
2508 "Like `expand-file-name' for tramp files."
2509 ;; If DIR is not given, use DEFAULT-DIRECTORY or "/".
2510 (setq dir
(or dir default-directory
"/"))
2511 ;; Unless NAME is absolute, concat DIR and NAME.
2512 (unless (file-name-absolute-p name
)
2513 (setq name
(concat (file-name-as-directory dir
) name
)))
2514 ;; If NAME is not a tramp file, run the real handler
2515 (if (not (tramp-tramp-file-p name
))
2516 (tramp-run-real-handler 'expand-file-name
2519 (with-parsed-tramp-file-name name nil
2520 (when (tramp-ange-ftp-file-name-p multi-method method
)
2521 (tramp-invoke-ange-ftp 'expand-file-name name nil
))
2522 (unless (file-name-absolute-p path
)
2523 (setq path
(concat "~/" path
)))
2525 ;; Tilde expansion if necessary. This needs a shell which
2526 ;; groks tilde expansion! The function `tramp-find-shell' is
2527 ;; supposed to find such a shell on the remote host. Please
2528 ;; tell me about it when this doesn't work on your system.
2529 (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" path
)
2530 (let ((uname (match-string 1 path
))
2531 (fname (match-string 2 path
)))
2532 ;; CCC fanatic error checking?
2533 (set-buffer (tramp-get-buffer multi-method method user host
))
2536 multi-method method user host
2537 (format "cd %s; pwd" uname
)
2539 (tramp-wait-for-output)
2540 (goto-char (point-min))
2541 (setq uname
(buffer-substring (point) (tramp-line-end-position)))
2542 (setq path
(concat uname fname
))
2544 ;; No tilde characters in file name, do normal
2545 ;; expand-file-name (this does "/./" and "/../"). We bind
2546 ;; directory-sep-char here for XEmacs on Windows, which would
2547 ;; otherwise use backslash.
2548 (let ((directory-sep-char ?
/))
2549 (tramp-make-tramp-file-name
2550 multi-method method user host
2551 (tramp-drop-volume-letter
2552 (tramp-run-real-handler 'expand-file-name
(list path
)))))))))
2556 (defun tramp-handle-shell-command (command &optional output-buffer error-buffer
)
2557 "Like `shell-command' for tramp files.
2558 This will break if COMMAND prints a newline, followed by the value of
2559 `tramp-end-of-output', followed by another newline."
2560 (when (tramp-tramp-file-p default-directory
)
2561 (with-parsed-tramp-file-name default-directory nil
2562 (when (tramp-ange-ftp-file-name-p multi-method method
)
2563 (let ((default-directory (tramp-make-ange-ftp-file-name
2565 (tramp-invoke-ange-ftp 'shell-command
2566 command output-buffer error-buffer
)))
2568 (when (string-match "&[ \t]*\\'" command
)
2569 (error "Tramp doesn't grok asynchronous shell commands, yet"))
2571 (error "Tramp doesn't grok optional third arg ERROR-BUFFER, yet"))
2573 (tramp-barf-unless-okay
2574 multi-method method user host
2575 (format "cd %s" (tramp-shell-quote-argument path
))
2577 "tramp-handle-shell-command: Couldn't `cd %s'"
2578 (tramp-shell-quote-argument path
))
2579 (tramp-send-command multi-method method user host
2580 (concat command
"; tramp_old_status=$?"))
2581 ;; This will break if the shell command prints "/////"
2582 ;; somewhere. Let's just hope for the best...
2583 (tramp-wait-for-output))
2584 (unless output-buffer
2585 (setq output-buffer
(get-buffer-create "*Shell Command Output*"))
2586 (set-buffer output-buffer
)
2588 (unless (bufferp output-buffer
)
2589 (setq output-buffer
(current-buffer)))
2590 (set-buffer output-buffer
)
2591 (insert-buffer (tramp-get-buffer multi-method method user host
))
2593 (tramp-send-command multi-method method user host
"cd")
2594 (tramp-wait-for-output)
2596 multi-method method user host
2597 (concat "tramp_set_exit_status $tramp_old_status;"
2598 " echo tramp_exit_status $?"))
2599 (tramp-wait-for-output)
2600 (goto-char (point-max))
2601 (unless (search-backward "tramp_exit_status " nil t
)
2602 (error "Couldn't find exit status of `%s'" command
))
2603 (skip-chars-forward "^ ")
2604 (setq status
(read (current-buffer))))
2605 (unless (zerop (buffer-size))
2606 (pop-to-buffer output-buffer
))
2608 ;; The following is only executed if something strange was
2609 ;; happening. Emit a helpful message and do it anyway.
2610 (message "tramp-handle-shell-command called with non-tramp directory: `%s'"
2612 (tramp-run-real-handler 'shell-command
2613 (list command output-buffer error-buffer
)))
2617 (defsubst tramp-make-temp-file
()
2618 (funcall (if (fboundp 'make-temp-file
) 'make-temp-file
'make-temp-name
)
2619 (expand-file-name tramp-temp-name-prefix
2620 (tramp-temporary-file-directory))))
2622 (defun tramp-handle-file-local-copy (filename)
2623 "Like `file-local-copy' for tramp files."
2624 (with-parsed-tramp-file-name filename nil
2625 (when (tramp-ange-ftp-file-name-p multi-method method
)
2626 (tramp-invoke-ange-ftp 'file-local-copy filename
))
2627 (let ((trampbuf (get-buffer-create "*tramp output*"))
2629 (unless (file-exists-p filename
)
2630 (error "Cannot make local copy of non-existing file `%s'"
2632 (setq tmpfil
(tramp-make-temp-file))
2633 (cond ((tramp-get-rcp-program multi-method method
)
2634 ;; Use rcp-like program for file transfer.
2635 (tramp-message-for-buffer
2636 multi-method method user host
2637 5 "Fetching %s to tmp file %s..." filename tmpfil
)
2638 (save-excursion (set-buffer trampbuf
) (erase-buffer))
2641 (apply #'call-process
2642 (tramp-get-rcp-program multi-method method
)
2644 (append (tramp-get-rcp-args multi-method method
)
2646 (tramp-make-rcp-program-file-name
2648 (tramp-shell-quote-argument path
))
2650 (pop-to-buffer trampbuf
)
2652 (concat "tramp-handle-file-local-copy: `%s' didn't work, "
2653 "see buffer `%s' for details")
2654 (tramp-get-rcp-program multi-method method
) trampbuf
))
2655 (tramp-message-for-buffer
2656 multi-method method user host
2657 5 "Fetching %s to tmp file %s...done" filename tmpfil
))
2658 ((and (tramp-get-encoding-command multi-method method user host
)
2659 (tramp-get-decoding-command multi-method method user host
))
2660 ;; Use inline encoding for file transfer.
2662 ;; Following line for setting tramp-current-method,
2663 ;; tramp-current-user, tramp-current-host.
2664 (set-buffer (tramp-get-buffer multi-method method user host
))
2665 (tramp-message 5 "Encoding remote file %s..." filename
)
2666 (tramp-barf-unless-okay
2667 multi-method method user host
2668 (concat (tramp-get-encoding-command multi-method method user host
)
2669 " < " (tramp-shell-quote-argument path
))
2671 "Encoding remote file failed, see buffer `%s' for details"
2672 (tramp-get-buffer multi-method method user host
))
2673 ;; Remove trailing status code
2674 (goto-char (point-max))
2675 (delete-region (point) (progn (forward-line -
1) (point)))
2677 (tramp-message 5 "Decoding remote file %s..." filename
)
2678 (if (and (tramp-get-decoding-function multi-method method user host
)
2679 (fboundp (tramp-get-decoding-function
2680 multi-method method user host
)))
2681 ;; If tramp-decoding-function is defined for this
2682 ;; method, we call it.
2683 (let ((tmpbuf (get-buffer-create " *tramp tmp*")))
2686 (insert-buffer (tramp-get-buffer multi-method method
2688 (tramp-message-for-buffer
2689 multi-method method user host
2690 6 "Decoding remote file %s with function %s..."
2692 (tramp-get-decoding-function multi-method method user host
))
2694 (let ((coding-system-for-write 'no-conversion
))
2695 (funcall (tramp-get-decoding-function
2696 multi-method method user host
)
2699 (write-region (point-min) (point-max) tmpfil
))
2700 (kill-buffer tmpbuf
))
2701 ;; If tramp-decoding-function is not defined for this
2702 ;; method, we invoke tramp-decoding-command instead.
2703 (let ((tmpfil2 (tramp-make-temp-file)))
2704 (write-region (point-min) (point-max) tmpfil2
)
2706 6 "Decoding remote file %s with command %s..."
2708 (tramp-get-decoding-command multi-method method user host
))
2714 "-c" (concat (tramp-get-decoding-command
2715 multi-method method user host
)
2717 (delete-file tmpfil2
)))
2718 (tramp-message-for-buffer
2719 multi-method method user host
2720 5 "Decoding remote file %s...done" filename
)))
2722 (t (error "Wrong method specification for `%s'" method
)))
2726 (defun tramp-handle-insert-file-contents
2727 (filename &optional visit beg end replace
)
2728 "Like `insert-file-contents' for tramp files."
2729 (barf-if-buffer-read-only)
2730 (setq filename
(expand-file-name filename
))
2731 (with-parsed-tramp-file-name filename nil
2732 (when (tramp-ange-ftp-file-name-p multi-method method
)
2733 (tramp-invoke-ange-ftp 'insert-file-contents
2734 filename visit beg end replace
))
2735 (if (not (tramp-handle-file-exists-p filename
))
2738 (setq buffer-file-name filename
)
2739 (set-visited-file-modtime)
2740 (set-buffer-modified-p nil
))
2742 (format "File `%s' not found on remote host" filename
))
2743 (list (tramp-handle-expand-file-name filename
) 0))
2744 (let ((local-copy (tramp-handle-file-local-copy filename
))
2745 (coding-system-used nil
)
2748 (setq buffer-file-name filename
)
2749 (set-visited-file-modtime)
2750 (set-buffer-modified-p nil
))
2751 (tramp-message-for-buffer
2752 multi-method method user host
2753 9 "Inserting local temp file `%s'..." local-copy
)
2755 (tramp-run-real-handler 'insert-file-contents
2756 (list local-copy nil beg end replace
)))
2757 ;; Now `last-coding-system-used' has right value. Remember it.
2758 (when (boundp 'last-coding-system-used
)
2759 (setq coding-system-used last-coding-system-used
))
2760 (tramp-message 9 "Inserting local temp file `%s'...done" local-copy
)
2761 (delete-file local-copy
)
2762 (when (boundp 'last-coding-system-used
)
2763 (setq last-coding-system-used coding-system-used
))
2764 (list (expand-file-name filename
)
2765 (second result
))))))
2767 ;; CCC grok APPEND, LOCKNAME, CONFIRM
2768 (defun tramp-handle-write-region
2769 (start end filename
&optional append visit lockname confirm
)
2770 "Like `write-region' for tramp files."
2771 (unless (eq append nil
)
2772 (error "Cannot append to file using tramp (`%s')" filename
))
2773 (setq filename
(expand-file-name filename
))
2774 ;; Following part commented out because we don't know what to do about
2775 ;; file locking, and it does not appear to be a problem to ignore it.
2776 ;; Ange-ftp ignores it, too.
2777 ;; (when (and lockname (stringp lockname))
2778 ;; (setq lockname (expand-file-name lockname)))
2779 ;; (unless (or (eq lockname nil)
2780 ;; (string= lockname filename))
2782 ;; "tramp-handle-write-region: LOCKNAME must be nil or equal FILENAME"))
2783 ;; XEmacs takes a coding system as the sevent argument, not `confirm'
2784 (when (and (not (featurep 'xemacs
))
2785 confirm
(file-exists-p filename
))
2786 (unless (y-or-n-p (format "File %s exists; overwrite anyway? "
2788 (error "File not overwritten")))
2789 (with-parsed-tramp-file-name filename nil
2790 (when (tramp-ange-ftp-file-name-p multi-method method
)
2791 (tramp-invoke-ange-ftp 'write-region
2792 start end filename append visit lockname confirm
))
2793 (let ((curbuf (current-buffer))
2794 (rcp-program (tramp-get-rcp-program multi-method method
))
2795 (rcp-args (tramp-get-rcp-args multi-method method
))
2797 (tramp-get-encoding-command multi-method method user host
))
2799 (tramp-get-encoding-function multi-method method user host
))
2801 (tramp-get-decoding-command multi-method method user host
))
2802 (trampbuf (get-buffer-create "*tramp output*"))
2803 ;; We use this to save the value of `last-coding-system-used'
2804 ;; after writing the tmp file. At the end of the function,
2805 ;; we set `last-coding-system-used' to this saved value.
2806 ;; This way, any intermediary coding systems used while
2807 ;; talking to the remote shell or suchlike won't hose this
2808 ;; variable. This approach was snarfed from ange-ftp.el.
2811 ;; Write region into a tmp file. This isn't really needed if we
2812 ;; use an encoding function, but currently we use it always
2813 ;; because this makes the logic simpler.
2814 (setq tmpfil
(tramp-make-temp-file))
2815 ;; We say `no-message' here because we don't want the visited file
2816 ;; modtime data to be clobbered from the temp file. We call
2817 ;; `set-visited-file-modtime' ourselves later on.
2818 (tramp-run-real-handler
2820 (if confirm
; don't pass this arg unless defined for backward compat.
2821 (list start end tmpfil append
'no-message lockname confirm
)
2822 (list start end tmpfil append
'no-message lockname
)))
2823 ;; Now, `last-coding-system-used' has the right value. Remember it.
2824 (when (boundp 'last-coding-system-used
)
2825 (setq coding-system-used last-coding-system-used
))
2826 ;; This is a bit lengthy due to the different methods possible for
2827 ;; file transfer. First, we check whether the method uses an rcp
2828 ;; program. If so, we call it. Otherwise, both encoding and
2829 ;; decoding command must be specified. However, if the method
2830 ;; _also_ specifies an encoding function, then that is used for
2831 ;; encoding the contents of the tmp file.
2833 ;; use rcp-like program for file transfer
2834 (let ((argl (append rcp-args
2837 (tramp-make-rcp-program-file-name
2839 (tramp-shell-quote-argument path
))))))
2840 (tramp-message-for-buffer
2841 multi-method method user host
2842 6 "Writing tmp file using `%s'..." rcp-program
)
2843 (save-excursion (set-buffer trampbuf
) (erase-buffer))
2844 (when tramp-debug-buffer
2846 (set-buffer (tramp-get-debug-buffer multi-method
2848 (goto-char (point-max))
2849 (tramp-insert-with-face
2850 'bold
(format "$ %s %s\n" rcp-program
2851 (mapconcat 'identity argl
" ")))))
2853 (apply #'call-process
2854 rcp-program nil trampbuf nil argl
))
2855 (pop-to-buffer trampbuf
)
2857 "Cannot write region to file `%s', command `%s' failed"
2858 filename rcp-program
))
2859 (tramp-message-for-buffer
2860 multi-method method user host
2861 6 "Transferring file using `%s'...done"
2863 ((and encoding-command decoding-command
)
2864 ;; Use inline file transfer
2865 (let ((tmpbuf (get-buffer-create " *tramp file transfer*")))
2867 ;; Encode tmpfil into tmpbuf
2868 (tramp-message-for-buffer multi-method method user host
2869 5 "Encoding region...")
2872 ;; Use encoding function or command.
2873 (if (and encoding-function
2874 (fboundp encoding-function
))
2876 (tramp-message-for-buffer
2877 multi-method method user host
2878 6 "Encoding region using function...")
2879 (insert-file-contents-literally tmpfil
)
2880 ;; CCC. The following `let' is a workaround for
2881 ;; the base64.el that comes with pgnus-0.84. If
2882 ;; both of the following conditions are
2883 ;; satisfied, it tries to write to a local file
2884 ;; in default-directory, but at this point,
2885 ;; default-directory is remote.
2886 ;; (CALL-PROCESS-REGION can't write to remote
2887 ;; files, it seems.) The file in question is a
2889 (let ((default-directory
2890 (tramp-temporary-file-directory)))
2891 (funcall encoding-function
(point-min) (point-max)))
2892 (goto-char (point-max))
2895 (tramp-message-for-buffer
2896 multi-method method user host
2897 6 "Encoding region using command...")
2901 tmpfil
;input = local tmp file
2902 t
;output is current buffer
2903 nil
;don't redisplay
2906 (pop-to-buffer trampbuf
)
2907 (error (concat "Cannot write to `%s', local encoding"
2908 " command `%s' failed")
2909 filename encoding-command
)))
2910 ;; Send tmpbuf into remote decoding command which
2911 ;; writes to remote file. Because this happens on the
2912 ;; remote host, we cannot use the function.
2913 (tramp-message-for-buffer
2914 multi-method method user host
2915 5 "Decoding region into remote file %s..." filename
)
2917 multi-method method user host
2918 (format "%s >%s <<'EOF'"
2920 (tramp-shell-quote-argument path
)))
2922 (tramp-message-for-buffer
2923 multi-method method user host
2924 6 "Sending data to remote host...")
2925 (tramp-send-region multi-method method user host
2926 (point-min) (point-max))
2927 ;; wait for remote decoding to complete
2928 (tramp-message-for-buffer
2929 multi-method method user host
2930 6 "Sending end of data token...")
2932 multi-method method user host
"EOF")
2933 (tramp-message-for-buffer
2934 multi-method method user host
6
2935 "Waiting for remote host to process data...")
2936 (set-buffer (tramp-get-buffer multi-method method user host
))
2937 (tramp-wait-for-output)
2938 (tramp-barf-unless-okay
2939 multi-method method user host nil nil
'file-error
2940 (concat "Couldn't write region to `%s',"
2941 " decode using `%s' failed")
2942 filename decoding-command
)
2943 (tramp-message 5 "Decoding region into remote file %s...done"
2945 (kill-buffer tmpbuf
))))
2948 (concat "Method `%s' should specify both encoding and "
2949 "decoding command or an rcp program")
2951 (delete-file tmpfil
)
2952 (unless (equal curbuf
(current-buffer))
2953 (error "Buffer has changed from `%s' to `%s'"
2954 curbuf
(current-buffer)))
2956 (set-visited-file-modtime))
2957 ;; Make `last-coding-system-used' have the right value.
2958 (when (boundp 'last-coding-system-used
)
2959 (setq last-coding-system-used coding-system-used
))
2960 (when (or (eq visit t
)
2963 (message "Wrote %s" filename
)))))
2965 ;; Call down to the real handler.
2966 ;; Because EFS does not play nicely with TRAMP (both systems match an
2967 ;; TRAMP path) it is needed to disable efs as well as tramp for the
2970 ;; Other than that, this is the canon file-handler code that the doco
2971 ;; says should be used here. Which is nice.
2973 ;; Under XEmacs current, EFS also hooks in as
2974 ;; efs-sifn-handler-function to handle any path with environment
2975 ;; variables. This has two implications:
2976 ;; 1) That EFS may not be completely dead (yet) for TRAMP paths
2977 ;; 2) That TRAMP might want to do the same thing.
2978 ;; Details as they come in.
2980 ;; Daniel Pittman <daniel@danann.net>
2982 ;; (defun tramp-run-real-handler (operation args)
2983 ;; "Invoke normal file name handler for OPERATION.
2984 ;; This inhibits EFS and Ange-FTP, too, because they conflict with tramp.
2985 ;; First arg specifies the OPERATION, remaining ARGS are passed to the
2987 ;; (let ((inhibit-file-name-handlers
2988 ;; (list 'tramp-file-name-handler
2989 ;; 'efs-file-handler-function
2990 ;; 'ange-ftp-hook-function
2991 ;; (and (eq inhibit-file-name-operation operation)
2992 ;; inhibit-file-name-handlers)))
2993 ;; (inhibit-file-name-operation operation))
2994 ;; (apply operation args)))
2996 (defun tramp-run-real-handler (operation args
)
2997 "Invoke normal file name handler for OPERATION.
2998 First arg specifies the OPERATION, second arg is a list of arguments to
2999 pass to the OPERATION."
3000 (let ((inhibit-file-name-handlers
3001 (list 'tramp-file-name-handler
3002 (and (eq inhibit-file-name-operation operation
)
3003 inhibit-file-name-handlers
)))
3004 (inhibit-file-name-operation operation
))
3005 (apply operation args
)))
3009 (defun tramp-file-name-handler (operation &rest args
)
3010 "Invoke tramp file name handler.
3011 Falls back to normal file name handler if no tramp file name handler exists."
3012 (let ((fn (assoc operation tramp-file-name-handler-alist
)))
3014 (catch 'tramp-forward-to-ange-ftp
3015 (save-match-data (apply (cdr fn
) args
)))
3016 (tramp-run-real-handler operation args
))))
3018 ;; Register in file name handler alist
3020 (add-to-list 'file-name-handler-alist
3021 (cons tramp-file-name-regexp
'tramp-file-name-handler
))
3023 ;; To handle EFS, the following functions need to be dealt with:
3025 ;; * dired-before-readin-hook contains efs-dired-before-readin
3026 ;; * file-name-handler-alist contains efs-file-handler-function
3027 ;; and efs-root-handler-function and efs-sifn-handler-function
3028 ;; * find-file-hooks contains efs-set-buffer-mode
3030 ;; But it won't happen for EFS since the XEmacs maintainers
3031 ;; don't want to use a unified filename syntax.
3032 (defun tramp-disable-ange-ftp ()
3034 This is useful for unified remoting. See
3035 `tramp-file-name-structure-unified' and
3036 `tramp-file-name-structure-separate' for details. Requests suitable
3037 for Ange-FTP will be forwarded to Ange-FTP. Also see the variables
3038 `tramp-ftp-method', `tramp-default-method', and
3039 `tramp-default-method-alist'.
3041 This function is not needed in Emacsen which include Tramp, but is
3042 present for backward compatibility."
3043 (let ((a1 (rassq 'ange-ftp-hook-function file-name-handler-alist
))
3044 (a2 (rassq 'ange-ftp-completion-hook-function file-name-handler-alist
)))
3045 (setq file-name-handler-alist
3046 (delete a1
(delete a2 file-name-handler-alist
)))))
3047 (tramp-disable-ange-ftp)
3049 (defun tramp-repair-jka-compr ()
3050 "If jka-compr is already loaded, move it to the front of
3051 `file-name-handler-alist'. On Emacs 21.4 or so this will not be
3053 (let ((jka (rassoc 'jka-compr-handler file-name-handler-alist
)))
3055 (setq file-name-handler-alist
3056 (cons jka
(delete jka file-name-handler-alist
))))))
3057 (tramp-repair-jka-compr)
3059 (defun tramp-invoke-ange-ftp (operation &rest args
)
3060 "Invoke the Ange-FTP handler function and throw."
3061 (or ange-ftp-name-format
(require 'ange-ftp
))
3062 (let ((ange-ftp-name-format
3063 (list (nth 0 tramp-file-name-structure
)
3064 (nth 3 tramp-file-name-structure
)
3065 (nth 2 tramp-file-name-structure
)
3066 (nth 4 tramp-file-name-structure
))))
3067 (throw 'tramp-forward-to-ange-ftp
3068 (apply 'ange-ftp-hook-function operation args
))))
3070 (defun tramp-ange-ftp-file-name-p (multi-method method
)
3071 "Check if it's a filename that should be forwarded to Ange-FTP."
3072 (and (null multi-method
) (string= method tramp-ftp-method
)))
3075 ;;; Interactions with other packages:
3077 ;; -- complete.el --
3079 ;; This function contributed by Ed Sabol
3080 (defun tramp-handle-expand-many-files (name)
3081 "Like `PC-expand-many-files' for tramp files."
3082 (with-parsed-tramp-file-name name nil
3083 (when (tramp-ange-ftp-file-name-p multi-method method
)
3084 (tramp-invoke-ange-ftp 'expand-many-files name
))
3086 (if (or (string-match "\\*" name
)
3087 (string-match "\\?" name
)
3088 (string-match "\\[.*\\]" name
))
3092 ;; Perhaps invoke Ange-FTP.
3093 (when (string= method tramp-ftp-method
)
3094 (signal 'tramp-run-ange-ftp
(list 0)))
3095 ;; CCC: To do it right, we should quote certain characters
3096 ;; in the file name, but since the echo command is going to
3097 ;; break anyway when there are spaces in the file names, we
3099 ;;-(let ((comint-file-name-quote-list
3100 ;;- (set-difference tramp-file-name-quote-list
3101 ;;- '(?\* ?\? ?[ ?]))))
3102 ;;- (tramp-send-command
3103 ;;- multi-method method user host
3104 ;;- (format "echo %s" (comint-quote-filename path)))
3105 ;;- (tramp-wait-for-output))
3106 (tramp-send-command multi-method method user host
3107 (format "echo %s" path
))
3108 (tramp-wait-for-output)
3109 (setq bufstr
(buffer-substring (point-min)
3110 (tramp-line-end-position)))
3111 (goto-char (point-min))
3112 (if (string-equal path bufstr
)
3115 (while (search-forward " " nil t
)
3116 (delete-backward-char 1)
3118 (goto-char (point-max))
3119 (delete-backward-char 1)
3121 (goto-char (point-min))
3123 (function (lambda (x)
3124 (tramp-make-tramp-file-name multi-method method
3126 (read (current-buffer))))))
3127 (list (tramp-handle-expand-file-name name
))))))
3129 ;; Check for complete.el and override PC-expand-many-files if appropriate.
3131 (defun tramp-save-PC-expand-many-files (name))); avoid compiler warning
3133 (defun tramp-setup-complete ()
3134 (fset 'tramp-save-PC-expand-many-files
3135 (symbol-function 'PC-expand-many-files
))
3136 (defun PC-expand-many-files (name)
3137 (if (tramp-tramp-file-p name
)
3138 (tramp-handle-expand-many-files name
)
3139 (tramp-save-PC-expand-many-files name
))))
3141 ;; Why isn't eval-after-load sufficient?
3142 (if (fboundp 'PC-expand-many-files
)
3143 (tramp-setup-complete)
3144 (eval-after-load "complete" '(tramp-setup-complete)))
3149 ;;; Internal Functions:
3151 (defun tramp-set-auto-save ()
3152 (when (and (buffer-file-name)
3153 (tramp-tramp-file-p (buffer-file-name))
3155 (auto-save-mode 1)))
3156 (add-hook 'find-file-hooks
'tramp-set-auto-save t
)
3158 (defun tramp-run-test (switch filename
)
3159 "Run `test' on the remote system, given a SWITCH and a FILENAME.
3160 Returns the exit code of the `test' program."
3161 (let ((v (tramp-dissect-file-name filename
)))
3163 (tramp-send-command-and-check
3164 (tramp-file-name-multi-method v
) (tramp-file-name-method v
)
3165 (tramp-file-name-user v
) (tramp-file-name-host v
)
3166 (format "test %s %s" switch
3167 (tramp-shell-quote-argument (tramp-file-name-path v
)))))))
3169 (defun tramp-run-test2 (program file1 file2
&optional switch
)
3170 "Run `test'-like PROGRAM on the remote system, given FILE1, FILE2.
3171 The optional SWITCH is inserted between the two files.
3172 Returns the exit code of the `test' PROGRAM. Barfs if the methods,
3173 hosts, or files, disagree."
3174 (let* ((v1 (tramp-dissect-file-name file1
))
3175 (v2 (tramp-dissect-file-name file2
))
3176 (mmethod1 (tramp-file-name-multi-method v1
))
3177 (mmethod2 (tramp-file-name-multi-method v2
))
3178 (method1 (tramp-file-name-method v1
))
3179 (method2 (tramp-file-name-method v2
))
3180 (user1 (tramp-file-name-user v1
))
3181 (user2 (tramp-file-name-user v2
))
3182 (host1 (tramp-file-name-host v1
))
3183 (host2 (tramp-file-name-host v2
))
3184 (path1 (tramp-file-name-path v1
))
3185 (path2 (tramp-file-name-path v2
)))
3186 (unless (and method1 method2 host1 host2
3187 (equal mmethod1 mmethod2
)
3188 (equal method1 method2
)
3190 (equal host1 host2
))
3191 (error "tramp-run-test2: %s"
3192 "only implemented for same method, same user, same host"))
3194 (tramp-send-command-and-check
3195 mmethod1 method1 user1 host1
3196 (format "%s %s %s %s"
3198 (tramp-shell-quote-argument path1
)
3200 (tramp-shell-quote-argument path2
))))))
3202 (defun tramp-buffer-name (multi-method method user host
)
3203 "A name for the connection buffer for USER at HOST using METHOD."
3205 (tramp-buffer-name-multi-method "tramp" multi-method method user host
))
3207 (format "*tramp/%s %s@%s*" method user host
))
3209 (format "*tramp/%s %s*" method host
))))
3211 (defun tramp-buffer-name-multi-method (prefix multi-method method user host
)
3212 "A name for the multi method connection buffer.
3213 MULTI-METHOD gives the multi method, METHOD the array of methods,
3214 USER the array of user names, HOST the array of host names."
3215 (unless (and (= (length method
) (length user
))
3216 (= (length method
) (length host
)))
3217 (error "Syntax error in multi method (implementation error)"))
3218 (let ((len (length method
))
3223 (cons (if (aref user i
)
3224 (format "%s#%s@%s:" (aref method i
)
3225 (aref user i
) (aref host i
))
3226 (format "%s@%s:" (aref method i
) (aref host i
)))
3229 (format "*%s/%s %s*"
3231 (apply 'concat
(reverse string-list
)))))
3233 (defun tramp-get-buffer (multi-method method user host
)
3234 "Get the connection buffer to be used for USER at HOST using METHOD."
3235 (get-buffer-create (tramp-buffer-name multi-method method user host
)))
3237 (defun tramp-debug-buffer-name (multi-method method user host
)
3238 "A name for the debug buffer for USER at HOST using METHOD."
3240 (tramp-buffer-name-multi-method "debug tramp"
3241 multi-method method user host
))
3243 (format "*debug tramp/%s %s@%s*" method user host
))
3245 (format "*debug tramp/%s %s*" method host
))))
3247 (defun tramp-get-debug-buffer (multi-method method user host
)
3248 "Get the debug buffer for USER at HOST using METHOD."
3249 (get-buffer-create (tramp-debug-buffer-name multi-method method user host
)))
3251 (defun tramp-find-executable (multi-method method user host
3252 progname dirlist ignore-tilde
)
3253 "Searches for PROGNAME in all directories mentioned in DIRLIST.
3254 First args METHOD, USER and HOST specify the connection, PROGNAME
3255 is the program to search for, and DIRLIST gives the list of directories
3256 to search. If IGNORE-TILDE is non-nil, directory names starting
3257 with `~' will be ignored.
3259 Returns the full path name of PROGNAME, if found, and nil otherwise.
3261 This function expects to be in the right *tramp* buffer."
3264 ;; Remove all ~/foo directories from dirlist. In Emacs 20,
3265 ;; `remove' is in CL, and we want to avoid CL dependencies.
3268 (setq d
(car dirlist
))
3269 (setq dirlist
(cdr dirlist
))
3270 (unless (char-equal ?~
(aref d
0))
3271 (setq newdl
(cons d newdl
))))
3272 (setq dirlist
(nreverse newdl
))))
3274 multi-method method user host
3275 (format (concat "while read d; "
3276 "do if test -x $d/%s -a -f $d/%s; "
3277 "then echo tramp_executable $d/%s; "
3278 "break; fi; done <<'EOF'")
3279 progname progname progname
))
3281 (tramp-send-command multi-method method user host d
))
3283 (tramp-send-command multi-method method user host
"EOF")
3284 (tramp-wait-for-output)
3285 (goto-char (point-max))
3286 (when (search-backward "tramp_executable " nil t
)
3287 (skip-chars-forward "^ ")
3288 (skip-chars-forward " ")
3289 (buffer-substring (point) (tramp-line-end-position)))))
3291 (defun tramp-set-remote-path (multi-method method user host var dirlist
)
3292 "Sets the remote environment VAR to existing directories from DIRLIST.
3293 I.e., for each directory in DIRLIST, it is tested whether it exists and if
3294 so, it is added to the environment variable VAR."
3295 (let ((existing-dirs
3300 (tramp-make-tramp-file-name multi-method method user host x
))
3302 (tramp-make-tramp-file-name multi-method method user host x
)))
3306 multi-method method user host
3308 (mapconcat 'identity
(delq nil existing-dirs
) ":")
3310 (tramp-wait-for-output)))
3312 ;; -- communication with external shell --
3314 (defun tramp-find-file-exists-command (multi-method method user host
)
3315 "Find a command on the remote host for checking if a file exists.
3316 Here, we are looking for a command which has zero exit status if the
3317 file exists and nonzero exit status otherwise."
3318 (make-local-variable 'tramp-file-exists-command
)
3319 (tramp-message 10 "Finding command to check if file exists")
3321 (tramp-make-tramp-file-name
3322 multi-method method user host
3323 "/")) ;assume this file always exists
3325 (tramp-make-tramp-file-name
3326 multi-method method user host
3327 "/ this file does not exist "))) ;assume this never exists
3328 ;; The algorithm is as follows: we try a list of several commands.
3329 ;; For each command, we first run `$cmd /' -- this should return
3330 ;; true, as the root directory always exists. And then we run
3331 ;; `$cmd /this\ file\ does\ not\ exist', hoping that the file indeed
3332 ;; does not exist. This should return false. We use the first
3333 ;; command we find that seems to work.
3334 ;; The list of commands to try is as follows:
3335 ;; `ls -d' This works on most systems, but NetBSD 1.4
3336 ;; has a bug: `ls' always returns zero exit
3337 ;; status, even for files which don't exist.
3338 ;; `test -e' Some Bourne shells have a `test' builtin
3339 ;; which does not know the `-e' option.
3340 ;; `/bin/test -e' For those, the `test' binary on disk normally
3341 ;; provides the option. Alas, the binary
3342 ;; is sometimes `/bin/test' and sometimes it's
3344 ;; `/usr/bin/test -e' In case `/bin/test' does not exist.
3346 (and (setq tramp-file-exists-command
"ls -d %s")
3347 (tramp-handle-file-exists-p existing
)
3348 (not (tramp-handle-file-exists-p nonexisting
)))
3349 (and (setq tramp-file-exists-command
"test -e %s")
3350 (tramp-handle-file-exists-p existing
)
3351 (not (tramp-handle-file-exists-p nonexisting
)))
3352 (and (setq tramp-file-exists-command
"/bin/test -e %s")
3353 (tramp-handle-file-exists-p existing
)
3354 (not (tramp-handle-file-exists-p nonexisting
)))
3355 (and (setq tramp-file-exists-command
"/usr/bin/test -e %s")
3356 (tramp-handle-file-exists-p existing
)
3357 (not (tramp-handle-file-exists-p nonexisting
))))
3358 (error "Couldn't find command to check if file exists."))))
3361 ;; CCC test ksh or bash found for tilde expansion?
3362 (defun tramp-find-shell (multi-method method user host
)
3363 "Find a shell on the remote host which groks tilde expansion."
3365 (tramp-send-command multi-method method user host
"echo ~root")
3366 (tramp-wait-for-output)
3368 ((string-match "^~root$" (buffer-string))
3370 (or (tramp-find-executable multi-method method user host
3371 "bash" tramp-remote-path t
)
3372 (tramp-find-executable multi-method method user host
3373 "ksh" tramp-remote-path t
)))
3375 (error "Couldn't find a shell which groks tilde expansion"))
3376 ;; Find arguments for this shell.
3377 (let ((alist tramp-sh-extra-args
)
3379 (while (and alist
(null extra-args
))
3380 (setq item
(pop alist
))
3381 (when (string-match (car item
) shell
)
3382 (setq extra-args
(cdr item
))))
3383 (when extra-args
(setq shell
(concat shell
" " extra-args
))))
3385 5 "Starting remote shell `%s' for tilde expansion..." shell
)
3387 multi-method method user host
3388 (concat "PS1='$ ' ; exec " shell
)) ;
3389 (unless (tramp-wait-for-regexp
3390 (get-buffer-process (current-buffer))
3391 60 (format "\\(\\$ *\\|\\(%s\\)\\'\\)" shell-prompt-pattern
))
3392 (pop-to-buffer (buffer-name))
3393 (error "Couldn't find remote `%s' prompt." shell
))
3394 (process-send-string nil
(format "PS1='%s%s%s'; PS2=''; PS3=''%s"
3395 tramp-rsh-end-of-line
3397 tramp-rsh-end-of-line
3398 tramp-rsh-end-of-line
))
3399 (tramp-wait-for-output)
3400 (tramp-send-command multi-method method user host
"echo hello")
3401 (tramp-message 5 "Waiting for remote `%s' to start up..." shell
)
3402 (unless (tramp-wait-for-output 5)
3403 (unless (tramp-wait-for-output 5)
3404 (pop-to-buffer (buffer-name))
3405 (error "Couldn't start remote `%s', see buffer `%s' for details"
3406 shell
(buffer-name))))
3407 (tramp-message 5 "Waiting for remote `%s' to start up...done" shell
))
3408 (t (tramp-message 5 "Remote `%s' groks tilde expansion, good"
3409 (tramp-get-remote-sh multi-method method
))))))
3411 (defun tramp-check-ls-command (multi-method method user host cmd
)
3412 "Checks whether the given `ls' executable groks `-n'.
3413 METHOD, USER and HOST specify the connection, CMD (the full path name of)
3414 the `ls' executable. Returns t if CMD supports the `-n' option, nil
3416 (tramp-message 9 "Checking remote `%s' command for `-n' option"
3418 (when (tramp-handle-file-executable-p
3419 (tramp-make-tramp-file-name multi-method method user host cmd
))
3421 (tramp-message 7 "Testing remote command `%s' for -n..." cmd
)
3423 (tramp-send-command-and-check
3424 multi-method method user host
3425 (format "%s -lnd / >/dev/null"
3427 (tramp-message 7 "Testing remote command `%s' for -n...%s"
3429 (if (zerop result
) "okay" "failed"))
3432 (defun tramp-check-ls-commands (multi-method method user host cmd dirlist
)
3433 "Checks whether the given `ls' executable in one of the dirs groks `-n'.
3434 Returns nil if none was found, else the command is returned."
3437 ;; It would be better to use the CL function `find', but
3438 ;; we don't want run-time dependencies on CL.
3439 (while (and dl
(not result
))
3440 (let ((x (concat (file-name-as-directory (car dl
)) cmd
)))
3441 (when (tramp-check-ls-command multi-method method user host x
)
3446 (defun tramp-find-ls-command (multi-method method user host
)
3447 "Finds an `ls' command which groks the `-n' option, returning nil if failed.
3448 \(This option prints numeric user and group ids in a long listing.)"
3449 (tramp-message 9 "Finding a suitable `ls' command")
3451 (tramp-check-ls-commands multi-method method user host
"ls" tramp-remote-path
)
3452 (tramp-check-ls-commands multi-method method user host
"gnuls" tramp-remote-path
)
3453 (tramp-check-ls-commands multi-method method user host
"gls" tramp-remote-path
)))
3455 ;; ------------------------------------------------------------
3456 ;; -- Functions for establishing connection --
3457 ;; ------------------------------------------------------------
3459 ;; The following functions are actions to be taken when seeing certain
3460 ;; prompts from the remote host. See the variable
3461 ;; `tramp-actions-before-shell' for usage of these functions.
3463 (defun tramp-action-login (p multi-method method user host
)
3464 "Send the login name."
3465 (tramp-message 9 "Sending login name `%s'"
3466 (or user
(user-login-name)))
3468 (process-send-string nil
(concat (or user
(user-login-name))
3469 tramp-rsh-end-of-line
)))
3471 (defun tramp-action-password (p multi-method method user host
)
3472 "Query the user for a password."
3473 (when (tramp-method-out-of-band-p multi-method method
)
3474 (kill-process (get-buffer-process (current-buffer)))
3475 (error (concat "Out of band method `%s' not applicable "
3476 "for remote shell asking for a password")
3478 (tramp-enter-password p
(match-string 0)))
3480 (defun tramp-action-succeed (p multi-method method user host
)
3481 "Signal success in finding shell prompt."
3482 (tramp-message 9 "Found remote shell prompt.")
3484 (throw 'tramp-action
'ok
))
3486 (defun tramp-action-permission-denied (p multi-method method user host
)
3487 "Signal permission denied."
3488 (tramp-message 9 "Permission denied by remote host.")
3491 (throw 'tramp-action
'permission-denied
))
3493 (defun tramp-action-yesno (p multi-method method user host
)
3494 "Ask the user if he is sure."
3495 (save-window-excursion
3496 (pop-to-buffer (tramp-get-buffer multi-method method user host
))
3497 (unless (yes-or-no-p (match-string 0))
3500 (throw 'tramp-action
'permission-denied
))
3501 (process-send-string p
(concat "yes" tramp-rsh-end-of-line
))
3504 ;; The following functions are specifically for multi connections.
3506 (defun tramp-multi-action-login (p method user host
)
3507 "Send the login name."
3508 (tramp-message 9 "Sending login name `%s'" user
)
3510 (process-send-string p
(concat user tramp-rsh-end-of-line
)))
3512 (defun tramp-multi-action-password (p method user host
)
3513 "Query the user for a password."
3514 (tramp-enter-password p
(match-string 0)))
3516 (defun tramp-multi-action-succeed (p method user host
)
3517 "Signal success in finding shell prompt."
3518 (tramp-message 9 "Found shell prompt on `%s'" host
)
3520 (throw 'tramp-action
'ok
))
3522 (defun tramp-multi-action-permission-denied (p method user host
)
3523 "Signal permission denied."
3524 (tramp-message 9 "Permission denied by remote host `%s'" host
)
3527 (throw 'tramp-action
'permission-denied
))
3529 ;; Functions for processing the actions.
3531 (defun tramp-process-one-action (p multi-method method user host actions
)
3532 "Wait for output from the shell and perform one action."
3533 (let (found item pattern action todo
)
3535 (tramp-message 9 "Waiting 60s for prompt from remote shell")
3536 (with-timeout (60 (throw 'tramp-action
'timeout
))
3538 (accept-process-output p
1)
3539 (goto-char (point-min))
3542 (goto-char (point-min))
3543 (setq item
(pop todo
))
3544 (setq pattern
(symbol-value (nth 0 item
)))
3545 (setq action
(nth 1 item
))
3546 (tramp-message 10 "Looking for pattern %s" pattern
)
3547 (when (re-search-forward (concat pattern
"\\'") nil t
)
3548 (setq found
(funcall action p multi-method method user host
)))))
3551 (defun tramp-process-actions (p multi-method method user host actions
)
3552 "Perform actions until success."
3555 (tramp-message 10 "Processing actions")
3557 (catch 'tramp-action
3558 (tramp-process-one-action
3559 p multi-method method user host actions
)
3561 (unless (eq exit
'ok
)
3562 (error "Login failed"))))
3564 ;; For multi-actions.
3566 (defun tramp-process-one-multi-action (p method user host actions
)
3567 "Wait for output from the shell and perform one action."
3568 (let (found item pattern action todo
)
3570 (tramp-message 9 "Waiting 60s for prompt from remote shell")
3571 (with-timeout (60 (throw 'tramp-action
'timeout
))
3573 (accept-process-output p
1)
3575 (goto-char (point-min))
3577 (goto-char (point-min))
3578 (setq item
(pop todo
))
3579 (setq pattern
(symbol-value (nth 0 item
)))
3580 (setq action
(nth 1 item
))
3581 (tramp-message 10 "Looking for pattern %s" pattern
)
3582 (when (re-search-forward (concat pattern
"\\'") nil t
)
3583 (setq found
(funcall action p method user host
)))))
3586 (defun tramp-process-multi-actions (p method user host actions
)
3587 "Perform actions until success."
3591 (catch 'tramp-action
3592 (tramp-process-one-multi-action p method user host actions
)
3594 (unless (eq exit
'ok
)
3595 (error "Login failed"))))
3597 ;; The actual functions for opening connections.
3599 (defun tramp-open-connection-telnet (multi-method method user host
)
3600 "Open a connection using a telnet METHOD.
3601 This starts the command `telnet HOST ARGS'[*], then waits for a remote
3602 login prompt, then sends the user name USER, then waits for a remote
3603 password prompt. It queries the user for the password, then sends the
3604 password to the remote host.
3606 If USER is nil, uses value returned by `(user-login-name)' instead.
3608 Recognition of the remote shell prompt is based on the variable
3609 `shell-prompt-pattern' which must be set up correctly.
3611 Please note that it is NOT possible to use this connection method
3612 together with an out-of-band transfer method! You must use an inline
3615 Maybe the different regular expressions need to be tuned.
3617 * Actually, the telnet program as well as the args to be used can be
3618 specified in the method parameters, see the variable `tramp-methods'."
3620 (when (tramp-method-out-of-band-p multi-method method
)
3621 (error "Cannot use out-of-band method `%s' with telnet connection method"
3624 (error "Cannot multi-connect using telnet connection method"))
3625 (tramp-pre-connection multi-method method user host
)
3626 (tramp-message 7 "Opening connection for %s@%s using %s..."
3627 (or user
(user-login-name)) host method
)
3628 (let ((process-environment (copy-sequence process-environment
)))
3629 (setenv "TERM" tramp-terminal-type
)
3630 (let* ((default-directory (tramp-temporary-file-directory))
3631 (coding-system-for-read (unless (and (not (featurep 'xemacs
))
3632 (> emacs-major-version
20))
3633 tramp-dos-coding-system
))
3634 (p (apply 'start-process
3635 (tramp-buffer-name multi-method method user host
)
3636 (tramp-get-buffer multi-method method user host
)
3637 (tramp-get-telnet-program multi-method method
)
3639 (tramp-get-telnet-args multi-method method
)))
3642 (process-kill-without-query p
)
3643 (set-buffer (tramp-get-buffer multi-method method user host
))
3645 (tramp-process-actions p multi-method method user host
3646 tramp-actions-before-shell
)
3648 ;; (tramp-message 9 "Waiting for login prompt...")
3649 ;; (unless (tramp-wait-for-regexp p nil tramp-login-prompt-regexp)
3650 ;; (pop-to-buffer (buffer-name))
3652 ;; (error "Couldn't find remote login prompt"))
3654 ;; ;; Remote login defaults to local one.
3655 ;; (tramp-message 9 "Sending login name %s" (or user (user-login-name)))
3656 ;; (process-send-string p (concat (or user (user-login-name))
3657 ;; tramp-rsh-end-of-line))
3658 ;; (tramp-message 9 "Waiting for password prompt...")
3659 ;; (unless (setq found (tramp-wait-for-regexp
3660 ;; p nil tramp-password-prompt-regexp))
3661 ;; (pop-to-buffer (buffer-name))
3663 ;; (error "Couldn't find remote password prompt"))
3665 ;; (setq pw (tramp-read-passwd (car found)))
3666 ;; (tramp-message 9 "Sending password")
3667 ;; (process-send-string p (concat pw tramp-rsh-end-of-line))
3668 ;; (tramp-message 9 "Waiting 30s for remote shell to come up...")
3669 ;; (unless (setq found
3670 ;; (tramp-wait-for-regexp
3671 ;; p 30 (format "\\(%s\\)\\|\\(%s\\)\\'"
3672 ;; tramp-wrong-passwd-regexp
3673 ;; shell-prompt-pattern)))
3674 ;; (pop-to-buffer (buffer-name))
3676 ;; (error "Couldn't find remote shell prompt"))
3677 ;; (when (nth 1 found)
3678 ;; (pop-to-buffer (buffer-name))
3680 ;; (error "Login failed: %s" (nth 1 found)))
3682 (tramp-open-connection-setup-interactive-shell
3683 p multi-method method user host
)
3684 (tramp-post-connection multi-method method user host
)))))
3687 (defun tramp-open-connection-rsh (multi-method method user host
)
3688 "Open a connection using an rsh METHOD.
3689 This starts the command `rsh HOST -l USER'[*], then waits for a remote
3690 password or shell prompt. If a password prompt is seen, the user is
3691 queried for a password, this function sends the password to the remote
3692 host and waits for a shell prompt.
3694 If USER is nil, start the command `rsh HOST'[*] instead
3696 Recognition of the remote shell prompt is based on the variable
3697 `shell-prompt-pattern' which must be set up correctly.
3699 Please note that it is NOT possible to use this connection method with
3700 an out-of-band transfer method if this function asks the user for a
3701 password! You must use an inline transfer method in this case.
3702 Sadly, the transfer method cannot be switched on the fly, instead you
3703 must specify the right method in the file name.
3705 Kludgy feature: if HOST has the form \"xx#yy\", then yy is assumed to
3706 be a port number for ssh, and \"-p yy\" will be added to the list of
3707 arguments, and xx will be used as the host name to connect to.
3709 * Actually, the rsh program to be used can be specified in the
3710 method parameters, see the variable `tramp-methods'."
3713 (error "Cannot multi-connect using rsh connection method"))
3714 (tramp-pre-connection multi-method method user host
)
3716 (tramp-message 7 "Opening connection for %s@%s using %s..."
3718 (tramp-message 7 "Opening connection at %s using %s..." host method
))
3719 (let ((process-environment (copy-sequence process-environment
))
3720 (bufnam (tramp-buffer-name multi-method method user host
))
3721 (buf (tramp-get-buffer multi-method method user host
))
3722 (rsh-program (tramp-get-rsh-program multi-method method
))
3723 (rsh-args (tramp-get-rsh-args multi-method method
)))
3724 ;; The following should be changed. We need a more general
3725 ;; mechanism to parse extra host args.
3726 (when (string-match "\\([^#]*\\)#\\(.*\\)" host
)
3727 (setq rsh-args
(cons "-p" (cons (match-string 2 host
) rsh-args
)))
3728 (setq host
(match-string 1 host
)))
3729 (setenv "TERM" tramp-terminal-type
)
3730 (let* ((default-directory (tramp-temporary-file-directory))
3731 (coding-system-for-read (unless (and (not (featurep 'xemacs
))
3732 (> emacs-major-version
20))
3733 tramp-dos-coding-system
))
3735 (apply #'start-process bufnam buf rsh-program
3736 host
"-l" user rsh-args
)
3737 (apply #'start-process bufnam buf rsh-program
3740 (process-kill-without-query p
)
3743 (tramp-process-actions p multi-method method user host
3744 tramp-actions-before-shell
)
3746 ;; (tramp-message 9 "Waiting 60s for shell or passwd prompt from %s" host)
3748 ;; (tramp-wait-for-regexp
3751 ;; "\\(%s\\)\\|\\(%s\\)\\'"
3752 ;; tramp-password-prompt-regexp
3753 ;; shell-prompt-pattern)))
3755 ;; (pop-to-buffer (buffer-name))
3757 ;; (error "Couldn't find remote shell or passwd prompt"))
3758 ;; (when (nth 1 found)
3759 ;; (when (tramp-method-out-of-band-p multi-method method)
3760 ;; (pop-to-buffer (buffer-name))
3762 ;; (error (concat "Out of band method `%s' not applicable"
3763 ;; " for remote shell asking for a password")
3766 ;; (tramp-message 9 "Sending password...")
3767 ;; (tramp-enter-password p (nth 1 found))
3768 ;; (tramp-message 9 "Sent password, waiting 60s for remote shell prompt")
3769 ;; (setq found (tramp-wait-for-regexp p 60
3770 ;; (format "\\(%s\\)\\|\\(%s\\)\\'"
3771 ;; tramp-wrong-passwd-regexp
3772 ;; shell-prompt-pattern))))
3774 ;; (pop-to-buffer (buffer-name))
3776 ;; (error "Couldn't find remote shell prompt"))
3777 ;; (when (nth 1 found)
3778 ;; (pop-to-buffer (buffer-name))
3780 ;; (error "Login failed: %s" (nth 1 found)))
3782 (tramp-message 7 "Initializing remote shell")
3783 (tramp-open-connection-setup-interactive-shell
3784 p multi-method method user host
)
3785 (tramp-post-connection multi-method method user host
)))))
3787 (defun tramp-open-connection-su (multi-method method user host
)
3788 "Open a connection using the `su' program with METHOD.
3789 This starts `su - USER', then waits for a password prompt. The HOST
3790 name must be equal to the local host name or to `localhost'.
3792 If USER is nil, uses value returned by user-login-name instead.
3794 Recognition of the remote shell prompt is based on the variable
3795 `shell-prompt-pattern' which must be set up correctly. Note that the
3796 other user may have a different shell prompt than you do, so it is not
3797 at all unlikely that this variable is set up wrongly!"
3799 (when (tramp-method-out-of-band-p multi-method method
)
3800 (error "Cannot use out-of-band method `%s' with `su' connection method"
3802 (unless (or (string-match (concat "^" (regexp-quote host
))
3804 (string= "localhost" host
))
3806 "Cannot connect to different host `%s' with `su' connection method"
3809 (error "Must give user name for `su' connection method"))
3810 (tramp-pre-connection multi-method method user host
)
3811 (tramp-message 7 "Opening connection for `%s' using `%s'..."
3812 (or user
(user-login-name)) method
)
3813 (let ((process-environment (copy-sequence process-environment
)))
3814 (setenv "TERM" tramp-terminal-type
)
3815 (let* ((default-directory (tramp-temporary-file-directory))
3816 (coding-system-for-read (unless (and (not (featurep 'xemacs
))
3817 (> emacs-major-version
20))
3818 tramp-dos-coding-system
))
3819 (p (apply 'start-process
3820 (tramp-buffer-name multi-method method user host
)
3821 (tramp-get-buffer multi-method method user host
)
3822 (tramp-get-su-program multi-method method
)
3825 (format-spec x
`((?u .
,user
))))
3826 (tramp-get-su-args multi-method method
))))
3829 (process-kill-without-query p
)
3830 (set-buffer (tramp-get-buffer multi-method method user host
))
3831 (tramp-process-actions p multi-method method user host
3832 tramp-actions-before-shell
)
3834 ;; (tramp-message 9 "Waiting 30s for shell or password prompt...")
3835 ;; (unless (setq found (tramp-wait-for-regexp
3837 ;; (format "\\(%s\\)\\|\\(%s\\)\\'"
3838 ;; tramp-password-prompt-regexp
3839 ;; shell-prompt-pattern)))
3840 ;; (pop-to-buffer (buffer-name))
3842 ;; (error "Couldn't find shell or password prompt"))
3843 ;; (when (nth 1 found)
3845 ;; (setq pw (tramp-read-passwd (car found)))
3846 ;; (tramp-message 9 "Sending password")
3847 ;; (process-send-string p (concat pw tramp-rsh-end-of-line))
3848 ;; (tramp-message 9 "Waiting 30s for remote shell to come up...")
3849 ;; (unless (setq found
3850 ;; (tramp-wait-for-regexp
3851 ;; p 30 (format "\\(%s\\)\\|\\(%s\\)\\'"
3852 ;; tramp-wrong-passwd-regexp
3853 ;; shell-prompt-pattern)))
3854 ;; (pop-to-buffer (buffer-name))
3856 ;; (error "Couldn't find remote shell prompt"))
3857 ;; (when (nth 1 found)
3858 ;; (pop-to-buffer (buffer-name))
3860 ;; (error "`su' failed: %s" (nth 1 found))))
3862 (tramp-open-connection-setup-interactive-shell
3863 p multi-method method user host
)
3864 (tramp-post-connection multi-method method
3867 ;; HHH: Not Changed. Multi method. It is not clear to me how this can
3868 ;; handle not giving a user name in the "file name".
3870 ;; This is more difficult than for the single-hop method. In the
3871 ;; multi-hop-method, the desired behaviour should be that the
3872 ;; user must specify names for the telnet hops of which the user
3873 ;; name is different than the "original" name (or different from
3874 ;; the previous hop.
3875 (defun tramp-open-connection-multi (multi-method method user host
)
3876 "Open a multi-hop connection using METHOD.
3877 This uses a slightly changed file name syntax. The idea is to say
3878 [multi/telnet:u1@h1/rsh:u2@h2]/path/to/file
3879 This will use telnet to log in as u1 to h1, then use rsh from there to
3880 log in as u2 to h2."
3882 (unless multi-method
3883 (error "Multi-hop open connection function called on non-multi method"))
3884 (when (tramp-method-out-of-band-p multi-method method
)
3885 (error "No out of band multi-hop connections"))
3886 (unless (and (arrayp method
) (not (stringp method
)))
3887 (error "METHOD must be an array of strings for multi methods"))
3888 (unless (and (arrayp user
) (not (stringp user
)))
3889 (error "USER must be an array of strings for multi methods"))
3890 (unless (and (arrayp host
) (not (stringp host
)))
3891 (error "HOST must be an array of strings for multi methods"))
3892 (unless (and (= (length method
) (length user
))
3893 (= (length method
) (length host
)))
3894 (error "Arrays METHOD, USER, HOST must have equal length"))
3895 (tramp-pre-connection multi-method method user host
)
3896 (tramp-message 7 "Opening `%s' connection..." multi-method
)
3897 (let ((process-environment (copy-sequence process-environment
)))
3898 (setenv "TERM" tramp-terminal-type
)
3899 (let* ((default-directory (tramp-temporary-file-directory))
3900 (coding-system-for-read (unless (and (not (featurep 'xemacs
))
3901 (> emacs-major-version
20))
3902 tramp-dos-coding-system
))
3903 (p (start-process (tramp-buffer-name multi-method method user host
)
3904 (tramp-get-buffer multi-method method user host
)
3905 tramp-multi-sh-program
))
3906 (num-hops (length method
))
3908 (process-kill-without-query p
)
3909 (tramp-message 9 "Waiting 60s for local shell to come up...")
3910 (unless (tramp-wait-for-regexp
3911 p
60 (format "%s\\'" shell-prompt-pattern
))
3912 (pop-to-buffer (buffer-name))
3914 (error "Couldn't find local shell prompt"))
3915 ;; Now do all the connections as specified.
3916 (while (< i num-hops
)
3917 (let* ((m (aref method i
))
3920 (entry (assoc m tramp-multi-connection-function-alist
))
3921 (multi-func (nth 1 entry
))
3922 (command (nth 2 entry
)))
3923 ;; The multi-funcs don't need to do save-match-data, as that
3925 (funcall multi-func p m u h command
)
3928 (tramp-open-connection-setup-interactive-shell
3929 p multi-method method user host
)
3930 (tramp-post-connection multi-method method user host
)))))
3932 ;; HHH: Changed. Multi method. Don't know how to handle this in the case
3933 ;; of no user name provided. Hack to make it work as it did before:
3934 ;; changed `user' to `(or user (user-login-name))' in the places where
3935 ;; the value is actually used.
3936 (defun tramp-multi-connect-telnet (p method user host command
)
3937 "Issue `telnet' command.
3938 Uses shell COMMAND to issue a `telnet' command to log in as USER to
3939 HOST. You can use percent escapes in COMMAND: `%h' is replaced with
3940 the host name, and `%n' is replaced with an end of line character, as
3941 set in `tramp-rsh-end-of-line'. Use `%%' if you want a literal percent
3944 If USER is nil, uses the return value of (user-login-name) instead."
3945 (let ((cmd (format-spec command
3946 `((?h .
,host
) (?n .
,tramp-rsh-end-of-line
))))
3947 (cmd1 (format-spec command
`((?h .
,host
) (?n .
""))))
3950 (tramp-message 9 "Sending telnet command `%s'" cmd1
)
3951 (process-send-string p cmd
)
3952 (tramp-process-multi-actions p method user host
3953 tramp-multi-actions
)
3955 ;; (tramp-message 9 "Waiting 30s for login prompt from %s" host)
3956 ;; (unless (tramp-wait-for-regexp p 30 tramp-login-prompt-regexp)
3957 ;; (pop-to-buffer (buffer-name))
3959 ;; (error "Couldn't find login prompt from host %s" host))
3961 ;; (tramp-message 9 "Sending login name %s" (or user (user-login-name)))
3962 ;; (process-send-string p (concat (or user (user-login-name)) tramp-rsh-end-of-line))
3963 ;; (tramp-message 9 "Waiting for password prompt")
3964 ;; (unless (setq found (tramp-wait-for-regexp p nil tramp-password-prompt-regexp))
3965 ;; (pop-to-buffer (buffer-name))
3967 ;; (error "Couldn't find password prompt from host %s" host))
3969 ;; (setq pw (tramp-read-passwd
3970 ;; (format "Password for %s@%s, %s" (or user (user-login-name)) host found)))
3971 ;; (tramp-message 9 "Sending password")
3972 ;; (process-send-string p (concat pw tramp-rsh-end-of-line))
3973 ;; (tramp-message 9 "Waiting 60s for remote shell to come up...")
3974 ;; (unless (setq found (tramp-wait-for-regexp
3975 ;; p 60 (format "\\(%s\\)\\|\\(%s\\)\\'"
3976 ;; tramp-wrong-passwd-regexp
3977 ;; shell-prompt-pattern)))
3978 ;; (pop-to-buffer (buffer-name))
3980 ;; (error "Couldn't find shell prompt from host %s" host))
3981 ;; (when (nth 1 found)
3982 ;; (pop-to-buffer (buffer-name))
3984 ;; (error "Login to %s failed: %s" (nth 2 found)))
3987 ;; HHH: Changed. Multi method. Don't know how to handle this in the case
3988 ;; of no user name provided. Hack to make it work as it did before:
3989 ;; changed `user' to `(or user (user-login-name))' in the places where
3990 ;; the value is actually used.
3991 (defun tramp-multi-connect-rlogin (p method user host command
)
3992 "Issue `rlogin' command.
3993 Uses shell COMMAND to issue an `rlogin' command to log in as USER to
3994 HOST. You can use percent escapes in COMMAND. `%u' will be replaced
3995 with the user name, `%h' will be replaced with the host name, and `%n'
3996 will be replaced with the value of `tramp-rsh-end-of-line'. You can use
3997 `%%' if you want to use a literal percent character.
3999 If USER is nil, uses the return value of (user-login-name) instead."
4000 (let ((cmd (format-spec command
`((?h .
,host
)
4001 (?u .
,(or user
(user-login-name)))
4002 (?n .
,tramp-rsh-end-of-line
))))
4003 (cmd1 (format-spec command
`((?h .
,host
)
4004 (?u .
,(or user
(user-login-name)))
4008 (tramp-message 9 "Sending rlogin command `%s'" cmd1
)
4009 (process-send-string p cmd
)
4010 (tramp-process-multi-actions p method user host
4011 tramp-multi-actions
)
4012 ;; (tramp-message 9 "Waiting 60s for shell or passwd prompt from %s" host)
4013 ;; (unless (setq found
4014 ;; (tramp-wait-for-regexp p 60
4015 ;; (format "\\(%s\\)\\|\\(%s\\)\\'"
4016 ;; tramp-password-prompt-regexp
4017 ;; shell-prompt-pattern)))
4018 ;; (pop-to-buffer (buffer-name))
4020 ;; (error "Couldn't find remote shell or passwd prompt"))
4021 ;; (when (nth 1 found)
4023 ;; (tramp-message 9 "Sending password...")
4024 ;; (tramp-enter-password p (nth 1 found))
4025 ;; (tramp-message 9 "Sent password, waiting 60s for remote shell prompt")
4026 ;; (setq found (tramp-wait-for-regexp p 60
4027 ;; (format "\\(%s\\)\\|\\(%s\\)\\'"
4028 ;; tramp-wrong-passwd-regexp
4029 ;; shell-prompt-pattern))))
4031 ;; (pop-to-buffer (buffer-name))
4033 ;; (error "Couldn't find remote shell prompt"))
4034 ;; (when (nth 1 found)
4035 ;; (pop-to-buffer (buffer-name))
4037 ;; (error "Login failed: %s" (nth 1 found)))
4040 ;; HHH: Changed. Multi method. Don't know how to handle this in the case
4041 ;; of no user name provided. Hack to make it work as it did before:
4042 ;; changed `user' to `(or user (user-login-name))' in the places where
4043 ;; the value is actually used.
4044 (defun tramp-multi-connect-su (p method user host command
)
4045 "Issue `su' command.
4046 Uses shell COMMAND to issue a `su' command to log in as USER on
4047 HOST. The HOST name is ignored, this just changes the user id on the
4048 host currently logged in to.
4050 If USER is nil, uses the return value of (user-login-name) instead.
4052 You can use percent escapes in the COMMAND. `%u' is replaced with the
4053 user name, and `%n' is replaced with the value of
4054 `tramp-rsh-end-of-line'. Use `%%' if you want a literal percent
4056 (let ((cmd (format-spec command
`((?u .
,(or user
(user-login-name)))
4057 (?n .
,tramp-rsh-end-of-line
))))
4058 (cmd1 (format-spec command
`((?u .
,(or user
(user-login-name)))
4062 (tramp-message 9 "Sending su command `%s'" cmd1
)
4063 (process-send-string p cmd
)
4064 (tramp-process-multi-actions p method user host
4065 tramp-multi-actions
)
4066 ;; (tramp-message 9 "Waiting 60s for shell or passwd prompt for %s" (or user (user-login-name)))
4067 ;; (unless (setq found (tramp-wait-for-regexp
4068 ;; p 60 (format "\\(%s\\)\\|\\(%s\\)\\'"
4069 ;; tramp-password-prompt-regexp
4070 ;; shell-prompt-pattern)))
4071 ;; (pop-to-buffer (buffer-name))
4073 ;; (error "Couldn't find shell or passwd prompt for %s"
4074 ;; (or user (user-login-name))))
4075 ;; (when (nth 1 found)
4076 ;; (tramp-message 9 "Sending password...")
4077 ;; (tramp-enter-password p (nth 1 found))
4079 ;; (tramp-message 9 "Sent password, waiting 60s for remote shell prompt")
4080 ;; (setq found (tramp-wait-for-regexp p 60
4081 ;; (format "\\(%s\\)\\|\\(%s\\)\\'"
4082 ;; tramp-wrong-passwd-regexp
4083 ;; shell-prompt-pattern))))
4085 ;; (pop-to-buffer (buffer-name))
4087 ;; (error "Couldn't find remote shell prompt"))
4088 ;; (when (nth 1 found)
4089 ;; (pop-to-buffer (buffer-name))
4091 ;; (error "Login failed: %s" (nth 1 found)))
4094 ;; Utility functions.
4096 (defun tramp-wait-for-regexp (proc timeout regexp
)
4097 "Wait for a REGEXP to appear from process PROC within TIMEOUT seconds.
4098 Expects the output of PROC to be sent to the current buffer. Returns
4099 the string that matched, or nil. Waits indefinitely if TIMEOUT is
4102 (start-time (current-time)))
4104 ;; Work around a bug in XEmacs 21, where the timeout
4105 ;; expires faster than it should. This degenerates
4106 ;; to polling for buggy XEmacsen, but oh, well.
4107 (while (and (not found
)
4108 (< (tramp-time-diff (current-time) start-time
)
4110 (with-timeout (timeout)
4112 (accept-process-output proc
1)
4113 (goto-char (point-min))
4114 (setq found
(when (re-search-forward regexp nil t
)
4115 (tramp-match-string-list)))))))
4118 (accept-process-output proc
1)
4119 (goto-char (point-min))
4120 (setq found
(when (re-search-forward regexp nil t
)
4121 (tramp-match-string-list))))))
4122 (when tramp-debug-buffer
4124 (tramp-get-debug-buffer tramp-current-multi-method tramp-current-method
4125 tramp-current-user tramp-current-host
)
4126 (point-min) (point-max))
4130 (tramp-get-debug-buffer tramp-current-multi-method tramp-current-method
4131 tramp-current-user tramp-current-host
))
4132 (goto-char (point-max))
4133 (insert "[[Regexp `" regexp
"' not found"
4134 (if timeout
(format " in %d secs" timeout
) "")
4138 (defun tramp-enter-password (p prompt
)
4139 "Prompt for a password and send it to the remote end.
4140 Uses PROMPT as a prompt and sends the password to process P."
4141 (let ((pw (tramp-read-passwd prompt
)))
4143 (process-send-string p
(concat pw tramp-rsh-end-of-line
))))
4145 ;; HHH: Not Changed. This might handle the case where USER is not
4146 ;; given in the "File name" very poorly. Then, the local
4147 ;; variable tramp-current user will be set to nil.
4148 (defun tramp-pre-connection (multi-method method user host
)
4149 "Do some setup before actually logging in.
4150 METHOD, USER and HOST specify the connection."
4151 (set-buffer (tramp-get-buffer multi-method method user host
))
4152 (set (make-local-variable 'tramp-current-multi-method
) multi-method
)
4153 (set (make-local-variable 'tramp-current-method
) method
)
4154 (set (make-local-variable 'tramp-current-user
) user
)
4155 (set (make-local-variable 'tramp-current-host
) host
)
4156 (set (make-local-variable 'inhibit-eol-conversion
) nil
)
4159 (defun tramp-open-connection-setup-interactive-shell
4160 (p multi-method method user host
)
4161 "Set up an interactive shell.
4162 Mainly sets the prompt and the echo correctly. P is the shell process
4163 to set up. METHOD, USER and HOST specify the connection."
4164 ;; Wait a bit in case the remote end feels like sending a little
4165 ;; junk first. It seems that fencepost.gnu.org does this when doing
4166 ;; a Kerberos login.
4168 (tramp-discard-garbage-erase-buffer p multi-method method user host
)
4169 (process-send-string nil
(format "exec %s%s"
4170 (tramp-get-remote-sh multi-method method
)
4171 tramp-rsh-end-of-line
))
4172 (when tramp-debug-buffer
4174 (set-buffer (tramp-get-debug-buffer multi-method method user host
))
4175 (goto-char (point-max))
4176 (tramp-insert-with-face
4177 'bold
(format "$ exec %s\n" (tramp-get-remote-sh multi-method method
)))))
4178 (tramp-message 9 "Waiting 30s for remote `%s' to come up..."
4179 (tramp-get-remote-sh multi-method method
))
4180 (unless (tramp-wait-for-regexp
4181 p
30 (format "\\(\\$ *\\|%s\\)\\'" shell-prompt-pattern
))
4182 (pop-to-buffer (buffer-name))
4183 (error "Remote `%s' didn't come up. See buffer `%s' for details"
4184 (tramp-get-remote-sh multi-method method
) (buffer-name)))
4185 (tramp-message 9 "Setting up remote shell environment")
4186 (tramp-discard-garbage-erase-buffer p multi-method method user host
)
4187 (process-send-string
4188 nil
(format "stty -inlcr -echo kill '^U'%s" tramp-rsh-end-of-line
))
4189 (unless (tramp-wait-for-regexp
4190 p
30 (format "\\(\\$ *\\|%s\\)\\'" shell-prompt-pattern
))
4191 (pop-to-buffer (buffer-name))
4192 (error "Couldn't `stty -echo', see buffer `%s'" (buffer-name)))
4194 (process-send-string nil
(format "TERM=dumb; export TERM%s"
4195 tramp-rsh-end-of-line
))
4196 (unless (tramp-wait-for-regexp
4197 p
30 (format "\\(\\$ *\\|%s\\)\\'" shell-prompt-pattern
))
4198 (pop-to-buffer (buffer-name))
4199 (error "Couldn't `TERM=dumb; export TERM', see buffer `%s'" (buffer-name)))
4200 ;; Try to set up the coding system correctly.
4201 ;; CCC this can't be the right way to do it. Hm.
4204 (tramp-message 9 "Determining coding system")
4205 (process-send-string nil
(format "echo foo ; echo bar %s"
4206 tramp-rsh-end-of-line
))
4207 (unless (tramp-wait-for-regexp
4208 p
30 (format "\\(\\$ *\\|%s\\)\\'" shell-prompt-pattern
))
4209 (pop-to-buffer (buffer-name))
4210 (error "Couldn't `echo foo; echo bar' to determine line endings'"))
4211 (goto-char (point-min))
4212 (if (featurep 'mule
)
4213 ;; Use MULE to select the right EOL convention for communicating
4214 ;; with the process.
4215 (let* ((cs (or (process-coding-system p
) (cons 'undecided
'undecided
)))
4216 cs-decode cs-encode
)
4217 (when (symbolp cs
) (setq cs
(cons cs cs
)))
4218 (setq cs-decode
(car cs
))
4219 (setq cs-encode
(cdr cs
))
4220 (unless cs-decode
(setq cs-decode
'undecided
))
4221 (unless cs-encode
(setq cs-encode
'undecided
))
4222 (setq cs-encode
(tramp-coding-system-change-eol-conversion
4224 (when (search-forward "\r" nil t
)
4225 (setq cs-decode
(tramp-coding-system-change-eol-conversion
4227 (set-buffer-process-coding-system cs-decode cs-encode
))
4228 ;; Look for ^M and do something useful if found.
4229 (when (search-forward "\r" nil t
)
4230 ;; We have found a ^M but cannot frob the process coding system
4231 ;; because we're running on a non-MULE Emacs. Let's try
4233 (tramp-message 9 "Trying `stty -onlcr'")
4234 (process-send-string nil
(format "stty -onlcr%s" tramp-rsh-end-of-line
))
4235 (unless (tramp-wait-for-regexp
4236 p
30 (format "\\(\\$ *\\|%s\\)\\'" shell-prompt-pattern
))
4237 (pop-to-buffer (buffer-name))
4238 (error "Couldn't `stty -onlcr', see buffer `%s'" (buffer-name))))))
4241 9 "Waiting 30s for `HISTFILE=$HOME/.tramp_history; HISTSIZE=1'")
4242 (process-send-string
4243 nil
(format "HISTFILE=$HOME/.tramp_history; HISTSIZE=1%s"
4244 tramp-rsh-end-of-line
))
4245 (unless (tramp-wait-for-regexp
4246 p
30 (format "\\(\\$ *\\|%s\\)\\'" shell-prompt-pattern
))
4247 (pop-to-buffer (buffer-name))
4248 (error (concat "Couldn't `HISTFILE=$HOME/.tramp_history; "
4249 "HISTSIZE=1', see buffer `%s'")
4252 (tramp-message 9 "Waiting 30s for `set +o vi +o emacs'")
4253 (process-send-string
4254 nil
(format "set +o vi +o emacs%s" ;mustn't `>/dev/null' with AIX?
4255 tramp-rsh-end-of-line
))
4256 (unless (tramp-wait-for-regexp
4257 p
30 (format "\\(\\$ *\\|%s\\)\\'" shell-prompt-pattern
))
4258 (pop-to-buffer (buffer-name))
4259 (error "Couldn't `set +o vi +o emacs', see buffer `%s'"
4262 (tramp-message 9 "Waiting 30s for `unset MAIL MAILCHECK MAILPATH'")
4263 (process-send-string
4264 nil
(format "unset MAIL MAILCHECK MAILPATH 1>/dev/null 2>/dev/null%s"
4265 tramp-rsh-end-of-line
))
4266 (unless (tramp-wait-for-regexp
4267 p
30 (format "\\(\\$ *\\|%s\\)\\'" shell-prompt-pattern
))
4268 (pop-to-buffer (buffer-name))
4269 (error "Couldn't `unset MAIL MAILCHECK MAILPATH', see buffer `%s'"
4272 (tramp-message 9 "Waiting 30s for `unset CDPATH'")
4273 (process-send-string
4274 nil
(format "unset CDPATH%s" tramp-rsh-end-of-line
))
4275 (unless (tramp-wait-for-regexp
4276 p
30 (format "\\(\\$ *\\|%s\\)\\'" shell-prompt-pattern
))
4277 (pop-to-buffer (buffer-name))
4278 (error "Couldn't `unset CDPATH', see buffer `%s'"
4281 (tramp-message 9 "Setting shell prompt")
4283 multi-method method user host
4284 (format "PS1='%s%s%s'; PS2=''; PS3=''"
4285 tramp-rsh-end-of-line
4287 tramp-rsh-end-of-line
))
4288 (tramp-wait-for-output)
4289 (tramp-send-command multi-method method user host
"echo hello")
4290 (tramp-message 9 "Waiting for remote `%s' to come up..."
4291 (tramp-get-remote-sh multi-method method
))
4292 (unless (tramp-wait-for-output 5)
4293 (unless (tramp-wait-for-output 5)
4294 (pop-to-buffer (buffer-name))
4295 (error "Couldn't set remote shell prompt. See buffer `%s' for details"
4297 (tramp-message 7 "Waiting for remote `%s' to come up...done"
4298 (tramp-get-remote-sh multi-method method
)))
4300 (defun tramp-post-connection (multi-method method user host
)
4301 "Prepare a remote shell before being able to work on it.
4302 METHOD, USER and HOST specify the connection.
4303 Among other things, this finds a shell which groks tilde expansion,
4304 tries to find an `ls' command which groks the `-n' option, sets the
4305 locale to C and sets up the remote shell search path."
4306 ;; Search for a good shell before searching for a command which
4307 ;; checks if a file exists. This is done because Tramp wants to use
4308 ;; "test foo; echo $?" to check if various conditions hold, and
4309 ;; there are buggy /bin/sh implementations which don't execute the
4310 ;; "echo $?" part if the "test" part has an error. In particular,
4311 ;; the Solaris /bin/sh is a problem. I'm betting that all systems
4312 ;; with buggy /bin/sh implementations will have a working bash or
4314 (tramp-find-shell multi-method method user host
)
4315 (tramp-find-file-exists-command multi-method method user host
)
4317 ;; Without (sit-for 0.1) at least, my machine will almost always blow
4318 ;; up on 'not numberp /root' - a race that causes the 'echo ~root'
4319 ;; output of (tramp-find-shell) to show up along with the output of
4320 ;; (tramp-find-ls-command) testing.
4322 ;; I can't work out why this is a problem though. The (tramp-wait-for-output)
4323 ;; call in (tramp-find-shell) *should* make this not happen, I thought.
4325 ;; After much debugging I couldn't find any problem with the implementation
4326 ;; of that function though. The workaround stays for me at least. :/
4328 ;; Daniel Pittman <daniel@danann.net>
4329 (make-local-variable 'tramp-ls-command
)
4330 (setq tramp-ls-command
(tramp-find-ls-command multi-method method user host
))
4331 (unless tramp-ls-command
4334 "Danger! Couldn't find ls which groks -n. Muddling through anyway")
4335 (setq tramp-ls-command
4336 (tramp-find-executable multi-method method user host
4337 "ls" tramp-remote-path nil
)))
4338 (unless tramp-ls-command
4339 (error "Fatal error: Couldn't find remote executable `ls'"))
4340 (tramp-message 5 "Using remote command `%s' for getting directory listings"
4342 (tramp-send-command multi-method method user host
4343 (concat "tramp_set_exit_status () {" tramp-rsh-end-of-line
4344 "return $1" tramp-rsh-end-of-line
4346 (tramp-wait-for-output)
4347 ;; Set remote PATH variable.
4348 (tramp-set-remote-path multi-method method user host
"PATH" tramp-remote-path
)
4349 ;; Tell remote shell to use standard time format, needed for
4350 ;; parsing `ls -l' output.
4351 (tramp-send-command multi-method method user host
4352 "LC_TIME=C; export LC_TIME; echo huhu")
4353 (tramp-wait-for-output)
4354 (tramp-send-command multi-method method user host
4355 "mesg n; echo huhu")
4356 (tramp-wait-for-output)
4357 (tramp-send-command multi-method method user host
4358 "biff n ; echo huhu")
4359 (tramp-wait-for-output)
4360 ;; Unalias ls(1) to work around issues with those silly people who make it
4361 ;; spit out ANSI escapes or whatever.
4362 (tramp-send-command multi-method method user host
4363 "unalias ls; echo huhu")
4364 (tramp-wait-for-output)
4365 ;; Does `test A -nt B' work? Use abominable `find' construct if it
4366 ;; doesn't. BSD/OS 4.0 wants the parentheses around the command,
4367 ;; for otherwise the shell crashes.
4369 (make-local-variable 'tramp-test-groks-nt
)
4370 (tramp-send-command multi-method method user host
4372 (tramp-wait-for-output)
4373 (goto-char (point-min))
4374 (setq tramp-test-groks-nt
4375 (looking-at (format "\n%s\n" (regexp-quote tramp-end-of-output
))))
4376 (unless tramp-test-groks-nt
4378 multi-method method user host
4379 (concat "tramp_test_nt () {" tramp-rsh-end-of-line
4380 "test -n \"`find $1 -prune -newer $2 -print`\"" tramp-rsh-end-of-line
4382 (tramp-wait-for-output)
4385 (let ((tramp-remote-perl
4386 (or (tramp-find-executable multi-method method user host
4387 "perl5" tramp-remote-path nil
)
4388 (tramp-find-executable multi-method method user host
4389 "perl" tramp-remote-path nil
))))
4390 (when tramp-remote-perl
4391 (tramp-set-connection-property "perl" tramp-remote-perl multi-method method user host
)
4392 ;; Set up stat in Perl if we can.
4393 (when tramp-remote-perl
4394 (tramp-message 5 "Sending the Perl `file-attributes' implementation.")
4395 (tramp-send-linewise
4396 multi-method method user host
4397 (concat "tramp_file_attributes () {\n"
4399 " -e '" tramp-perl-file-attributes
"' $1 2>/dev/null\n"
4401 (tramp-wait-for-output)
4402 (tramp-message 5 "Sending the Perl `mime-encode' implementation.")
4403 (tramp-send-linewise
4404 multi-method method user host
4405 (concat "tramp_encode () {\n"
4406 (format tramp-perl-encode tramp-remote-perl
)
4409 (tramp-wait-for-output)
4410 (tramp-message 5 "Sending the Perl `mime-decode' implementation.")
4411 (tramp-send-linewise
4412 multi-method method user host
4413 (concat "tramp_decode () {\n"
4414 (format tramp-perl-decode tramp-remote-perl
)
4417 (tramp-wait-for-output))))
4420 (let ((ln (tramp-find-executable multi-method method user host
4421 "ln" tramp-remote-path nil
)))
4423 (tramp-set-connection-property "ln" ln multi-method method user host
)))
4425 ;; Find the right encoding/decoding commands to use.
4426 (unless (tramp-get-rcp-program multi-method method
)
4427 (tramp-find-inline-encoding multi-method method user host
))
4428 ;; If encoding/decoding command are given, test to see if they work.
4429 ;; CCC: Maybe it would be useful to run the encoder both locally and
4430 ;; remotely to see if they produce the same result.
4431 (let ((decoding (tramp-get-decoding-command multi-method method user host
))
4432 (encoding (tramp-get-encoding-command multi-method method user host
))
4433 (magic-string "xyzzy"))
4434 (when (and (or decoding encoding
) (not (and decoding encoding
)))
4435 (tramp-kill-process multi-method method user host
)
4437 "Must give both decoding and encoding command in method definition"))
4438 (when (and decoding encoding
)
4441 "Checking to see if encoding/decoding commands work on remote host...")
4443 multi-method method user host
4444 (format "echo %s | %s | %s"
4445 (tramp-shell-quote-argument magic-string
) encoding decoding
))
4446 (tramp-wait-for-output)
4447 (unless (looking-at (regexp-quote magic-string
))
4448 (tramp-kill-process multi-method method user host
)
4449 (error "Remote host cannot execute de/encoding commands. See buffer `%s' for details"
4453 5 "Checking to see if encoding/decoding commands work on remote host...done"))))
4455 ;; CCC: We should either implement a Perl version of base64 encoding
4456 ;; and decoding. Then we just use that in the last item. The other
4457 ;; alternative is to use the Perl version of UU encoding. But then
4458 ;; we need a Lisp version of uuencode.
4459 (defvar tramp-coding-commands
4460 '(("mimencode -b" "mimencode -u -b"
4461 base64-encode-region base64-decode-region
)
4462 ("mmencode -b" "mmencode -u -b"
4463 base64-encode-region base64-decode-region
)
4464 ("recode data..base64" "recode base64..data"
4465 base64-encode-region base64-decode-region
)
4466 ("uuencode xxx" "uudecode -o -"
4467 nil uudecode-decode-region
)
4468 ("uuencode xxx" "uudecode -p"
4469 nil uudecode-decode-region
)
4470 ("tramp_encode" "tramp_decode"
4471 base64-encode-region base64-decode-region
))
4472 "List of coding commands for inline transfer.
4473 Each item is a list (ENCODING-COMMAND DECODING-COMMAND
4474 ENCODING-FUNCTION DECODING-FUNCTION).
4476 Each item can be a string, giving a command, or a symbol, giving
4479 The ENCODING-COMMAND should be a command accepting a plain file on
4480 standard input and writing the encoded file to standard output. The
4481 DECODING-COMMAND should be a command accepting an encoded file on
4482 standard input and writing the decoded file to standard output.
4484 The ENCODING-FUNCTION and DECODING-FUNCTION functions will be called
4485 with two arguments, start and end of region, and are expected to
4486 replace the region contents with the encoded or decoded results,
4489 (defun tramp-find-inline-encoding (multi-method method user host
)
4490 "Find an inline transfer encoding that works.
4491 Goes through the list `tramp-coding-commands'."
4492 (let ((commands tramp-coding-commands
)
4494 (while (and commands
(null found
))
4495 (setq item
(pop commands
))
4497 (let ((ec (nth 0 item
))
4501 ;; Check if encoding and decoding commands can be called
4502 ;; remotely with null input and output. This makes sure there
4503 ;; are no syntax errors and the command is really found.
4504 (tramp-message-for-buffer
4505 multi-method method user host
10
4506 "Checking remote encoding command `%s' for sanity" ec
)
4507 (unless (zerop (tramp-send-command-and-check
4508 multi-method method user host
4509 (format "%s </dev/null >/dev/null" ec
) t
))
4510 (throw 'wont-work nil
))
4511 (tramp-message-for-buffer
4512 multi-method method user host
10
4513 "Checking remote decoding command `%s' for sanity" dc
)
4514 (unless (zerop (tramp-send-command-and-check
4515 multi-method method user host
4516 (format "%s </dev/null >/dev/null" dc
) t
))
4517 (throw 'wont-work nil
))
4518 ;; If no encoding/decoding function is given, the
4519 ;; corresponding encoding/decoding command also has to work
4521 (when (not (fboundp ef
))
4522 (tramp-message-for-buffer
4523 multi-method method user host
10
4524 "Checking local encoding command `%s' for sanity" ec
)
4525 (unless (zerop (call-process
4526 tramp-sh-program
;program
4531 (format "%s </dev/null >/dev/null" ec
)))
4532 (throw 'wont-work nil
)))
4533 (when (not (fboundp df
))
4534 (tramp-message-for-buffer
4535 multi-method method user host
10
4536 "Checking local decoding command `%s' for sanity" dc
)
4537 (unless (zerop (call-process
4538 tramp-sh-program
;program
4543 (format "%s </dev/null >/dev/null" dc
)))
4544 (throw 'wont-work nil
)))
4545 ;; CCC: At this point, maybe we should check that the output
4546 ;; of the commands is correct. But for the moment we will
4547 ;; assume that commands working on empty input will also
4548 ;; work in practice.
4549 (setq found item
))))
4550 ;; Did we find something? If not, issue error. If so,
4551 ;; set connection properties.
4553 (error "Couldn't find an inline transfer encoding"))
4554 (let ((ec (nth 0 found
))
4558 (tramp-set-encoding-command multi-method method user host ec
)
4559 (tramp-set-decoding-command multi-method method user host dc
)
4560 (tramp-set-encoding-function multi-method method user host ef
)
4561 (tramp-set-decoding-function multi-method method user host df
))))
4564 (defun tramp-maybe-open-connection (multi-method method user host
)
4565 "Maybe open a connection to HOST, logging in as USER, using METHOD.
4566 Does not do anything if a connection is already open, but re-opens the
4567 connection if a previous connection has died for some reason."
4568 (let ((p (get-buffer-process (tramp-get-buffer multi-method method user host
)))
4570 ;; If too much time has passed since last command was sent, look
4571 ;; whether process is still alive. If it isn't, kill it. When
4572 ;; using ssh, it can sometimes happen that the remote end has hung
4573 ;; up but the local ssh client doesn't recognize this until it
4574 ;; tries to send some data to the remote end. So that's why we
4575 ;; try to send a command from time to time, then look again
4576 ;; whether the process is really alive.
4578 (set-buffer (tramp-get-buffer multi-method method user host
))
4579 (when (and tramp-last-cmd-time
4580 (> (tramp-time-diff tramp-last-cmd-time
(current-time)) 60))
4581 (process-send-string p
(concat "echo hello" tramp-rsh-end-of-line
))
4582 (unless (accept-process-output p
2)
4586 (unless (and p
(processp p
) (memq (process-status p
) '(run open
)))
4587 (when (and p
(processp p
))
4589 (funcall (tramp-get-connection-function multi-method method
)
4590 multi-method method user host
))))
4592 (defun tramp-send-command
4593 (multi-method method user host command
&optional noerase
)
4594 "Send the COMMAND to USER at HOST (logged in using METHOD).
4595 Erases temporary buffer before sending the command (unless NOERASE
4597 (tramp-maybe-open-connection multi-method method user host
)
4598 (setq tramp-last-cmd-time
(current-time))
4599 (when tramp-debug-buffer
4601 (set-buffer (tramp-get-debug-buffer multi-method method user host
))
4602 (goto-char (point-max))
4603 (tramp-insert-with-face 'bold
(format "$ %s\n" command
))))
4605 (set-buffer (tramp-get-buffer multi-method method user host
))
4606 (unless noerase
(erase-buffer))
4607 (setq proc
(get-buffer-process (current-buffer)))
4608 (process-send-string proc
4609 (concat command tramp-rsh-end-of-line
))))
4611 ;; It seems that Tru64 Unix does not like it if long strings are sent
4612 ;; to it in one go. (This happens when sending the Perl
4613 ;; `file-attributes' implementation, for instance.) Therefore, we
4614 ;; have this function which waits a bit at each line.
4615 (defun tramp-send-linewise
4616 (multi-method method user host string
&optional noerase
)
4617 "Send the STRING to USER at HOST linewise.
4618 Erases temporary buffer before sending the STRING (unless NOERASE
4621 The STRING is expected to use Unix line-endings, but the lines sent to
4622 the remote host use line-endings as defined in the variable
4623 `tramp-rsh-end-of-line'."
4624 (tramp-maybe-open-connection multi-method method user host
)
4625 (when tramp-debug-buffer
4627 (set-buffer (tramp-get-debug-buffer multi-method method user host
))
4628 (goto-char (point-max))
4629 (tramp-insert-with-face 'bold
(format "$ %s\n" string
))))
4631 (lines (split-string string
"\n")))
4632 (set-buffer (tramp-get-buffer multi-method method user host
))
4633 (unless noerase
(erase-buffer))
4634 (setq proc
(get-buffer-process (current-buffer)))
4637 (process-send-string proc
4638 (concat x tramp-rsh-end-of-line
)))
4641 (defun tramp-wait-for-output (&optional timeout
)
4642 "Wait for output from remote rsh command."
4643 (let ((proc (get-buffer-process (current-buffer)))
4645 (start-time (current-time))
4646 (end-of-output (concat "^"
4647 (regexp-quote tramp-end-of-output
)
4649 ;; Algorithm: get waiting output. See if last line contains
4650 ;; end-of-output sentinel. If not, wait a bit and again get
4651 ;; waiting output. Repeat until timeout expires or end-of-output
4652 ;; sentinel is seen. Will hang if timeout is nil and
4653 ;; end-of-output sentinel never appears.
4656 ;; Work around an XEmacs bug, where the timeout expires
4657 ;; faster than it should. This degenerates into polling
4658 ;; for buggy XEmacsen, but oh, well.
4659 (while (and (not found
)
4660 (< (tramp-time-diff (current-time) start-time
)
4662 (with-timeout (timeout)
4664 (accept-process-output proc
1)
4665 (goto-char (point-max))
4667 (setq found
(looking-at end-of-output
))))))
4670 (accept-process-output proc
1)
4671 (goto-char (point-max))
4673 (setq found
(looking-at end-of-output
))))))
4674 ;; At this point, either the timeout has expired or we have found
4675 ;; the end-of-output sentinel.
4677 (goto-char (point-max))
4679 (delete-region (point) (point-max)))
4680 ;; Add output to debug buffer if appropriate.
4681 (when tramp-debug-buffer
4683 (tramp-get-debug-buffer tramp-current-multi-method tramp-current-method
4684 tramp-current-user tramp-current-host
)
4685 (point-min) (point-max))
4689 (tramp-get-debug-buffer tramp-current-multi-method tramp-current-method
4690 tramp-current-user tramp-current-host
))
4691 (goto-char (point-max))
4692 (insert "[[Remote prompt `" end-of-output
"' not found"
4693 (if timeout
(format " in %d secs" timeout
) "")
4695 (goto-char (point-min))
4696 ;; Return value is whether end-of-output sentinel was found.
4699 (defun tramp-match-string-list (&optional string
)
4700 "Returns list of all match strings.
4701 That is, (list (match-string 0) (match-string 1) ...), according to the
4703 (let* ((nmatches (/ (length (match-data)) 2))
4707 (setq res
(cons (match-string i string
) res
))
4711 (defun tramp-send-command-and-check (multi-method method user host command
4713 "Run COMMAND and check its exit status.
4714 MULTI-METHOD and METHOD specify how to log in (as USER) to the remote HOST.
4715 Sends `echo $?' along with the COMMAND for checking the exit status. If
4716 COMMAND is nil, just sends `echo $?'. Returns the exit status found.
4718 If the optional argument SUBSHELL is non-nil, the command is executed in
4719 a subshell, ie surrounded by parentheses."
4720 (tramp-send-command multi-method method user host
4721 (concat (if subshell
"( " "")
4723 (if command
" 2>/dev/null; " "")
4724 "echo tramp_exit_status $?"
4725 (if subshell
" )" " ")))
4726 (tramp-wait-for-output)
4727 (goto-char (point-max))
4728 (unless (search-backward "tramp_exit_status " nil t
)
4729 (error "Couldn't find exit status of `%s'" command
))
4730 (skip-chars-forward "^ ")
4731 (read (current-buffer)))
4733 (defun tramp-barf-unless-okay (multi-method method user host command subshell
4734 signal fmt
&rest args
)
4735 "Run COMMAND, check exit status, throw error if exit status not okay.
4736 Similar to `tramp-send-command-and-check' but accepts two more arguments
4737 FMT and ARGS which are passed to `error'."
4738 (unless (zerop (tramp-send-command-and-check
4739 multi-method method user host command subshell
))
4740 ;; CCC: really pop-to-buffer? Maybe it's appropriate to be more
4742 (pop-to-buffer (current-buffer))
4743 (funcall 'signal signal
(apply 'format fmt args
))))
4745 (defun tramp-send-region (multi-method method user host start end
)
4746 "Send the region from START to END to remote command
4747 running as USER on HOST using METHOD."
4748 (let ((proc (get-buffer-process
4749 (tramp-get-buffer multi-method method user host
))))
4751 (error "Can't send region to remote host -- not logged in"))
4752 (process-send-region proc start end
)
4753 (when tramp-debug-buffer
4755 (tramp-get-debug-buffer multi-method method user host
)
4758 (defun tramp-send-eof (multi-method method user host
)
4759 "Send EOF to the remote end.
4760 METHOD, HOST and USER specify the connection."
4761 (let ((proc (get-buffer-process
4762 (tramp-get-buffer multi-method method user host
))))
4764 (error "Can't send EOF to remote host -- not logged in"))
4765 (process-send-eof proc
)))
4766 ; (process-send-string proc "\^D")))
4768 (defun tramp-kill-process (multi-method method user host
)
4769 "Kill the connection process used by Tramp.
4770 MULTI-METHOD, METHOD, USER, and HOST specify the connection."
4771 (let ((proc (get-buffer-process
4772 (tramp-get-buffer multi-method method user host
))))
4773 (kill-process proc
)))
4775 (defun tramp-discard-garbage-erase-buffer (p multi-method method user host
)
4776 "Erase buffer, then discard subsequent garbage.
4777 If `tramp-discard-garbage' is nil, just erase buffer."
4778 (if (not tramp-discard-garbage
)
4780 (while (prog1 (erase-buffer) (accept-process-output p
0.25))
4781 (when tramp-debug-buffer
4783 (set-buffer (tramp-get-debug-buffer multi-method method user host
))
4784 (goto-char (point-max))
4785 (tramp-insert-with-face
4786 'bold
(format "Additional characters detected\n")))))))
4788 (defun tramp-mode-string-to-int (mode-string)
4789 "Converts a ten-letter `drwxrwxrwx'-style mode string into mode bits."
4790 (let* ((mode-chars (string-to-vector mode-string
))
4791 (owner-read (aref mode-chars
1))
4792 (owner-write (aref mode-chars
2))
4793 (owner-execute-or-setid (aref mode-chars
3))
4794 (group-read (aref mode-chars
4))
4795 (group-write (aref mode-chars
5))
4796 (group-execute-or-setid (aref mode-chars
6))
4797 (other-read (aref mode-chars
7))
4798 (other-write (aref mode-chars
8))
4799 (other-execute-or-sticky (aref mode-chars
9)))
4803 (?r
(tramp-octal-to-decimal "00400")) (?-
0)
4804 (t (error "Second char `%c' must be one of `r-'" owner-read
)))
4806 (?w
(tramp-octal-to-decimal "00200")) (?-
0)
4807 (t (error "Third char `%c' must be one of `w-'" owner-write
)))
4808 (case owner-execute-or-setid
4809 (?x
(tramp-octal-to-decimal "00100"))
4810 (?S
(tramp-octal-to-decimal "04000"))
4811 (?s
(tramp-octal-to-decimal "04100"))
4813 (t (error "Fourth char `%c' must be one of `xsS-'"
4814 owner-execute-or-setid
)))
4816 (?r
(tramp-octal-to-decimal "00040")) (?-
0)
4817 (t (error "Fifth char `%c' must be one of `r-'" group-read
)))
4819 (?w
(tramp-octal-to-decimal "00020")) (?-
0)
4820 (t (error "Sixth char `%c' must be one of `w-'" group-write
)))
4821 (case group-execute-or-setid
4822 (?x
(tramp-octal-to-decimal "00010"))
4823 (?S
(tramp-octal-to-decimal "02000"))
4824 (?s
(tramp-octal-to-decimal "02010"))
4826 (t (error "Seventh char `%c' must be one of `xsS-'"
4827 group-execute-or-setid
)))
4829 (?r
(tramp-octal-to-decimal "00004")) (?-
0)
4830 (t (error "Eighth char `%c' must be one of `r-'" other-read
)))
4832 (?w
(tramp-octal-to-decimal "00002")) (?-
0)
4833 (t (error "Nineth char `%c' must be one of `w-'" other-write
)))
4834 (case other-execute-or-sticky
4835 (?x
(tramp-octal-to-decimal "00001"))
4836 (?T
(tramp-octal-to-decimal "01000"))
4837 (?t
(tramp-octal-to-decimal "01001"))
4839 (t (error "Tenth char `%c' must be one of `xtT-'"
4840 other-execute-or-sticky
)))))))
4843 (defun tramp-file-mode-from-int (mode)
4844 "Turn an integer representing a file mode into an ls(1)-like string."
4845 (let ((type (cdr (assoc (logand (lsh mode -
12) 15) tramp-file-mode-type-map
)))
4846 (user (logand (lsh mode -
6) 7))
4847 (group (logand (lsh mode -
3) 7))
4848 (other (logand (lsh mode -
0) 7))
4849 (suid (> (logand (lsh mode -
9) 4) 0))
4850 (sgid (> (logand (lsh mode -
9) 2) 0))
4851 (sticky (> (logand (lsh mode -
9) 1) 0)))
4852 (setq user
(tramp-file-mode-permissions user suid
"s"))
4853 (setq group
(tramp-file-mode-permissions group sgid
"s"))
4854 (setq other
(tramp-file-mode-permissions other sticky
"t"))
4855 (concat type user group other
)))
4858 (defun tramp-file-mode-permissions (perm suid suid-text
)
4859 "Convert a permission bitset into a string.
4860 This is used internally by `tramp-file-mode-from-int'."
4861 (let ((r (> (logand perm
4) 0))
4862 (w (> (logand perm
2) 0))
4863 (x (> (logand perm
1) 0)))
4864 (concat (or (and r
"r") "-")
4865 (or (and w
"w") "-")
4866 (or (and suid x suid-text
) ; suid, execute
4867 (and suid
(upcase suid-text
)) ; suid, !execute
4868 (and x
"x") "-")))) ; !suid
4871 (defun tramp-decimal-to-octal (i)
4872 "Return a string consisting of the octal digits of I.
4873 Not actually used. Use `(format \"%o\" i)' instead?"
4874 (cond ((< i
0) (error "Cannot convert negative number to octal"))
4875 ((not (integerp i
)) (error "Cannot convert non-integer to octal"))
4877 (t (concat (tramp-decimal-to-octal (/ i
8))
4878 (number-to-string (% i
8))))))
4881 ;;(defun tramp-octal-to-decimal (ostr)
4882 ;; "Given a string of octal digits, return a decimal number."
4883 ;; (cond ((null ostr) 0)
4884 ;; ((string= "" ostr) 0)
4885 ;; (t (let ((last (aref ostr (1- (length ostr))))
4886 ;; (rest (substring ostr 0 (1- (length ostr)))))
4887 ;; (unless (and (>= last ?0)
4889 ;; (error "Not an octal digit: %c" last))
4890 ;; (+ (- last ?0) (* 8 (tramp-octal-to-decimal rest)))))))
4891 ;; Kudos to Gerd Moellmann for this suggestion.
4892 (defun tramp-octal-to-decimal (ostr)
4893 "Given a string of octal digits, return a decimal number."
4894 (let ((x (or ostr
"")))
4895 ;; `save-match' is in `tramp-mode-string-to-int' which calls this.
4896 (unless (string-match "\\`[0-7]*\\'" x
)
4897 (error "Non-octal junk in string `%s'" x
))
4898 (string-to-number ostr
8)))
4900 (defun tramp-shell-case-fold (string)
4901 "Converts STRING to shell glob pattern which ignores case."
4904 (if (equal (downcase c
) (upcase c
))
4906 (format "[%c%c]" (downcase c
) (upcase c
))))
4911 ;; ------------------------------------------------------------
4912 ;; -- TRAMP file names --
4913 ;; ------------------------------------------------------------
4914 ;; Conversion functions between external representation and
4915 ;; internal data structure. Convenience functions for internal
4918 (defstruct tramp-file-name multi-method method user host path
)
4920 (defun tramp-tramp-file-p (name)
4921 "Return t iff NAME is a tramp file."
4923 (string-match tramp-file-name-regexp name
)))
4925 ;; HHH: Changed. Used to assign the return value of (user-login-name)
4926 ;; to the `user' part of the structure if a user name was not
4927 ;; provided, now it assigns nil.
4928 (defun tramp-dissect-file-name (name)
4929 "Return an `tramp-file-name' structure.
4930 The structure consists of remote method, remote user, remote host and
4934 (unless (string-match (nth 0 tramp-file-name-structure
) name
)
4935 (error "Not a tramp file name: %s" name
))
4936 (setq method
(match-string (nth 1 tramp-file-name-structure
) name
))
4937 (if (and method
(member method tramp-multi-methods
))
4938 ;; If it's a multi method, the file name structure contains
4939 ;; arrays of method, user and host.
4940 (tramp-dissect-multi-file-name name
)
4941 ;; Normal method. First, find out default method.
4942 (let ((user (match-string (nth 2 tramp-file-name-structure
) name
))
4943 (host (match-string (nth 3 tramp-file-name-structure
) name
))
4944 (path (match-string (nth 4 tramp-file-name-structure
) name
)))
4946 (setq method
(tramp-find-default-method user host
)))
4947 (make-tramp-file-name
4954 (defun tramp-find-default-method (user host
)
4955 "Look up the right method to use in `tramp-default-method-alist'."
4956 (let ((choices tramp-default-method-alist
)
4957 (method tramp-default-method
)
4960 (setq item
(pop choices
))
4961 (when (and (string-match (nth 0 item
) host
)
4962 (string-match (nth 1 item
) (or user
"")))
4963 (setq method
(nth 2 item
))
4964 (setq choices nil
)))
4967 ;; HHH: Not Changed. Multi method. Will probably not handle the case where
4968 ;; a user name is not provided in the "file name" very well.
4969 (defun tramp-dissect-multi-file-name (name)
4970 "Not implemented yet."
4971 (let ((regexp (nth 0 tramp-multi-file-name-structure
))
4972 (method-index (nth 1 tramp-multi-file-name-structure
))
4973 (hops-index (nth 2 tramp-multi-file-name-structure
))
4974 (path-index (nth 3 tramp-multi-file-name-structure
))
4975 (hop-regexp (nth 0 tramp-multi-file-name-hop-structure
))
4976 (hop-method-index (nth 1 tramp-multi-file-name-hop-structure
))
4977 (hop-user-index (nth 2 tramp-multi-file-name-hop-structure
))
4978 (hop-host-index (nth 3 tramp-multi-file-name-hop-structure
))
4979 method hops len hop-methods hop-users hop-hosts path
)
4980 (unless (string-match (format regexp hop-regexp
) name
)
4981 (error "Not a multi tramp file name: %s" name
))
4982 (setq method
(match-string method-index name
))
4983 (setq hops
(match-string hops-index name
))
4984 (setq len
(/ (length (match-data t
)) 2))
4985 (when (< path-index
0) (incf path-index len
))
4986 (setq path
(match-string path-index name
))
4988 (while (string-match hop-regexp hops index
)
4989 (setq index
(match-end 0))
4991 (cons (match-string hop-method-index hops
) hop-methods
))
4993 (cons (match-string hop-user-index hops
) hop-users
))
4995 (cons (match-string hop-host-index hops
) hop-hosts
))))
4996 (make-tramp-file-name
4997 :multi-method method
4998 :method
(apply 'vector
(reverse hop-methods
))
4999 :user
(apply 'vector
(reverse hop-users
))
5000 :host
(apply 'vector
(reverse hop-hosts
))
5003 (defun tramp-make-tramp-file-name (multi-method method user host path
)
5004 "Constructs a tramp file name from METHOD, USER, HOST and PATH."
5005 (unless tramp-make-tramp-file-format
5006 (error "`tramp-make-tramp-file-format' is nil"))
5008 (tramp-make-tramp-multi-file-name multi-method method user host path
)
5010 (format-spec tramp-make-tramp-file-format
5011 `((?m .
,method
) (?u .
,user
) (?h .
,host
) (?p .
,path
)))
5012 (format-spec tramp-make-tramp-file-user-nil-format
5013 `((?m .
,method
) (?h .
,host
) (?p .
,path
))))))
5015 ;; CCC: Henrik Holm: Not Changed. Multi Method. What should be done
5016 ;; with this when USER is nil?
5017 (defun tramp-make-tramp-multi-file-name (multi-method method user host path
)
5018 "Constructs a tramp file name for a multi-hop method."
5019 (unless tramp-make-multi-tramp-file-format
5020 (error "`tramp-make-multi-tramp-file-format' is nil"))
5021 (let* ((prefix-format (nth 0 tramp-make-multi-tramp-file-format
))
5022 (hop-format (nth 1 tramp-make-multi-tramp-file-format
))
5023 (path-format (nth 2 tramp-make-multi-tramp-file-format
))
5024 (prefix (format-spec prefix-format
`((?m .
,multi-method
))))
5026 (path (format-spec path-format
`((?p .
,path
))))
5028 (len (length method
)))
5030 (let ((m (aref method i
)) (u (aref user i
)) (h (aref host i
)))
5031 (setq hops
(concat hops
(format-spec hop-format
5032 `((?m .
,m
) (?u .
,u
) (?h .
,h
)))))
5034 (concat prefix hops path
)))
5036 (defun tramp-make-rcp-program-file-name (user host path
)
5037 "Create a file name suitable to be passed to `rcp'."
5039 (format "%s@%s:%s" user host path
)
5040 (format "%s:%s" host path
)))
5042 (defun tramp-make-ange-ftp-file-name (user host path
)
5043 "Given user, host, and path, return an Ange-FTP filename."
5045 (format "/%s@%s:%s" user host path
)
5046 (format "/%s:%s" host path
)))
5048 (defun tramp-method-out-of-band-p (multi-method method
)
5049 "Return t if this is an out-of-band method, nil otherwise.
5050 It is important to check for this condition, since it is not possible
5051 to enter a password for the `tramp-rcp-program'."
5052 (tramp-get-rcp-program multi-method method
))
5054 ;; Variables local to connection.
5056 (defun tramp-get-ls-command (multi-method method user host
)
5058 (tramp-maybe-open-connection multi-method method user host
)
5059 (set-buffer (tramp-get-buffer multi-method method user host
))
5062 (defun tramp-get-test-groks-nt (multi-method method user host
)
5064 (tramp-maybe-open-connection multi-method method user host
)
5065 (set-buffer (tramp-get-buffer multi-method method user host
))
5066 tramp-test-groks-nt
))
5068 (defun tramp-get-file-exists-command (multi-method method user host
)
5070 (tramp-maybe-open-connection multi-method method user host
)
5071 (set-buffer (tramp-get-buffer multi-method method user host
))
5072 tramp-file-exists-command
))
5074 (defun tramp-get-remote-perl (multi-method method user host
)
5075 (tramp-get-connection-property "perl" nil multi-method method user host
))
5077 (defun tramp-get-remote-ln (multi-method method user host
)
5078 (tramp-get-connection-property "ln" nil multi-method method user host
))
5080 ;; Get a property of a TRAMP connection.
5081 (defun tramp-get-connection-property
5082 (property default multi-method method user host
)
5083 "Get the named property for the connection.
5084 If the value is not set for the connection, return `default'"
5085 (tramp-maybe-open-connection multi-method method user host
)
5086 (with-current-buffer (tramp-get-buffer multi-method method user host
)
5089 (symbol-value (intern (concat "tramp-connection-property-" property
)))
5092 ;; Set a property of a TRAMP connection.
5093 (defun tramp-set-connection-property
5094 (property value multi-method method user host
)
5095 "Set the named property of a TRAMP connection."
5096 (tramp-maybe-open-connection multi-method method user host
)
5097 (with-current-buffer (tramp-get-buffer multi-method method user host
)
5098 (set (make-local-variable
5099 (intern (concat "tramp-connection-property-" property
)))
5102 ;; Some predefined connection properties.
5103 (defun tramp-get-encoding-command (multi-method method user host
)
5104 (tramp-get-connection-property "encoding-command" nil
5105 multi-method method user host
))
5106 (defun tramp-set-encoding-command (multi-method method user host command
)
5107 (tramp-set-connection-property "encoding-command" command
5108 multi-method method user host
))
5109 (defun tramp-get-decoding-command (multi-method method user host
)
5110 (tramp-get-connection-property "decoding-command" nil
5111 multi-method method user host
))
5112 (defun tramp-set-decoding-command (multi-method method user host command
)
5113 (tramp-set-connection-property "decoding-command" command
5114 multi-method method user host
))
5115 (defun tramp-get-encoding-function (multi-method method user host
)
5116 (tramp-get-connection-property "encoding-function" nil
5117 multi-method method user host
))
5118 (defun tramp-set-encoding-function (multi-method method user host func
)
5119 (tramp-set-connection-property "encoding-function" func
5120 multi-method method user host
))
5121 (defun tramp-get-decoding-function (multi-method method user host
)
5122 (tramp-get-connection-property "decoding-function" nil
5123 multi-method method user host
))
5124 (defun tramp-set-decoding-function (multi-method method user host func
)
5125 (tramp-set-connection-property "decoding-function" func
5126 multi-method method user host
))
5129 (defun tramp-get-connection-function (multi-method method
)
5130 (second (or (assoc 'tramp-connection-function
5131 (assoc (or multi-method method tramp-default-method
)
5133 (error "Method `%s' didn't specify a connection function"
5134 (or multi-method method
)))))
5136 (defun tramp-get-remote-sh (multi-method method
)
5137 (second (or (assoc 'tramp-remote-sh
5138 (assoc (or multi-method method tramp-default-method
)
5140 (error "Method `%s' didn't specify a remote shell"
5141 (or multi-method method
)))))
5143 (defun tramp-get-rsh-program (multi-method method
)
5144 (second (or (assoc 'tramp-rsh-program
5145 (assoc (or multi-method method tramp-default-method
)
5147 (error "Method `%s' didn't specify an rsh program"
5148 (or multi-method method
)))))
5150 (defun tramp-get-rsh-args (multi-method method
)
5151 (second (or (assoc 'tramp-rsh-args
5152 (assoc (or multi-method method tramp-default-method
)
5154 (error "Method `%s' didn't specify rsh args"
5155 (or multi-method method
)))))
5157 (defun tramp-get-rcp-program (multi-method method
)
5158 (second (or (assoc 'tramp-rcp-program
5159 (assoc (or multi-method method tramp-default-method
)
5161 (error "Method `%s' didn't specify an rcp program"
5162 (or multi-method method
)))))
5164 (defun tramp-get-rcp-args (multi-method method
)
5165 (second (or (assoc 'tramp-rcp-args
5166 (assoc (or multi-method method tramp-default-method
)
5168 (error "Method `%s' didn't specify rcp args"
5169 (or multi-method method
)))))
5171 (defun tramp-get-rcp-keep-date-arg (multi-method method
)
5172 (second (or (assoc 'tramp-rcp-keep-date-arg
5173 (assoc (or multi-method method tramp-default-method
)
5175 (error "Method `%s' didn't specify `keep-date' arg for tramp"
5176 (or multi-method method
)))))
5178 (defun tramp-get-su-program (multi-method method
)
5179 (second (or (assoc 'tramp-su-program
5180 (assoc (or multi-method method tramp-default-method
)
5182 (error "Method `%s' didn't specify a su program"
5183 (or multi-method method
)))))
5185 (defun tramp-get-su-args (multi-method method
)
5186 (second (or (assoc 'tramp-su-args
5187 (assoc (or multi-method method tramp-default-method
)
5189 (error "Method `%s' didn't specify su args"
5190 (or multi-method method
)))))
5192 (defun tramp-get-telnet-program (multi-method method
)
5193 (second (or (assoc 'tramp-telnet-program
5194 (assoc (or multi-method method tramp-default-method
)
5196 (error "Method `%s' didn't specify a telnet program"
5197 (or multi-method method
)))))
5199 (defun tramp-get-telnet-args (multi-method method
)
5200 (second (or (assoc 'tramp-telnet-args
5201 (assoc (or multi-method method tramp-default-method
)
5203 (error "Method `%s' didn't specify telnet args"
5204 (or multi-method method
)))))
5206 ;; (defun tramp-get-encoding-command (multi-method method)
5207 ;; (second (or (assoc 'tramp-encoding-command
5208 ;; (assoc (or multi-method method tramp-default-method)
5210 ;; (error "Method `%s' didn't specify an encoding command"
5211 ;; (or multi-method method)))))
5213 ;; (defun tramp-get-decoding-command (multi-method method)
5214 ;; (second (or (assoc 'tramp-decoding-command
5215 ;; (assoc (or multi-method method tramp-default-method)
5217 ;; (error "Method `%s' didn't specify a decoding command"
5218 ;; (or multi-method method)))))
5220 ;; (defun tramp-get-encoding-function (multi-method method)
5221 ;; (second (or (assoc 'tramp-encoding-function
5222 ;; (assoc (or multi-method method tramp-default-method)
5224 ;; (error "Method `%s' didn't specify an encoding function"
5225 ;; (or multi-method method)))))
5227 ;; (defun tramp-get-decoding-function (multi-method method)
5228 ;; (second (or (assoc 'tramp-decoding-function
5229 ;; (assoc (or multi-method method tramp-default-method)
5231 ;; (error "Method `%s' didn't specify a decoding function"
5232 ;; (or multi-method method)))))
5234 ;; Auto saving to a special directory.
5236 (defun tramp-make-auto-save-file-name (fn)
5237 "Returns a file name in `tramp-auto-save-directory' for autosaving this file."
5238 (when tramp-auto-save-directory
5239 (unless (file-exists-p tramp-auto-save-directory
)
5240 (make-directory tramp-auto-save-directory t
)))
5241 ;; jka-compr doesn't like auto-saving, so by appending "~" to the
5242 ;; file name we make sure that jka-compr isn't used for the
5244 (let ((buffer-file-name (expand-file-name
5245 (tramp-subst-strs-in-string '(("_" .
"|")
5252 tramp-auto-save-directory
)))
5253 (make-auto-save-file-name)))
5255 (defadvice make-auto-save-file-name
5256 (around tramp-advice-make-auto-save-file-name
() activate
)
5257 "Invoke `tramp-make-auto-save-file-name' for tramp files."
5258 (if (and (buffer-file-name) (tramp-tramp-file-p (buffer-file-name))
5259 tramp-auto-save-directory
)
5260 (setq ad-return-value
5261 (tramp-make-auto-save-file-name (buffer-file-name)))
5264 (defun tramp-subst-strs-in-string (alist string
)
5265 "Replace all occurrences of the string FROM with TO in STRING.
5266 ALIST is of the form ((FROM . TO) ...)."
5269 (let* ((pr (car alist
))
5272 (while (string-match (regexp-quote from
) string
)
5273 (setq string
(replace-match to t t string
)))
5274 (setq alist
(cdr alist
))))
5277 (defun tramp-insert-with-face (face string
)
5278 "Insert text with a specific face."
5279 (let ((start (point)))
5281 (add-text-properties start
(point) (list 'face face
))))
5283 ;; ------------------------------------------------------------
5284 ;; -- Compatibility functions section --
5285 ;; ------------------------------------------------------------
5287 (defun tramp-temporary-file-directory ()
5288 "Return name of directory for temporary files (compat function).
5289 For Emacs, this is the variable `temporary-file-directory', for XEmacs
5290 this is the function `temp-directory'."
5291 (cond ((boundp 'temporary-file-directory
)
5292 (symbol-value 'temporary-file-directory
))
5293 ((fboundp 'temp-directory
)
5294 (funcall (symbol-function 'temp-directory
))) ;pacify byte-compiler
5295 ((let ((d (getenv "TEMP"))) (and d
(file-directory-p d
)))
5296 (file-name-as-directory (getenv "TEMP")))
5297 ((let ((d (getenv "TMP"))) (and d
(file-directory-p d
)))
5298 (file-name-as-directory (getenv "TMP")))
5299 ((let ((d (getenv "TMPDIR"))) (and d
(file-directory-p d
)))
5300 (file-name-as-directory (getenv "TMPDIR")))
5301 ((file-exists-p "c:/temp") (file-name-as-directory "c:/temp"))
5302 (t (message (concat "Neither `temporary-file-directory' nor "
5303 "`temp-directory' is defined -- using /tmp."))
5304 (file-name-as-directory "/tmp"))))
5306 (defun tramp-read-passwd (prompt)
5307 "Read a password from user (compat function).
5308 Invokes `read-passwd' if that is defined, else `ange-ftp-read-passwd'."
5310 (if (fboundp 'read-passwd
) #'read-passwd
#'ange-ftp-read-passwd
)
5313 (defun tramp-time-diff (t1 t2
)
5314 "Return the difference between the two times, in seconds.
5315 T1 and T2 are time values (as returned by `current-time' for example).
5317 NOTE: This function will fail if the time difference is too large to
5319 ;; Pacify byte-compiler with `symbol-function'.
5320 (cond ((fboundp 'subtract-time
)
5321 (cadr (funcall (symbol-function 'subtract-time
) t1 t2
)))
5322 ((fboundp 'itimer-time-difference
)
5324 (symbol-function 'itimer-time-difference
)
5325 (if (< (length t1
) 3) (append t1
'(0)) t1
)
5326 (if (< (length t2
) 3) (append t2
'(0)) t2
))))
5328 ;; snarfed from Emacs 21 time-date.el
5329 (cadr (let ((borrow (< (cadr t1
) (cadr t2
))))
5330 (list (- (car t1
) (car t2
) (if borrow
1 0))
5331 (- (+ (if borrow
65536 0) (cadr t1
)) (cadr t2
))))))))
5333 (defun tramp-coding-system-change-eol-conversion (coding-system eol-type
)
5334 "Return a coding system like CODING-SYSTEM but with given EOL-TYPE.
5335 EOL-TYPE can be one of `dos', `unix', or `mac'."
5336 (cond ((fboundp 'coding-system-change-eol-conversion
)
5337 (apply #'coding-system-change-eol-conversion
5338 (list coding-system eol-type
)))
5339 ((fboundp 'subsidiary-coding-system
)
5341 #'subsidiary-coding-system
5343 (cond ((eq eol-type
'dos
) 'crlf
)
5344 ((eq eol-type
'unix
) 'lf
)
5345 ((eq eol-type
'mac
) 'cr
)
5347 (error "Unknown EOL-TYPE `%s', must be %s"
5349 "`dos', `unix', or `mac'"))))))
5350 (t (error "Can't change EOL conversion -- is MULE missing?"))))
5352 (defun tramp-split-string (string pattern
)
5353 "Like `split-string' but omit empty strings.
5354 In Emacs, (split-string \"/foo/bar\" \"/\") returns (\"foo\" \"bar\").
5355 This is, the first, empty, element is omitted. In XEmacs, the first
5356 element is not omitted.
5358 Note: this function has been written for `tramp-handle-file-truename'.
5359 If you want to use it for something else, you'll have to check whether
5360 it does the right thing."
5361 (delete "" (split-string string pattern
)))
5363 ;; ------------------------------------------------------------
5364 ;; -- Kludges section --
5365 ;; ------------------------------------------------------------
5367 ;; Currently (as of Emacs 20.5), the function `shell-quote-argument'
5368 ;; does not deal well with newline characters. Newline is replaced by
5369 ;; backslash newline. But if, say, the string `a backslash newline b'
5370 ;; is passed to a shell, the shell will expand this into "ab",
5371 ;; completely omitting the newline. This is not what was intended.
5372 ;; It does not appear to be possible to make the function
5373 ;; `shell-quote-argument' work with newlines without making it
5374 ;; dependent on the shell used. But within this package, we know that
5375 ;; we will always use a Bourne-like shell, so we use an approach which
5378 ;; The approach is simple: we call `shell-quote-argument', then
5379 ;; massage the newline part of the result.
5381 ;; This function should produce a string which is grokked by a Unix
5382 ;; shell, even if the Emacs is running on Windows. Since this is the
5383 ;; kludges section, we bind `system-type' in such a way that
5384 ;; `shell-quote-arguments' behaves as if on Unix.
5386 ;; Thanks to Mario DeWeerd for the hint that it is sufficient for this
5387 ;; function to work with Bourne-like shells.
5389 ;; CCC: This function should be rewritten so that
5390 ;; `shell-quote-argument' is not used. This way, we are safe from
5391 ;; changes in `shell-quote-argument'.
5392 (defun tramp-shell-quote-argument (s)
5393 "Similar to `shell-quote-argument', but groks newlines.
5394 Only works for Bourne-like shells."
5395 (let ((system-type 'not-windows
))
5397 (let ((result (shell-quote-argument s
))
5398 (nl (regexp-quote (format "\\%s" tramp-rsh-end-of-line
))))
5399 (when (and (>= (length result
) 2)
5400 (string= (substring result
0 2) "\\~"))
5401 (setq result
(substring result
1)))
5402 (while (string-match nl result
)
5403 (setq result
(replace-match (format "'%s'" tramp-rsh-end-of-line
)
5407 ;; ;; EFS hooks itself into the file name handling stuff in more places
5408 ;; ;; than just `file-name-handler-alist'. The following tells EFS to stay
5409 ;; ;; away from tramp.el paths.
5411 ;; ;; This is needed because EFS installs (efs-dired-before-readin) into
5412 ;; ;; 'dired-before-readin-hook'. This prevents EFS from opening an FTP
5413 ;; ;; connection to help it's dired process. Not that I have any real
5414 ;; ;; idea *why* this is helpful to dired.
5416 ;; ;; Anyway, this advice fixes the problem (with a sledgehammer :)
5418 ;; ;; Daniel Pittman <daniel@danann.net>
5420 ;; ;; CCC: when the other defadvice calls have disappeared, make sure
5421 ;; ;; not to call defadvice unless it's necessary. How do we find out whether
5422 ;; ;; it is necessary? (featurep 'efs) is surely the wrong way --
5423 ;; ;; EFS might nicht be loaded yet.
5424 ;; (defadvice efs-ftp-path (around dont-match-tramp-path activate protect)
5425 ;; "Cause efs-ftp-path to fail when the path is a TRAMP path."
5426 ;; (if (tramp-tramp-file-p (ad-get-arg 0))
5430 ;; We currently use "[" and "]" in the filename format. In Emacs
5431 ;; 20.x, this means that Emacs wants to expand wildcards if
5432 ;; `find-file-wildcards' is non-nil, and then barfs because no
5433 ;; expansion could be found. We detect this situation and do
5434 ;; something really awful: we have `file-expand-wildcards' return the
5435 ;; original filename if it can't expand anything. Let's just hope
5436 ;; that this doesn't break anything else.
5438 ;; Another problem is that the check is done by Emacs version, which
5439 ;; is really not what we want to do. Oh, well.
5441 ;;(when (and (not (featurep 'xemacs))
5442 ;; (= emacs-major-version 20))
5443 ;; It seems that this advice is needed in Emacs 21, too.
5444 (defadvice file-expand-wildcards
(around tramp-fix activate
)
5445 (let ((name (ad-get-arg 0)))
5446 (if (tramp-tramp-file-p name
)
5447 ;; If it's a Tramp file, dissect it and look if wildcards
5448 ;; need to be expanded at all.
5449 (let ((v (tramp-dissect-file-name name
)))
5450 (if (string-match "[[*?]" (tramp-file-name-path v
))
5451 (let ((res ad-do-it
))
5452 (setq ad-return-value
(or res
(list name
))))
5453 (setq ad-return-value
(list name
))))
5454 ;; If it is not a Tramp file, just run the original function.
5455 (let ((res ad-do-it
))
5456 (setq ad-return-value
(or res
(list name
)))))))
5459 ;; Tramp version is useful in a number of situations.
5461 (defun tramp-version (arg)
5462 "Print version number of tramp.el in minibuffer or current buffer."
5464 (if arg
(insert tramp-version
) (message tramp-version
)))
5466 ;; Make the `reporter` functionality available for making bug reports about
5467 ;; the package. A most useful piece of code.
5469 (unless (fboundp 'reporter-submit-bug-report
)
5470 (autoload 'reporter-submit-bug-report
"reporter"))
5473 "Submit a bug report to the TRAMP developers."
5476 (let ((reporter-prompt-for-summary-p t
))
5477 (reporter-submit-bug-report
5478 tramp-bug-report-address
; to-address
5479 (format "tramp (%s)" tramp-version
) ; package name and version
5483 tramp-file-exists-command
5484 tramp-current-multi-method
5485 tramp-current-method
5490 tramp-auto-save-directory
; vars to dump
5491 tramp-default-method
5492 tramp-rsh-end-of-line
5494 tramp-login-prompt-regexp
5495 tramp-password-prompt-regexp
5496 tramp-wrong-passwd-regexp
5497 tramp-temp-name-prefix
5498 tramp-file-name-structure
5499 tramp-file-name-regexp
5500 tramp-multi-file-name-structure
5501 tramp-multi-file-name-hop-structure
5503 tramp-multi-connection-function-alist
5504 tramp-make-tramp-file-format
5507 ;; Non-tramp variables of interest
5508 shell-prompt-pattern
5510 backup-by-copying-when-linked
5511 backup-by-copying-when-mismatch
5512 ,(when (boundp 'backup-by-copying-when-privileged-mismatch
)
5513 'backup-by-copying-when-privileged-mismatch
)
5514 file-name-handler-alist
)
5518 Enter your bug report in this message, including as much detail as you
5519 possibly can about the problem, what you did to cause it and what the
5520 local and remote machines are.
5522 If you can give a simple set of instructions to make this bug happen
5523 reliably, please include those. Thank you for helping kill bugs in
5525 --bug report follows this line--")))
5527 (defalias 'tramp-submit-bug
'tramp-bug
)
5531 ;; Make sure that we get integration with the VC package.
5532 ;; When it is loaded, we need to pull in the integration module.
5533 ;; This must come after (provide 'tramp) because tramp-vc.el
5535 (eval-after-load "vc"
5536 '(require 'tramp-vc
))
5540 ;; * Revise the comments near the beginning of the file.
5541 ;; * Cooperate with PCL-CVS. It uses start-process, which doesn't
5542 ;; work for remote files.
5543 ;; * Rewrite `tramp-shell-quote-argument' to abstain from using
5544 ;; `shell-quote-argument'.
5545 ;; * Completion gets confused when you leave out the method name.
5546 ;; * Support `dired-compress-file' filename handler.
5547 ;; * In Emacs 21, `insert-directory' shows total number of bytes used
5548 ;; by the files in that directory. Add this here.
5549 ;; * Avoid screen blanking when hitting `g' in dired. (Eli Tziperman)
5550 ;; * Make ffap.el grok Tramp filenames. (Eli Tziperman)
5551 ;; * When logging in, keep looking for questions according to an alist
5552 ;; and then invoke the right function.
5553 ;; * Case-insensitive filename completion. (Norbert Goevert.)
5554 ;; * Running CVS remotely doesn't appear to work right. It thinks
5555 ;; files are locked by somebody else even if I'm the locking user.
5556 ;; Sometimes, one gets `No CVSROOT specified' errors from CVS.
5558 ;; * Don't use globbing for directories with many files, as this is
5559 ;; likely to produce long command lines, and some shells choke on
5560 ;; long command lines.
5561 ;; * Find out about the new auto-save mechanism in Emacs 21 and
5562 ;; do the right thing.
5563 ;; * `vc-directory' does not work. It never displays any files, even
5564 ;; if it does show files when run locally.
5565 ;; * Allow correction of passwords, if the remote end allows this.
5566 ;; (Mark Hershberger)
5567 ;; * Make sure permissions of tmp file are good.
5568 ;; (Nelson Minar <nelson@media.mit.edu>)
5569 ;; * Grok passwd prompts with scp? (David Winter
5570 ;; <winter@nevis1.nevis.columbia.edu>). Maybe just do `ssh -l user
5571 ;; host', then wait a while for the passwd or passphrase prompt. If
5572 ;; there is one, remember the passwd/phrase.
5573 ;; * How to deal with MULE in `insert-file-contents' and `write-region'?
5574 ;; * Do asynchronous `shell-command's.
5575 ;; * Grok `append' parameter for `write-region'.
5576 ;; * Test remote ksh or bash for tilde expansion in `tramp-find-shell'?
5577 ;; * abbreviate-file-name
5578 ;; * grok ~ in tramp-remote-path (Henrik Holm <henrikh@tele.ntnu.no>)
5579 ;; * `C' in dired gives error `not tramp file name'.
5580 ;; * Also allow to omit user names when doing multi-hop. Not sure yet
5581 ;; what the user names should default to, though.
5582 ;; * better error checking. At least whenever we see something
5583 ;; strange when doing zerop, we should kill the process and start
5584 ;; again. (Greg Stark)
5585 ;; * Add caching for filename completion. (Greg Stark)
5586 ;; Of course, this has issues with usability (stale cache bites)
5587 ;; -- <daniel@danann.net>
5588 ;; * Provide a local cache of old versions of remote files for the rsync
5589 ;; transfer method to use. (Greg Stark)
5590 ;; * Remove unneeded parameters from methods.
5591 ;; * Invoke rsync once for copying a whole directory hierarchy.
5592 ;; (Francesco Potortì)
5593 ;; * Should we set PATH ourselves or should we rely on the remote end
5595 ;; * Do the autoconf thing.
5596 ;; * Make it work for XEmacs 20, which is missing `with-timeout'.
5597 ;; * Allow non-Unix remote systems. (More a long-term thing.)
5598 ;; * Make it work for different encodings, and for different file name
5599 ;; encodings, too. (Daniel Pittman)
5600 ;; * Change applicable functions to pass a struct tramp-file-name rather
5601 ;; than the individual items MULTI-METHOD, METHOD, USER, HOST, PATH.
5602 ;; * Implement asynchronous shell commands.
5603 ;; * Clean up unused *tramp/foo* buffers after a while. (Pete Forman)
5604 ;; * Progress reports while copying files. (Michael Kifer)
5605 ;; * `Smart' connection method that uses inline for small and out of
5606 ;; band for large files. (Michael Kifer)
5607 ;; * Don't search for perl5 and perl. Instead, only search for perl and
5608 ;; then look if it's the right version (with `perl -v').
5609 ;; * When editing a remote CVS controlled file as a different user, VC
5610 ;; gets confused about the file locking status. Try to find out why
5611 ;; the workaround doesn't work.
5612 ;; * When user is running ssh-agent, it would be useful to add the
5613 ;; passwords typed by the user to that agent. This way, the next time
5614 ;; round, the users don't have to type all this in again.
5615 ;; This would be especially useful for start-process, I think.
5616 ;; An easy way to implement start-process is to open a second shell
5617 ;; connection which is inconvenient if the user has to reenter
5619 ;; * Change `copy-file' to grok the case where the filename handler
5620 ;; for the source and the target file are different. Right now,
5621 ;; it looks at the source file and then calls that handler, if
5622 ;; there is one. But since ange-ftp, for instance, does not know
5623 ;; about Tramp, it does not do the right thing if the target file
5624 ;; name is a Tramp name.
5626 ;; Functions for file-name-handler-alist:
5627 ;; diff-latest-backup-file -- in diff.el
5628 ;; dired-compress-file
5629 ;; dired-uncache -- this will be needed when we do insert-directory caching
5630 ;; file-name-as-directory -- use primitive?
5631 ;; file-name-directory -- use primitive?
5632 ;; file-name-nondirectory -- use primitive?
5633 ;; file-name-sans-versions -- use primitive?
5634 ;; file-newer-than-file-p
5635 ;; find-backup-file-name
5636 ;; get-file-buffer -- use primitive
5638 ;; unhandled-file-name-directory
5641 ;;; tramp.el ends here