1 ;;; -*- mode: Emacs-Lisp; coding: iso-2022-7bit; -*-
2 ;;; tramp.el --- Transparent Remote Access, Multiple Protocol
4 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 ;; 2005 Free Software Foundation, Inc.
7 ;; Author: Kai Gro\e,A_\e(Bjohann <kai.grossjohann@gmx.net>
8 ;; Michael Albinus <michael.albinus@gmx.de>
9 ;; Keywords: comm, processes
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
30 ;; This package provides remote file editing, similar to ange-ftp.
31 ;; The difference is that ange-ftp uses FTP to transfer files between
32 ;; the local and the remote host, whereas tramp.el uses a combination
33 ;; of rsh and rcp or other work-alike programs, such as ssh/scp.
35 ;; For more detailed instructions, please see the info file.
40 ;; This package only works for Emacs 20 and higher, and for XEmacs 21
41 ;; and higher. (XEmacs 20 is missing the `with-timeout' macro. Emacs
42 ;; 19 is reported to have other problems. For XEmacs 21, you need the
43 ;; package `fsf-compat' for the `with-timeout' macro.)
45 ;; This version might not work with pre-Emacs 21 VC unless VC is
46 ;; loaded before tramp.el. Could you please test this and tell me about
47 ;; the result? Thanks.
49 ;; Also see the todo list at the bottom of this file.
51 ;; The current version of Tramp can be retrieved from the following URL:
52 ;; http://ftp.gnu.org/gnu/tramp/
54 ;; There's a mailing list for this, as well. Its name is:
55 ;; tramp-devel@gnu.org
56 ;; You can use the Web to subscribe, under the following URL:
57 ;; http://lists.gnu.org/mailman/listinfo/tramp-devel
59 ;; For the adventurous, the current development sources are available
60 ;; via CVS. You can find instructions about this at the following URL:
61 ;; http://savannah.gnu.org/projects/tramp/
62 ;; Click on "CVS" in the navigation bar near the top.
64 ;; Don't forget to put on your asbestos longjohns, first!
68 ;; The Tramp version number and bug report address, as prepared by configure.
72 (require 'format-spec
) ;from Gnus 5.8, also in tar ball
73 ;; As long as password.el is not part of (X)Emacs, it shouldn't
75 (if (featurep 'xemacs
)
76 (load "password" 'noerror
)
77 (require 'password nil
'noerror
)) ;from No Gnus, also in tar ball
79 ;; The explicit check is not necessary in Emacs, which provides the
80 ;; feature even if implemented in C, but it appears to be necessary
82 (unless (and (fboundp 'base64-encode-region
)
83 (fboundp 'base64-decode-region
))
84 (require 'base64
)) ;for the mimencode methods
88 (autoload 'tramp-uuencode-region
"tramp-uu"
89 "Implementation of `uuencode' in Lisp.")
91 (unless (fboundp 'uudecode-decode-region
)
92 (autoload 'uudecode-decode-region
"uudecode"))
94 ;; XEmacs is distributed with few Lisp packages. Further packages are
95 ;; installed using EFS. If we use a unified filename format, then
96 ;; Tramp is required in addition to EFS. (But why can't Tramp just
97 ;; disable EFS when Tramp is loaded? Then XEmacs can ship with EFS
98 ;; just like before.) Another reason for using a separate filename
99 ;; syntax on XEmacs is that EFS hooks into XEmacs in many places, but
100 ;; Tramp only knows how to deal with `file-name-handler-alist', not
103 (defvar tramp-unified-filenames
(not (featurep 'xemacs
))
104 "Non-nil means to use unified Ange-FTP/Tramp filename syntax.
105 Nil means to use a separate filename syntax for Tramp.")
107 ;; Load foreign methods. Because they do require Tramp internally, this
108 ;; must be done with the `eval-after-load' trick.
110 ;; tramp-ftp supports Ange-FTP only. Not suited for XEmacs therefore.
111 (unless (featurep 'xemacs
)
112 (eval-after-load "tramp"
113 '(require 'tramp-ftp
)))
114 (when (and tramp-unified-filenames
(featurep 'xemacs
))
115 (eval-after-load "tramp"
116 '(require 'tramp-efs
)))
118 ;; tramp-smb uses "smbclient" from Samba.
119 ;; Not available under Cygwin and Windows, because they don't offer
120 ;; "smbclient". And even not necessary there, because Emacs supports
121 ;; UNC file names like "//host/share/localname".
122 (unless (memq system-type
'(cygwin windows-nt
))
123 (eval-after-load "tramp"
124 '(require 'tramp-smb
)))
129 ;; Emacs 19.34 compatibility hack -- is this needed?
130 (or (>= emacs-major-version
20)
133 (unless (boundp 'custom-print-functions
)
134 (defvar custom-print-functions nil
)) ; not autoloaded before Emacs 20.4
136 ;; Avoid byte-compiler warnings if the byte-compiler supports this.
137 ;; Currently, XEmacs supports this.
139 (when (fboundp 'byte-compiler-options
)
140 (let (unused-vars) ; Pacify Emacs byte-compiler
141 (defalias 'warnings
'identity
) ; Pacify Emacs byte-compiler
142 (byte-compiler-options (warnings (- unused-vars
))))))
144 ;; `directory-sep-char' is an obsolete variable in Emacs. But it is
145 ;; used in XEmacs, so we set it here and there. The following is needed
146 ;; to pacify Emacs byte-compiler.
148 (when (boundp 'byte-compile-not-obsolete-var
)
149 (setq byte-compile-not-obsolete-var
'directory-sep-char
)))
151 ;;; User Customizable Internal Variables:
154 "Edit remote files with a combination of rsh and rcp or similar programs."
158 (defcustom tramp-verbose
9
159 "*Verbosity level for tramp.el. 0 means be silent, 10 is most verbose."
163 (defcustom tramp-debug-buffer nil
164 "*Whether to send all commands and responses to a debug buffer."
170 (when (boundp 'backup-directory-alist
)
171 (defcustom tramp-backup-directory-alist nil
172 "Alist of filename patterns and backup directory names.
173 Each element looks like (REGEXP . DIRECTORY), with the same meaning like
174 in `backup-directory-alist'. If a Tramp file is backed up, and DIRECTORY
175 is a local file name, the backup directory is prepended with Tramp file
176 name prefix \(multi-method, method, user, host\) of file.
178 \(setq tramp-backup-directory-alist backup-directory-alist\)
180 gives the same backup policy for Tramp files on their hosts like the
181 policy for local files."
183 :type
'(repeat (cons (regexp :tag
"Regexp matching filename")
184 (directory :tag
"Backup directory name"))))))
186 ;; XEmacs case. We cannot check for `bkup-backup-directory-info', because
187 ;; the package "backup-dir" might not be loaded yet.
189 (when (featurep 'xemacs
)
190 (defcustom tramp-bkup-backup-directory-info nil
191 "*Alist of (FILE-REGEXP BACKUP-DIR OPTIONS ...))
192 It has the same meaning like `bkup-backup-directory-info' from package
193 `backup-dir'. If a Tramp file is backed up, and BACKUP-DIR is a local
194 file name, the backup directory is prepended with Tramp file name prefix
195 \(multi-method, method, user, host\) of file.
197 \(setq tramp-bkup-backup-directory-info bkup-backup-directory-info\)
199 gives the same backup policy for Tramp files on their hosts like the
200 policy for local files."
202 (list (regexp :tag
"File regexp")
203 (string :tag
"Backup Dir")
208 (const search-upward
))))
211 (defcustom tramp-auto-save-directory nil
212 "*Put auto-save files in this directory, if set.
213 The idea is to use a local directory so that auto-saving is faster."
215 :type
'(choice (const nil
)
218 (defcustom tramp-encoding-shell
219 (if (memq system-type
'(windows-nt))
222 "*Use this program for encoding and decoding commands on the local host.
223 This shell is used to execute the encoding and decoding command on the
224 local host, so if you want to use `~' in those commands, you should
225 choose a shell here which groks tilde expansion. `/bin/sh' normally
226 does not understand tilde expansion.
228 For encoding and deocding, commands like the following are executed:
230 /bin/sh -c COMMAND < INPUT > OUTPUT
232 This variable can be used to change the \"/bin/sh\" part. See the
233 variable `tramp-encoding-command-switch' for the \"-c\" part. Also, see the
234 variable `tramp-encoding-reads-stdin' to specify whether the commands read
235 standard input or a file.
237 Note that this variable is not used for remote commands. There are
238 mechanisms in tramp.el which automatically determine the right shell to
239 use for the remote host."
241 :type
'(file :must-match t
))
243 (defcustom tramp-encoding-command-switch
244 (if (string-match "cmd\\.exe" tramp-encoding-shell
)
247 "*Use this switch together with `tramp-encoding-shell' for local commands.
248 See the variable `tramp-encoding-shell' for more information."
252 (defcustom tramp-encoding-reads-stdin t
253 "*If non-nil, encoding commands read from standard input.
254 If nil, the filename is the last argument.
256 Note that the commands always must write to standard output."
260 (defcustom tramp-multi-sh-program
262 "*Use this program for bootstrapping multi-hop connections.
263 This variable is similar to `tramp-encoding-shell', but it is only used
264 when initializing a multi-hop connection. Therefore, the set of
265 commands sent to this shell is quite restricted, and if you are
266 careful it works to use CMD.EXE under Windows (instead of a Bourne-ish
267 shell which does not normally exist on Windows anyway).
269 To use multi-hop methods from Windows, you also need suitable entries
270 in `tramp-multi-connection-function-alist' for the first hop.
272 This variable defaults to the value of `tramp-encoding-shell'."
274 :type
'(file :must-match t
))
276 ;; CCC I have changed all occurrences of comint-quote-filename with
277 ;; tramp-shell-quote-argument, except in tramp-handle-expand-many-files.
278 ;; There, comint-quote-filename was removed altogether. If it turns
279 ;; out to be necessary there, something will need to be done.
280 ;;-(defcustom tramp-file-name-quote-list
281 ;;- '(?] ?[ ?\| ?& ?< ?> ?\( ?\) ?\; ?\ ?\* ?\? ?\! ?\" ?\' ?\` ?# ?\@ ?\+ )
282 ;;- "*Protect these characters from the remote shell.
283 ;;-Any character in this list is quoted (preceded with a backslash)
284 ;;-because it means something special to the shell. This takes effect
285 ;;-when sending file and directory names to the remote shell.
287 ;;-See `comint-file-name-quote-list' for details."
289 ;;- :type '(repeat character))
291 (defcustom tramp-methods
292 '( ("rcp" (tramp-connection-function tramp-open-connection-rsh
)
293 (tramp-login-program "rsh")
294 (tramp-copy-program "rcp")
295 (tramp-remote-sh "/bin/sh")
296 (tramp-login-args nil
)
297 (tramp-copy-args nil
)
298 (tramp-copy-keep-date-arg "-p")
299 (tramp-password-end-of-line nil
))
300 ("scp" (tramp-connection-function tramp-open-connection-rsh
)
301 (tramp-login-program "ssh")
302 (tramp-copy-program "scp")
303 (tramp-remote-sh "/bin/sh")
304 (tramp-login-args ("-e" "none"))
305 (tramp-copy-args nil
)
306 (tramp-copy-keep-date-arg "-p")
307 (tramp-password-end-of-line nil
))
308 ("scp1" (tramp-connection-function tramp-open-connection-rsh
)
309 (tramp-login-program "ssh")
310 (tramp-copy-program "scp")
311 (tramp-remote-sh "/bin/sh")
312 (tramp-login-args ("-1" "-e" "none"))
313 (tramp-copy-args ("-1"))
314 (tramp-copy-keep-date-arg "-p")
315 (tramp-password-end-of-line nil
))
316 ("scp2" (tramp-connection-function tramp-open-connection-rsh
)
317 (tramp-login-program "ssh")
318 (tramp-copy-program "scp")
319 (tramp-remote-sh "/bin/sh")
320 (tramp-login-args ("-2" "-e" "none"))
321 (tramp-copy-args ("-2"))
322 (tramp-copy-keep-date-arg "-p")
323 (tramp-password-end-of-line nil
))
325 (tramp-connection-function tramp-open-connection-rsh
)
326 (tramp-login-program "ssh1")
327 (tramp-copy-program "scp1")
328 (tramp-remote-sh "/bin/sh")
329 (tramp-login-args ("-e" "none"))
330 (tramp-copy-args nil
)
331 (tramp-copy-keep-date-arg "-p")
332 (tramp-password-end-of-line nil
))
334 (tramp-connection-function tramp-open-connection-rsh
)
335 (tramp-login-program "ssh2")
336 (tramp-copy-program "scp2")
337 (tramp-remote-sh "/bin/sh")
338 (tramp-login-args ("-e" "none"))
339 (tramp-copy-args nil
)
340 (tramp-copy-keep-date-arg "-p")
341 (tramp-password-end-of-line nil
))
342 ("rsync" (tramp-connection-function tramp-open-connection-rsh
)
343 (tramp-login-program "ssh")
344 (tramp-copy-program "rsync")
345 (tramp-remote-sh "/bin/sh")
346 (tramp-login-args ("-e" "none"))
347 (tramp-copy-args ("-e" "ssh"))
348 (tramp-copy-keep-date-arg "-t")
349 (tramp-password-end-of-line nil
))
350 ("remcp" (tramp-connection-function tramp-open-connection-rsh
)
351 (tramp-login-program "remsh")
352 (tramp-copy-program "rcp")
353 (tramp-remote-sh "/bin/sh")
354 (tramp-login-args nil
)
355 (tramp-copy-args nil
)
356 (tramp-copy-keep-date-arg "-p")
357 (tramp-password-end-of-line nil
))
358 ("rsh" (tramp-connection-function tramp-open-connection-rsh
)
359 (tramp-login-program "rsh")
360 (tramp-copy-program nil
)
361 (tramp-remote-sh "/bin/sh")
362 (tramp-login-args nil
)
363 (tramp-copy-args nil
)
364 (tramp-copy-keep-date-arg nil
)
365 (tramp-password-end-of-line nil
))
366 ("ssh" (tramp-connection-function tramp-open-connection-rsh
)
367 (tramp-login-program "ssh")
368 (tramp-copy-program nil
)
369 (tramp-remote-sh "/bin/sh")
370 (tramp-login-args ("-e" "none"))
371 (tramp-copy-args nil
)
372 (tramp-copy-keep-date-arg nil
)
373 (tramp-password-end-of-line nil
))
374 ("ssh1" (tramp-connection-function tramp-open-connection-rsh
)
375 (tramp-login-program "ssh")
376 (tramp-copy-program nil
)
377 (tramp-remote-sh "/bin/sh")
378 (tramp-login-args ("-1" "-e" "none"))
379 (tramp-copy-args ("-1"))
380 (tramp-copy-keep-date-arg nil
)
381 (tramp-password-end-of-line nil
))
382 ("ssh2" (tramp-connection-function tramp-open-connection-rsh
)
383 (tramp-login-program "ssh")
384 (tramp-copy-program nil
)
385 (tramp-remote-sh "/bin/sh")
386 (tramp-login-args ("-2" "-e" "none"))
387 (tramp-copy-args ("-2"))
388 (tramp-copy-keep-date-arg nil
)
389 (tramp-password-end-of-line nil
))
391 (tramp-connection-function tramp-open-connection-rsh
)
392 (tramp-login-program "ssh1")
393 (tramp-copy-program nil
)
394 (tramp-remote-sh "/bin/sh")
395 (tramp-login-args ("-e" "none"))
396 (tramp-copy-args nil
)
397 (tramp-copy-keep-date-arg nil
)
398 (tramp-password-end-of-line nil
))
400 (tramp-connection-function tramp-open-connection-rsh
)
401 (tramp-login-program "ssh2")
402 (tramp-copy-program nil
)
403 (tramp-remote-sh "/bin/sh")
404 (tramp-login-args ("-e" "none"))
405 (tramp-copy-args nil
)
406 (tramp-copy-keep-date-arg nil
)
407 (tramp-password-end-of-line nil
))
408 ("remsh" (tramp-connection-function tramp-open-connection-rsh
)
409 (tramp-login-program "remsh")
410 (tramp-copy-program nil
)
411 (tramp-remote-sh "/bin/sh")
412 (tramp-login-args nil
)
413 (tramp-copy-args nil
)
414 (tramp-copy-keep-date-arg nil
)
415 (tramp-password-end-of-line nil
))
417 (tramp-connection-function tramp-open-connection-telnet
)
418 (tramp-login-program "telnet")
419 (tramp-copy-program nil
)
420 (tramp-remote-sh "/bin/sh")
421 (tramp-login-args nil
)
422 (tramp-copy-args nil
)
423 (tramp-copy-keep-date-arg nil
)
424 (tramp-password-end-of-line nil
))
425 ("su" (tramp-connection-function tramp-open-connection-su
)
426 (tramp-login-program "su")
427 (tramp-copy-program nil
)
428 (tramp-remote-sh "/bin/sh")
429 (tramp-login-args ("-" "%u"))
430 (tramp-copy-args nil
)
431 (tramp-copy-keep-date-arg nil
)
432 (tramp-password-end-of-line nil
))
433 ("sudo" (tramp-connection-function tramp-open-connection-su
)
434 (tramp-login-program "sudo")
435 (tramp-copy-program nil
)
436 (tramp-remote-sh "/bin/sh")
437 (tramp-login-args ("-u" "%u" "-s"
439 (tramp-copy-args nil
)
440 (tramp-copy-keep-date-arg nil
)
441 (tramp-password-end-of-line nil
))
442 ("multi" (tramp-connection-function tramp-open-connection-multi
)
443 (tramp-login-program nil
)
444 (tramp-copy-program nil
)
445 (tramp-remote-sh "/bin/sh")
446 (tramp-login-args nil
)
447 (tramp-copy-args nil
)
448 (tramp-copy-keep-date-arg nil
)
449 (tramp-password-end-of-line nil
))
450 ("scpx" (tramp-connection-function tramp-open-connection-rsh
)
451 (tramp-login-program "ssh")
452 (tramp-copy-program "scp")
453 (tramp-remote-sh "/bin/sh")
454 (tramp-login-args ("-e" "none" "-t" "-t" "/bin/sh"))
455 (tramp-copy-args nil
)
456 (tramp-copy-keep-date-arg "-p")
457 (tramp-password-end-of-line nil
))
458 ("sshx" (tramp-connection-function tramp-open-connection-rsh
)
459 (tramp-login-program "ssh")
460 (tramp-copy-program nil
)
461 (tramp-remote-sh "/bin/sh")
462 (tramp-login-args ("-e" "none" "-t" "-t" "/bin/sh"))
463 (tramp-copy-args nil
)
464 (tramp-copy-keep-date-arg nil
)
465 (tramp-password-end-of-line nil
))
467 (tramp-connection-function tramp-open-connection-rsh
)
468 (tramp-login-program "krlogin")
469 (tramp-copy-program nil
)
470 (tramp-remote-sh "/bin/sh")
471 (tramp-login-args ("-x"))
472 (tramp-copy-args nil
)
473 (tramp-copy-keep-date-arg nil
)
474 (tramp-password-end-of-line nil
))
476 (tramp-connection-function tramp-open-connection-rsh
)
477 (tramp-login-program "plink")
478 (tramp-copy-program nil
)
479 (tramp-remote-sh "/bin/sh")
480 (tramp-login-args ("-ssh")) ;optionally add "-v"
481 (tramp-copy-args nil
)
482 (tramp-copy-keep-date-arg nil
)
483 (tramp-password-end-of-line "xy")) ;see docstring for "xy"
485 (tramp-connection-function tramp-open-connection-rsh
)
486 (tramp-login-program "plink")
487 (tramp-copy-program nil
)
488 (tramp-remote-sh "/bin/sh")
489 (tramp-login-args ("-1" "-ssh")) ;optionally add "-v"
490 (tramp-copy-args nil
)
491 (tramp-copy-keep-date-arg nil
)
492 (tramp-password-end-of-line "xy")) ;see docstring for "xy"
494 (tramp-connection-function tramp-open-connection-rsh
)
495 (tramp-login-program "plink")
496 (tramp-copy-program "pscp")
497 (tramp-remote-sh "/bin/sh")
498 (tramp-login-args ("-ssh"))
499 (tramp-copy-args nil
)
500 (tramp-copy-keep-date-arg "-p")
501 (tramp-password-end-of-line "xy")) ;see docstring for "xy"
503 (tramp-connection-function tramp-open-connection-rsh
)
504 (tramp-login-program "fsh")
505 (tramp-copy-program "fcp")
506 (tramp-remote-sh "/bin/sh -i")
507 (tramp-login-args ("sh" "-i"))
508 (tramp-copy-args nil
)
509 (tramp-copy-keep-date-arg "-p")
510 (tramp-password-end-of-line nil
))
512 "*Alist of methods for remote files.
513 This is a list of entries of the form (NAME PARAM1 PARAM2 ...).
514 Each NAME stands for a remote access method. Each PARAM is a
515 pair of the form (KEY VALUE). The following KEYs are defined:
516 * `tramp-connection-function'
517 This specifies the function to use to connect to the remote host.
518 Currently, `tramp-open-connection-rsh', `tramp-open-connection-telnet'
519 and `tramp-open-connection-su' are defined. See the documentation
520 of these functions for more details.
522 This specifies the Bourne shell to use on the remote host. This
523 MUST be a Bourne-like shell. It is normally not necessary to set
524 this to any value other than \"/bin/sh\": tramp wants to use a shell
525 which groks tilde expansion, but it can search for it. Also note
526 that \"/bin/sh\" exists on all Unixen, this might not be true for
527 the value that you decide to use. You Have Been Warned.
528 * `tramp-login-program'
529 This specifies the name of the program to use for logging in to the
530 remote host. Depending on `tramp-connection-function', this may be
531 the name of rsh or a workalike program (when
532 `tramp-connection-function' is `tramp-open-connection-rsh'), or the
533 name of telnet or a workalike (for `tramp-open-connection-telnet'),
534 or the name of su or a workalike (for `tramp-open-connection-su').
536 This specifies the list of arguments to pass to the above
537 mentioned program. Please note that this is a list of arguments,
538 that is, normally you don't want to put \"-a -b\" or \"-f foo\"
539 here. Instead, you want two list elements, one for \"-a\" and one
540 for \"-b\", or one for \"-f\" and one for \"foo\".
541 If `tramp-connection-function' is `tramp-open-connection-su', then
542 \"%u\" in this list is replaced by the user name, and \"%%\" can
543 be used to obtain a literal percent character.
544 * `tramp-copy-program'
545 This specifies the name of the program to use for remotely copying
546 the file; this might be the absolute filename of rcp or the name of
549 This specifies the list of parameters to pass to the above mentioned
550 program, the hints for `tramp-login-args' also apply here.
551 * `tramp-copy-keep-date-arg'
552 This specifies the parameter to use for the copying program when the
553 timestamp of the original file should be kept. For `rcp', use `-p', for
555 * `tramp-password-end-of-line'
556 This specifies the string to use for terminating the line after
557 submitting the password. If this method parameter is nil, then the
558 value of the normal variable `tramp-default-password-end-of-line'
559 is used. This parameter is necessary because the \"plink\" program
560 requires any two characters after sending the password. These do
561 not have to be newline or carriage return characters. Other login
562 programs are happy with just one character, the newline character.
563 We use \"xy\" as the value for methods using \"plink\".
565 What does all this mean? Well, you should specify `tramp-login-program'
566 for all methods; this program is used to log in to the remote site. Then,
567 there are two ways to actually transfer the files between the local and the
568 remote side. One way is using an additional rcp-like program. If you want
569 to do this, set `tramp-copy-program' in the method.
571 Another possibility for file transfer is inline transfer, i.e. the
572 file is passed through the same buffer used by `tramp-login-program'. In
573 this case, the file contents need to be protected since the
574 `tramp-login-program' might use escape codes or the connection might not
575 be eight-bit clean. Therefore, file contents are encoded for transit.
576 See the variable `tramp-coding-commands' for details.
578 So, to summarize: if the method is an out-of-band method, then you
579 must specify `tramp-copy-program' and `tramp-copy-args'. If it is an
580 inline method, then these two parameters should be nil. Every method,
581 inline or out of band, must specify `tramp-connection-function' plus
582 the associated arguments (for example, the login program if you chose
583 `tramp-open-connection-telnet').
587 When using `tramp-open-connection-su' the phrase `open connection to a
588 remote host' sounds strange, but it is used nevertheless, for
589 consistency. No connection is opened to a remote host, but `su' is
590 started on the local host. You are not allowed to specify a remote
591 host other than `localhost' or the name of the local host."
595 (set (list (const tramp-connection-function
) function
)
596 (list (const tramp-login-program
)
597 (choice (const nil
) string
))
598 (list (const tramp-copy-program
)
599 (choice (const nil
) string
))
600 (list (const tramp-remote-sh
)
601 (choice (const nil
) string
))
602 (list (const tramp-login-args
) (repeat string
))
603 (list (const tramp-copy-args
) (repeat string
))
604 (list (const tramp-copy-keep-date-arg
)
605 (choice (const nil
) string
))
606 (list (const tramp-encoding-command
)
607 (choice (const nil
) string
))
608 (list (const tramp-decoding-command
)
609 (choice (const nil
) string
))
610 (list (const tramp-encoding-function
)
611 (choice (const nil
) function
))
612 (list (const tramp-decoding-function
)
613 (choice (const nil
) function
))
614 (list (const tramp-password-end-of-line
)
615 (choice (const nil
) string
))))))
617 (defcustom tramp-multi-methods
'("multi" "multiu")
618 "*List of multi-hop methods.
619 Each entry in this list should be a method name as mentioned in the
620 variable `tramp-methods'."
622 :type
'(repeat string
))
624 (defcustom tramp-multi-connection-function-alist
625 '(("telnet" tramp-multi-connect-telnet
"telnet %h%n")
626 ("rsh" tramp-multi-connect-rlogin
"rsh %h -l %u%n")
627 ("remsh" tramp-multi-connect-rlogin
"remsh %h -l %u%n")
628 ("ssh" tramp-multi-connect-rlogin
"ssh %h -l %u%n")
629 ("ssht" tramp-multi-connect-rlogin
"ssh %h -e none -t -t -l %u%n")
630 ("su" tramp-multi-connect-su
"su - %u%n")
631 ("sudo" tramp-multi-connect-su
"sudo -u %u -s -p Password:%n"))
632 "*List of connection functions for multi-hop methods.
633 Each list item is a list of three items (METHOD FUNCTION COMMAND),
634 where METHOD is the name as used in the file name, FUNCTION is the
635 function to be executed, and COMMAND is the shell command used for
638 COMMAND may contain percent escapes. `%u' will be replaced with the
639 user name, `%h' will be replaced with the host name, and `%n' will be
640 replaced with an end-of-line character, as specified in the variable
641 `tramp-rsh-end-of-line'. Use `%%' for a literal percent character.
642 Note that the interpretation of the percent escapes also depends on
643 the FUNCTION. For example, the `%u' escape is forbidden with the
644 function `tramp-multi-connect-telnet'. See the documentation of the
645 various functions for details."
647 :type
'(repeat (list string function string
)))
649 (defcustom tramp-default-method
650 (if (and (fboundp 'executable-find
)
651 (executable-find "plink"))
654 "*Default method to use for transferring files.
655 See `tramp-methods' for possibilities.
656 Also see `tramp-default-method-alist'."
660 (defcustom tramp-default-method-alist
661 '(("\\`localhost\\'" "\\`root\\'" "su"))
662 "*Default method to use for specific user/host pairs.
663 This is an alist of items (HOST USER METHOD). The first matching item
664 specifies the method to use for a file name which does not specify a
665 method. HOST and USER are regular expressions or nil, which is
666 interpreted as a regular expression which always matches. If no entry
667 matches, the variable `tramp-default-method' takes effect.
669 If the file name does not specify the user, lookup is done using the
670 empty string for the user name.
672 See `tramp-methods' for a list of possibilities for METHOD."
674 :type
'(repeat (list (regexp :tag
"Host regexp")
675 (regexp :tag
"User regexp")
676 (string :tag
"Method"))))
678 ;; Default values for non-Unices seeked
679 (defconst tramp-completion-function-alist-rsh
680 (unless (memq system-type
'(windows-nt))
681 '((tramp-parse-rhosts "/etc/hosts.equiv")
682 (tramp-parse-rhosts "~/.rhosts")))
683 "Default list of (FUNCTION FILE) pairs to be examined for rsh methods.")
685 ;; Default values for non-Unices seeked
686 (defconst tramp-completion-function-alist-ssh
687 (unless (memq system-type
'(windows-nt))
688 '((tramp-parse-rhosts "/etc/hosts.equiv")
689 (tramp-parse-rhosts "/etc/shosts.equiv")
690 (tramp-parse-shosts "/etc/ssh_known_hosts")
691 (tramp-parse-sconfig "/etc/ssh_config")
692 (tramp-parse-shostkeys "/etc/ssh2/hostkeys")
693 (tramp-parse-sknownhosts "/etc/ssh2/knownhosts")
694 (tramp-parse-rhosts "~/.rhosts")
695 (tramp-parse-rhosts "~/.shosts")
696 (tramp-parse-shosts "~/.ssh/known_hosts")
697 (tramp-parse-sconfig "~/.ssh/config")
698 (tramp-parse-shostkeys "~/.ssh2/hostkeys")
699 (tramp-parse-sknownhosts "~/.ssh2/knownhosts")))
700 "Default list of (FUNCTION FILE) pairs to be examined for ssh methods.")
702 ;; Default values for non-Unices seeked
703 (defconst tramp-completion-function-alist-telnet
704 (unless (memq system-type
'(windows-nt))
705 '((tramp-parse-hosts "/etc/hosts")))
706 "Default list of (FUNCTION FILE) pairs to be examined for telnet methods.")
708 ;; Default values for non-Unices seeked
709 (defconst tramp-completion-function-alist-su
710 (unless (memq system-type
'(windows-nt))
711 '((tramp-parse-passwd "/etc/passwd")))
712 "Default list of (FUNCTION FILE) pairs to be examined for su methods.")
714 (defvar tramp-completion-function-alist nil
715 "*Alist of methods for remote files.
716 This is a list of entries of the form (NAME PAIR1 PAIR2 ...).
717 Each NAME stands for a remote access method. Each PAIR is of the form
718 \(FUNCTION FILE). FUNCTION is responsible to extract user names and host
719 names from FILE for completion. The following predefined FUNCTIONs exists:
721 * `tramp-parse-rhosts' for \"~/.rhosts\" like files,
722 * `tramp-parse-shosts' for \"~/.ssh/known_hosts\" like files,
723 * `tramp-parse-sconfig' for \"~/.ssh/config\" like files,
724 * `tramp-parse-shostkeys' for \"~/.ssh2/hostkeys/*\" like files,
725 * `tramp-parse-sknownhosts' for \"~/.ssh2/knownhosts/*\" like files,
726 * `tramp-parse-hosts' for \"/etc/hosts\" like files,
727 * `tramp-parse-passwd' for \"/etc/passwd\" like files.
728 * `tramp-parse-netrc' for \"~/.netrc\" like files.
730 FUNCTION can also be a customer defined function. For more details see
733 (eval-after-load "tramp"
735 (tramp-set-completion-function
736 "rcp" tramp-completion-function-alist-rsh
)
737 (tramp-set-completion-function
738 "scp" tramp-completion-function-alist-ssh
)
739 (tramp-set-completion-function
740 "scp1" tramp-completion-function-alist-ssh
)
741 (tramp-set-completion-function
742 "scp2" tramp-completion-function-alist-ssh
)
743 (tramp-set-completion-function
744 "scp1_old" tramp-completion-function-alist-ssh
)
745 (tramp-set-completion-function
746 "scp2_old" tramp-completion-function-alist-ssh
)
747 (tramp-set-completion-function
748 "rsync" tramp-completion-function-alist-rsh
)
749 (tramp-set-completion-function
750 "remcp" tramp-completion-function-alist-rsh
)
751 (tramp-set-completion-function
752 "rsh" tramp-completion-function-alist-rsh
)
753 (tramp-set-completion-function
754 "ssh" tramp-completion-function-alist-ssh
)
755 (tramp-set-completion-function
756 "ssh1" tramp-completion-function-alist-ssh
)
757 (tramp-set-completion-function
758 "ssh2" tramp-completion-function-alist-ssh
)
759 (tramp-set-completion-function
760 "ssh1_old" tramp-completion-function-alist-ssh
)
761 (tramp-set-completion-function
762 "ssh2_old" tramp-completion-function-alist-ssh
)
763 (tramp-set-completion-function
764 "remsh" tramp-completion-function-alist-rsh
)
765 (tramp-set-completion-function
766 "telnet" tramp-completion-function-alist-telnet
)
767 (tramp-set-completion-function
768 "su" tramp-completion-function-alist-su
)
769 (tramp-set-completion-function
770 "sudo" tramp-completion-function-alist-su
)
771 (tramp-set-completion-function
773 (tramp-set-completion-function
774 "scpx" tramp-completion-function-alist-ssh
)
775 (tramp-set-completion-function
776 "sshx" tramp-completion-function-alist-ssh
)
777 (tramp-set-completion-function
778 "krlogin" tramp-completion-function-alist-rsh
)
779 (tramp-set-completion-function
780 "plink" tramp-completion-function-alist-ssh
)
781 (tramp-set-completion-function
782 "plink1" tramp-completion-function-alist-ssh
)
783 (tramp-set-completion-function
784 "pscp" tramp-completion-function-alist-ssh
)
785 (tramp-set-completion-function
786 "fcp" tramp-completion-function-alist-ssh
)))
788 (defcustom tramp-rsh-end-of-line
"\n"
789 "*String used for end of line in rsh connections.
790 I don't think this ever needs to be changed, so please tell me about it
791 if you need to change this.
792 Also see the method parameter `tramp-password-end-of-line' and the normal
793 variable `tramp-default-password-end-of-line'."
797 (defcustom tramp-default-password-end-of-line
798 tramp-rsh-end-of-line
799 "*String used for end of line after sending a password.
800 This variable provides the default value for the method parameter
801 `tramp-password-end-of-line', see `tramp-methods' for more details.
803 It seems that people using plink under Windows need to send
804 \"\\r\\n\" (carriage-return, then newline) after a password, but just
805 \"\\n\" after all other lines. This variable can be used for the
806 password, see `tramp-rsh-end-of-line' for the other cases.
808 The default value is to use the same value as `tramp-rsh-end-of-line'."
812 (defcustom tramp-remote-path
813 '("/bin" "/usr/bin" "/usr/sbin" "/usr/local/bin" "/usr/ccs/bin"
814 "/local/bin" "/local/freeware/bin" "/local/gnu/bin"
815 "/usr/freeware/bin" "/usr/pkg/bin" "/usr/contrib/bin")
816 "*List of directories to search for executables on remote host.
817 Please notify me about other semi-standard directories to include here.
819 You can use `~' in this list, but when searching for a shell which groks
820 tilde expansion, all directory names starting with `~' will be ignored."
822 :type
'(repeat string
))
824 (defcustom tramp-login-prompt-regexp
826 "*Regexp matching login-like prompts.
827 The regexp should match at end of buffer."
831 (defcustom tramp-shell-prompt-pattern
832 "^[^#$%>\n]*[#$%>] *\\(\e\\[[0-9;]*[a-zA-Z] *\\)*"
833 "Regexp to match prompts from remote shell.
834 Normally, Tramp expects you to configure `shell-prompt-pattern'
835 correctly, but sometimes it happens that you are connecting to a
836 remote host which sends a different kind of shell prompt. Therefore,
837 Tramp recognizes things matched by `shell-prompt-pattern' as prompt,
838 and also things matched by this variable. The default value of this
839 variable is similar to the default value of `shell-prompt-pattern',
840 which should work well in many cases."
844 (defcustom tramp-password-prompt-regexp
845 "^.*\\([pP]assword\\|passphrase.*\\):\^@? *"
846 "*Regexp matching password-like prompts.
847 The regexp should match at end of buffer.
849 The `sudo' program appears to insert a `^@' character into the prompt."
853 (defcustom tramp-wrong-passwd-regexp
855 ;; These strings should be on the last line
856 (regexp-opt '("Permission denied."
862 "Name or service not known"
863 "Host key verification failed.") t
)
867 ;; Here comes a list of regexes, separated by \\|
868 "Received signal [0-9]+"
870 "*Regexp matching a `login failed' message.
871 The regexp should match at end of buffer."
875 (defcustom tramp-yesno-prompt-regexp
877 (regexp-opt '("Are you sure you want to continue connecting (yes/no)?") t
)
879 "Regular expression matching all yes/no queries which need to be confirmed.
880 The confirmation should be done with yes or no.
881 The regexp should match at end of buffer.
882 See also `tramp-yn-prompt-regexp'."
886 (defcustom tramp-yn-prompt-regexp
887 (concat (regexp-opt '("Store key in cache? (y/n)") t
)
889 "Regular expression matching all y/n queries which need to be confirmed.
890 The confirmation should be done with y or n.
891 The regexp should match at end of buffer.
892 See also `tramp-yesno-prompt-regexp'."
896 (defcustom tramp-terminal-prompt-regexp
900 "Terminal type\\? \\[.*\\]"
902 "Regular expression matching all terminal setting prompts.
903 The regexp should match at end of buffer.
904 The answer will be provided by `tramp-action-terminal', which see."
908 (defcustom tramp-operation-not-permitted-regexp
909 (concat "\\(" "preserving times.*" "\\|" "set mode" "\\)" ":\\s-*"
910 (regexp-opt '("Operation not permitted") t
))
911 "Regular expression matching keep-date problems in (s)cp operations.
912 Copying has been performed successfully already, so this message can
917 (defcustom tramp-process-alive-regexp
919 "Regular expression indicating a process has finished.
920 In fact this expression is empty by intention, it will be used only to
921 check regularly the status of the associated process.
922 The answer will be provided by `tramp-action-process-alive',
923 `tramp-multi-action-process-alive' and`tramp-action-out-of-band', which see."
927 (defcustom tramp-temp-name-prefix
"tramp."
928 "*Prefix to use for temporary files.
929 If this is a relative file name (such as \"tramp.\"), it is considered
930 relative to the directory name returned by the function
931 `tramp-temporary-file-directory' (which see). It may also be an
932 absolute file name; don't forget to include a prefix for the filename
937 (defcustom tramp-discard-garbage nil
938 "*If non-nil, try to discard garbage sent by remote shell.
939 Some shells send such garbage upon connection setup."
943 (defcustom tramp-sh-extra-args
'(("/bash\\'" .
"-norc -noprofile"))
944 "*Alist specifying extra arguments to pass to the remote shell.
945 Entries are (REGEXP . ARGS) where REGEXP is a regular expression
946 matching the shell file name and ARGS is a string specifying the
949 This variable is only used when Tramp needs to start up another shell
950 for tilde expansion. The extra arguments should typically prevent the
951 shell from reading its init file."
953 ;; This might be the wrong way to test whether the widget type
954 ;; `alist' is available. Who knows the right way to test it?
955 :type
(if (get 'alist
'widget-type
)
956 '(alist :key-type string
:value-type string
)
957 '(repeat (cons string string
))))
959 (defcustom tramp-prefix-format
960 (if tramp-unified-filenames
"/" "/[")
961 "*String matching the very beginning of tramp file names.
962 Used in `tramp-make-tramp-file-name' and `tramp-make-tramp-multi-file-name'."
966 (defcustom tramp-prefix-regexp
967 (concat "^" (regexp-quote tramp-prefix-format
))
968 "*Regexp matching the very beginning of tramp file names.
969 Should always start with \"^\". Derived from `tramp-prefix-format'."
973 (defcustom tramp-method-regexp
975 "*Regexp matching methods identifiers."
979 ;; It is a little bit annoying that in XEmacs case this delimeter is different
980 ;; for single-hop and multi-hop cases.
981 (defcustom tramp-postfix-single-method-format
982 (if tramp-unified-filenames
":" "/")
983 "*String matching delimeter between method and user or host names.
984 Applicable for single-hop methods.
985 Used in `tramp-make-tramp-file-name'."
989 (defcustom tramp-postfix-single-method-regexp
990 (regexp-quote tramp-postfix-single-method-format
)
991 "*Regexp matching delimeter between method and user or host names.
992 Applicable for single-hop methods.
993 Derived from `tramp-postfix-single-method-format'."
997 (defcustom tramp-postfix-multi-method-format
999 "*String matching delimeter between method and user or host names.
1000 Applicable for multi-hop methods.
1001 Used in `tramp-make-tramp-multi-file-name'."
1005 (defcustom tramp-postfix-multi-method-regexp
1006 (regexp-quote tramp-postfix-multi-method-format
)
1007 "*Regexp matching delimeter between method and user or host names.
1008 Applicable for multi-hop methods.
1009 Derived from `tramp-postfix-multi-method-format'."
1013 (defcustom tramp-postfix-multi-hop-format
1014 (if tramp-unified-filenames
":" "/")
1015 "*String matching delimeter between host and next method.
1016 Applicable for multi-hop methods.
1017 Used in `tramp-make-tramp-multi-file-name'."
1021 (defcustom tramp-postfix-multi-hop-regexp
1022 (regexp-quote tramp-postfix-multi-hop-format
)
1023 "*Regexp matching delimeter between host and next method.
1024 Applicable for multi-hop methods.
1025 Derived from `tramp-postfix-multi-hop-format'."
1029 (defcustom tramp-user-regexp
1031 "*Regexp matching user names."
1035 (defcustom tramp-postfix-user-format
1037 "*String matching delimeter between user and host names.
1038 Used in `tramp-make-tramp-file-name' and `tramp-make-tramp-multi-file-name'."
1042 (defcustom tramp-postfix-user-regexp
1043 (regexp-quote tramp-postfix-user-format
)
1044 "*Regexp matching delimeter between user and host names.
1045 Derived from `tramp-postfix-user-format'."
1049 (defcustom tramp-host-regexp
1051 "*Regexp matching host names."
1055 (defcustom tramp-host-with-port-regexp
1057 "*Regexp matching host names."
1061 (defcustom tramp-postfix-host-format
1062 (if tramp-unified-filenames
":" "]")
1063 "*String matching delimeter between host names and localnames.
1064 Used in `tramp-make-tramp-file-name' and `tramp-make-tramp-multi-file-name'."
1068 (defcustom tramp-postfix-host-regexp
1069 (regexp-quote tramp-postfix-host-format
)
1070 "*Regexp matching delimeter between host names and localnames.
1071 Derived from `tramp-postfix-host-format'."
1075 (defcustom tramp-localname-regexp
1077 "*Regexp matching localnames."
1081 ;; File name format.
1083 (defcustom tramp-file-name-structure
1087 "\\(" "\\(" tramp-method-regexp
"\\)" tramp-postfix-single-method-regexp
"\\)?"
1088 "\\(" "\\(" tramp-user-regexp
"\\)" tramp-postfix-user-regexp
"\\)?"
1089 "\\(" tramp-host-with-port-regexp
"\\)" tramp-postfix-host-regexp
1090 "\\(" tramp-localname-regexp
"\\)")
1093 "*List of five elements (REGEXP METHOD USER HOST FILE), detailing \
1094 the tramp file name structure.
1096 The first element REGEXP is a regular expression matching a tramp file
1097 name. The regex should contain parentheses around the method name,
1098 the user name, the host name, and the file name parts.
1100 The second element METHOD is a number, saying which pair of
1101 parentheses matches the method name. The third element USER is
1102 similar, but for the user name. The fourth element HOST is similar,
1103 but for the host name. The fifth element FILE is for the file name.
1104 These numbers are passed directly to `match-string', which see. That
1105 means the opening parentheses are counted to identify the pair.
1107 See also `tramp-file-name-regexp'."
1109 :type
'(list (regexp :tag
"File name regexp")
1110 (integer :tag
"Paren pair for method name")
1111 (integer :tag
"Paren pair for user name ")
1112 (integer :tag
"Paren pair for host name ")
1113 (integer :tag
"Paren pair for file name ")))
1116 (defconst tramp-file-name-regexp-unified
1118 "Value for `tramp-file-name-regexp' for unified remoting.
1119 Emacs (not XEmacs) uses a unified filename syntax for Ange-FTP and
1120 Tramp. See `tramp-file-name-structure-unified' for more explanations.")
1123 (defconst tramp-file-name-regexp-separate
1125 "Value for `tramp-file-name-regexp' for separate remoting.
1126 XEmacs uses a separate filename syntax for Tramp and EFS.
1127 See `tramp-file-name-structure-separate' for more explanations.")
1130 (defcustom tramp-file-name-regexp
1131 (if tramp-unified-filenames
1132 tramp-file-name-regexp-unified
1133 tramp-file-name-regexp-separate
)
1134 "*Regular expression matching file names handled by tramp.
1135 This regexp should match tramp file names but no other file names.
1136 \(When tramp.el is loaded, this regular expression is prepended to
1137 `file-name-handler-alist', and that is searched sequentially. Thus,
1138 if the tramp entry appears rather early in the `file-name-handler-alist'
1139 and is a bit too general, then some files might be considered tramp
1140 files which are not really tramp files.
1142 Please note that the entry in `file-name-handler-alist' is made when
1143 this file (tramp.el) is loaded. This means that this variable must be set
1144 before loading tramp.el. Alternatively, `file-name-handler-alist' can be
1145 updated after changing this variable.
1147 Also see `tramp-file-name-structure'."
1152 (defconst tramp-completion-file-name-regexp-unified
1153 "^/$\\|^/[^/:][^/]*$"
1154 "Value for `tramp-completion-file-name-regexp' for unified remoting.
1155 Emacs (not XEmacs) uses a unified filename syntax for Ange-FTP and
1156 Tramp. See `tramp-file-name-structure-unified' for more explanations.")
1159 (defconst tramp-completion-file-name-regexp-separate
1160 "^/\\([[][^]]*\\)?$"
1161 "Value for `tramp-completion-file-name-regexp' for separate remoting.
1162 XEmacs uses a separate filename syntax for Tramp and EFS.
1163 See `tramp-file-name-structure-separate' for more explanations.")
1166 (defcustom tramp-completion-file-name-regexp
1167 (if tramp-unified-filenames
1168 tramp-completion-file-name-regexp-unified
1169 tramp-completion-file-name-regexp-separate
)
1170 "*Regular expression matching file names handled by tramp completion.
1171 This regexp should match partial tramp file names only.
1173 Please note that the entry in `file-name-handler-alist' is made when
1174 this file (tramp.el) is loaded. This means that this variable must be set
1175 before loading tramp.el. Alternatively, `file-name-handler-alist' can be
1176 updated after changing this variable.
1178 Also see `tramp-file-name-structure'."
1182 (defcustom tramp-multi-file-name-structure
1186 "\\(" "\\(" tramp-method-regexp
"\\)" "\\)?"
1187 "\\(" "\\(" tramp-postfix-multi-hop-regexp
"%s" "\\)+" "\\)?"
1188 tramp-postfix-host-regexp
"\\(" tramp-localname-regexp
"\\)")
1190 "*Describes the file name structure of `multi' files.
1191 Multi files allow you to contact a remote host in several hops.
1192 This is a list of four elements (REGEXP METHOD HOP LOCALNAME).
1194 The first element, REGEXP, gives a regular expression to match against
1195 the file name. In this regular expression, `%s' is replaced with the
1196 value of `tramp-multi-file-name-hop-structure'. (Note: in order to
1197 allow multiple hops, you normally want to use something like
1198 \"\\\\(\\\\(%s\\\\)+\\\\)\" in the regular expression. The outer pair
1199 of parentheses is used for the HOP element, see below.)
1201 All remaining elements are numbers. METHOD gives the number of the
1202 paren pair which matches the method name. HOP gives the number of the
1203 paren pair which matches the hop sequence. LOCALNAME gives the number of
1204 the paren pair which matches the localname (pathname) on the remote host.
1206 LOCALNAME can also be negative, which means to count from the end. Ie, a
1207 value of -1 means the last paren pair.
1209 I think it would be good if the regexp matches the whole of the
1210 string, but I haven't actually tried what happens if it doesn't..."
1212 :type
'(list (regexp :tag
"File name regexp")
1213 (integer :tag
"Paren pair for method name")
1214 (integer :tag
"Paren pair for hops")
1215 (integer :tag
"Paren pair to match localname")))
1217 (defcustom tramp-multi-file-name-hop-structure
1220 "\\(" tramp-method-regexp
"\\)" tramp-postfix-multi-method-regexp
1221 "\\(" tramp-user-regexp
"\\)" tramp-postfix-user-regexp
1222 "\\(" tramp-host-with-port-regexp
"\\)")
1224 "*Describes the structure of a hop in multi files.
1225 This is a list of four elements (REGEXP METHOD USER HOST). First
1226 element REGEXP is used to match against the hop. Pair number METHOD
1227 matches the method of one hop, pair number USER matches the user of
1228 one hop, pair number HOST matches the host of one hop.
1230 This regular expression should match exactly all of one hop."
1232 :type
'(list (regexp :tag
"Hop regexp")
1233 (integer :tag
"Paren pair for method name")
1234 (integer :tag
"Paren pair for user name")
1235 (integer :tag
"Paren pair for host name")))
1237 (defcustom tramp-make-multi-tramp-file-format
1239 (concat tramp-prefix-format
"%m")
1240 (concat tramp-postfix-multi-hop-format
1241 "%m" tramp-postfix-multi-method-format
1242 "%u" tramp-postfix-user-format
1244 (concat tramp-postfix-host-format
"%p"))
1245 "*Describes how to construct a `multi' file name.
1246 This is a list of three elements PREFIX, HOP and LOCALNAME.
1248 The first element PREFIX says how to construct the prefix, the second
1249 element HOP specifies what each hop looks like, and the final element
1250 LOCALNAME says how to construct the localname (pathname).
1252 In PREFIX, `%%' means `%' and `%m' means the method name.
1254 In HOP, `%%' means `%' and `%m', `%u', `%h' mean the hop method, hop
1255 user and hop host, respectively.
1257 In LOCALNAME, `%%' means `%' and `%p' means the localname.
1259 The resulting file name always contains one copy of PREFIX and one
1260 copy of LOCALNAME, but there is one copy of HOP for each hop in the file
1263 Note: the current implementation requires the prefix to contain the
1264 method name, followed by all the hops, and the localname must come
1267 :type
'(list string string string
))
1269 (defcustom tramp-terminal-type
"dumb"
1270 "*Value of TERM environment variable for logging in to remote host.
1271 Because Tramp wants to parse the output of the remote shell, it is easily
1272 confused by ANSI color escape sequences and suchlike. Often, shell init
1273 files conditionalize this setup based on the TERM environment variable."
1277 (defcustom tramp-completion-without-shell-p nil
1278 "*If nil, use shell wildcards for completion, else rely on Lisp only.
1279 Using shell wildcards for completions has the advantage that it can be
1280 fast even in large directories, but completion is always
1281 case-sensitive. Relying on Lisp only means that case-insensitive
1282 completion is possible (subject to the variable `completion-ignore-case'),
1283 but it might be slow on large directories."
1287 (defcustom tramp-actions-before-shell
1288 '((tramp-password-prompt-regexp tramp-action-password
)
1289 (tramp-login-prompt-regexp tramp-action-login
)
1290 (shell-prompt-pattern tramp-action-succeed
)
1291 (tramp-shell-prompt-pattern tramp-action-succeed
)
1292 (tramp-wrong-passwd-regexp tramp-action-permission-denied
)
1293 (tramp-yesno-prompt-regexp tramp-action-yesno
)
1294 (tramp-yn-prompt-regexp tramp-action-yn
)
1295 (tramp-terminal-prompt-regexp tramp-action-terminal
)
1296 (tramp-process-alive-regexp tramp-action-process-alive
))
1297 "List of pattern/action pairs.
1298 Whenever a pattern matches, the corresponding action is performed.
1299 Each item looks like (PATTERN ACTION).
1301 The PATTERN should be a symbol, a variable. The value of this
1302 variable gives the regular expression to search for. Note that the
1303 regexp must match at the end of the buffer, \"\\'\" is implicitly
1306 The ACTION should also be a symbol, but a function. When the
1307 corresponding PATTERN matches, the ACTION function is called."
1309 :type
'(repeat (list variable function
)))
1311 (defcustom tramp-actions-copy-out-of-band
1312 '((tramp-password-prompt-regexp tramp-action-password
)
1313 (tramp-wrong-passwd-regexp tramp-action-permission-denied
)
1314 (tramp-process-alive-regexp tramp-action-out-of-band
))
1315 "List of pattern/action pairs.
1316 This list is used for copying/renaming with out-of-band methods.
1317 See `tramp-actions-before-shell' for more info."
1319 :type
'(repeat (list variable function
)))
1321 (defcustom tramp-multi-actions
1322 '((tramp-password-prompt-regexp tramp-multi-action-password
)
1323 (tramp-login-prompt-regexp tramp-multi-action-login
)
1324 (shell-prompt-pattern tramp-multi-action-succeed
)
1325 (tramp-shell-prompt-pattern tramp-multi-action-succeed
)
1326 (tramp-wrong-passwd-regexp tramp-multi-action-permission-denied
)
1327 (tramp-process-alive-regexp tramp-multi-action-process-alive
))
1328 "List of pattern/action pairs.
1329 This list is used for each hop in multi-hop connections.
1330 See `tramp-actions-before-shell' for more info."
1332 :type
'(repeat (list variable function
)))
1334 (defcustom tramp-initial-commands
1337 "unset autocorrect")
1338 "List of commands to send to the first remote shell that we see.
1339 These commands will be sent to any shell, and thus they should be
1340 designed to work in such circumstances. Also, restrict the commands
1341 to the bare necessity for getting the remote shell into a state
1342 where it is possible to execute the Bourne-ish shell.
1344 At the moment, the command to execute the Bourne-ish shell uses strange
1345 quoting which `tcsh' tries to correct, so we send the command \"unset
1346 autocorrect\" to the remote host."
1348 :type
'(repeat string
))
1350 ;; Chunked sending kluge. We set this to 500 for black-listed constellations
1351 ;; known to have a bug in `process-send-string'; some ssh connections appear
1352 ;; to drop bytes when data is sent too quickly. There is also a connection
1353 ;; buffer local variable, which is computed depending on remote host properties
1354 ;; when `tramp-chunksize' is zero or nil.
1355 (defcustom tramp-chunksize
1356 (when (and (not (featurep 'xemacs
))
1357 (memq system-type
'(hpux)))
1359 "*If non-nil, chunksize for sending input to local process.
1360 It is necessary only on systems which have a buggy `process-send-string'
1361 implementation. The necessity, whether this variable must be set, can be
1362 checked via the following code:
1366 (proc (start-process (buffer-name) (current-buffer) \"wc\" \"-c\")))
1367 (process-send-string proc (make-string bytes ?x))
1368 (process-send-eof proc)
1369 (process-send-eof proc)
1370 (accept-process-output proc 1)
1371 (goto-char (point-min))
1372 (re-search-forward \"\\\\w+\")
1373 (message \"Bytes sent: %s\\tBytes received: %s\" bytes (match-string 0))))
1375 In the Emacs normally running Tramp, evaluate the above code.
1376 You can do this, for example, by pasting it into the `*scratch*'
1377 buffer and then hitting C-j with the cursor after the last
1378 closing parenthesis.
1380 If your Emacs is buggy, the sent and received numbers will be
1381 different. In that case, you'll want to set this variable to
1382 some number. For those people who have needed it, the value 500
1383 seems to have worked well. There is no way to predict what value
1384 you need; maybe you could just experiment a bit.
1386 Please raise a bug report via \"M-x tramp-bug\" if your system needs
1387 this variable to be set as well."
1389 :type
'(choice (const nil
) integer
))
1391 ;; Logging in to a remote host normally requires obtaining a pty. But
1392 ;; Emacs on MacOS X has process-connection-type set to nil by default,
1393 ;; so on those systems Tramp doesn't obtain a pty. Here, we allow
1394 ;; for an override of the system default.
1395 (defcustom tramp-process-connection-type t
1396 "Overrides `process-connection-type' for connections from Tramp.
1397 Tramp binds process-connection-type to the value given here before
1398 opening a connection to a remote host."
1400 :type
'(choice (const nil
) (const t
) (const pty
)))
1402 ;;; Internal Variables:
1404 (defvar tramp-buffer-file-attributes nil
1405 "Holds the `ls -ild' output for the current buffer.
1406 This variable is local to each buffer. It is not used if the remote
1407 machine groks Perl. If it is used, it's used as an emulation for
1408 the visited file modtime.")
1409 (make-variable-buffer-local 'tramp-buffer-file-attributes
)
1411 (defvar tramp-md5-function
1412 (cond ((and (require 'md5
) (fboundp 'md5
)) 'md5
)
1413 ((fboundp 'md5-encode
)
1414 (lambda (x) (base64-encode-string
1415 (funcall (symbol-function 'md5-encode
) x
))))
1416 (t (error "Coulnd't find an `md5' function")))
1417 "Function to call for running the MD5 algorithm.")
1419 (defvar tramp-end-of-output
1421 (funcall tramp-md5-function
1423 (prin1-to-string process-environment
)
1424 (current-time-string)
1426 ;; (if (fboundp 'directory-files-and-attributes)
1427 ;; (funcall 'directory-files-and-attributes
1428 ;; (or (getenv "HOME")
1429 ;; (tramp-temporary-file-directory)))
1432 ;; (cons x (file-attributes x)))
1433 ;; (directory-files (or (getenv "HOME")
1434 ;; (tramp-temporary-file-directory))
1437 "String used to recognize end of output.")
1439 (defvar tramp-connection-function nil
1440 "This internal variable holds a parameter for `tramp-methods'.
1441 In the connection buffer, this variable has the value of the like-named
1442 method parameter, as specified in `tramp-methods' (which see).")
1444 (defvar tramp-remote-sh nil
1445 "This internal variable holds a parameter for `tramp-methods'.
1446 In the connection buffer, this variable has the value of the like-named
1447 method parameter, as specified in `tramp-methods' (which see).")
1449 (defvar tramp-login-program nil
1450 "This internal variable holds a parameter for `tramp-methods'.
1451 In the connection buffer, this variable has the value of the like-named
1452 method parameter, as specified in `tramp-methods' (which see).")
1454 (defvar tramp-login-args nil
1455 "This internal variable holds a parameter for `tramp-methods'.
1456 In the connection buffer, this variable has the value of the like-named
1457 method parameter, as specified in `tramp-methods' (which see).")
1459 (defvar tramp-copy-program nil
1460 "This internal variable holds a parameter for `tramp-methods'.
1461 In the connection buffer, this variable has the value of the like-named
1462 method parameter, as specified in `tramp-methods' (which see).")
1464 (defvar tramp-copy-args nil
1465 "This internal variable holds a parameter for `tramp-methods'.
1466 In the connection buffer, this variable has the value of the like-named
1467 method parameter, as specified in `tramp-methods' (which see).")
1469 (defvar tramp-copy-keep-date-arg nil
1470 "This internal variable holds a parameter for `tramp-methods'.
1471 In the connection buffer, this variable has the value of the like-named
1472 method parameter, as specified in `tramp-methods' (which see).")
1474 (defvar tramp-encoding-command nil
1475 "This internal variable holds a parameter for `tramp-methods'.
1476 In the connection buffer, this variable has the value of the like-named
1477 method parameter, as specified in `tramp-methods' (which see).")
1479 (defvar tramp-decoding-command nil
1480 "This internal variable holds a parameter for `tramp-methods'.
1481 In the connection buffer, this variable has the value of the like-named
1482 method parameter, as specified in `tramp-methods' (which see).")
1484 (defvar tramp-encoding-function nil
1485 "This internal variable holds a parameter for `tramp-methods'.
1486 In the connection buffer, this variable has the value of the like-named
1487 method parameter, as specified in `tramp-methods' (which see).")
1489 (defvar tramp-decoding-function nil
1490 "This internal variable holds a parameter for `tramp-methods'.
1491 In the connection buffer, this variable has the value of the like-named
1492 method parameter, as specified in `tramp-methods' (which see).")
1494 (defvar tramp-password-end-of-line nil
1495 "This internal variable holds a parameter for `tramp-methods'.
1496 In the connection buffer, this variable has the value of the like-named
1497 method parameter, as specified in `tramp-methods' (which see).")
1499 ;; CCC `local in each buffer'?
1500 (defvar tramp-ls-command nil
1501 "This command is used to get a long listing with numeric user and group ids.
1502 This variable is automatically made buffer-local to each rsh process buffer
1503 upon opening the connection.")
1505 (defvar tramp-current-multi-method nil
1506 "Name of `multi' connection method for this *tramp* buffer, or nil if not multi.
1507 This variable is automatically made buffer-local to each rsh process buffer
1508 upon opening the connection.")
1510 (defvar tramp-current-method nil
1511 "Connection method for this *tramp* buffer.
1512 This variable is automatically made buffer-local to each rsh process buffer
1513 upon opening the connection.")
1515 (defvar tramp-current-user nil
1516 "Remote login name for this *tramp* buffer.
1517 This variable is automatically made buffer-local to each rsh process buffer
1518 upon opening the connection.")
1520 (defvar tramp-current-host nil
1521 "Remote host for this *tramp* buffer.
1522 This variable is automatically made buffer-local to each rsh process buffer
1523 upon opening the connection.")
1525 (defvar tramp-test-groks-nt nil
1526 "Whether the `test' command groks the `-nt' switch.
1527 \(`test A -nt B' tests if file A is newer than file B.)
1528 This variable is automatically made buffer-local to each rsh process buffer
1529 upon opening the connection.")
1531 (defvar tramp-file-exists-command nil
1532 "Command to use for checking if a file exists.
1533 This variable is automatically made buffer-local to each rsh process buffer
1534 upon opening the connection.")
1536 (defconst tramp-uudecode
"\
1538 \(echo begin 600 /tmp/tramp.$$; tail +2) | uudecode
1542 "Shell function to implement `uudecode' to standard output.
1543 Many systems support `uudecode -o /dev/stdout' or `uudecode -o -'
1544 for this or `uudecode -p', but some systems don't, and for them
1545 we have this shell function.")
1547 ;; Perl script to implement `file-attributes' in a Lisp `read'able
1548 ;; output. If you are hacking on this, note that you get *no* output
1549 ;; unless this spits out a complete line, including the '\n' at the
1551 ;; The device number is returned as "-1", because there will be a virtual
1552 ;; device number set in `tramp-handle-file-attributes'
1553 (defconst tramp-perl-file-attributes
"\
1554 @stat = lstat($ARGV[0]);
1555 if (($stat[2] & 0170000) == 0120000)
1557 $type = readlink($ARGV[0]);
1558 $type = \"\\\"$type\\\"\";
1560 elsif (($stat[2] & 0170000) == 040000)
1568 $uid = ($ARGV[1] eq \"integer\") ? $stat[4] : \"\\\"\" . getpwuid($stat[4]) . \"\\\"\";
1569 $gid = ($ARGV[1] eq \"integer\") ? $stat[5] : \"\\\"\" . getgrgid($stat[5]) . \"\\\"\";
1571 \"(%s %u %s %s (%u %u) (%u %u) (%u %u) %u %u t (%u . %u) -1)\\n\",
1576 $stat[8] >> 16 & 0xffff,
1578 $stat[9] >> 16 & 0xffff,
1580 $stat[10] >> 16 & 0xffff,
1584 $stat[1] >> 16 & 0xffff,
1587 "Perl script to produce output suitable for use with `file-attributes'
1588 on the remote file system.")
1590 (defconst tramp-perl-directory-files-and-attributes
"\
1593 @list = readdir(DIR);
1597 for($i = 0; $i < $n; $i++)
1599 $filename = $list[$i];
1600 @stat = lstat($filename);
1601 if (($stat[2] & 0170000) == 0120000)
1603 $type = readlink($filename);
1604 $type = \"\\\"$type\\\"\";
1606 elsif (($stat[2] & 0170000) == 040000)
1614 $uid = ($ARGV[1] eq \"integer\") ? $stat[4] : \"\\\"\" . getpwuid($stat[4]) . \"\\\"\";
1615 $gid = ($ARGV[1] eq \"integer\") ? $stat[5] : \"\\\"\" . getgrgid($stat[5]) . \"\\\"\";
1617 \"(\\\"%s\\\" %s %u %s %s (%u %u) (%u %u) (%u %u) %u %u t (%u . %u) (%u %u))\\n\",
1623 $stat[8] >> 16 & 0xffff,
1625 $stat[9] >> 16 & 0xffff,
1627 $stat[10] >> 16 & 0xffff,
1631 $stat[1] >> 16 & 0xffff,
1633 $stat[0] >> 16 & 0xffff,
1637 "Perl script implementing `directory-files-attributes' as Lisp `read'able
1640 ;; ;; These two use uu encoding.
1641 ;; (defvar tramp-perl-encode "%s -e'\
1642 ;; print qq(begin 644 xxx\n);
1645 ;; while (read(STDIN, $s, 45)) {
1646 ;; print pack(q(u), $s);
1651 ;; "Perl program to use for encoding a file.
1652 ;; Escape sequence %s is replaced with name of Perl binary.")
1654 ;; (defvar tramp-perl-decode "%s -ne '
1655 ;; print unpack q(u), $_;
1657 ;; "Perl program to use for decoding a file.
1658 ;; Escape sequence %s is replaced with name of Perl binary.")
1660 ;; These two use base64 encoding.
1661 (defvar tramp-perl-encode-with-module
1662 "perl -MMIME::Base64 -0777 -ne 'print encode_base64($_)'"
1663 "Perl program to use for encoding a file.
1664 Escape sequence %s is replaced with name of Perl binary.
1665 This string is passed to `format', so percent characters need to be doubled.
1666 This implementation requires the MIME::Base64 Perl module to be installed
1667 on the remote host.")
1669 (defvar tramp-perl-decode-with-module
1670 "perl -MMIME::Base64 -0777 -ne 'print decode_base64($_)'"
1671 "Perl program to use for decoding a file.
1672 Escape sequence %s is replaced with name of Perl binary.
1673 This string is passed to `format', so percent characters need to be doubled.
1674 This implementation requires the MIME::Base64 Perl module to be installed
1675 on the remote host.")
1677 (defvar tramp-perl-encode
1679 # This script contributed by Juanma Barranquero <lektu@terra.es>.
1680 # Copyright (C) 2002 Free Software Foundation, Inc.
1685 map {(substr(unpack(q(B8), chr $i++), 2, 6), $_)}
1686 split //, q(ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/);
1691 # We read in chunks of 54 bytes, to generate output lines
1692 # of 72 chars (plus end of line)
1695 while (my $data = <STDIN>) {
1698 # Only for the last chunk, and only if did not fill the last three-byte packet
1700 my $mod = length($data) %% 3;
1701 $pad = q(=) x (3 - $mod) if $mod;
1704 # Not the fastest method, but it is simple: unpack to binary string, split
1705 # by groups of 6 bits and convert back from binary to byte; then map into
1706 # the translation table
1710 (substr(unpack(q(B*), $data) . q(00000), 0, 432) =~ /....../g)),
1715 "Perl program to use for encoding a file.
1716 Escape sequence %s is replaced with name of Perl binary.
1717 This string is passed to `format', so percent characters need to be doubled.")
1719 (defvar tramp-perl-decode
1721 # This script contributed by Juanma Barranquero <lektu@terra.es>.
1722 # Copyright (C) 2002 Free Software Foundation, Inc.
1727 map {($_, substr(unpack(q(B8), chr $i++), 2, 6))}
1728 split //, q(ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/)
1731 my %%bytes = map {(unpack(q(B8), chr $_), chr $_)} 0 .. 255;
1735 # We are going to accumulate into $pending to accept any line length
1736 # (we do not check they are <= 76 chars as the RFC says)
1739 while (my $data = <STDIN>) {
1742 # If we find one or two =, we have reached the end and
1743 # any following data is to be discarded
1744 my $finished = $data =~ s/(==?).*/$1/;
1747 my $len = length($pending);
1748 my $chunk = substr($pending, 0, $len & ~3);
1749 $pending = substr($pending, $len & ~3 + 1);
1751 # Easy method: translate from chars to (pregenerated) six-bit packets, join,
1752 # split in 8-bit chunks and convert back to char.
1755 ((join q(), map {$trans{$_} || q()} split //, $chunk) =~ /......../g);
1760 "Perl program to use for decoding a file.
1761 Escape sequence %s is replaced with name of Perl binary.
1762 This string is passed to `format', so percent characters need to be doubled.")
1764 ; These values conform to `file-attributes' from XEmacs 21.2.
1765 ; GNU Emacs and other tools not checked.
1766 (defconst tramp-file-mode-type-map
'((0 .
"-") ; Normal file (SVID-v2 and XPG2)
1768 (2 .
"c") ; character device
1769 (3 .
"m") ; multiplexed character device (v7)
1770 (4 .
"d") ; directory
1771 (5 .
"?") ; Named special file (XENIX)
1772 (6 .
"b") ; block device
1773 (7 .
"?") ; multiplexed block device (v7)
1774 (8 .
"-") ; regular file
1775 (9 .
"n") ; network special file (HP-UX)
1776 (10 .
"l") ; symlink
1777 (11 .
"?") ; ACL shadow inode (Solaris, not userspace)
1779 (13 .
"D") ; door special (Solaris)
1780 (14 .
"w")) ; whiteout (BSD)
1781 "A list of file types returned from the `stat' system call.
1782 This is used to map a mode number to a permission string.")
1784 (defvar tramp-dos-coding-system
1785 (if (and (fboundp 'coding-system-p
)
1786 (funcall 'coding-system-p
'(dos)))
1789 "Some Emacsen know the `dos' coding system, others need `undecided-dos'.")
1791 (defvar tramp-last-cmd nil
1792 "Internal Tramp variable recording the last command sent.
1793 This variable is buffer-local in every buffer.")
1794 (make-variable-buffer-local 'tramp-last-cmd
)
1796 (defvar tramp-process-echoes nil
1797 "Whether to process echoes from the remote shell.")
1799 (defvar tramp-last-cmd-time nil
1800 "Internal Tramp variable recording the time when the last cmd was sent.
1801 This variable is buffer-local in every buffer.")
1802 (make-variable-buffer-local 'tramp-last-cmd-time
)
1804 ;; This variable does not have the right value in XEmacs. What should
1805 ;; I use instead of find-operation-coding-system in XEmacs?
1806 (defvar tramp-feature-write-region-fix
1807 (when (fboundp 'find-operation-coding-system
)
1808 (let ((file-coding-system-alist '(("test" emacs-mule
))))
1809 (funcall (symbol-function 'find-operation-coding-system
)
1810 'write-region
0 0 "" nil
"test")))
1811 "Internal variable to say if `write-region' chooses the right coding.
1812 Older versions of Emacs chose the coding system for `write-region' based
1813 on the FILENAME argument, even if VISIT was a string.")
1815 ;; New handlers should be added here. The following operations can be
1816 ;; handled using the normal primitives: file-name-as-directory,
1817 ;; file-name-directory, file-name-nondirectory,
1818 ;; file-name-sans-versions, get-file-buffer.
1819 (defconst tramp-file-name-handler-alist
1821 (load . tramp-handle-load
)
1822 (make-symbolic-link . tramp-handle-make-symbolic-link
)
1823 (file-name-directory . tramp-handle-file-name-directory
)
1824 (file-name-nondirectory . tramp-handle-file-name-nondirectory
)
1825 (file-truename . tramp-handle-file-truename
)
1826 (file-exists-p . tramp-handle-file-exists-p
)
1827 (file-directory-p . tramp-handle-file-directory-p
)
1828 (file-executable-p . tramp-handle-file-executable-p
)
1829 (file-accessible-directory-p . tramp-handle-file-accessible-directory-p
)
1830 (file-readable-p . tramp-handle-file-readable-p
)
1831 (file-regular-p . tramp-handle-file-regular-p
)
1832 (file-symlink-p . tramp-handle-file-symlink-p
)
1833 (file-writable-p . tramp-handle-file-writable-p
)
1834 (file-ownership-preserved-p . tramp-handle-file-ownership-preserved-p
)
1835 (file-newer-than-file-p . tramp-handle-file-newer-than-file-p
)
1836 (file-attributes . tramp-handle-file-attributes
)
1837 (file-modes . tramp-handle-file-modes
)
1838 (directory-files . tramp-handle-directory-files
)
1839 (directory-files-and-attributes . tramp-handle-directory-files-and-attributes
)
1840 (file-name-all-completions . tramp-handle-file-name-all-completions
)
1841 (file-name-completion . tramp-handle-file-name-completion
)
1842 (add-name-to-file . tramp-handle-add-name-to-file
)
1843 (copy-file . tramp-handle-copy-file
)
1844 (rename-file . tramp-handle-rename-file
)
1845 (set-file-modes . tramp-handle-set-file-modes
)
1846 (make-directory . tramp-handle-make-directory
)
1847 (delete-directory . tramp-handle-delete-directory
)
1848 (delete-file . tramp-handle-delete-file
)
1849 (directory-file-name . tramp-handle-directory-file-name
)
1850 (shell-command . tramp-handle-shell-command
)
1851 (process-file . tramp-handle-process-file
)
1852 (insert-directory . tramp-handle-insert-directory
)
1853 (expand-file-name . tramp-handle-expand-file-name
)
1854 (file-local-copy . tramp-handle-file-local-copy
)
1855 (file-remote-p . tramp-handle-file-remote-p
)
1856 (insert-file-contents . tramp-handle-insert-file-contents
)
1857 (write-region . tramp-handle-write-region
)
1858 (find-backup-file-name . tramp-handle-find-backup-file-name
)
1859 (make-auto-save-file-name . tramp-handle-make-auto-save-file-name
)
1860 (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory
)
1861 (dired-compress-file . tramp-handle-dired-compress-file
)
1862 (dired-call-process . tramp-handle-dired-call-process
)
1863 (dired-recursive-delete-directory
1864 . tramp-handle-dired-recursive-delete-directory
)
1865 (set-visited-file-modtime . tramp-handle-set-visited-file-modtime
)
1866 (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime
))
1867 "Alist of handler functions.
1868 Operations not mentioned here will be handled by the normal Emacs functions.")
1870 ;; Handlers for partial tramp file names. For GNU Emacs just
1871 ;; `file-name-all-completions' is needed. The other ones are necessary
1873 (defconst tramp-completion-file-name-handler-alist
1875 (file-name-directory . tramp-completion-handle-file-name-directory
)
1876 (file-name-nondirectory . tramp-completion-handle-file-name-nondirectory
)
1877 (file-exists-p . tramp-completion-handle-file-exists-p
)
1878 (file-name-all-completions . tramp-completion-handle-file-name-all-completions
)
1879 (file-name-completion . tramp-completion-handle-file-name-completion
)
1880 (expand-file-name . tramp-completion-handle-expand-file-name
))
1881 "Alist of completion handler functions.
1882 Used for file names matching `tramp-file-name-regexp'. Operations not
1883 mentioned here will be handled by `tramp-file-name-handler-alist' or the
1884 normal Emacs functions.")
1886 ;; Handlers for foreign methods, like FTP or SMB, shall be plugged here.
1887 (defvar tramp-foreign-file-name-handler-alist
1888 ;; (identity . tramp-sh-file-name-handler) should always be the last
1889 ;; entry, since `identity' always matches.
1890 '((identity . tramp-sh-file-name-handler
))
1891 "Alist of elements (FUNCTION . HANDLER) for foreign methods handled specially.
1892 If (FUNCTION FILENAME) returns non-nil, then all I/O on that file is done by
1895 ;;; Internal functions which must come first.
1897 (defsubst tramp-message
(level fmt-string
&rest args
)
1898 "Emit a message depending on verbosity level.
1899 First arg LEVEL says to be quiet if `tramp-verbose' is less than LEVEL. The
1900 message is emitted only if `tramp-verbose' is greater than or equal to LEVEL.
1901 Calls function `message' with FMT-STRING as control string and the remaining
1902 ARGS to actually emit the message (if applicable).
1904 This function expects to be called from the tramp buffer only!"
1905 (when (<= level tramp-verbose
)
1906 (apply #'message
(concat "tramp: " fmt-string
) args
)
1907 (when tramp-debug-buffer
1910 (tramp-get-debug-buffer
1911 tramp-current-multi-method tramp-current-method
1912 tramp-current-user tramp-current-host
))
1913 (goto-char (point-max))
1916 (tramp-insert-with-face
1918 (concat "# " (apply #'format fmt-string args
) "\n"))))))
1920 (defun tramp-message-for-buffer
1921 (multi-method method user host level fmt-string
&rest args
)
1922 "Like `tramp-message' but temporarily switches to the tramp buffer.
1923 First three args METHOD, USER, and HOST identify the tramp buffer to use,
1924 remaining args passed to `tramp-message'."
1926 (set-buffer (tramp-get-buffer multi-method method user host
))
1927 (apply 'tramp-message level fmt-string args
)))
1929 (defsubst tramp-line-end-position nil
1930 "Return point at end of line.
1931 Calls `line-end-position' or `point-at-eol' if defined, else
1932 own implementation."
1934 ((fboundp 'line-end-position
) (funcall (symbol-function 'line-end-position
)))
1935 ((fboundp 'point-at-eol
) (funcall (symbol-function 'point-at-eol
)))
1936 (t (save-excursion (end-of-line) (point)))))
1938 (defmacro with-parsed-tramp-file-name
(filename var
&rest body
)
1939 "Parse a Tramp filename and make components available in the body.
1941 First arg FILENAME is evaluated and dissected into its components.
1942 Second arg VAR is a symbol. It is used as a variable name to hold
1943 the filename structure. It is also used as a prefix for the variables
1944 holding the components. For example, if VAR is the symbol `foo', then
1945 `foo' will be bound to the whole structure, `foo-multi-method' will
1946 be bound to the multi-method component, and so on for `foo-method',
1947 `foo-user', `foo-host', `foo-localname'.
1949 Remaining args are Lisp expressions to be evaluated (inside an implicit
1952 If VAR is nil, then we bind `v' to the structure and `multi-method',
1953 `method', `user', `host', `localname' to the components."
1954 `(let* ((,(or var
'v
) (tramp-dissect-file-name ,filename
))
1955 (,(if var
(intern (concat (symbol-name var
) "-multi-method")) 'multi-method
)
1956 (tramp-file-name-multi-method ,(or var
'v
)))
1957 (,(if var
(intern (concat (symbol-name var
) "-method")) 'method
)
1958 (tramp-file-name-method ,(or var
'v
)))
1959 (,(if var
(intern (concat (symbol-name var
) "-user")) 'user
)
1960 (tramp-file-name-user ,(or var
'v
)))
1961 (,(if var
(intern (concat (symbol-name var
) "-host")) 'host
)
1962 (tramp-file-name-host ,(or var
'v
)))
1963 (,(if var
(intern (concat (symbol-name var
) "-localname")) 'localname
)
1964 (tramp-file-name-localname ,(or var
'v
))))
1967 (put 'with-parsed-tramp-file-name
'lisp-indent-function
2)
1968 ;; To be activated for debugging containing this macro
1969 ;; It works only when VAR is nil. Otherwise, it can be deactivated by
1970 ;; (put 'with-parsed-tramp-file-name 'edebug-form-spec 0)
1971 ;; I'm too stupid to write a precise SPEC for it.
1972 (put 'with-parsed-tramp-file-name
'edebug-form-spec t
)
1974 (defmacro tramp-let-maybe
(variable value
&rest body
)
1975 "Let-bind VARIABLE to VALUE in BODY, but only if VARIABLE is not obsolete.
1976 BODY is executed whether or not the variable is obsolete.
1977 The intent is to protect against `obsolete variable' warnings."
1978 `(if (get ',variable
'byte-obsolete-variable
)
1980 (let ((,variable
,value
))
1982 (put 'tramp-let-maybe
'lisp-indent-function
2)
1984 ;;; Config Manipulation Functions:
1986 (defun tramp-set-completion-function (method function-list
)
1987 "Sets the list of completion functions for METHOD.
1988 FUNCTION-LIST is a list of entries of the form (FUNCTION FILE).
1989 The FUNCTION is intended to parse FILE according its syntax.
1990 It might be a predefined FUNCTION, or a user defined FUNCTION.
1991 Predefined FUNCTIONs are `tramp-parse-rhosts', `tramp-parse-shosts',
1992 `tramp-parse-sconfig',`tramp-parse-hosts', `tramp-parse-passwd',
1993 and `tramp-parse-netrc'.
1997 (tramp-set-completion-function
1999 '((tramp-parse-sconfig \"/etc/ssh_config\")
2000 (tramp-parse-sconfig \"~/.ssh/config\")))"
2002 (let ((r function-list
)
2004 (setq tramp-completion-function-alist
2005 (delete (assoc method tramp-completion-function-alist
)
2006 tramp-completion-function-alist
))
2009 ;; Remove double entries
2010 (when (member (car v
) (cdr v
))
2011 (setcdr v
(delete (car v
) (cdr v
))))
2012 ;; Check for function and file
2013 (unless (and (functionp (nth 0 (car v
)))
2014 (file-exists-p (nth 1 (car v
))))
2015 (setq r
(delete (car v
) r
)))
2019 (add-to-list 'tramp-completion-function-alist
2022 (defun tramp-get-completion-function (method)
2023 "Returns list of completion functions for METHOD.
2024 For definition of that list see `tramp-set-completion-function'."
2025 (cdr (assoc method tramp-completion-function-alist
)))
2027 ;;; File Name Handler Functions:
2029 (defun tramp-handle-make-symbolic-link
2030 (filename linkname
&optional ok-if-already-exists
)
2031 "Like `make-symbolic-link' for tramp files.
2032 If LINKNAME is a non-Tramp file, it is used verbatim as the target of
2033 the symlink. If LINKNAME is a Tramp file, only the localname component is
2034 used as the target of the symlink.
2036 If LINKNAME is a Tramp file and the localname component is relative, then
2037 it is expanded first, before the localname component is taken. Note that
2038 this can give surprising results if the user/host for the source and
2039 target of the symlink differ."
2040 (with-parsed-tramp-file-name linkname l
2041 (let ((ln (tramp-get-remote-ln l-multi-method l-method l-user l-host
))
2042 (cwd (file-name-directory l-localname
)))
2045 (list "Making a symbolic link."
2046 "ln(1) does not exist on the remote host.")))
2048 ;; Do the 'confirm if exists' thing.
2049 (when (file-exists-p linkname
)
2051 (if (or (null ok-if-already-exists
) ; not allowed to exist
2052 (and (numberp ok-if-already-exists
)
2055 "File %s already exists; make it a link anyway? "
2057 (signal 'file-already-exists
(list "File already exists" l-localname
))
2058 (delete-file linkname
)))
2060 ;; If FILENAME is a Tramp name, use just the localname component.
2061 (when (tramp-tramp-file-p filename
)
2062 (setq filename
(tramp-file-name-localname
2063 (tramp-dissect-file-name
2064 (expand-file-name filename
)))))
2066 ;; Right, they are on the same host, regardless of user, method, etc.
2067 ;; We now make the link on the remote machine. This will occur as the user
2068 ;; that FILENAME belongs to.
2070 (tramp-send-command-and-check
2071 l-multi-method l-method l-user l-host
2072 (format "cd %s && %s -sf %s %s"
2079 (defun tramp-handle-load (file &optional noerror nomessage nosuffix must-suffix
)
2080 "Like `load' for tramp files. Not implemented!"
2081 (unless (file-name-absolute-p file
)
2082 (error "Tramp cannot `load' files without absolute file name"))
2083 (with-parsed-tramp-file-name file nil
2085 (cond ((file-exists-p (concat file
".elc"))
2086 (setq file
(concat file
".elc")))
2087 ((file-exists-p (concat file
".el"))
2088 (setq file
(concat file
".el")))))
2090 ;; The first condition is always true for absolute file names.
2091 ;; Included for safety's sake.
2092 (unless (or (file-name-directory file
)
2093 (string-match "\\.elc?\\'" file
))
2094 (error "File `%s' does not include a `.el' or `.elc' suffix"
2097 (when (not (file-exists-p file
))
2098 (error "Cannot load nonexistent file `%s'" file
)))
2099 (if (not (file-exists-p file
))
2102 (message "Loading %s..." file
))
2103 (let ((local-copy (file-local-copy file
)))
2104 ;; MUST-SUFFIX doesn't exist on XEmacs, so let it default to nil.
2105 (load local-copy noerror t t
)
2106 (delete-file local-copy
))
2108 (message "Loading %s...done" file
))
2111 ;; Localname manipulation functions that grok TRAMP localnames...
2112 (defun tramp-handle-file-name-directory (file)
2113 "Like `file-name-directory' but aware of TRAMP files."
2114 ;; everything except the last filename thing is the directory
2115 (with-parsed-tramp-file-name file nil
2116 ;; For the following condition, two possibilities should be tried:
2117 ;; (1) (string= localname "")
2118 ;; (2) (or (string= localname "") (string= localname "/"))
2119 ;; The second variant fails when completing a "/" directory on
2120 ;; the remote host, that is a filename which looks like
2121 ;; "/user@host:/". But maybe wildcards fail with the first variant.
2122 ;; We should do some investigation.
2123 (if (string= localname
"")
2124 ;; For a filename like "/[foo]", we return "/". The `else'
2125 ;; case would return "/[foo]" unchanged. But if we do that,
2126 ;; then `file-expand-wildcards' ceases to work. It's not
2127 ;; quite clear to me what's the intuition that tells that this
2128 ;; behavior is the right behavior, but oh, well.
2130 ;; run the command on the localname portion only
2131 ;; CCC: This should take into account the remote machine type, no?
2132 ;; --daniel <daniel@danann.net>
2133 (tramp-make-tramp-file-name multi-method method user host
2134 ;; This will not recurse...
2135 (or (file-name-directory localname
) "")))))
2137 (defun tramp-handle-file-name-nondirectory (file)
2138 "Like `file-name-nondirectory' but aware of TRAMP files."
2139 (with-parsed-tramp-file-name file nil
2140 (file-name-nondirectory localname
)))
2142 (defun tramp-handle-file-truename (filename &optional counter prev-dirs
)
2143 "Like `file-truename' for tramp files."
2144 (with-parsed-tramp-file-name (expand-file-name filename
) nil
2145 (let* ((steps (tramp-split-string localname
"/"))
2146 (localnamedir (tramp-let-maybe directory-sep-char ?
/ ;for XEmacs
2147 (file-name-as-directory localname
)))
2148 (is-dir (string= localname localnamedir
))
2151 ;; Don't make the following value larger than necessary.
2152 ;; People expect an error message in a timely fashion when
2153 ;; something is wrong; otherwise they might think that Emacs
2154 ;; is hung. Of course, correctness has to come first.
2156 (result nil
) ;result steps in reverse order
2158 (tramp-message-for-buffer
2159 multi-method method user host
2160 10 "Finding true name for `%s'" filename
)
2161 (while (and steps
(< numchase numchase-limit
))
2162 (setq thisstep
(pop steps
))
2163 (tramp-message-for-buffer
2164 multi-method method user host
2166 (mapconcat 'identity
2167 (append '("") (reverse result
) (list thisstep
))
2169 (setq symlink-target
2170 (nth 0 (file-attributes
2171 (tramp-make-tramp-file-name
2172 multi-method method user host
2173 (mapconcat 'identity
2178 (cond ((string= "." thisstep
)
2179 (tramp-message-for-buffer multi-method method user host
2180 10 "Ignoring step `.'"))
2181 ((string= ".." thisstep
)
2182 (tramp-message-for-buffer multi-method method user host
2183 10 "Processing step `..'")
2185 ((stringp symlink-target
)
2186 ;; It's a symlink, follow it.
2187 (tramp-message-for-buffer
2188 multi-method method user host
2189 10 "Follow symlink to %s" symlink-target
)
2190 (setq numchase
(1+ numchase
))
2191 (when (file-name-absolute-p symlink-target
)
2193 ;; If the symlink was absolute, we'll get a string like
2194 ;; "/user@host:/some/target"; extract the
2195 ;; "/some/target" part from it.
2196 (when (tramp-tramp-file-p symlink-target
)
2197 (with-parsed-tramp-file-name symlink-target sym
2198 (unless (equal (list multi-method method user host
)
2199 (list sym-multi-method sym-method
2201 (error "Symlink target `%s' on wrong host"
2203 (setq symlink-target localname
)))
2205 (append (tramp-split-string symlink-target
"/") steps
)))
2208 (setq result
(cons thisstep result
)))))
2209 (when (>= numchase numchase-limit
)
2210 (error "Maximum number (%d) of symlinks exceeded" numchase-limit
))
2211 (setq result
(reverse result
))
2212 ;; Combine list to form string.
2215 (mapconcat 'identity
(cons "" result
) "/")
2217 (when (and is-dir
(or (string= "" result
)
2218 (not (string= (substring result -
1) "/"))))
2219 (setq result
(concat result
"/")))
2220 (tramp-message-for-buffer
2221 multi-method method user host
2222 10 "True name of `%s' is `%s'" filename result
)
2223 (tramp-make-tramp-file-name
2224 multi-method method user host result
))))
2228 (defun tramp-handle-file-exists-p (filename)
2229 "Like `file-exists-p' for tramp files."
2230 (with-parsed-tramp-file-name filename nil
2232 (zerop (tramp-send-command-and-check
2233 multi-method method user host
2235 (tramp-get-file-exists-command multi-method method user host
)
2236 (tramp-shell-quote-argument localname
)))))))
2238 ;; Devices must distinguish physical file systems. The device numbers
2239 ;; provided by "lstat" aren't unique, because we operate on different hosts.
2240 ;; So we use virtual device numbers, generated by Tramp. Both Ange-FTP and
2241 ;; EFS use device number "-1". In order to be different, we use device number
2242 ;; (-1 x), whereby "x" is unique for a given (multi-method method user host).
2243 (defvar tramp-devices nil
2244 "Keeps virtual device numbers.")
2246 ;; CCC: This should check for an error condition and signal failure
2247 ;; when something goes wrong.
2248 ;; Daniel Pittman <daniel@danann.net>
2249 (defun tramp-handle-file-attributes (filename &optional id-format
)
2250 "Like `file-attributes' for tramp files."
2251 (when (file-exists-p filename
)
2252 ;; file exists, find out stuff
2253 (unless id-format
(setq id-format
'integer
))
2254 (with-parsed-tramp-file-name filename nil
2256 (tramp-convert-file-attributes
2257 multi-method method user host
2258 (if (tramp-get-remote-perl multi-method method user host
)
2259 (tramp-handle-file-attributes-with-perl multi-method method user host
2260 localname id-format
)
2261 (tramp-handle-file-attributes-with-ls multi-method method user host
2262 localname id-format
)))))))
2264 (defun tramp-handle-file-attributes-with-ls
2265 (multi-method method user host localname
&optional id-format
)
2266 "Implement `file-attributes' for tramp files using the ls(1) command."
2268 res-inode res-filemodes res-numlinks
2269 res-uid res-gid res-size res-symlink-target
)
2270 (tramp-message-for-buffer multi-method method user host
10
2271 "file attributes with ls: %s"
2272 (tramp-make-tramp-file-name
2273 multi-method method user host localname
))
2275 multi-method method user host
2277 (tramp-get-ls-command multi-method method user host
)
2278 (if (eq id-format
'integer
) "-ildn" "-ild")
2279 (tramp-shell-quote-argument localname
)))
2280 (tramp-wait-for-output)
2281 ;; parse `ls -l' output ...
2285 (read (current-buffer))
2286 (invalid-read-syntax
2287 (when (and (equal (cadr err
)
2288 "Integer constant overflow in reader")
2290 "^[0-9]+\\([0-9][0-9][0-9][0-9][0-9]\\)\\'"
2292 (let* ((big (read (substring (caddr err
) 0
2293 (match-beginning 1))))
2294 (small (read (match-string 1 (caddr err
))))
2295 (twiddle (/ small
65536)))
2296 (cons (+ big twiddle
)
2297 (- small
(* twiddle
65536))))))))
2298 ;; ... file mode flags
2299 (setq res-filemodes
(symbol-name (read (current-buffer))))
2301 (setq res-numlinks
(read (current-buffer)))
2303 (setq res-uid
(read (current-buffer)))
2304 (setq res-gid
(read (current-buffer)))
2305 (when (eq id-format
'integer
)
2306 (unless (numberp res-uid
) (setq res-uid -
1))
2307 (unless (numberp res-gid
) (setq res-gid -
1)))
2309 (setq res-size
(read (current-buffer)))
2310 ;; From the file modes, figure out other stuff.
2311 (setq symlinkp
(eq ?l
(aref res-filemodes
0)))
2312 (setq dirp
(eq ?d
(aref res-filemodes
0)))
2313 ;; if symlink, find out file name pointed to
2315 (search-forward "-> ")
2316 (setq res-symlink-target
2317 (buffer-substring (point)
2318 (tramp-line-end-position))))
2319 ;; return data gathered
2321 ;; 0. t for directory, string (name linked to) for symbolic
2323 (or dirp res-symlink-target nil
)
2324 ;; 1. Number of links to file.
2330 ;; 4. Last access time, as a list of two integers. First
2331 ;; integer has high-order 16 bits of time, second has low 16
2333 ;; 5. Last modification time, likewise.
2334 ;; 6. Last status change time, likewise.
2335 '(0 0) '(0 0) '(0 0) ;CCC how to find out?
2336 ;; 7. Size in bytes (-1, if number is out of range).
2338 ;; 8. File modes, as a string of ten letters or dashes as in ls -l.
2340 ;; 9. t iff file's gid would change if file were deleted and
2343 ;; 10. inode number.
2345 ;; 11. Device number. Will be replaced by a virtual device number.
2349 (defun tramp-handle-file-attributes-with-perl
2350 (multi-method method user host localname
&optional id-format
)
2351 "Implement `file-attributes' for tramp files using a Perl script."
2352 (tramp-message-for-buffer multi-method method user host
10
2353 "file attributes with perl: %s"
2354 (tramp-make-tramp-file-name
2355 multi-method method user host localname
))
2356 (tramp-maybe-send-perl-script multi-method method user host
2357 tramp-perl-file-attributes
2358 "tramp_file_attributes")
2359 (tramp-send-command multi-method method user host
2360 (format "tramp_file_attributes %s %s"
2361 (tramp-shell-quote-argument localname
) id-format
))
2362 (tramp-wait-for-output)
2363 (read (current-buffer)))
2365 (defun tramp-handle-set-visited-file-modtime (&optional time-list
)
2366 "Like `set-visited-file-modtime' for tramp files."
2367 (unless (buffer-file-name)
2368 (error "Can't set-visited-file-modtime: buffer `%s' not visiting a file"
2371 (tramp-run-real-handler 'set-visited-file-modtime
(list time-list
))
2372 (let ((f (buffer-file-name)))
2373 (with-parsed-tramp-file-name f nil
2374 (let* ((attr (file-attributes f
))
2375 ;; '(-1 65535) means file doesn't exists yet.
2376 (modtime (or (nth 5 attr
) '(-1 65535))))
2377 ;; We use '(0 0) as a don't-know value. See also
2378 ;; `tramp-handle-file-attributes-with-ls'.
2379 (if (not (equal modtime
'(0 0)))
2380 (tramp-run-real-handler 'set-visited-file-modtime
(list modtime
))
2383 multi-method method user host
2384 (format "%s -ild %s"
2385 (tramp-get-ls-command multi-method method user host
)
2386 (tramp-shell-quote-argument localname
)))
2387 (tramp-wait-for-output)
2388 (setq attr
(buffer-substring (point)
2389 (progn (end-of-line) (point)))))
2390 (setq tramp-buffer-file-attributes attr
))
2393 ;; CCC continue here
2395 ;; This function makes the same assumption as
2396 ;; `tramp-handle-set-visited-file-modtime'.
2397 (defun tramp-handle-verify-visited-file-modtime (buf)
2398 "Like `verify-visited-file-modtime' for tramp files.
2399 At the time `verify-visited-file-modtime' calls this function, we
2400 already know that the buffer is visiting a file and that
2401 `visited-file-modtime' does not return 0. Do not call this
2402 function directly, unless those two cases are already taken care
2404 (with-current-buffer buf
2405 ;; There is no file visiting the buffer, or the buffer has no
2406 ;; recorded last modification time.
2407 (if (or (not (buffer-file-name))
2408 (eq (visited-file-modtime) 0))
2410 (let ((f (buffer-file-name)))
2411 (with-parsed-tramp-file-name f nil
2412 (let* ((attr (file-attributes f
))
2413 (modtime (nth 5 attr
))
2414 (mt (visited-file-modtime)))
2417 ;; file exists, and has a known modtime.
2418 ((and attr
(not (equal modtime
'(0 0))))
2419 (< (abs (tramp-time-diff
2421 ;; For compatibility, deal with both the old
2422 ;; (HIGH . LOW) and the new (HIGH LOW)
2423 ;; return values of `visited-file-modtime'.
2425 (list (car mt
) (cdr mt
))
2428 ;; modtime has the don't know value.
2432 multi-method method user host
2433 (format "%s -ild %s"
2434 (tramp-get-ls-command multi-method method user host
)
2435 (tramp-shell-quote-argument localname
)))
2436 (tramp-wait-for-output)
2437 (setq attr
(buffer-substring
2438 (point) (progn (end-of-line) (point)))))
2439 (equal tramp-buffer-file-attributes attr
))
2440 ;; If file does not exist, say it is not modified
2441 ;; if and only if that agrees with the buffer's record.
2442 (t (equal mt
'(-1 65535))))))))))
2444 (defun tramp-handle-set-file-modes (filename mode
)
2445 "Like `set-file-modes' for tramp files."
2446 (with-parsed-tramp-file-name filename nil
2448 (unless (zerop (tramp-send-command-and-check
2449 multi-method method user host
2450 (format "chmod %s %s"
2451 (tramp-decimal-to-octal mode
)
2452 (tramp-shell-quote-argument localname
))))
2455 ;; FIXME: extract the proper text from chmod's stderr.
2456 "error while changing file's mode"
2459 ;; Simple functions using the `test' command.
2461 (defun tramp-handle-file-executable-p (filename)
2462 "Like `file-executable-p' for tramp files."
2463 (with-parsed-tramp-file-name filename nil
2464 (zerop (tramp-run-test "-x" filename
))))
2466 (defun tramp-handle-file-readable-p (filename)
2467 "Like `file-readable-p' for tramp files."
2468 (with-parsed-tramp-file-name filename nil
2469 (zerop (tramp-run-test "-r" filename
))))
2471 (defun tramp-handle-file-accessible-directory-p (filename)
2472 "Like `file-accessible-directory-p' for tramp files."
2473 (with-parsed-tramp-file-name filename nil
2474 (and (zerop (tramp-run-test "-d" filename
))
2475 (zerop (tramp-run-test "-r" filename
))
2476 (zerop (tramp-run-test "-x" filename
)))))
2478 ;; When the remote shell is started, it looks for a shell which groks
2479 ;; tilde expansion. Here, we assume that all shells which grok tilde
2480 ;; expansion will also provide a `test' command which groks `-nt' (for
2481 ;; newer than). If this breaks, tell me about it and I'll try to do
2482 ;; something smarter about it.
2483 (defun tramp-handle-file-newer-than-file-p (file1 file2
)
2484 "Like `file-newer-than-file-p' for tramp files."
2485 (cond ((not (file-exists-p file1
))
2487 ((not (file-exists-p file2
))
2489 ;; We are sure both files exist at this point.
2492 ;; We try to get the mtime of both files. If they are not
2493 ;; equal to the "dont-know" value, then we subtract the times
2494 ;; and obtain the result.
2495 (let ((fa1 (file-attributes file1
))
2496 (fa2 (file-attributes file2
)))
2497 (if (and (not (equal (nth 5 fa1
) '(0 0)))
2498 (not (equal (nth 5 fa2
) '(0 0))))
2499 (> 0 (tramp-time-diff (nth 5 fa2
) (nth 5 fa1
)))
2500 ;; If one of them is the dont-know value, then we can
2501 ;; still try to run a shell command on the remote host.
2502 ;; However, this only works if both files are Tramp
2503 ;; files and both have the same method, same user, same
2505 (unless (and (tramp-tramp-file-p file1
)
2506 (tramp-tramp-file-p file2
))
2510 "Cannot check if Tramp file is newer than non-Tramp file"
2512 (with-parsed-tramp-file-name file1 v1
2513 (with-parsed-tramp-file-name file2 v2
2514 (unless (and (equal v1-multi-method v2-multi-method
)
2515 (equal v1-method v2-method
)
2516 (equal v1-user v2-user
)
2517 (equal v1-host v2-host
))
2519 (list "Files must have same method, user, host"
2521 (unless (and (tramp-tramp-file-p file1
)
2522 (tramp-tramp-file-p file2
))
2524 (list "Files must be tramp files on same host"
2526 (if (tramp-get-test-groks-nt
2527 v1-multi-method v1-method v1-user v1-host
)
2528 (zerop (tramp-run-test2 "test" file1 file2
"-nt"))
2529 (zerop (tramp-run-test2
2530 "tramp_test_nt" file1 file2
)))))))))))
2532 ;; Functions implemented using the basic functions above.
2534 (defun tramp-handle-file-modes (filename)
2535 "Like `file-modes' for tramp files."
2536 (with-parsed-tramp-file-name filename nil
2537 (when (file-exists-p filename
)
2538 (tramp-mode-string-to-int
2539 (nth 8 (file-attributes filename
))))))
2541 (defun tramp-handle-file-directory-p (filename)
2542 "Like `file-directory-p' for tramp files."
2543 ;; Care must be taken that this function returns `t' for symlinks
2544 ;; pointing to directories. Surely the most obvious implementation
2545 ;; would be `test -d', but that returns false for such symlinks.
2546 ;; CCC: Stefan Monnier says that `test -d' follows symlinks. And
2547 ;; I now think he's right. So we could be using `test -d', couldn't
2550 ;; Alternatives: `cd %s', `test -d %s'
2551 (with-parsed-tramp-file-name filename nil
2554 (tramp-send-command-and-check
2555 multi-method method user host
2556 (format "test -d %s"
2557 (tramp-shell-quote-argument localname
))
2558 t
))))) ;run command in subshell
2560 (defun tramp-handle-file-regular-p (filename)
2561 "Like `file-regular-p' for tramp files."
2562 (with-parsed-tramp-file-name filename nil
2563 (and (file-exists-p filename
)
2564 (eq ?-
(aref (nth 8 (file-attributes filename
)) 0)))))
2566 (defun tramp-handle-file-symlink-p (filename)
2567 "Like `file-symlink-p' for tramp files."
2568 (with-parsed-tramp-file-name filename nil
2569 (let ((x (car (file-attributes filename
))))
2571 ;; When Tramp is running on VMS, then `file-name-absolute-p'
2572 ;; might do weird things.
2573 (if (file-name-absolute-p x
)
2574 (tramp-make-tramp-file-name
2575 multi-method method user host x
)
2578 (defun tramp-handle-file-writable-p (filename)
2579 "Like `file-writable-p' for tramp files."
2580 (with-parsed-tramp-file-name filename nil
2581 (if (file-exists-p filename
)
2582 ;; Existing files must be writable.
2583 (zerop (tramp-run-test "-w" filename
))
2584 ;; If file doesn't exist, check if directory is writable.
2585 (and (zerop (tramp-run-test
2586 "-d" (file-name-directory filename
)))
2587 (zerop (tramp-run-test
2588 "-w" (file-name-directory filename
)))))))
2590 (defun tramp-handle-file-ownership-preserved-p (filename)
2591 "Like `file-ownership-preserved-p' for tramp files."
2592 (with-parsed-tramp-file-name filename nil
2593 (or (not (file-exists-p filename
))
2594 ;; Existing files must be writable.
2595 (zerop (tramp-run-test "-O" filename
)))))
2597 ;; Other file name ops.
2599 ;; ;; Matthias K\e,Av\e(Bppe <mkoeppe@mail.math.uni-magdeburg.de>
2600 ;; (defun tramp-handle-directory-file-name (directory)
2601 ;; "Like `directory-file-name' for tramp files."
2602 ;; (if (and (eq (aref directory (- (length directory) 1)) ?/)
2603 ;; (not (eq (aref directory (- (length directory) 2)) ?:)))
2604 ;; (substring directory 0 (- (length directory) 1))
2607 ;; ;; Philippe Troin <phil@fifi.org>
2608 ;; (defun tramp-handle-directory-file-name (directory)
2609 ;; "Like `directory-file-name' for tramp files."
2610 ;; (with-parsed-tramp-file-name directory nil
2611 ;; (let ((directory-length-1 (1- (length directory))))
2613 ;; (if (and (eq (aref directory directory-length-1) ?/)
2614 ;; (eq (string-match tramp-file-name-regexp directory) 0)
2615 ;; (/= (match-end 0) directory-length-1))
2616 ;; (substring directory 0 directory-length-1)
2619 (defun tramp-handle-directory-file-name (directory)
2620 "Like `directory-file-name' for tramp files."
2621 ;; If localname component of filename is "/", leave it unchanged.
2622 ;; Otherwise, remove any trailing slash from localname component.
2623 ;; Method, host, etc, are unchanged. Does it make sense to try
2624 ;; to avoid parsing the filename?
2625 (with-parsed-tramp-file-name directory nil
2626 (if (and (not (zerop (length localname
)))
2627 (eq (aref localname
(1- (length localname
))) ?
/)
2628 (not (string= localname
"/")))
2629 (substring directory
0 -
1)
2632 ;; Directory listings.
2634 (defun tramp-handle-directory-files (directory
2635 &optional full match nosort files-only
)
2636 "Like `directory-files' for tramp files."
2637 (with-parsed-tramp-file-name directory nil
2640 (tramp-barf-unless-okay
2641 multi-method method user host
2642 (concat "cd " (tramp-shell-quote-argument localname
))
2645 "tramp-handle-directory-files: couldn't `cd %s'"
2646 (tramp-shell-quote-argument localname
))
2648 multi-method method user host
2649 (concat (tramp-get-ls-command multi-method method user host
)
2651 (tramp-wait-for-output)
2652 (goto-char (point-max))
2653 (while (zerop (forward-line -
1))
2654 (setq x
(buffer-substring (point)
2655 (tramp-line-end-position)))
2656 (when (or (not match
) (string-match match x
))
2658 (push (concat (file-name-as-directory directory
)
2662 (tramp-send-command multi-method method user host
"cd")
2663 (tramp-wait-for-output)
2664 ;; Remove non-files or non-directories if necessary. Using
2665 ;; the remote shell for this would probably be way faster.
2666 ;; Maybe something could be adapted from
2667 ;; tramp-handle-file-name-all-completions.
2669 (let ((temp (nreverse result
))
2672 (if (equal files-only t
)
2675 (setq item
(pop temp
))
2676 (when (file-regular-p item
)
2677 (push item result
)))
2680 (setq item
(pop temp
))
2681 (when (file-directory-p item
)
2682 (push item result
)))))))
2685 (defun tramp-handle-directory-files-and-attributes
2686 (directory &optional full match nosort id-format
)
2687 "Like `directory-files-and-attributes' for tramp files."
2688 (when (tramp-handle-file-exists-p directory
)
2690 (setq directory
(tramp-handle-expand-file-name directory
))
2691 (with-parsed-tramp-file-name directory nil
2692 (tramp-maybe-send-perl-script multi-method method user host
2693 tramp-perl-directory-files-and-attributes
2694 "tramp_directory_files_and_attributes")
2695 (tramp-send-command multi-method method user host
2696 (format "tramp_directory_files_and_attributes %s %s"
2697 (tramp-shell-quote-argument localname
)
2698 (or id-format
'integer
)))
2699 (tramp-wait-for-output)
2700 (let* ((root (cons nil
(read (current-buffer))))
2703 (if (and match
(not (string-match match
(caadr cell
))))
2705 (setcdr cell
(cddr cell
))
2707 (setq cell
(cdr cell
))
2708 (let ((l (car cell
)))
2709 (tramp-convert-file-attributes multi-method method user host
2711 ;; If FULL, make file name absolute
2712 (when full
(setcar l
(concat directory
"/" (car l
)))))))
2715 (sort (cdr root
) (lambda (x y
) (string< (car x
) (car y
))))))))))
2717 ;; This function should return "foo/" for directories and "bar" for
2718 ;; files. We use `ls -ad' to get a list of files (including
2719 ;; directories), and `find . -type d \! -name . -prune' to get a list
2721 (defun tramp-handle-file-name-all-completions (filename directory
)
2722 "Like `file-name-all-completions' for tramp files."
2723 (with-parsed-tramp-file-name directory nil
2724 (unless (save-match-data (string-match "/" filename
))
2725 (let* ((nowild tramp-completion-without-shell-p
)
2728 (tramp-barf-unless-okay
2729 multi-method method user host
2730 (format "cd %s" (tramp-shell-quote-argument localname
))
2732 "tramp-handle-file-name-all-completions: Couldn't `cd %s'"
2733 (tramp-shell-quote-argument localname
))
2735 ;; Get a list of directories and files, including reliably
2736 ;; tagging the directories with a trailing '/'. Because I
2737 ;; rock. --daniel@danann.net
2739 multi-method method user host
2740 (format (concat "%s -a %s 2>/dev/null | while read f; do "
2741 "if test -d \"$f\" 2>/dev/null; "
2742 "then echo \"$f/\"; else echo \"$f\"; fi; done")
2743 (tramp-get-ls-command multi-method method user host
)
2744 (if (or nowild
(zerop (length filename
)))
2747 (tramp-shell-quote-argument filename
)))))
2749 ;; Now grab the output.
2750 (tramp-wait-for-output)
2751 (goto-char (point-max))
2752 (while (zerop (forward-line -
1))
2753 (push (buffer-substring (point)
2754 (tramp-line-end-position))
2757 (tramp-send-command multi-method method user host
"cd")
2758 (tramp-wait-for-output)
2762 (all-completions filename
(mapcar 'list result
))
2766 ;; The following isn't needed for Emacs 20 but for 19.34?
2767 (defun tramp-handle-file-name-completion (filename directory
)
2768 "Like `file-name-completion' for tramp files."
2769 (unless (tramp-tramp-file-p directory
)
2771 "tramp-handle-file-name-completion invoked on non-tramp directory `%s'"
2773 (with-parsed-tramp-file-name directory nil
2776 (mapcar (lambda (x) (cons x nil
))
2777 (file-name-all-completions filename directory
)))))
2781 (defun tramp-handle-add-name-to-file
2782 (filename newname
&optional ok-if-already-exists
)
2783 "Like `add-name-to-file' for tramp files."
2784 (with-parsed-tramp-file-name filename v1
2785 (with-parsed-tramp-file-name newname v2
2786 (let ((ln (when v1
(tramp-get-remote-ln
2787 v1-multi-method v1-method v1-user v1-host
))))
2788 (unless (and v1-method v2-method v1-user v2-user v1-host v2-host
2789 (equal v1-multi-method v2-multi-method
)
2790 (equal v1-method v2-method
)
2791 (equal v1-user v2-user
)
2792 (equal v1-host v2-host
))
2793 (error "add-name-to-file: %s"
2794 "only implemented for same method, same user, same host"))
2795 (when (and (not ok-if-already-exists
)
2796 (file-exists-p newname
)
2797 (not (numberp ok-if-already-exists
))
2800 "File %s already exists; make it a new name anyway? "
2802 (error "add-name-to-file: file %s already exists" newname
))
2803 (tramp-barf-unless-okay
2804 v1-multi-method v1-method v1-user v1-host
2805 (format "%s %s %s" ln
(tramp-shell-quote-argument v1-localname
)
2806 (tramp-shell-quote-argument v2-localname
))
2808 "error with add-name-to-file, see buffer `%s' for details"
2811 (defun tramp-handle-copy-file
2812 (filename newname
&optional ok-if-already-exists keep-date
)
2813 "Like `copy-file' for tramp files."
2814 ;; Check if both files are local -- invoke normal copy-file.
2815 ;; Otherwise, use tramp from local system.
2816 (setq filename
(expand-file-name filename
))
2817 (setq newname
(expand-file-name newname
))
2818 ;; At least one file a tramp file?
2819 (if (or (tramp-tramp-file-p filename
)
2820 (tramp-tramp-file-p newname
))
2821 (tramp-do-copy-or-rename-file
2822 'copy filename newname ok-if-already-exists keep-date
)
2823 (tramp-run-real-handler
2825 (list filename newname ok-if-already-exists keep-date
))))
2827 (defun tramp-handle-rename-file
2828 (filename newname
&optional ok-if-already-exists
)
2829 "Like `rename-file' for tramp files."
2830 ;; Check if both files are local -- invoke normal rename-file.
2831 ;; Otherwise, use tramp from local system.
2832 (setq filename
(expand-file-name filename
))
2833 (setq newname
(expand-file-name newname
))
2834 ;; At least one file a tramp file?
2835 (if (or (tramp-tramp-file-p filename
)
2836 (tramp-tramp-file-p newname
))
2837 (tramp-do-copy-or-rename-file
2838 'rename filename newname ok-if-already-exists
)
2839 (tramp-run-real-handler 'rename-file
2840 (list filename newname ok-if-already-exists
))))
2842 (defun tramp-do-copy-or-rename-file
2843 (op filename newname
&optional ok-if-already-exists keep-date
)
2844 "Copy or rename a remote file.
2845 OP must be `copy' or `rename' and indicates the operation to perform.
2846 FILENAME specifies the file to copy or rename, NEWNAME is the name of
2847 the new file (for copy) or the new name of the file (for rename).
2848 OK-IF-ALREADY-EXISTS means don't barf if NEWNAME exists already.
2849 KEEP-DATE means to make sure that NEWNAME has the same timestamp
2852 This function is invoked by `tramp-handle-copy-file' and
2853 `tramp-handle-rename-file'. It is an error if OP is neither of `copy'
2854 and `rename'. FILENAME and NEWNAME must be absolute file names."
2855 (unless (memq op
'(copy rename
))
2856 (error "Unknown operation `%s', must be `copy' or `rename'" op
))
2857 (unless ok-if-already-exists
2858 (when (file-exists-p newname
)
2859 (signal 'file-already-exists
2861 (let ((t1 (tramp-tramp-file-p filename
))
2862 (t2 (tramp-tramp-file-p newname
))
2863 v1-multi-method v1-method v1-user v1-host v1-localname
2864 v2-multi-method v2-method v2-user v2-host v2-localname
)
2866 ;; Check which ones of source and target are Tramp files.
2867 ;; We cannot invoke `with-parsed-tramp-file-name';
2868 ;; it fails if the file isn't a Tramp file name.
2870 (with-parsed-tramp-file-name filename l
2871 (setq v1-multi-method l-multi-method
2875 v1-localname l-localname
))
2876 (setq v1-localname filename
))
2878 (with-parsed-tramp-file-name newname l
2879 (setq v2-multi-method l-multi-method
2883 v2-localname l-localname
))
2884 (setq v2-localname newname
))
2887 ;; Both are Tramp files.
2890 ;; Shortcut: if method, host, user are the same for both
2891 ;; files, we invoke `cp' or `mv' on the remote host
2893 ((and (equal v1-multi-method v2-multi-method
)
2894 (equal v1-method v2-method
)
2895 (equal v1-user v2-user
)
2896 (equal v1-host v2-host
))
2897 (tramp-do-copy-or-rename-file-directly
2898 op v1-multi-method v1-method v1-user v1-host
2899 v1-localname v2-localname keep-date
))
2900 ;; If both source and target are Tramp files,
2901 ;; both are using the same copy-program, then we
2902 ;; can invoke rcp directly. Note that
2903 ;; default-directory should point to a local
2904 ;; directory if we want to invoke rcp.
2905 ((and (not v1-multi-method
)
2906 (not v2-multi-method
)
2907 (equal v1-method v2-method
)
2908 (tramp-method-out-of-band-p
2909 v1-multi-method v1-method v1-user v1-host
)
2910 (not (string-match "\\([^#]*\\)#\\(.*\\)" v1-host
))
2911 (not (string-match "\\([^#]*\\)#\\(.*\\)" v2-host
)))
2912 (tramp-do-copy-or-rename-file-out-of-band
2913 op filename newname keep-date
))
2914 ;; No shortcut was possible. So we copy the
2915 ;; file first. If the operation was `rename', we go
2916 ;; back and delete the original file (if the copy was
2917 ;; successful). The approach is simple-minded: we
2918 ;; create a new buffer, insert the contents of the
2919 ;; source file into it, then write out the buffer to
2920 ;; the target file. The advantage is that it doesn't
2921 ;; matter which filename handlers are used for the
2922 ;; source and target file.
2924 (tramp-do-copy-or-rename-file-via-buffer
2925 op filename newname keep-date
))))
2927 ;; One file is a Tramp file, the other one is local.
2929 ;; If the Tramp file has an out-of-band method, the corresponding
2930 ;; copy-program can be invoked.
2931 (if (and (not v1-multi-method
)
2932 (not v2-multi-method
)
2933 (or (tramp-method-out-of-band-p
2934 v1-multi-method v1-method v1-user v1-host
)
2935 (tramp-method-out-of-band-p
2936 v2-multi-method v2-method v2-user v2-host
)))
2937 (tramp-do-copy-or-rename-file-out-of-band
2938 op filename newname keep-date
)
2939 ;; Use the generic method via a Tramp buffer.
2940 (tramp-do-copy-or-rename-file-via-buffer
2941 op filename newname keep-date
)))
2944 ;; One of them must be a Tramp file.
2945 (error "Tramp implementation says this cannot happen")))))
2947 (defun tramp-do-copy-or-rename-file-via-buffer (op filename newname keep-date
)
2948 "Use an Emacs buffer to copy or rename a file.
2949 First arg OP is either `copy' or `rename' and indicates the operation.
2950 FILENAME is the source file, NEWNAME the target file.
2951 KEEP-DATE is non-nil if NEWNAME should have the same timestamp as FILENAME."
2952 (let ((trampbuf (get-buffer-create "*tramp output*"))
2953 (modtime (nth 5 (file-attributes filename
))))
2954 (when (and keep-date
(or (null modtime
) (equal modtime
'(0 0))))
2956 1 (concat "Warning: cannot preserve file time stamp"
2957 " with inline copying across machines")))
2959 (set-buffer trampbuf
) (erase-buffer)
2960 (insert-file-contents-literally filename
)
2961 ;; We don't want the target file to be compressed, so we let-bind
2962 ;; `jka-compr-inhibit' to t.
2963 (let ((coding-system-for-write 'binary
)
2964 (jka-compr-inhibit t
))
2965 (write-region (point-min) (point-max) newname
))
2966 ;; KEEP-DATE handling.
2968 (when (and (not (null modtime
))
2969 (not (equal modtime
'(0 0))))
2970 (tramp-touch newname modtime
)))
2972 (set-file-modes newname
(file-modes filename
)))
2973 ;; If the operation was `rename', delete the original file.
2974 (unless (eq op
'copy
)
2975 (delete-file filename
))))
2977 (defun tramp-do-copy-or-rename-file-directly
2978 (op multi-method method user host localname1 localname2 keep-date
)
2979 "Invokes `cp' or `mv' on the remote system.
2980 OP must be one of `copy' or `rename', indicating `cp' or `mv',
2981 respectively. METHOD, USER, and HOST specify the connection.
2982 LOCALNAME1 and LOCALNAME2 specify the two arguments of `cp' or `mv'.
2983 If KEEP-DATE is non-nil, preserve the time stamp when copying."
2984 ;; CCC: What happens to the timestamp when renaming?
2985 (let ((cmd (cond ((and (eq op
'copy
) keep-date
) "cp -f -p")
2986 ((eq op
'copy
) "cp -f")
2987 ((eq op
'rename
) "mv -f")
2989 "Unknown operation `%s', must be `copy' or `rename'"
2993 multi-method method user host
2996 (tramp-shell-quote-argument localname1
)
2997 (tramp-shell-quote-argument localname2
)))
2998 (tramp-wait-for-output)
2999 (goto-char (point-min))
3002 (and (eq op
'copy
) keep-date
3003 ;; Mask cp -f error.
3004 (re-search-forward tramp-operation-not-permitted-regexp nil t
))
3005 (zerop (tramp-send-command-and-check
3006 multi-method method user host nil nil
)))
3007 (pop-to-buffer (current-buffer))
3009 (format "Copying directly failed, see buffer `%s' for details."
3012 ;; CCC: Maybe `chmod --reference=localname1 localname2' could be used
3014 (unless (or (eq op
'rename
) keep-date
)
3016 (tramp-make-tramp-file-name multi-method method user host localname2
)
3018 (tramp-make-tramp-file-name
3019 multi-method method user host localname1
))))))
3021 (defun tramp-do-copy-or-rename-file-out-of-band (op filename newname keep-date
)
3022 "Invoke rcp program to copy.
3023 One of FILENAME and NEWNAME must be a Tramp name, the other must
3024 be a local filename. The method used must be an out-of-band method."
3025 (let ((t1 (tramp-tramp-file-p filename
))
3026 (t2 (tramp-tramp-file-p newname
))
3027 v1-multi-method v1-method v1-user v1-host v1-localname
3028 v2-multi-method v2-method v2-user v2-host v2-localname
3029 multi-method method user host copy-program copy-args
3030 source target trampbuf
)
3032 ;; Check which ones of source and target are Tramp files.
3033 ;; We cannot invoke `with-parsed-tramp-file-name';
3034 ;; it fails if the file isn't a Tramp file name.
3036 (with-parsed-tramp-file-name filename l
3037 (setq v1-multi-method l-multi-method
3041 v1-localname l-localname
3042 multi-method l-multi-method
3043 method
(tramp-find-method
3044 v1-multi-method v1-method v1-user v1-host
)
3047 copy-program
(tramp-get-method-parameter
3048 v1-multi-method method
3049 v1-user v1-host
'tramp-copy-program
)
3050 copy-args
(tramp-get-method-parameter
3051 v1-multi-method method
3052 v1-user v1-host
'tramp-copy-args
)))
3053 (setq v1-localname filename
))
3056 (with-parsed-tramp-file-name newname l
3057 (setq v2-multi-method l-multi-method
3061 v2-localname l-localname
3062 multi-method l-multi-method
3063 method
(tramp-find-method
3064 v2-multi-method v2-method v2-user v2-host
)
3067 copy-program
(tramp-get-method-parameter
3068 v2-multi-method method
3069 v2-user v2-host
'tramp-copy-program
)
3070 copy-args
(tramp-get-method-parameter
3071 v2-multi-method method
3072 v2-user v2-host
'tramp-copy-args
)))
3073 (setq v2-localname newname
))
3075 ;; The following should be changed. We need a more general
3076 ;; mechanism to parse extra host args.
3078 (setq source v1-localname
)
3079 (when (string-match "\\([^#]*\\)#\\(.*\\)" v1-host
)
3080 (setq copy-args
(cons "-P" (cons (match-string 2 v1-host
) copy-args
)))
3081 (setq v1-host
(match-string 1 v1-host
)))
3083 (tramp-make-copy-program-file-name
3085 (tramp-shell-quote-argument v1-localname
))))
3088 (setq target v2-localname
)
3089 (when (string-match "\\([^#]*\\)#\\(.*\\)" v2-host
)
3090 (setq copy-args
(cons "-P" (cons (match-string 2 v2-host
) copy-args
)))
3091 (setq v2-host
(match-string 1 v2-host
)))
3093 (tramp-make-copy-program-file-name
3095 (tramp-shell-quote-argument v2-localname
))))
3097 ;; Handle keep-date argument
3101 (cons (tramp-get-method-parameter
3102 v1-multi-method method
3103 v1-user v1-host
'tramp-copy-keep-date-arg
)
3106 (cons (tramp-get-method-parameter
3107 v2-multi-method method
3108 v2-user v2-host
'tramp-copy-keep-date-arg
)
3111 (setq copy-args
(append copy-args
(list source target
))
3112 trampbuf
(generate-new-buffer
3113 (tramp-buffer-name multi-method method user host
)))
3115 ;; Use an asynchronous process. By this, password can be handled.
3118 ;; Check for program.
3119 (when (and (fboundp 'executable-find
)
3120 (not (executable-find copy-program
)))
3121 (error "Cannot find copy program: %s" copy-program
))
3123 (set-buffer trampbuf
)
3124 (setq tramp-current-multi-method multi-method
3125 tramp-current-method method
3126 tramp-current-user user
3127 tramp-current-host host
)
3128 (message "Transferring %s to %s..." filename newname
)
3130 ;; Use rcp-like program for file transfer.
3131 (let ((p (apply 'start-process
(buffer-name trampbuf
) trampbuf
3132 copy-program copy-args
)))
3133 (tramp-set-process-query-on-exit-flag p nil
)
3134 (tramp-process-actions p multi-method method user host
3135 tramp-actions-copy-out-of-band
))
3136 (kill-buffer trampbuf
)
3137 (message "Transferring %s to %s...done" filename newname
)
3141 (set-file-modes newname
(file-modes filename
))))
3143 ;; If the operation was `rename', delete the original file.
3144 (unless (eq op
'copy
)
3145 (delete-file filename
))))
3148 (defun tramp-handle-make-directory (dir &optional parents
)
3149 "Like `make-directory' for tramp files."
3150 (setq dir
(expand-file-name dir
))
3151 (with-parsed-tramp-file-name dir nil
3153 (tramp-barf-unless-okay
3154 multi-method method user host
3156 (if parents
"mkdir -p" "mkdir")
3157 (tramp-shell-quote-argument localname
))
3159 "Couldn't make directory %s" dir
))))
3161 ;; CCC error checking?
3162 (defun tramp-handle-delete-directory (directory)
3163 "Like `delete-directory' for tramp files."
3164 (setq directory
(expand-file-name directory
))
3165 (with-parsed-tramp-file-name directory nil
3168 multi-method method user host
3169 (format "rmdir %s ; echo ok"
3170 (tramp-shell-quote-argument localname
)))
3171 (tramp-wait-for-output))))
3173 (defun tramp-handle-delete-file (filename)
3174 "Like `delete-file' for tramp files."
3175 (setq filename
(expand-file-name filename
))
3176 (with-parsed-tramp-file-name filename nil
3178 (unless (zerop (tramp-send-command-and-check
3179 multi-method method user host
3181 (tramp-shell-quote-argument localname
))))
3182 (signal 'file-error
"Couldn't delete Tramp file")))))
3186 ;; CCC: This does not seem to be enough. Something dies when
3187 ;; we try and delete two directories under TRAMP :/
3188 (defun tramp-handle-dired-recursive-delete-directory (filename)
3189 "Recursively delete the directory given.
3190 This is like `dired-recursive-delete-directory' for tramp files."
3191 (with-parsed-tramp-file-name filename nil
3192 ;; run a shell command 'rm -r <localname>'
3193 ;; Code shamelessly stolen for the dired implementation and, um, hacked :)
3194 (or (file-exists-p filename
)
3197 (list "Removing old file name" "no such directory" filename
)))
3198 ;; Which is better, -r or -R? (-r works for me <daniel@danann.net>)
3199 (tramp-send-command multi-method method user host
3200 (format "rm -r %s" (tramp-shell-quote-argument localname
)))
3201 ;; Wait for the remote system to return to us...
3202 ;; This might take a while, allow it plenty of time.
3203 (tramp-wait-for-output 120)
3204 ;; Make sure that it worked...
3205 (and (file-exists-p filename
)
3206 (error "Failed to recursively delete %s" filename
))))
3208 (defun tramp-handle-dired-call-process (program discard
&rest arguments
)
3209 "Like `dired-call-process' for tramp files."
3210 (with-parsed-tramp-file-name default-directory nil
3212 (tramp-barf-unless-okay
3213 multi-method method user host
3214 (format "cd %s" (tramp-shell-quote-argument localname
))
3216 "tramp-handle-dired-call-process: Couldn't `cd %s'"
3217 (tramp-shell-quote-argument localname
))
3219 multi-method method user host
3220 (mapconcat #'tramp-shell-quote-argument
(cons program arguments
) " "))
3221 (tramp-wait-for-output))
3223 ;; We cannot use `insert-buffer' because the tramp buffer
3224 ;; changes its contents before insertion due to calling
3225 ;; `expand-file' and alike.
3227 (with-current-buffer
3228 (tramp-get-buffer multi-method method user host
)
3232 (tramp-send-command-and-check multi-method method user host nil
)
3233 (tramp-send-command multi-method method user host
"cd")
3234 (tramp-wait-for-output)))))
3236 (defun tramp-handle-dired-compress-file (file &rest ok-flag
)
3237 "Like `dired-compress-file' for tramp files."
3238 ;; OK-FLAG is valid for XEmacs only, but not implemented.
3239 ;; Code stolen mainly from dired-aux.el.
3240 (with-parsed-tramp-file-name file nil
3243 (if (not (featurep 'xemacs
))
3245 (symbol-value 'dired-compress-file-suffixes
)
3246 ;; XEmacs has `dired-compression-method-alist', which is
3247 ;; transformed into `dired-compress-file-suffixes' structure.
3250 (list (concat (regexp-quote (nth 1 x
)) "\\'")
3252 (mapconcat 'identity
(nth 3 x
) " ")))
3253 (symbol-value 'dired-compression-method-alist
))))
3255 ;; See if any suffix rule matches this file name.
3257 (let (case-fold-search)
3258 (if (string-match (car (car suffixes
)) localname
)
3259 (setq suffix
(car suffixes
) suffixes nil
))
3260 (setq suffixes
(cdr suffixes
))))
3262 (cond ((file-symlink-p file
)
3264 ((and suffix
(nth 2 suffix
))
3265 ;; We found an uncompression rule.
3266 (message "Uncompressing %s..." file
)
3267 (when (zerop (tramp-send-command-and-check
3268 multi-method method user host
3269 (concat (nth 2 suffix
) " " localname
)))
3270 (message "Uncompressing %s...done" file
)
3271 ;; `dired-remove-file' is not defined in XEmacs
3272 (funcall (symbol-function 'dired-remove-file
) file
)
3273 (string-match (car suffix
) file
)
3274 (concat (substring file
0 (match-beginning 0)))))
3276 ;; We don't recognize the file as compressed, so compress it.
3278 (message "Compressing %s..." file
)
3279 (when (zerop (tramp-send-command-and-check
3280 multi-method method user host
3281 (concat "gzip -f " localname
)))
3282 (message "Compressing %s...done" file
)
3283 ;; `dired-remove-file' is not defined in XEmacs
3284 (funcall (symbol-function 'dired-remove-file
) file
)
3285 (cond ((file-exists-p (concat file
".gz"))
3286 (concat file
".gz"))
3287 ((file-exists-p (concat file
".z"))
3291 ;; Pacify byte-compiler. The function is needed on XEmacs only. I'm
3292 ;; not sure at all that this is the right way to do it, but let's hope
3293 ;; it works for now, and wait for a guru to point out the Right Way to
3295 ;;(eval-when-compile
3296 ;; (unless (fboundp 'dired-insert-set-properties)
3297 ;; (fset 'dired-insert-set-properties 'ignore)))
3298 ;; Gerd suggests this:
3299 (eval-when-compile (require 'dired
))
3300 ;; Note that dired is required at run-time, too, when it is needed.
3301 ;; It is only needed on XEmacs for the function
3302 ;; `dired-insert-set-properties'.
3304 (defun tramp-handle-insert-directory
3305 (filename switches
&optional wildcard full-directory-p
)
3306 "Like `insert-directory' for tramp files."
3307 (if (and (boundp 'ls-lisp-use-insert-directory-program
)
3308 (not (symbol-value 'ls-lisp-use-insert-directory-program
)))
3309 (tramp-run-real-handler 'insert-directory
3310 (list filename switches wildcard full-directory-p
))
3311 ;; For the moment, we assume that the remote "ls" program does not
3312 ;; grok "--dired". In the future, we should detect this on
3313 ;; connection setup.
3314 (when (string-match "^--dired\\s-+" switches
)
3315 (setq switches
(replace-match "" nil t switches
)))
3316 (setq filename
(expand-file-name filename
))
3317 (with-parsed-tramp-file-name filename nil
3318 (tramp-message-for-buffer
3319 multi-method method user host
10
3320 "Inserting directory `ls %s %s', wildcard %s, fulldir %s"
3321 switches filename
(if wildcard
"yes" "no")
3322 (if full-directory-p
"yes" "no"))
3324 (setq wildcard
(file-name-nondirectory localname
))
3325 (setq localname
(file-name-directory localname
)))
3326 (when (listp switches
)
3327 (setq switches
(mapconcat 'identity switches
" ")))
3328 (unless full-directory-p
3329 (setq switches
(concat "-d " switches
)))
3331 (setq switches
(concat switches
" " wildcard
)))
3333 ;; If `full-directory-p', we just say `ls -l FILENAME'.
3334 ;; Else we chdir to the parent directory, then say `ls -ld BASENAME'.
3335 (if full-directory-p
3337 multi-method method user host
3339 (tramp-get-ls-command multi-method method user host
)
3343 (tramp-shell-quote-argument (concat localname
".")))))
3344 (tramp-barf-unless-okay
3345 multi-method method user host
3346 (format "cd %s" (tramp-shell-quote-argument
3347 (file-name-directory localname
)))
3350 (tramp-shell-quote-argument (file-name-directory localname
)))
3352 multi-method method user host
3354 (tramp-get-ls-command multi-method method user host
)
3358 (if (zerop (length (file-name-nondirectory localname
)))
3360 (tramp-shell-quote-argument
3361 (file-name-nondirectory localname
)))))))
3362 (sit-for 1) ;needed for rsh but not ssh?
3363 (tramp-wait-for-output))
3364 ;; The following let-binding is used by code that's commented
3365 ;; out. Let's leave the let-binding in for a while to see
3366 ;; that the commented-out code is really not needed. Commenting-out
3367 ;; happened on 2003-03-13.
3368 (let ((old-pos (point)))
3369 ;; We cannot use `insert-buffer' because the tramp buffer
3370 ;; changes its contents before insertion due to calling
3371 ;; `expand-file' and alike.
3373 (with-current-buffer
3374 (tramp-get-buffer multi-method method user host
)
3376 ;; On XEmacs, we want to call (exchange-point-and-mark t), but
3377 ;; that doesn't exist on Emacs, so we use this workaround instead.
3378 ;; Since zmacs-region-stays doesn't exist in Emacs, this ought to
3379 ;; be safe. Thanks to Daniel Pittman <daniel@danann.net>.
3380 ;; (let ((zmacs-region-stays t))
3381 ;; (exchange-point-and-mark))
3383 (tramp-send-command multi-method method user host
"cd")
3384 (tramp-wait-for-output))
3385 ;; For the time being, the XEmacs kludge is commented out.
3386 ;; Please test it on various XEmacs versions to see if it works.
3387 ;; ;; Another XEmacs specialty follows. What's the right way to do
3389 ;; (when (and (featurep 'xemacs)
3390 ;; (eq major-mode 'dired-mode))
3393 ;; (dired-insert-set-properties old-pos (point))))
3396 ;; Continuation of kluge to pacify byte-compiler.
3397 ;;(eval-when-compile
3398 ;; (when (eq (symbol-function 'dired-insert-set-properties) 'ignore)
3399 ;; (fmakunbound 'dired-insert-set-properties)))
3401 ;; CCC is this the right thing to do?
3402 (defun tramp-handle-unhandled-file-name-directory (filename)
3403 "Like `unhandled-file-name-directory' for tramp files."
3404 (with-parsed-tramp-file-name filename nil
3405 (expand-file-name "~/")))
3407 ;; Canonicalization of file names.
3409 (defun tramp-drop-volume-letter (name)
3410 "Cut off unnecessary drive letter from file NAME.
3411 The function `tramp-handle-expand-file-name' calls `expand-file-name'
3412 locally on a remote file name. When the local system is a W32 system
3413 but the remote system is Unix, this introduces a superfluous drive
3414 letter into the file name. This function removes it.
3416 Doesn't do anything if the NAME does not start with a drive letter."
3417 (if (and (> (length name
) 1)
3418 (char-equal (aref name
1) ?
:)
3419 (let ((c1 (aref name
0)))
3420 (or (and (>= c1 ?A
) (<= c1 ?Z
))
3421 (and (>= c1 ?a
) (<= c1 ?z
)))))
3425 (defun tramp-handle-expand-file-name (name &optional dir
)
3426 "Like `expand-file-name' for tramp files.
3427 If the localname part of the given filename starts with \"/../\" then
3428 the result will be a local, non-Tramp, filename."
3429 ;; If DIR is not given, use DEFAULT-DIRECTORY or "/".
3430 (setq dir
(or dir default-directory
"/"))
3431 ;; Unless NAME is absolute, concat DIR and NAME.
3432 (unless (file-name-absolute-p name
)
3433 (setq name
(concat (file-name-as-directory dir
) name
)))
3434 ;; If NAME is not a tramp file, run the real handler
3435 (if (not (tramp-tramp-file-p name
))
3436 (tramp-run-real-handler 'expand-file-name
3439 (with-parsed-tramp-file-name name nil
3440 (unless (file-name-absolute-p localname
)
3441 (setq localname
(concat "~/" localname
)))
3443 ;; Tilde expansion if necessary. This needs a shell which
3444 ;; groks tilde expansion! The function `tramp-find-shell' is
3445 ;; supposed to find such a shell on the remote host. Please
3446 ;; tell me about it when this doesn't work on your system.
3447 (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname
)
3448 (let ((uname (match-string 1 localname
))
3449 (fname (match-string 2 localname
)))
3450 ;; CCC fanatic error checking?
3451 (set-buffer (tramp-get-buffer multi-method method user host
))
3454 multi-method method user host
3455 (format "cd %s; pwd" uname
)
3457 (tramp-wait-for-output)
3458 (goto-char (point-min))
3459 (setq uname
(buffer-substring (point) (tramp-line-end-position)))
3460 (setq localname
(concat uname fname
))
3462 ;; No tilde characters in file name, do normal
3463 ;; expand-file-name (this does "/./" and "/../"). We bind
3464 ;; directory-sep-char here for XEmacs on Windows, which
3465 ;; would otherwise use backslash.
3466 (tramp-let-maybe directory-sep-char ?
/
3467 (tramp-make-tramp-file-name
3468 multi-method
(or method
(tramp-find-default-method user host
))
3470 (tramp-drop-volume-letter
3471 (tramp-run-real-handler 'expand-file-name
3472 (list localname
)))))))))
3474 ;; old version follows. it uses ".." to cross file handler
3476 ;; ;; Look if localname starts with "/../" construct. If this is
3477 ;; ;; the case, then we return a local name instead of a remote name.
3478 ;; (if (string-match "^/\\.\\./" localname)
3479 ;; (expand-file-name (substring localname 3))
3480 ;; ;; No tilde characters in file name, do normal
3481 ;; ;; expand-file-name (this does "/./" and "/../"). We bind
3482 ;; ;; directory-sep-char here for XEmacs on Windows, which
3483 ;; ;; would otherwise use backslash.
3484 ;; (let ((directory-sep-char ?/))
3485 ;; (tramp-make-tramp-file-name
3486 ;; multi-method method user host
3487 ;; (tramp-drop-volume-letter
3488 ;; (tramp-run-real-handler 'expand-file-name
3489 ;; (list localname))))))))))
3493 (defvar tramp-async-proc nil
3494 "Global variable keeping asynchronous process object.
3495 Used in `tramp-handle-shell-command'")
3497 (defun tramp-handle-shell-command (command &optional output-buffer error-buffer
)
3498 "Like `shell-command' for tramp files.
3499 This will break if COMMAND prints a newline, followed by the value of
3500 `tramp-end-of-output', followed by another newline."
3501 ;; Asynchronous processes are far from being perfect. But it works at least
3502 ;; for `find-grep-dired' and `find-name-dired' in Emacs 22.
3503 (if (tramp-tramp-file-p default-directory
)
3504 (with-parsed-tramp-file-name default-directory nil
3505 (let ((asynchronous (string-match "[ \t]*&[ \t]*\\'" command
))
3507 (unless output-buffer
3511 "*Async Shell Command*"
3512 "*Shell Command Output*")))
3513 (set-buffer output-buffer
)
3515 (unless (bufferp output-buffer
)
3516 (setq output-buffer
(current-buffer)))
3517 (set-buffer output-buffer
)
3518 ;; Tramp doesn't handle the asynchronous case by an asynchronous
3519 ;; process. Instead of, another asynchronous process is opened
3520 ;; which gets the output of the (synchronous) Tramp process
3521 ;; via process-filter. ERROR-BUFFER is disabled.
3523 (setq command
(substring command
0 (match-beginning 0))
3525 tramp-async-proc
(start-process (buffer-name output-buffer
)
3526 output-buffer
"cat")))
3528 (tramp-barf-unless-okay
3529 multi-method method user host
3530 (format "cd %s" (tramp-shell-quote-argument localname
))
3532 "tramp-handle-shell-command: Couldn't `cd %s'"
3533 (tramp-shell-quote-argument localname
))
3534 ;; Define the process filter
3538 (tramp-get-buffer multi-method method user host
))
3539 '(lambda (process string
)
3540 ;; Write the output into the Tramp Process
3541 (save-current-buffer
3542 (set-buffer (process-buffer process
))
3543 (goto-char (point-max))
3545 ;; Hand-over output to asynchronous process.
3548 (regexp-quote tramp-end-of-output
) string
)))
3551 (substring string
0 (1- (match-beginning 0)))))
3552 (process-send-string tramp-async-proc string
)
3554 (set-process-filter process nil
)
3555 (process-send-eof tramp-async-proc
))))))
3558 multi-method method user host
3560 (format "( %s ) 2>/tmp/tramp.$$.err; tramp_old_status=$?"
3562 (format "%s; tramp_old_status=$?" command
)))
3563 (unless asynchronous
3564 (tramp-wait-for-output)))
3565 (unless asynchronous
3566 ;; We cannot use `insert-buffer' because the tramp buffer
3567 ;; changes its contents before insertion due to calling
3568 ;; `expand-file' and alike.
3570 (with-current-buffer
3571 (tramp-get-buffer multi-method method user host
)
3575 (unless (bufferp error-buffer
)
3576 (setq error-buffer
(get-buffer-create error-buffer
)))
3578 multi-method method user host
3579 "cat /tmp/tramp.$$.err")
3580 (tramp-wait-for-output)
3581 (set-buffer error-buffer
)
3582 ;; Same comment as above
3584 (with-current-buffer
3585 (tramp-get-buffer multi-method method user host
)
3587 (tramp-send-command-and-check
3588 multi-method method user host
"rm -f /tmp/tramp.$$.err")))
3590 (tramp-send-command multi-method method user host
"cd")
3591 (unless asynchronous
3592 (tramp-wait-for-output))
3594 multi-method method user host
3595 (concat "tramp_set_exit_status $tramp_old_status;"
3596 " echo tramp_exit_status $?"))
3597 (unless asynchronous
3598 (tramp-wait-for-output)
3599 (goto-char (point-max))
3600 (unless (search-backward "tramp_exit_status " nil t
)
3601 (error "Couldn't find exit status of `%s'" command
))
3602 (skip-chars-forward "^ ")
3603 (setq status
(read (current-buffer)))))
3604 (unless (zerop (buffer-size))
3605 (display-buffer output-buffer
))
3607 ;; The following is only executed if something strange was
3608 ;; happening. Emit a helpful message and do it anyway.
3609 (message "tramp-handle-shell-command called with non-tramp directory: `%s'"
3611 (tramp-run-real-handler 'shell-command
3612 (list command output-buffer error-buffer
))))
3614 (defun tramp-handle-process-file (program &optional infile buffer display
&rest args
)
3615 "Like `process-file' for Tramp files."
3616 (when infile
(error "Implementation does not handle input from file"))
3617 (when (and (numberp buffer
) (zerop buffer
))
3618 (error "Implementation does not handle immediate return"))
3619 (when (consp buffer
) (error "Implementation does not handle error files"))
3621 (mapconcat 'tramp-shell-quote-argument
3628 (defsubst tramp-make-temp-file
()
3629 (funcall (if (fboundp 'make-temp-file
) 'make-temp-file
'make-temp-name
)
3630 (expand-file-name tramp-temp-name-prefix
3631 (tramp-temporary-file-directory))))
3633 (defun tramp-handle-file-local-copy (filename)
3634 "Like `file-local-copy' for tramp files."
3635 (with-parsed-tramp-file-name filename nil
3636 (let ((tramp-buf (tramp-get-buffer multi-method method user host
))
3637 ;; We used to bind the following as late as possible.
3638 ;; loc-enc and loc-dec were bound directly before the if
3639 ;; statement that checks them. But the functions
3640 ;; tramp-get-* might invoke the "are you awake" check in
3641 ;; tramp-maybe-open-connection, which is an unfortunate time
3642 ;; since we rely on the buffer contents at that spot.
3643 (rem-enc (tramp-get-remote-encoding multi-method method user host
))
3644 (rem-dec (tramp-get-remote-decoding multi-method method user host
))
3645 (loc-enc (tramp-get-local-encoding multi-method method user host
))
3646 (loc-dec (tramp-get-local-decoding multi-method method user host
))
3648 (unless (file-exists-p filename
)
3649 (error "Cannot make local copy of non-existing file `%s'"
3651 (setq tmpfil
(tramp-make-temp-file))
3653 (cond ((tramp-method-out-of-band-p multi-method method user host
)
3654 ;; `copy-file' handles out-of-band methods
3655 (copy-file filename tmpfil t t
))
3657 ((and rem-enc rem-dec
)
3658 ;; Use inline encoding for file transfer.
3660 ;; Following line for setting tramp-current-method,
3661 ;; tramp-current-user, tramp-current-host.
3662 (set-buffer tramp-buf
)
3663 (tramp-message 5 "Encoding remote file %s..." filename
)
3664 (tramp-barf-unless-okay
3665 multi-method method user host
3666 (concat rem-enc
" < " (tramp-shell-quote-argument localname
))
3668 "Encoding remote file failed, see buffer `%s' for details"
3670 ;; Remove trailing status code
3671 (goto-char (point-max))
3672 (delete-region (point) (progn (forward-line -
1) (point)))
3674 (tramp-message 5 "Decoding remote file %s..." filename
)
3676 ;; Here is where loc-enc and loc-dec used to be let-bound.
3677 (if (and (symbolp loc-dec
) (fboundp loc-dec
))
3678 ;; If local decoding is a function, we call it.
3679 (let ((tmpbuf (get-buffer-create " *tramp tmp*")))
3682 (insert-buffer tramp-buf
)
3683 (tramp-message-for-buffer
3684 multi-method method user host
3685 6 "Decoding remote file %s with function %s..."
3688 ;; Douglas Gray Stephens <DGrayStephens@slb.com>
3689 ;; says that we need to strip tramp_exit_status
3690 ;; line from the output here. Go to point-max,
3691 ;; search backward for tramp_exit_status, delete
3692 ;; between point and point-max if found.
3693 (let ((coding-system-for-write 'binary
))
3694 (funcall loc-dec
(point-min) (point-max))
3695 (write-region (point-min) (point-max) tmpfil
))
3696 (kill-buffer tmpbuf
))
3697 ;; If tramp-decoding-function is not defined for this
3698 ;; method, we invoke tramp-decoding-command instead.
3699 (let ((tmpfil2 (tramp-make-temp-file)))
3700 (write-region (point-min) (point-max) tmpfil2
)
3702 6 "Decoding remote file %s with command %s..."
3704 (tramp-call-local-coding-command
3705 loc-dec tmpfil2 tmpfil
)
3706 (delete-file tmpfil2
)))
3707 (tramp-message-for-buffer
3708 multi-method method user host
3709 5 "Decoding remote file %s...done" filename
)
3710 ;; Set proper permissions.
3711 (set-file-modes tmpfil
(file-modes filename
))))
3713 (t (error "Wrong method specification for `%s'" method
)))
3716 (defun tramp-handle-file-remote-p (filename)
3717 "Like `file-remote-p' for tramp files."
3718 (when (tramp-tramp-file-p filename
)
3719 (with-parsed-tramp-file-name filename nil
3720 (make-tramp-file-name
3721 :multi-method multi-method
3727 (defun tramp-handle-insert-file-contents
3728 (filename &optional visit beg end replace
)
3729 "Like `insert-file-contents' for tramp files."
3730 (barf-if-buffer-read-only)
3731 (setq filename
(expand-file-name filename
))
3732 (with-parsed-tramp-file-name filename nil
3733 (if (not (file-exists-p filename
))
3736 (setq buffer-file-name filename
)
3737 (set-visited-file-modtime)
3738 (set-buffer-modified-p nil
))
3740 (format "File `%s' not found on remote host" filename
))
3741 (list (expand-file-name filename
) 0))
3742 ;; `insert-file-contents-literally' takes care to avoid calling
3743 ;; jka-compr. By let-binding inhibit-file-name-operation, we
3744 ;; propagate that care to the file-local-copy operation.
3746 (let ((inhibit-file-name-operation
3747 (when (eq inhibit-file-name-operation
3748 'insert-file-contents
)
3750 (file-local-copy filename
)))
3753 (setq buffer-file-name filename
)
3754 (set-visited-file-modtime)
3755 (set-buffer-modified-p nil
))
3756 (tramp-message-for-buffer
3757 multi-method method user host
3758 9 "Inserting local temp file `%s'..." local-copy
)
3759 (setq result
(insert-file-contents local-copy nil beg end replace
))
3760 (tramp-message-for-buffer
3761 multi-method method user host
3762 9 "Inserting local temp file `%s'...done" local-copy
)
3763 (delete-file local-copy
)
3764 (list (expand-file-name filename
)
3765 (second result
))))))
3768 (defun tramp-handle-find-backup-file-name (filename)
3769 "Like `find-backup-file-name' for tramp files."
3770 (with-parsed-tramp-file-name filename nil
3771 ;; We set both variables. It doesn't matter whether it is
3773 (let ((backup-directory-alist
3775 (when (boundp 'backup-directory-alist
)
3776 (if (boundp 'tramp-backup-directory-alist
)
3781 (if (and (stringp (cdr x
))
3782 (file-name-absolute-p (cdr x
))
3783 (not (tramp-file-name-p (cdr x
))))
3784 (tramp-make-tramp-file-name
3785 multi-method method user host
(cdr x
))
3787 (symbol-value 'tramp-backup-directory-alist
))
3788 (symbol-value 'backup-directory-alist
))))
3790 (bkup-backup-directory-info
3792 (when (boundp 'bkup-backup-directory-info
)
3793 (if (boundp 'tramp-bkup-backup-directory-info
)
3799 (if (and (stringp (car (cdr x
)))
3800 (file-name-absolute-p (car (cdr x
)))
3801 (not (tramp-file-name-p (car (cdr x
)))))
3802 (tramp-make-tramp-file-name
3803 multi-method method user host
(car (cdr x
)))
3806 (symbol-value 'tramp-bkup-backup-directory-info
))
3807 (symbol-value 'bkup-backup-directory-info
)))))
3809 (tramp-run-real-handler 'find-backup-file-name
(list filename
)))))
3811 (defun tramp-handle-make-auto-save-file-name ()
3812 "Like `make-auto-save-file-name' for tramp files.
3813 Returns a file name in `tramp-auto-save-directory' for autosaving this file."
3814 (when tramp-auto-save-directory
3815 (unless (file-exists-p tramp-auto-save-directory
)
3816 (make-directory tramp-auto-save-directory t
)))
3817 ;; jka-compr doesn't like auto-saving, so by appending "~" to the
3818 ;; file name we make sure that jka-compr isn't used for the
3820 (let ((buffer-file-name
3821 (if tramp-auto-save-directory
3823 (tramp-subst-strs-in-string
3831 tramp-auto-save-directory
)
3832 (buffer-file-name)))
3833 ;; We set it to nil because `make-auto-save-file-name' shouldn't
3834 ;; recurse infinitely.
3835 tramp-auto-save-directory
)
3836 (tramp-run-real-handler
3837 'make-auto-save-file-name nil
)))
3840 ;; CCC grok APPEND, LOCKNAME, CONFIRM
3841 (defun tramp-handle-write-region
3842 (start end filename
&optional append visit lockname confirm
)
3843 "Like `write-region' for tramp files."
3844 (unless (eq append nil
)
3845 (error "Cannot append to file using tramp (`%s')" filename
))
3846 (setq filename
(expand-file-name filename
))
3847 ;; Following part commented out because we don't know what to do about
3848 ;; file locking, and it does not appear to be a problem to ignore it.
3849 ;; Ange-ftp ignores it, too.
3850 ;; (when (and lockname (stringp lockname))
3851 ;; (setq lockname (expand-file-name lockname)))
3852 ;; (unless (or (eq lockname nil)
3853 ;; (string= lockname filename))
3855 ;; "tramp-handle-write-region: LOCKNAME must be nil or equal FILENAME"))
3856 ;; XEmacs takes a coding system as the seventh argument, not `confirm'
3857 (when (and (not (featurep 'xemacs
))
3858 confirm
(file-exists-p filename
))
3859 (unless (y-or-n-p (format "File %s exists; overwrite anyway? "
3861 (error "File not overwritten")))
3862 (with-parsed-tramp-file-name filename nil
3863 (let ((curbuf (current-buffer))
3864 (rem-enc (tramp-get-remote-encoding multi-method method user host
))
3865 (rem-dec (tramp-get-remote-decoding multi-method method user host
))
3866 (loc-enc (tramp-get-local-encoding multi-method method user host
))
3867 (loc-dec (tramp-get-local-decoding multi-method method user host
))
3868 (trampbuf (get-buffer-create "*tramp output*"))
3869 (modes (file-modes filename
))
3871 ;; Write region into a tmp file. This isn't really needed if we
3872 ;; use an encoding function, but currently we use it always
3873 ;; because this makes the logic simpler.
3874 (setq tmpfil
(tramp-make-temp-file))
3875 ;; Set current buffer. If connection wasn't open, `file-modes' has
3876 ;; changed it accidently.
3878 ;; We say `no-message' here because we don't want the visited file
3879 ;; modtime data to be clobbered from the temp file. We call
3880 ;; `set-visited-file-modtime' ourselves later on.
3881 (tramp-run-real-handler
3883 (if confirm
; don't pass this arg unless defined for backward compat.
3884 (list start end tmpfil append
'no-message lockname confirm
)
3885 (list start end tmpfil append
'no-message lockname
)))
3886 ;; The permissions of the temporary file should be set. If
3887 ;; filename does not exist (eq modes nil) it has been renamed to
3888 ;; the backup file. This case `save-buffer' handles
3890 (when modes
(set-file-modes tmpfil modes
))
3891 ;; This is a bit lengthy due to the different methods possible for
3892 ;; file transfer. First, we check whether the method uses an rcp
3893 ;; program. If so, we call it. Otherwise, both encoding and
3894 ;; decoding command must be specified. However, if the method
3895 ;; _also_ specifies an encoding function, then that is used for
3896 ;; encoding the contents of the tmp file.
3897 (cond ((tramp-method-out-of-band-p multi-method method user host
)
3898 ;; `copy-file' handles out-of-band methods
3899 (copy-file tmpfil filename t t
))
3901 ((and rem-enc rem-dec
)
3902 ;; Use inline file transfer
3903 (let ((tmpbuf (get-buffer-create " *tramp file transfer*")))
3905 ;; Encode tmpfil into tmpbuf
3906 (tramp-message-for-buffer multi-method method user host
3907 5 "Encoding region...")
3910 ;; Use encoding function or command.
3911 (if (and (symbolp loc-enc
) (fboundp loc-enc
))
3913 (tramp-message-for-buffer
3914 multi-method method user host
3915 6 "Encoding region using function `%s'..."
3916 (symbol-name loc-enc
))
3917 (insert-file-contents-literally tmpfil
)
3918 ;; CCC. The following `let' is a workaround for
3919 ;; the base64.el that comes with pgnus-0.84. If
3920 ;; both of the following conditions are
3921 ;; satisfied, it tries to write to a local file
3922 ;; in default-directory, but at this point,
3923 ;; default-directory is remote.
3924 ;; (CALL-PROCESS-REGION can't write to remote
3925 ;; files, it seems.) The file in question is a
3927 (let ((default-directory
3928 (tramp-temporary-file-directory)))
3929 (funcall loc-enc
(point-min) (point-max)))
3930 (goto-char (point-max))
3933 (tramp-message-for-buffer
3934 multi-method method user host
3935 6 "Encoding region using command `%s'..." loc-enc
)
3936 (unless (equal 0 (tramp-call-local-coding-command
3938 (pop-to-buffer trampbuf
)
3939 (error (concat "Cannot write to `%s', local encoding"
3940 " command `%s' failed")
3942 ;; Send tmpbuf into remote decoding command which
3943 ;; writes to remote file. Because this happens on the
3944 ;; remote host, we cannot use the function.
3945 (tramp-message-for-buffer
3946 multi-method method user host
3947 5 "Decoding region into remote file %s..." filename
)
3949 multi-method method user host
3950 (format "%s >%s <<'EOF'"
3952 (tramp-shell-quote-argument localname
)))
3954 (tramp-message-for-buffer
3955 multi-method method user host
3956 6 "Sending data to remote host...")
3957 (tramp-send-string multi-method method user host
3959 ;; wait for remote decoding to complete
3960 (tramp-message-for-buffer
3961 multi-method method user host
3962 6 "Sending end of data token...")
3964 multi-method method user host
"EOF" nil t
)
3965 (tramp-message-for-buffer
3966 multi-method method user host
6
3967 "Waiting for remote host to process data...")
3968 (set-buffer (tramp-get-buffer multi-method method user host
))
3969 (tramp-wait-for-output)
3970 (tramp-barf-unless-okay
3971 multi-method method user host nil nil
'file-error
3972 (concat "Couldn't write region to `%s',"
3973 " decode using `%s' failed")
3975 (tramp-message 5 "Decoding region into remote file %s...done"
3977 (kill-buffer tmpbuf
))))
3980 (concat "Method `%s' should specify both encoding and "
3981 "decoding command or an rcp program")
3983 (delete-file tmpfil
)
3984 (unless (equal curbuf
(current-buffer))
3985 (error "Buffer has changed from `%s' to `%s'"
3986 curbuf
(current-buffer)))
3987 (when (or (eq visit t
) (stringp visit
))
3988 (set-visited-file-modtime
3989 ;; We must pass modtime explicitely, because filename can be different
3990 ;; from (buffer-file-name), f.e. if `file-precious-flag' is set.
3991 (nth 5 (file-attributes filename
))))
3992 (when (or (eq visit t
)
3995 (message "Wrote %s" filename
)))))
3997 ;; Call down to the real handler.
3998 ;; Because EFS does not play nicely with TRAMP (both systems match a
3999 ;; TRAMP file name) it is needed to disable efs as well as tramp for the
4002 ;; Other than that, this is the canon file-handler code that the doco
4003 ;; says should be used here. Which is nice.
4005 ;; Under XEmacs current, EFS also hooks in as
4006 ;; efs-sifn-handler-function to handle any filename with environment
4007 ;; variables. This has two implications:
4008 ;; 1) That EFS may not be completely dead (yet) for TRAMP filenames
4009 ;; 2) That TRAMP might want to do the same thing.
4010 ;; Details as they come in.
4012 ;; Daniel Pittman <daniel@danann.net>
4014 ;; (defun tramp-run-real-handler (operation args)
4015 ;; "Invoke normal file name handler for OPERATION.
4016 ;; This inhibits EFS and Ange-FTP, too, because they conflict with tramp.
4017 ;; First arg specifies the OPERATION, remaining ARGS are passed to the
4019 ;; (let ((inhibit-file-name-handlers
4020 ;; (list 'tramp-file-name-handler
4021 ;; 'efs-file-handler-function
4022 ;; 'ange-ftp-hook-function
4023 ;; (and (eq inhibit-file-name-operation operation)
4024 ;; inhibit-file-name-handlers)))
4025 ;; (inhibit-file-name-operation operation))
4026 ;; (apply operation args)))
4028 (defun tramp-run-real-handler (operation args
)
4029 "Invoke normal file name handler for OPERATION.
4030 First arg specifies the OPERATION, second arg is a list of arguments to
4031 pass to the OPERATION."
4032 (let* ((inhibit-file-name-handlers
4033 `(tramp-file-name-handler
4034 tramp-completion-file-name-handler
4035 cygwin-mount-name-hook-function
4036 cygwin-mount-map-drive-hook-function
4038 ,(and (eq inhibit-file-name-operation operation
)
4039 inhibit-file-name-handlers
)))
4040 (inhibit-file-name-operation operation
))
4041 (apply operation args
)))
4043 ;; This function is used from `tramp-completion-file-name-handler' functions
4044 ;; only, if `tramp-completion-mode' is true. But this cannot be checked here
4045 ;; because the check is based on a full filename, not available for all
4046 ;; basic I/O operations.
4047 (defun tramp-completion-run-real-handler (operation args
)
4048 "Invoke `tramp-file-name-handler' for OPERATION.
4049 First arg specifies the OPERATION, second arg is a list of arguments to
4050 pass to the OPERATION."
4051 (let* ((inhibit-file-name-handlers
4052 `(tramp-completion-file-name-handler
4053 cygwin-mount-name-hook-function
4054 cygwin-mount-map-drive-hook-function
4056 ,(and (eq inhibit-file-name-operation operation
)
4057 inhibit-file-name-handlers
)))
4058 (inhibit-file-name-operation operation
))
4059 (apply operation args
)))
4061 ;; We handle here all file primitives. Most of them have the file
4062 ;; name as first parameter; nevertheless we check for them explicitly
4063 ;; in order to be signalled if a new primitive appears. This
4064 ;; scenario is needed because there isn't a way to decide by
4065 ;; syntactical means whether a foreign method must be called. It would
4066 ;; ease the life if `file-name-handler-alist' would support a decision
4067 ;; function as well but regexp only.
4068 (defun tramp-file-name-for-operation (operation &rest args
)
4069 "Return file name related to OPERATION file primitive.
4070 ARGS are the arguments OPERATION has been called with."
4072 ; FILE resp DIRECTORY
4074 (list 'access-file
'byte-compiler-base-file-name
'delete-directory
4075 'delete-file
'diff-latest-backup-file
'directory-file-name
4076 'directory-files
'directory-files-and-attributes
4077 'dired-compress-file
'dired-uncache
4078 'file-accessible-directory-p
'file-attributes
4079 'file-directory-p
'file-executable-p
'file-exists-p
4080 'file-local-copy
'file-remote-p
'file-modes
4081 'file-name-as-directory
'file-name-directory
4082 'file-name-nondirectory
'file-name-sans-versions
4083 'file-ownership-preserved-p
'file-readable-p
4084 'file-regular-p
'file-symlink-p
'file-truename
4085 'file-writable-p
'find-backup-file-name
'find-file-noselect
4086 'get-file-buffer
'insert-directory
'insert-file-contents
4087 'load
'make-directory
'make-directory-internal
4088 'set-file-modes
'substitute-in-file-name
4089 'unhandled-file-name-directory
'vc-registered
4091 'abbreviate-file-name
'create-file-buffer
4092 'dired-file-modtime
'dired-make-compressed-filename
4093 'dired-recursive-delete-directory
'dired-set-file-modtime
4094 'dired-shell-unhandle-file-name
'dired-uucode-file
4095 'insert-file-contents-literally
'recover-file
4096 'vm-imap-check-mail
'vm-pop-check-mail
'vm-spool-check-mail
))
4097 (if (file-name-absolute-p (nth 0 args
))
4099 (expand-file-name (nth 0 args
))))
4100 ; FILE DIRECTORY resp FILE1 FILE2
4102 (list 'add-name-to-file
'copy-file
'expand-file-name
4103 'file-name-all-completions
'file-name-completion
4104 'file-newer-than-file-p
'make-symbolic-link
'rename-file
4106 'dired-make-relative-symlink
4107 'vm-imap-move-mail
'vm-pop-move-mail
'vm-spool-move-mail
))
4110 ((string-match tramp-file-name-regexp
(nth 0 args
)) (nth 0 args
))
4111 ((string-match tramp-file-name-regexp
(nth 1 args
)) (nth 1 args
))
4112 (t (buffer-file-name (current-buffer))))))
4114 ((eq operation
'write-region
)
4118 (list 'make-auto-save-file-name
4119 'set-visited-file-modtime
'verify-visited-file-modtime
4123 (if (bufferp (nth 0 args
)) (nth 0 args
) (current-buffer))))
4126 (list 'dired-call-process
4132 'dired-print-file
'dired-shell-call-process
))
4134 ; unknown file primitive
4135 (t (error "unknown file I/O primitive: %s" operation
))))
4137 (defun tramp-find-foreign-file-name-handler (filename)
4138 "Return foreign file name handler if exists."
4139 (when (tramp-tramp-file-p filename
)
4142 (handler-alist tramp-foreign-file-name-handler-alist
))
4143 (while handler-alist
4144 (setq elt
(car handler-alist
)
4145 handler-alist
(cdr handler-alist
))
4146 (when (funcall (car elt
) filename
)
4147 (setq handler-alist nil
)
4148 (setq res
(cdr elt
))))
4153 (defun tramp-file-name-handler (operation &rest args
)
4154 "Invoke Tramp file name handler.
4155 Falls back to normal file name handler if no tramp file name handler exists."
4157 (let* ((filename (apply 'tramp-file-name-for-operation operation args
))
4158 (foreign (tramp-find-foreign-file-name-handler filename
)))
4160 (foreign (apply foreign operation args
))
4161 (t (tramp-run-real-handler operation args
))))))
4164 ;; In Emacs, there is some concurrency due to timers. If a timer
4165 ;; interrupts Tramp and wishes to use the same connection buffer as
4166 ;; the "main" Emacs, then garbage might occur in the connection
4167 ;; buffer. Therefore, we need to make sure that a timer does not use
4168 ;; the same connection buffer as the "main" Emacs. We implement a
4169 ;; cheap global lock, instead of locking each connection buffer
4170 ;; separately. The global lock is based on two variables,
4171 ;; `tramp-locked' and `tramp-locker'. `tramp-locked' is set to true
4172 ;; (with setq) to indicate a lock. But Tramp also calls itself during
4173 ;; processing of a single file operation, so we need to allow
4174 ;; recursive calls. That's where the `tramp-locker' variable comes in
4175 ;; -- it is let-bound to t during the execution of the current
4176 ;; handler. So if `tramp-locked' is t and `tramp-locker' is also t,
4177 ;; then we should just proceed because we have been called
4178 ;; recursively. But if `tramp-locker' is nil, then we are a timer
4179 ;; interrupting the "main" Emacs, and then we signal an error.
4181 (defvar tramp-locked nil
4182 "If non-nil, then Tramp is currently busy.
4183 Together with `tramp-locker', this implements a locking mechanism
4184 preventing reentrant calls of Tramp.")
4186 (defvar tramp-locker nil
4187 "If non-nil, then a caller has locked Tramp.
4188 Together with `tramp-locked', this implements a locking mechanism
4189 preventing reentrant calls of Tramp.")
4191 (defun tramp-sh-file-name-handler (operation &rest args
)
4192 "Invoke remote-shell Tramp file name handler.
4193 Fall back to normal file name handler if no Tramp handler exists."
4194 (when (and tramp-locked
(not tramp-locker
))
4195 (signal 'file-error
"Forbidden reentrant call of Tramp"))
4196 (let ((tl tramp-locked
))
4199 (setq tramp-locked t
)
4200 (let ((tramp-locker t
))
4202 (let ((fn (assoc operation tramp-file-name-handler-alist
)))
4204 (apply (cdr fn
) args
)
4205 (tramp-run-real-handler operation args
))))))
4206 (setq tramp-locked tl
))))
4209 (defun tramp-completion-file-name-handler (operation &rest args
)
4210 "Invoke tramp file name completion handler.
4211 Falls back to normal file name handler if no tramp file name handler exists."
4212 ;; (setq tramp-debug-buffer t)
4213 ;; (tramp-message 1 "%s %s" operation args)
4214 ;; (tramp-message 1 "%s %s\n%s"
4215 ;; operation args (with-output-to-string (backtrace)))
4216 (let ((fn (assoc operation tramp-completion-file-name-handler-alist
)))
4218 (save-match-data (apply (cdr fn
) args
))
4219 (tramp-completion-run-real-handler operation args
))))
4222 (put 'tramp-completion-file-name-handler
'safe-magic t
)
4224 ;; Register in file name handler alist
4226 (add-to-list 'file-name-handler-alist
4227 (cons tramp-file-name-regexp
'tramp-file-name-handler
))
4228 (add-to-list 'file-name-handler-alist
4229 (cons tramp-completion-file-name-regexp
4230 'tramp-completion-file-name-handler
))
4232 (defun tramp-repair-jka-compr ()
4233 "If jka-compr is already loaded, move it to the front of
4234 `file-name-handler-alist'. On Emacs 22 or so this will not be
4236 (let ((jka (rassoc 'jka-compr-handler file-name-handler-alist
)))
4238 (setq file-name-handler-alist
4239 (cons jka
(delete jka file-name-handler-alist
))))))
4240 (tramp-repair-jka-compr)
4243 ;;; Interactions with other packages:
4245 ;; -- complete.el --
4247 ;; This function contributed by Ed Sabol
4248 (defun tramp-handle-expand-many-files (name)
4249 "Like `PC-expand-many-files' for tramp files."
4250 (with-parsed-tramp-file-name name nil
4252 (if (or (string-match "\\*" name
)
4253 (string-match "\\?" name
)
4254 (string-match "\\[.*\\]" name
))
4257 ;; CCC: To do it right, we should quote certain characters
4258 ;; in the file name, but since the echo command is going to
4259 ;; break anyway when there are spaces in the file names, we
4261 ;;-(let ((comint-file-name-quote-list
4262 ;;- (set-difference tramp-file-name-quote-list
4263 ;;- '(?\* ?\? ?[ ?]))))
4264 ;;- (tramp-send-command
4265 ;;- multi-method method user host
4266 ;;- (format "echo %s" (comint-quote-filename localname)))
4267 ;;- (tramp-wait-for-output))
4268 (tramp-send-command multi-method method user host
4269 (format "echo %s" localname
))
4270 (tramp-wait-for-output)
4271 (setq bufstr
(buffer-substring (point-min)
4272 (tramp-line-end-position)))
4273 (goto-char (point-min))
4274 (if (string-equal localname bufstr
)
4277 (while (search-forward " " nil t
)
4278 (delete-backward-char 1)
4280 (goto-char (point-max))
4281 (delete-backward-char 1)
4283 (goto-char (point-min))
4285 (function (lambda (x)
4286 (tramp-make-tramp-file-name multi-method method
4288 (read (current-buffer))))))
4289 (list (expand-file-name name
))))))
4291 ;; Check for complete.el and override PC-expand-many-files if appropriate.
4293 (defun tramp-save-PC-expand-many-files (name))); avoid compiler warning
4295 (defun tramp-setup-complete ()
4296 (fset 'tramp-save-PC-expand-many-files
4297 (symbol-function 'PC-expand-many-files
))
4298 (defun PC-expand-many-files (name)
4299 (if (tramp-tramp-file-p name
)
4300 (funcall (symbol-function 'expand-many-files
) name
)
4301 (tramp-save-PC-expand-many-files name
))))
4303 ;; Why isn't eval-after-load sufficient?
4304 (if (fboundp 'PC-expand-many-files
)
4305 (tramp-setup-complete)
4306 (eval-after-load "complete" '(tramp-setup-complete)))
4308 ;;; File name handler functions for completion mode
4310 ;; Necessary because `tramp-file-name-regexp-unified' and
4311 ;; `tramp-completion-file-name-regexp-unified' aren't different.
4312 ;; If nil, `tramp-completion-run-real-handler' is called (i.e. forwarding to
4313 ;; `tramp-file-name-handler'). Otherwise, it takes `tramp-run-real-handler'.
4314 ;; Using `last-input-event' is a little bit risky, because completing a file
4315 ;; might require loading other files, like "~/.netrc", and for them it
4316 ;; shouldn't be decided based on that variable. On the other hand, those files
4317 ;; shouldn't have partial tramp file name syntax. Maybe another variable should
4318 ;; be introduced overwriting this check in such cases. Or we change tramp
4319 ;; file name syntax in order to avoid ambiguities, like in XEmacs ...
4320 ;; In case of non unified file names it can be always true (and wouldn't be
4321 ;; necessary, because there are different regexp).
4322 (defun tramp-completion-mode (file)
4323 "Checks whether method / user name / host name completion is active."
4325 ((not tramp-unified-filenames
) t
)
4326 ((string-match "^/.*:.*:$" file
) nil
)
4328 (concat tramp-prefix-regexp
4329 "\\(" tramp-method-regexp
"\\)" tramp-postfix-single-method-regexp
"$")
4331 (member (match-string 1 file
) (mapcar 'car tramp-methods
)))
4332 ((or (equal last-input-event
'tab
)
4334 (and (integerp last-input-event
)
4335 (not (event-modifiers last-input-event
))
4336 (or (char-equal last-input-event ?
\?)
4337 (char-equal last-input-event ?
\t) ; handled by 'tab already?
4338 (char-equal last-input-event ?\
)))
4340 (and (featurep 'xemacs
)
4341 (not (event-modifiers last-input-event
))
4343 (funcall (symbol-function 'event-to-character
)
4344 last-input-event
) ?
\?)
4346 (funcall (symbol-function 'event-to-character
)
4347 last-input-event
) ?
\t)
4349 (funcall (symbol-function 'event-to-character
)
4350 last-input-event
) ?\
))))
4353 (defun tramp-completion-handle-file-exists-p (filename)
4354 "Like `file-exists-p' for tramp files."
4355 (if (tramp-completion-mode filename
)
4356 (tramp-run-real-handler
4357 'file-exists-p
(list filename
))
4358 (tramp-completion-run-real-handler
4359 'file-exists-p
(list filename
))))
4361 ;; Localname manipulation in case of partial TRAMP file names.
4362 (defun tramp-completion-handle-file-name-directory (file)
4363 "Like `file-name-directory' but aware of TRAMP files."
4364 (if (tramp-completion-mode file
)
4366 (tramp-completion-run-real-handler
4367 'file-name-directory
(list file
))))
4369 ;; Localname manipulation in case of partial TRAMP file names.
4370 (defun tramp-completion-handle-file-name-nondirectory (file)
4371 "Like `file-name-nondirectory' but aware of TRAMP files."
4373 file
(length (tramp-completion-handle-file-name-directory file
))))
4375 ;; Method, host name and user name completion.
4376 ;; `tramp-completion-dissect-file-name' returns a list of
4377 ;; tramp-file-name structures. For all of them we return possible completions.
4378 (defun tramp-completion-handle-file-name-all-completions (filename directory
)
4379 "Like `file-name-all-completions' for partial tramp files."
4382 ((fullname (concat directory filename
))
4385 (if (tramp-completion-mode fullname
)
4386 (tramp-run-real-handler
4387 'file-name-all-completions
(list filename directory
))
4388 (tramp-completion-run-real-handler
4389 'file-name-all-completions
(list filename directory
))))
4390 ;; possible completion structures
4391 (v (tramp-completion-dissect-file-name fullname
)))
4394 (let* ((car (car v
))
4395 (multi-method (tramp-file-name-multi-method car
))
4396 (method (tramp-file-name-method car
))
4397 (user (tramp-file-name-user car
))
4398 (host (tramp-file-name-host car
))
4399 (localname (tramp-file-name-localname car
))
4400 (m (tramp-find-method multi-method method user host
))
4401 (tramp-current-user user
) ; see `tramp-parse-passwd'
4404 (unless (or multi-method
;; Not handled (yet).
4405 localname
) ;; Nothing to complete
4409 ;; Method dependent user / host combinations
4413 (setq all-user-hosts
4414 (append all-user-hosts
4415 (funcall (nth 0 x
) (nth 1 x
)))))
4416 (tramp-get-completion-function m
))
4418 (setq result
(append result
4421 (tramp-get-completion-user-host
4422 method user host
(nth 0 x
) (nth 1 x
)))
4423 (delq nil all-user-hosts
)))))
4427 (append result
(tramp-get-completion-methods m
)))))
4429 (setq v
(delq car v
))))
4431 ;;; unify list, remove nil elements
4434 (let ((car (car result
)))
4435 (when car
(add-to-list 'result1 car
))
4436 (setq result
(delq car result
))))
4440 ;; Method, host name and user name completion for a file.
4441 (defun tramp-completion-handle-file-name-completion (filename directory
)
4442 "Like `file-name-completion' for tramp files."
4443 (try-completion filename
4444 (mapcar 'list
(file-name-all-completions filename directory
))))
4446 ;; I misuse a little bit the tramp-file-name structure in order to handle
4447 ;; completion possibilities for partial methods / user names / host names.
4448 ;; Return value is a list of tramp-file-name structures according to possible
4449 ;; completions. If "multi-method" or "localname" is non-nil it means there
4450 ;; shouldn't be a completion anymore.
4452 ;; Expected results:
4454 ;; "/x" "/[x" "/x@" "/[x@" "/x@y" "/[x@y"
4455 ;; [nil nil nil "x" nil] [nil nil "x" nil nil] [nil nil "x" "y" nil]
4456 ;; [nil nil "x" nil nil]
4457 ;; [nil "x" nil nil nil]
4459 ;; "/x:" "/x:y" "/x:y:"
4460 ;; [nil nil nil "x" ""] [nil nil nil "x" "y"] [nil "x" nil "y" ""]
4462 ;; [nil "x" nil "" nil] [nil "x" nil "y" nil]
4463 ;; [nil "x" "" nil nil] [nil "x" "y" nil nil]
4465 ;; "/x:y@" "/x:y@z" "/x:y@z:"
4466 ;; [nil nil nil "x" "y@"] [nil nil nil "x" "y@z"] [nil "x" "y" "z" ""]
4467 ;; "/[x/y@" "/[x/y@z"
4468 ;; [nil "x" nil "y" nil] [nil "x" "y" "z" nil]
4469 (defun tramp-completion-dissect-file-name (name)
4470 "Returns a list of `tramp-file-name' structures.
4471 They are collected by `tramp-completion-dissect-file-name1'."
4475 ;; "/method" "/[method"
4476 (tramp-completion-file-name-structure1
4477 (list (concat tramp-prefix-regexp
"\\(" tramp-method-regexp x-nil
"\\)$")
4480 (tramp-completion-file-name-structure2
4481 (list (concat tramp-prefix-regexp
"\\(" tramp-user-regexp x-nil
"\\)$")
4484 (tramp-completion-file-name-structure3
4485 (list (concat tramp-prefix-regexp
"\\(" tramp-host-regexp x-nil
"\\)$")
4487 ;; "/user@host" "/[user@host"
4488 (tramp-completion-file-name-structure4
4489 (list (concat tramp-prefix-regexp
4490 "\\(" tramp-user-regexp
"\\)" tramp-postfix-user-regexp
4491 "\\(" tramp-host-regexp x-nil
"\\)$")
4493 ;; "/method:user" "/[method/user"
4494 (tramp-completion-file-name-structure5
4495 (list (concat tramp-prefix-regexp
4496 "\\(" tramp-method-regexp
"\\)" tramp-postfix-single-method-regexp
4497 "\\(" tramp-user-regexp x-nil
"\\)$")
4499 ;; "/method:host" "/[method/host"
4500 (tramp-completion-file-name-structure6
4501 (list (concat tramp-prefix-regexp
4502 "\\(" tramp-method-regexp
"\\)" tramp-postfix-single-method-regexp
4503 "\\(" tramp-host-regexp x-nil
"\\)$")
4505 ;; "/method:user@host" "/[method/user@host"
4506 (tramp-completion-file-name-structure7
4507 (list (concat tramp-prefix-regexp
4508 "\\(" tramp-method-regexp
"\\)" tramp-postfix-single-method-regexp
4509 "\\(" tramp-user-regexp
"\\)" tramp-postfix-user-regexp
4510 "\\(" tramp-host-regexp x-nil
"\\)$")
4513 (mapcar (lambda (regexp)
4514 (add-to-list 'result
4515 (tramp-completion-dissect-file-name1 regexp name
)))
4517 tramp-completion-file-name-structure1
4518 tramp-completion-file-name-structure2
4519 tramp-completion-file-name-structure3
4520 tramp-completion-file-name-structure4
4521 tramp-completion-file-name-structure5
4522 tramp-completion-file-name-structure6
4523 tramp-completion-file-name-structure7
4524 tramp-file-name-structure
))
4528 (defun tramp-completion-dissect-file-name1 (structure name
)
4529 "Returns a `tramp-file-name' structure matching STRUCTURE.
4530 The structure consists of multi-method, remote method, remote user,
4531 remote host and localname (filename on remote host)."
4535 (when (string-match (nth 0 structure
) name
)
4536 (setq method
(and (nth 1 structure
)
4537 (match-string (nth 1 structure
) name
)))
4538 (if (and method
(member method tramp-multi-methods
))
4539 ;; Not handled (yet).
4540 (make-tramp-file-name
4541 :multi-method method
4546 (let ((user (and (nth 2 structure
)
4547 (match-string (nth 2 structure
) name
)))
4548 (host (and (nth 3 structure
)
4549 (match-string (nth 3 structure
) name
)))
4550 (localname (and (nth 4 structure
)
4551 (match-string (nth 4 structure
) name
))))
4552 (make-tramp-file-name
4557 :localname localname
)))))))
4559 ;; This function returns all possible method completions, adding the
4560 ;; trailing method delimeter.
4561 (defun tramp-get-completion-methods (partial-method)
4562 "Returns all method completions for PARTIAL-METHOD."
4566 (string-match (concat "^" (regexp-quote partial-method
)) method
)
4567 ;; we must remove leading "/".
4568 (substring (tramp-make-tramp-file-name nil method nil nil nil
) 1)))
4569 (delete "multi" (mapcar 'car tramp-methods
))))
4571 ;; Compares partial user and host names with possible completions.
4572 (defun tramp-get-completion-user-host (method partial-user partial-host user host
)
4573 "Returns the most expanded string for user and host name completion.
4574 PARTIAL-USER must match USER, PARTIAL-HOST must match HOST."
4577 ((and partial-user partial-host
)
4579 (string-match (concat "^" (regexp-quote partial-host
)) host
)
4580 (string-equal partial-user
(or user partial-user
)))
4581 (setq user partial-user
)
4588 (and user
(string-match (concat "^" (regexp-quote partial-user
)) user
))
4594 (and host
(string-match (concat "^" (regexp-quote partial-host
)) host
))
4600 (unless (zerop (+ (length user
) (length host
)))
4601 ;; we must remove leading "/".
4602 (substring (tramp-make-tramp-file-name nil method user host nil
) 1)))
4604 (defun tramp-parse-rhosts (filename)
4605 "Return a list of (user host) tuples allowed to access.
4606 Either user or host may be nil."
4609 (when (file-readable-p filename
)
4611 (insert-file-contents filename
)
4612 (goto-char (point-min))
4614 (push (tramp-parse-rhosts-group) res
))))
4617 ;; Taken from gnus/netrc.el
4619 (defalias 'tramp-point-at-eol
4620 (if (fboundp 'point-at-eol
)
4622 'line-end-position
)))
4624 (defun tramp-parse-rhosts-group ()
4625 "Return a (user host) tuple allowed to access.
4626 Either user or host may be nil."
4631 "^\\(" tramp-host-regexp
"\\)"
4632 "\\([ \t]+" "\\(" tramp-user-regexp
"\\)" "\\)?")))
4634 (narrow-to-region (point) (tramp-point-at-eol))
4635 (when (re-search-forward regexp nil t
)
4636 (setq result
(append (list (match-string 3) (match-string 1)))))
4641 (defun tramp-parse-shosts (filename)
4642 "Return a list of (user host) tuples allowed to access.
4643 User is always nil."
4646 (when (file-readable-p filename
)
4648 (insert-file-contents filename
)
4649 (goto-char (point-min))
4651 (push (tramp-parse-shosts-group) res
))))
4654 (defun tramp-parse-shosts-group ()
4655 "Return a (user host) tuple allowed to access.
4656 User is always nil."
4659 (regexp (concat "^\\(" tramp-host-regexp
"\\)")))
4661 (narrow-to-region (point) (tramp-point-at-eol))
4662 (when (re-search-forward regexp nil t
)
4663 (setq result
(list nil
(match-string 1))))
4666 (> (skip-chars-forward ",") 0)
4670 (defun tramp-parse-sconfig (filename)
4671 "Return a list of (user host) tuples allowed to access.
4672 User is always nil."
4675 (when (file-readable-p filename
)
4677 (insert-file-contents filename
)
4678 (goto-char (point-min))
4680 (push (tramp-parse-sconfig-group) res
))))
4683 (defun tramp-parse-sconfig-group ()
4684 "Return a (user host) tuple allowed to access.
4685 User is always nil."
4688 (regexp (concat "^[ \t]*Host[ \t]+" "\\(" tramp-host-regexp
"\\)")))
4690 (narrow-to-region (point) (tramp-point-at-eol))
4691 (when (re-search-forward regexp nil t
)
4692 (setq result
(list nil
(match-string 1))))
4695 (> (skip-chars-forward ",") 0)
4699 (defun tramp-parse-shostkeys (dirname)
4700 "Return a list of (user host) tuples allowed to access.
4701 User is always nil."
4703 (let ((regexp (concat "^key_[0-9]+_\\(" tramp-host-regexp
"\\)\\.pub$"))
4704 (files (when (file-directory-p dirname
) (directory-files dirname
)))
4708 (when (string-match regexp
(car files
))
4709 (push (list nil
(match-string 1 (car files
))) result
))
4710 (setq files
(cdr files
)))
4713 (defun tramp-parse-sknownhosts (dirname)
4714 "Return a list of (user host) tuples allowed to access.
4715 User is always nil."
4717 (let ((regexp (concat "^\\(" tramp-host-regexp
4718 "\\)\\.ssh-\\(dss\\|rsa\\)\\.pub$"))
4719 (files (when (file-directory-p dirname
) (directory-files dirname
)))
4723 (when (string-match regexp
(car files
))
4724 (push (list nil
(match-string 1 (car files
))) result
))
4725 (setq files
(cdr files
)))
4728 (defun tramp-parse-hosts (filename)
4729 "Return a list of (user host) tuples allowed to access.
4730 User is always nil."
4733 (when (file-readable-p filename
)
4735 (insert-file-contents filename
)
4736 (goto-char (point-min))
4738 (push (tramp-parse-hosts-group) res
))))
4741 (defun tramp-parse-hosts-group ()
4742 "Return a (user host) tuple allowed to access.
4743 User is always nil."
4746 (regexp (concat "^\\(" tramp-host-regexp
"\\)")))
4748 (narrow-to-region (point) (tramp-point-at-eol))
4749 (when (re-search-forward regexp nil t
)
4750 (unless (char-equal (or (char-after) ?
\n) ?
:) ; no IPv6
4751 (setq result
(list nil
(match-string 1)))))
4754 (> (skip-chars-forward " \t") 0)
4758 ;; For su-alike methods it would be desirable to return "root@localhost"
4759 ;; as default. Unfortunately, we have no information whether any user name
4760 ;; has been typed already. So we (mis-)use tramp-current-user as indication,
4761 ;; assuming it is set in `tramp-completion-handle-file-name-all-completions'.
4762 (defun tramp-parse-passwd (filename)
4763 "Return a list of (user host) tuples allowed to access.
4764 Host is always \"localhost\"."
4767 (if (zerop (length tramp-current-user
))
4769 (when (file-readable-p filename
)
4771 (insert-file-contents filename
)
4772 (goto-char (point-min))
4774 (push (tramp-parse-passwd-group) res
))))
4777 (defun tramp-parse-passwd-group ()
4778 "Return a (user host) tuple allowed to access.
4779 Host is always \"localhost\"."
4782 (regexp (concat "^\\(" tramp-user-regexp
"\\):")))
4784 (narrow-to-region (point) (tramp-point-at-eol))
4785 (when (re-search-forward regexp nil t
)
4786 (setq result
(list (match-string 1) "localhost")))
4791 (defun tramp-parse-netrc (filename)
4792 "Return a list of (user host) tuples allowed to access.
4796 (when (file-readable-p filename
)
4798 (insert-file-contents filename
)
4799 (goto-char (point-min))
4801 (push (tramp-parse-netrc-group) res
))))
4804 (defun tramp-parse-netrc-group ()
4805 "Return a (user host) tuple allowed to access.
4811 "^[ \t]*machine[ \t]+" "\\(" tramp-host-regexp
"\\)"
4812 "\\([ \t]+login[ \t]+" "\\(" tramp-user-regexp
"\\)" "\\)?")))
4814 (narrow-to-region (point) (tramp-point-at-eol))
4815 (when (re-search-forward regexp nil t
)
4816 (setq result
(list (match-string 3) (match-string 1))))
4821 (defun tramp-completion-handle-expand-file-name (name &optional dir
)
4822 "Like `expand-file-name' for tramp files."
4823 (let ((fullname (concat (or dir default-directory
) name
)))
4824 (if (tramp-completion-mode fullname
)
4825 (tramp-run-real-handler
4826 'expand-file-name
(list name dir
))
4827 (tramp-completion-run-real-handler
4828 'expand-file-name
(list name dir
)))))
4830 ;;; Internal Functions:
4832 (defun tramp-maybe-send-perl-script (multi-method method user host script name
)
4833 "Define in remote shell function NAME implemented as perl SCRIPT.
4834 Only send the definition if it has not already been done.
4835 Function may have 0-3 parameters."
4836 (let ((remote-perl (tramp-get-remote-perl multi-method method user host
)))
4837 (unless remote-perl
(error "No remote perl"))
4838 (let ((perl-scripts (tramp-get-connection-property "perl-scripts" nil
4839 multi-method method user host
)))
4840 (unless (memq name perl-scripts
)
4841 (with-current-buffer (tramp-get-buffer multi-method method user host
)
4842 (tramp-message 5 (concat "Sending the Perl script `" name
"'..."))
4843 (tramp-send-string multi-method method user host
4849 "' \"$1\" \"$2\" \"$3\" 2>/dev/null\n}"))
4850 (tramp-wait-for-output)
4851 (tramp-set-connection-property "perl-scripts" (cons name perl-scripts
)
4852 multi-method method user host
)
4853 (tramp-message 5 (concat "Sending the Perl script `" name
"'...done.")))))))
4855 (defun tramp-set-auto-save ()
4856 (when (and (buffer-file-name)
4857 (tramp-tramp-file-p (buffer-file-name))
4858 ;; ange-ftp has its own auto-save mechanism
4859 (eq (tramp-find-foreign-file-name-handler (buffer-file-name))
4860 'tramp-sh-file-name-handler
)
4862 (auto-save-mode 1)))
4863 (add-hook 'find-file-hooks
'tramp-set-auto-save t
)
4865 (defun tramp-run-test (switch filename
)
4866 "Run `test' on the remote system, given a SWITCH and a FILENAME.
4867 Returns the exit code of the `test' program."
4868 (let ((v (tramp-dissect-file-name filename
)))
4870 (tramp-send-command-and-check
4871 (tramp-file-name-multi-method v
) (tramp-file-name-method v
)
4872 (tramp-file-name-user v
) (tramp-file-name-host v
)
4873 (format "test %s %s" switch
4874 (tramp-shell-quote-argument (tramp-file-name-localname v
)))))))
4876 (defun tramp-run-test2 (program file1 file2
&optional switch
)
4877 "Run `test'-like PROGRAM on the remote system, given FILE1, FILE2.
4878 The optional SWITCH is inserted between the two files.
4879 Returns the exit code of the `test' PROGRAM. Barfs if the methods,
4880 hosts, or files, disagree."
4881 (let* ((v1 (tramp-dissect-file-name file1
))
4882 (v2 (tramp-dissect-file-name file2
))
4883 (mmethod1 (tramp-file-name-multi-method v1
))
4884 (mmethod2 (tramp-file-name-multi-method v2
))
4885 (method1 (tramp-file-name-method v1
))
4886 (method2 (tramp-file-name-method v2
))
4887 (user1 (tramp-file-name-user v1
))
4888 (user2 (tramp-file-name-user v2
))
4889 (host1 (tramp-file-name-host v1
))
4890 (host2 (tramp-file-name-host v2
))
4891 (localname1 (tramp-file-name-localname v1
))
4892 (localname2 (tramp-file-name-localname v2
)))
4893 (unless (and method1 method2 host1 host2
4894 (equal mmethod1 mmethod2
)
4895 (equal method1 method2
)
4897 (equal host1 host2
))
4898 (error "tramp-run-test2: %s"
4899 "only implemented for same method, same user, same host"))
4901 (tramp-send-command-and-check
4902 mmethod1 method1 user1 host1
4903 (format "%s %s %s %s"
4905 (tramp-shell-quote-argument localname1
)
4907 (tramp-shell-quote-argument localname2
))))))
4909 (defun tramp-touch (file time
)
4910 "Set the last-modified timestamp of the given file.
4911 TIME is an Emacs internal time value as returned by `current-time'."
4912 (let ((touch-time (format-time-string "%Y%m%d%H%M.%S" time
)))
4913 (if (tramp-tramp-file-p file
)
4914 (with-parsed-tramp-file-name file nil
4915 (let ((buf (tramp-get-buffer multi-method method user host
)))
4916 (unless (zerop (tramp-send-command-and-check
4917 multi-method method user host
4918 (format "touch -t %s %s"
4922 (error "tramp-touch: touch failed, see buffer `%s' for details"
4924 ;; It's a local file
4926 (unless (zerop (call-process
4927 "touch" nil
(current-buffer) nil
"-t" touch-time file
))
4928 (pop-to-buffer (current-buffer))
4929 (error "tramp-touch: touch failed"))))))
4931 (defun tramp-buffer-name (multi-method method user host
)
4932 "A name for the connection buffer for USER at HOST using METHOD."
4934 (tramp-buffer-name-multi-method "tramp" multi-method method user host
)
4935 (let ((method (tramp-find-method multi-method method user host
)))
4937 (format "*tramp/%s %s@%s*" method user host
)
4938 (format "*tramp/%s %s*" method host
)))))
4940 (defun tramp-buffer-name-multi-method (prefix multi-method method user host
)
4941 "A name for the multi method connection buffer.
4942 MULTI-METHOD gives the multi method, METHOD the array of methods,
4943 USER the array of user names, HOST the array of host names."
4944 (unless (and (= (length method
) (length user
))
4945 (= (length method
) (length host
)))
4946 (error "Syntax error in multi method (implementation error)"))
4947 (let ((len (length method
))
4952 (cons (if (aref user i
)
4953 (format "%s#%s@%s:" (aref method i
)
4954 (aref user i
) (aref host i
))
4955 (format "%s@%s:" (aref method i
) (aref host i
)))
4958 (format "*%s/%s %s*"
4960 (apply 'concat
(reverse string-list
)))))
4962 (defun tramp-get-buffer (multi-method method user host
)
4963 "Get the connection buffer to be used for USER at HOST using METHOD."
4964 (with-current-buffer
4965 (get-buffer-create (tramp-buffer-name multi-method method user host
))
4966 (setq buffer-undo-list t
)
4969 (defun tramp-debug-buffer-name (multi-method method user host
)
4970 "A name for the debug buffer for USER at HOST using METHOD."
4972 (tramp-buffer-name-multi-method "debug tramp"
4973 multi-method method user host
)
4974 (let ((method (tramp-find-method multi-method method user host
)))
4976 (format "*debug tramp/%s %s@%s*" method user host
)
4977 (format "*debug tramp/%s %s*" method host
)))))
4979 (defun tramp-get-debug-buffer (multi-method method user host
)
4980 "Get the debug buffer for USER at HOST using METHOD."
4981 (with-current-buffer
4983 (tramp-debug-buffer-name multi-method method user host
))
4984 (setq buffer-undo-list t
)
4987 (defun tramp-find-executable (multi-method method user host
4988 progname dirlist ignore-tilde
)
4989 "Searches for PROGNAME in all directories mentioned in DIRLIST.
4990 First args METHOD, USER and HOST specify the connection, PROGNAME
4991 is the program to search for, and DIRLIST gives the list of directories
4992 to search. If IGNORE-TILDE is non-nil, directory names starting
4993 with `~' will be ignored.
4995 Returns the absolute file name of PROGNAME, if found, and nil otherwise.
4997 This function expects to be in the right *tramp* buffer."
5000 ;; Remove all ~/foo directories from dirlist. In Emacs 20,
5001 ;; `remove' is in CL, and we want to avoid CL dependencies.
5004 (setq d
(car dirlist
))
5005 (setq dirlist
(cdr dirlist
))
5006 (unless (char-equal ?~
(aref d
0))
5007 (setq newdl
(cons d newdl
))))
5008 (setq dirlist
(nreverse newdl
))))
5010 multi-method method user host
5011 (format (concat "while read d; "
5012 "do if test -x $d/%s -a -f $d/%s; "
5013 "then echo tramp_executable $d/%s; "
5014 "break; fi; done <<'EOF'")
5015 progname progname progname
))
5017 (tramp-send-command multi-method method user host d
))
5019 (tramp-send-command multi-method method user host
"EOF")
5020 (tramp-wait-for-output)
5021 (goto-char (point-max))
5022 (when (search-backward "tramp_executable " nil t
)
5023 (skip-chars-forward "^ ")
5024 (skip-chars-forward " ")
5025 (buffer-substring (point) (tramp-line-end-position)))))
5027 (defun tramp-set-remote-path (multi-method method user host var dirlist
)
5028 "Sets the remote environment VAR to existing directories from DIRLIST.
5029 I.e., for each directory in DIRLIST, it is tested whether it exists and if
5030 so, it is added to the environment variable VAR."
5031 (let ((existing-dirs
5036 (tramp-make-tramp-file-name multi-method method user host x
))
5038 (tramp-make-tramp-file-name multi-method method user host x
)))
5042 multi-method method user host
5044 (mapconcat 'identity
(delq nil existing-dirs
) ":")
5046 (tramp-wait-for-output)))
5048 ;; -- communication with external shell --
5050 (defun tramp-find-file-exists-command (multi-method method user host
)
5051 "Find a command on the remote host for checking if a file exists.
5052 Here, we are looking for a command which has zero exit status if the
5053 file exists and nonzero exit status otherwise."
5054 (make-local-variable 'tramp-file-exists-command
)
5055 (tramp-message 9 "Finding command to check if file exists")
5057 (tramp-make-tramp-file-name
5058 multi-method method user host
5059 "/")) ;assume this file always exists
5061 (tramp-make-tramp-file-name
5062 multi-method method user host
5063 "/ this file does not exist "))) ;assume this never exists
5064 ;; The algorithm is as follows: we try a list of several commands.
5065 ;; For each command, we first run `$cmd /' -- this should return
5066 ;; true, as the root directory always exists. And then we run
5067 ;; `$cmd /this\ file\ does\ not\ exist', hoping that the file indeed
5068 ;; does not exist. This should return false. We use the first
5069 ;; command we find that seems to work.
5070 ;; The list of commands to try is as follows:
5071 ;; `ls -d' This works on most systems, but NetBSD 1.4
5072 ;; has a bug: `ls' always returns zero exit
5073 ;; status, even for files which don't exist.
5074 ;; `test -e' Some Bourne shells have a `test' builtin
5075 ;; which does not know the `-e' option.
5076 ;; `/bin/test -e' For those, the `test' binary on disk normally
5077 ;; provides the option. Alas, the binary
5078 ;; is sometimes `/bin/test' and sometimes it's
5080 ;; `/usr/bin/test -e' In case `/bin/test' does not exist.
5082 (and (setq tramp-file-exists-command
"test -e %s")
5083 (file-exists-p existing
)
5084 (not (file-exists-p nonexisting
)))
5085 (and (setq tramp-file-exists-command
"/bin/test -e %s")
5086 (file-exists-p existing
)
5087 (not (file-exists-p nonexisting
)))
5088 (and (setq tramp-file-exists-command
"/usr/bin/test -e %s")
5089 (file-exists-p existing
)
5090 (not (file-exists-p nonexisting
)))
5091 (and (setq tramp-file-exists-command
"ls -d %s")
5092 (file-exists-p existing
)
5093 (not (file-exists-p nonexisting
))))
5094 (error "Couldn't find command to check if file exists"))))
5097 ;; CCC test ksh or bash found for tilde expansion?
5098 (defun tramp-find-shell (multi-method method user host
)
5099 "Find a shell on the remote host which groks tilde expansion."
5101 (tramp-send-command multi-method method user host
"echo ~root")
5102 (tramp-wait-for-output)
5104 ((string-match "^~root$" (buffer-string))
5106 (or (tramp-find-executable multi-method method user host
5107 "bash" tramp-remote-path t
)
5108 (tramp-find-executable multi-method method user host
5109 "ksh" tramp-remote-path t
)))
5111 (error "Couldn't find a shell which groks tilde expansion"))
5112 ;; Find arguments for this shell.
5113 (let ((alist tramp-sh-extra-args
)
5115 (while (and alist
(null extra-args
))
5116 (setq item
(pop alist
))
5117 (when (string-match (car item
) shell
)
5118 (setq extra-args
(cdr item
))))
5119 (when extra-args
(setq shell
(concat shell
" " extra-args
))))
5121 5 "Starting remote shell `%s' for tilde expansion..." shell
)
5123 multi-method method user host
5124 (concat "PS1='$ ' exec " shell
)) ;
5125 (tramp-barf-if-no-shell-prompt
5126 (get-buffer-process (current-buffer))
5127 60 "Couldn't find remote `%s' prompt" shell
)
5129 9 "Setting remote shell prompt...")
5130 ;; Douglas Gray Stephens <DGrayStephens@slb.com> says that we
5131 ;; must use "\n" here, not tramp-rsh-end-of-line. Kai left the
5132 ;; last tramp-rsh-end-of-line, Douglas wanted to replace that,
5134 (process-send-string nil
(format "PS1='%s%s%s'; PS2=''; PS3=''%s"
5135 tramp-rsh-end-of-line
5137 tramp-rsh-end-of-line
5138 tramp-rsh-end-of-line
))
5139 (tramp-wait-for-output)
5141 9 "Setting remote shell prompt...done")
5143 (t (tramp-message 5 "Remote `%s' groks tilde expansion, good"
5144 (tramp-get-method-parameter
5145 multi-method method user host
'tramp-remote-sh
))))))
5147 (defun tramp-check-ls-command (multi-method method user host cmd
)
5148 "Checks whether the given `ls' executable groks `-n'.
5149 METHOD, USER and HOST specify the connection, CMD (the absolute file name of)
5150 the `ls' executable. Returns t if CMD supports the `-n' option, nil
5152 (tramp-message 9 "Checking remote `%s' command for `-n' option" cmd
)
5153 (when (file-executable-p
5154 (tramp-make-tramp-file-name multi-method method user host cmd
))
5156 (tramp-message 7 "Testing remote command `%s' for -n..." cmd
)
5158 (tramp-send-command-and-check
5159 multi-method method user host
5160 (format "%s -lnd / >/dev/null"
5162 (tramp-message 7 "Testing remote command `%s' for -n...%s"
5164 (if (zerop result
) "okay" "failed"))
5167 (defun tramp-check-ls-commands (multi-method method user host cmd dirlist
)
5168 "Checks whether the given `ls' executable in one of the dirs groks `-n'.
5169 Returns nil if none was found, else the command is returned."
5172 (tramp-let-maybe directory-sep-char ?
/ ;for XEmacs
5173 ;; It would be better to use the CL function `find', but
5174 ;; we don't want run-time dependencies on CL.
5175 (while (and dl
(not result
))
5176 (let ((x (concat (file-name-as-directory (car dl
)) cmd
)))
5177 (when (tramp-check-ls-command multi-method method user host x
)
5182 (defun tramp-find-ls-command (multi-method method user host
)
5183 "Finds an `ls' command which groks the `-n' option, returning nil if failed.
5184 \(This option prints numeric user and group ids in a long listing.)"
5185 (tramp-message 9 "Finding a suitable `ls' command")
5187 (tramp-check-ls-commands multi-method method user host
"ls" tramp-remote-path
)
5188 (tramp-check-ls-commands multi-method method user host
"gnuls" tramp-remote-path
)
5189 (tramp-check-ls-commands multi-method method user host
"gls" tramp-remote-path
)))
5191 ;; ------------------------------------------------------------
5192 ;; -- Functions for establishing connection --
5193 ;; ------------------------------------------------------------
5195 ;; The following functions are actions to be taken when seeing certain
5196 ;; prompts from the remote host. See the variable
5197 ;; `tramp-actions-before-shell' for usage of these functions.
5199 (defun tramp-action-login (p multi-method method user host
)
5200 "Send the login name."
5201 (tramp-message 9 "Sending login name `%s'"
5202 (or user
(user-login-name)))
5204 (process-send-string nil
(concat (or user
(user-login-name))
5205 tramp-rsh-end-of-line
)))
5207 (defun tramp-action-password (p multi-method method user host
)
5208 "Query the user for a password."
5209 (let ((pw-prompt (match-string 0)))
5210 (tramp-message 9 "Sending password")
5211 (tramp-enter-password p pw-prompt user host
)))
5213 (defun tramp-action-succeed (p multi-method method user host
)
5214 "Signal success in finding shell prompt."
5215 (tramp-message 9 "Found remote shell prompt.")
5217 (throw 'tramp-action
'ok
))
5219 (defun tramp-action-permission-denied (p multi-method method user host
)
5220 "Signal permission denied."
5221 (pop-to-buffer (tramp-get-buffer multi-method method user host
))
5222 (tramp-message 9 "Permission denied by remote host.")
5224 (throw 'tramp-action
'permission-denied
))
5226 (defun tramp-action-yesno (p multi-method method user host
)
5227 "Ask the user for confirmation using `yes-or-no-p'.
5228 Send \"yes\" to remote process on confirmation, abort otherwise.
5229 See also `tramp-action-yn'."
5230 (save-window-excursion
5231 (pop-to-buffer (tramp-get-buffer multi-method method user host
))
5232 (unless (yes-or-no-p (match-string 0))
5235 (throw 'tramp-action
'permission-denied
))
5236 (process-send-string p
(concat "yes" tramp-rsh-end-of-line
))
5239 (defun tramp-action-yn (p multi-method method user host
)
5240 "Ask the user for confirmation using `y-or-n-p'.
5241 Send \"y\" to remote process on confirmation, abort otherwise.
5242 See also `tramp-action-yesno'."
5243 (save-window-excursion
5244 (pop-to-buffer (tramp-get-buffer multi-method method user host
))
5245 (unless (y-or-n-p (match-string 0))
5247 (throw 'tramp-action
'permission-denied
))
5249 (process-send-string p
(concat "y" tramp-rsh-end-of-line
))))
5251 (defun tramp-action-terminal (p multi-method method user host
)
5252 "Tell the remote host which terminal type to use.
5253 The terminal type can be configured with `tramp-terminal-type'."
5254 (tramp-message 9 "Setting `%s' as terminal type."
5255 tramp-terminal-type
)
5257 (process-send-string nil
(concat tramp-terminal-type
5258 tramp-rsh-end-of-line
)))
5260 (defun tramp-action-process-alive (p multi-method method user host
)
5261 "Check whether a process has finished."
5262 (unless (memq (process-status p
) '(run open
))
5263 (throw 'tramp-action
'process-died
)))
5265 (defun tramp-action-out-of-band (p multi-method method user host
)
5266 "Check whether an out-of-band copy has finished."
5267 (cond ((and (memq (process-status p
) '(stop exit
))
5268 (zerop (process-exit-status p
)))
5269 (tramp-message 9 "Process has finished.")
5270 (throw 'tramp-action
'ok
))
5271 ((or (and (memq (process-status p
) '(stop exit
))
5272 (not (zerop (process-exit-status p
))))
5273 (memq (process-status p
) '(signal)))
5274 ;; `scp' could have copied correctly, but set modes could have failed.
5275 ;; This can be ignored.
5276 (goto-char (point-min))
5277 (if (re-search-forward tramp-operation-not-permitted-regexp nil t
)
5279 (tramp-message 10 "'set mode' error ignored.")
5280 (tramp-message 9 "Process has finished.")
5281 (throw 'tramp-action
'ok
))
5282 (tramp-message 9 "Process has died.")
5283 (throw 'tramp-action
'process-died
)))
5286 ;; The following functions are specifically for multi connections.
5288 (defun tramp-multi-action-login (p method user host
)
5289 "Send the login name."
5290 (tramp-message 9 "Sending login name `%s'" user
)
5292 (process-send-string p
(concat user tramp-rsh-end-of-line
)))
5294 (defun tramp-multi-action-password (p method user host
)
5295 "Query the user for a password."
5296 (tramp-message 9 "Sending password")
5297 (tramp-enter-password p
(match-string 0) user host
))
5299 (defun tramp-multi-action-succeed (p method user host
)
5300 "Signal success in finding shell prompt."
5301 (tramp-message 9 "Found shell prompt on `%s'" host
)
5303 (throw 'tramp-action
'ok
))
5305 (defun tramp-multi-action-permission-denied (p method user host
)
5306 "Signal permission denied."
5307 (tramp-message 9 "Permission denied by remote host `%s'" host
)
5310 (throw 'tramp-action
'permission-denied
))
5312 (defun tramp-multi-action-process-alive (p method user host
)
5313 "Check whether a process has finished."
5314 (unless (memq (process-status p
) '(run open
))
5315 (throw 'tramp-action
'process-died
)))
5317 ;; Functions for processing the actions.
5319 (defun tramp-process-one-action (p multi-method method user host actions
)
5320 "Wait for output from the shell and perform one action."
5321 (let (found item pattern action todo
)
5323 (tramp-message 9 "Waiting 60s for prompt from remote shell")
5324 (with-timeout (60 (throw 'tramp-action
'timeout
))
5326 (tramp-accept-process-output p
1)
5327 (goto-char (point-min))
5330 (goto-char (point-min))
5331 (setq item
(pop todo
))
5332 (setq pattern
(symbol-value (nth 0 item
)))
5333 (setq action
(nth 1 item
))
5334 (tramp-message 10 "Looking for regexp \"%s\" from remote shell"
5336 (when (re-search-forward (concat pattern
"\\'") nil t
)
5337 (setq found
(funcall action p multi-method method user host
)))))
5340 (defun tramp-process-actions (p multi-method method user host actions
)
5341 "Perform actions until success."
5344 (tramp-message 9 "Waiting for prompts from remote shell")
5346 (catch 'tramp-action
5347 (tramp-process-one-action
5348 p multi-method method user host actions
)
5350 (unless (eq exit
'ok
)
5351 (tramp-clear-passwd user host
)
5352 (error "Login failed"))))
5354 ;; For multi-actions.
5356 (defun tramp-process-one-multi-action (p method user host actions
)
5357 "Wait for output from the shell and perform one action."
5358 (let (found item pattern action todo
)
5360 (tramp-message 9 "Waiting 60s for prompt from remote shell")
5361 (with-timeout (60 (throw 'tramp-action
'timeout
))
5363 (tramp-accept-process-output p
1)
5365 (goto-char (point-min))
5367 (goto-char (point-min))
5368 (setq item
(pop todo
))
5369 (setq pattern
(symbol-value (nth 0 item
)))
5370 (setq action
(nth 1 item
))
5371 (tramp-message 10 "Looking for regexp \"%s\" from remote shell"
5373 (when (re-search-forward (concat pattern
"\\'") nil t
)
5374 (setq found
(funcall action p method user host
)))))
5377 (defun tramp-process-multi-actions (p method user host actions
)
5378 "Perform actions until success."
5381 (tramp-message 9 "Waiting for prompts from remote shell")
5383 (catch 'tramp-action
5384 (tramp-process-one-multi-action p method user host actions
)
5386 (unless (eq exit
'ok
)
5387 (tramp-clear-passwd user host
)
5388 (error "Login failed"))))
5390 ;; Functions to execute when we have seen the remote shell prompt but
5391 ;; before we exec the Bourne-ish shell. Note that these commands
5392 ;; might be sent to any shell, not just a Bourne-ish shell. This
5393 ;; means that the commands need to work in all shells. (It is also
5394 ;; okay for some commands to just fail with an error message, but
5395 ;; please make sure that they at least don't crash the odd shell people
5396 ;; might be running...)
5397 (defun tramp-process-initial-commands (p
5398 multi-method method user host
5400 "Send list of commands to remote host, in order."
5403 (setq cmd
(pop commands
))
5405 (tramp-message 10 "Sending command to remote shell: %s"
5407 (tramp-send-command multi-method method user host cmd nil t
)
5408 (tramp-barf-if-no-shell-prompt
5409 p
60 "Remote shell command failed: %s" cmd
))
5412 ;; The actual functions for opening connections.
5414 (defun tramp-open-connection-telnet (multi-method method user host
)
5415 "Open a connection using a telnet METHOD.
5416 This starts the command `telnet HOST ARGS'[*], then waits for a remote
5417 login prompt, then sends the user name USER, then waits for a remote
5418 password prompt. It queries the user for the password, then sends the
5419 password to the remote host.
5421 If USER is nil, uses value returned by `(user-login-name)' instead.
5423 Recognition of the remote shell prompt is based on the variables
5424 `shell-prompt-pattern' and `tramp-shell-prompt-pattern' which must be
5427 Please note that it is NOT possible to use this connection method
5428 together with an out-of-band transfer method! You must use an inline
5431 Maybe the different regular expressions need to be tuned.
5433 * Actually, the telnet program as well as the args to be used can be
5434 specified in the method parameters, see the variable `tramp-methods'."
5436 (when (tramp-method-out-of-band-p multi-method method user host
)
5437 (error "Cannot use out-of-band method `%s' with telnet connection method"
5440 (error "Cannot multi-connect using telnet connection method"))
5441 (tramp-pre-connection multi-method method user host tramp-chunksize
)
5442 (tramp-message 7 "Opening connection for %s@%s using %s..."
5443 (or user
(user-login-name)) host method
)
5444 (let ((process-environment (copy-sequence process-environment
)))
5445 (setenv "TERM" tramp-terminal-type
)
5446 (let* ((default-directory (tramp-temporary-file-directory))
5447 ;; If we omit the conditional here, then we would use
5448 ;; `undecided-dos' in some cases. With the conditional,
5449 ;; we use nil in these cases. Which one is right?
5450 (coding-system-for-read (unless (and (not (featurep 'xemacs
))
5451 (> emacs-major-version
20))
5452 tramp-dos-coding-system
))
5453 (p (apply 'start-process
5454 (tramp-buffer-name multi-method method user host
)
5455 (tramp-get-buffer multi-method method user host
)
5456 (tramp-get-method-parameter
5458 (tramp-find-method multi-method method user host
)
5459 user host
'tramp-login-program
)
5461 (tramp-get-method-parameter
5463 (tramp-find-method multi-method method user host
)
5464 user host
'tramp-login-args
)))
5467 (tramp-set-process-query-on-exit-flag p nil
)
5468 (set-buffer (tramp-get-buffer multi-method method user host
))
5470 (tramp-process-actions p multi-method method user host
5471 tramp-actions-before-shell
)
5472 (tramp-open-connection-setup-interactive-shell
5473 p multi-method method user host
)
5474 (tramp-post-connection multi-method method user host
)))))
5477 (defun tramp-open-connection-rsh (multi-method method user host
)
5478 "Open a connection using an rsh METHOD.
5479 This starts the command `rsh HOST -l USER'[*], then waits for a remote
5480 password or shell prompt. If a password prompt is seen, the user is
5481 queried for a password, this function sends the password to the remote
5482 host and waits for a shell prompt.
5484 If USER is nil, start the command `rsh HOST'[*] instead
5486 Recognition of the remote shell prompt is based on the variables
5487 `shell-prompt-pattern' and `tramp-shell-prompt-pattern' which must be
5490 Kludgy feature: if HOST has the form \"xx#yy\", then yy is assumed to
5491 be a port number for ssh, and \"-p yy\" will be added to the list of
5492 arguments, and xx will be used as the host name to connect to.
5494 * Actually, the rsh program to be used can be specified in the
5495 method parameters, see the variable `tramp-methods'."
5498 (error "Cannot multi-connect using rsh connection method"))
5499 (tramp-pre-connection multi-method method user host tramp-chunksize
)
5500 (if (and user
(not (string= user
"")))
5501 (tramp-message 7 "Opening connection for %s@%s using %s..."
5503 (tramp-message 7 "Opening connection at %s using %s..." host method
))
5504 (let ((process-environment (copy-sequence process-environment
))
5505 (bufnam (tramp-buffer-name multi-method method user host
))
5506 (buf (tramp-get-buffer multi-method method user host
))
5507 (login-program (tramp-get-method-parameter
5509 (tramp-find-method multi-method method user host
)
5510 user host
'tramp-login-program
))
5511 (login-args (tramp-get-method-parameter
5513 (tramp-find-method multi-method method user host
)
5514 user host
'tramp-login-args
))
5516 ;; The following should be changed. We need a more general
5517 ;; mechanism to parse extra host args.
5518 (when (string-match "\\([^#]*\\)#\\(.*\\)" host
)
5519 (setq login-args
(cons "-p" (cons (match-string 2 host
) login-args
)))
5520 (setq real-host
(match-string 1 host
)))
5521 (setenv "TERM" tramp-terminal-type
)
5522 (let* ((default-directory (tramp-temporary-file-directory))
5523 ;; If we omit the conditional, we would use
5524 ;; `undecided-dos' in some cases. With the conditional,
5525 ;; we use nil in these cases. Which one is right?
5526 (coding-system-for-read (unless (and (not (featurep 'xemacs
))
5527 (> emacs-major-version
20))
5528 tramp-dos-coding-system
))
5529 (p (if (and user
(not (string= user
"")))
5530 (apply #'start-process bufnam buf login-program
5531 real-host
"-l" user login-args
)
5532 (apply #'start-process bufnam buf login-program
5533 real-host login-args
)))
5535 (tramp-set-process-query-on-exit-flag p nil
)
5538 (tramp-process-actions p multi-method method user host
5539 tramp-actions-before-shell
)
5540 (tramp-message 7 "Initializing remote shell")
5541 (tramp-open-connection-setup-interactive-shell
5542 p multi-method method user host
)
5543 (tramp-post-connection multi-method method user host
)))))
5545 (defun tramp-open-connection-su (multi-method method user host
)
5546 "Open a connection using the `su' program with METHOD.
5547 This starts `su - USER', then waits for a password prompt. The HOST
5548 name must be equal to the local host name or to `localhost'.
5550 If USER is nil, uses value returned by user-login-name instead.
5552 Recognition of the remote shell prompt is based on the variables
5553 `shell-prompt-pattern' and `tramp-shell-prompt-pattern' which must be
5554 set up correctly. Note that the other user may have a different shell
5555 prompt than you do, so it is not at all unlikely that the variable
5556 `shell-prompt-pattern' is set up wrongly!"
5558 (when (tramp-method-out-of-band-p multi-method method user host
)
5559 (error "Cannot use out-of-band method `%s' with `su' connection method"
5561 (unless (or (string-match (concat "^" (regexp-quote host
))
5563 (string= "localhost" host
)
5566 "Cannot connect to different host `%s' with `su' connection method"
5568 (tramp-pre-connection multi-method method user host tramp-chunksize
)
5569 (tramp-message 7 "Opening connection for `%s' using `%s'..."
5570 (or user
"<root>") method
)
5571 (let ((process-environment (copy-sequence process-environment
)))
5572 (setenv "TERM" tramp-terminal-type
)
5573 (let* ((default-directory (tramp-temporary-file-directory))
5574 ;; If we omit the conditional, we use `undecided-dos' in
5575 ;; some cases. With the conditional, we use nil in these
5576 ;; cases. What's the difference? Which one is right?
5577 (coding-system-for-read (unless (and (not (featurep 'xemacs
))
5578 (> emacs-major-version
20))
5579 tramp-dos-coding-system
))
5580 (p (apply 'start-process
5581 (tramp-buffer-name multi-method method user host
)
5582 (tramp-get-buffer multi-method method user host
)
5583 (tramp-get-method-parameter
5585 (tramp-find-method multi-method method user host
)
5586 user host
'tramp-login-program
)
5589 (format-spec x
`((?u .
,(or user
"root")))))
5590 (tramp-get-method-parameter
5592 (tramp-find-method multi-method method user host
)
5593 user host
'tramp-login-args
))))
5596 (tramp-set-process-query-on-exit-flag p nil
)
5597 (set-buffer (tramp-get-buffer multi-method method user host
))
5598 (tramp-process-actions p multi-method method user host
5599 tramp-actions-before-shell
)
5600 (tramp-open-connection-setup-interactive-shell
5601 p multi-method method user host
)
5602 (tramp-post-connection multi-method method
5605 ;; HHH: Not Changed. Multi method. It is not clear to me how this can
5606 ;; handle not giving a user name in the "file name".
5608 ;; This is more difficult than for the single-hop method. In the
5609 ;; multi-hop-method, the desired behaviour should be that the
5610 ;; user must specify names for the telnet hops of which the user
5611 ;; name is different than the "original" name (or different from
5612 ;; the previous hop.
5613 (defun tramp-open-connection-multi (multi-method method user host
)
5614 "Open a multi-hop connection using METHOD.
5615 This uses a slightly changed file name syntax. The idea is to say
5616 [multi/telnet:u1@h1/rsh:u2@h2]/path/to/file
5617 This will use telnet to log in as u1 to h1, then use rsh from there to
5618 log in as u2 to h2."
5620 (unless multi-method
5621 (error "Multi-hop open connection function called on non-multi method"))
5622 (when (tramp-method-out-of-band-p multi-method method user host
)
5623 (error "No out of band multi-hop connections"))
5624 (unless (and (arrayp method
) (not (stringp method
)))
5625 (error "METHOD must be an array of strings for multi methods"))
5626 (unless (and (arrayp user
) (not (stringp user
)))
5627 (error "USER must be an array of strings for multi methods"))
5628 (unless (and (arrayp host
) (not (stringp host
)))
5629 (error "HOST must be an array of strings for multi methods"))
5630 (unless (and (= (length method
) (length user
))
5631 (= (length method
) (length host
)))
5632 (error "Arrays METHOD, USER, HOST must have equal length"))
5633 (tramp-pre-connection multi-method method user host tramp-chunksize
)
5634 (tramp-message 7 "Opening `%s' connection..." multi-method
)
5635 (let ((process-environment (copy-sequence process-environment
)))
5636 (setenv "TERM" tramp-terminal-type
)
5637 (let* ((default-directory (tramp-temporary-file-directory))
5638 ;; If we omit the conditional, we use `undecided-dos' in
5639 ;; some cases. With the conditional, we use nil in these
5640 ;; cases. What's the difference? Which one is right?
5641 (coding-system-for-read (unless (and (not (featurep 'xemacs
))
5642 (> emacs-major-version
20))
5643 tramp-dos-coding-system
))
5644 (p (start-process (tramp-buffer-name multi-method method user host
)
5645 (tramp-get-buffer multi-method method user host
)
5646 tramp-multi-sh-program
))
5647 (num-hops (length method
))
5649 (tramp-set-process-query-on-exit-flag p nil
)
5650 (tramp-message 9 "Waiting 60s for local shell to come up...")
5651 (unless (tramp-wait-for-regexp
5652 p
60 (format "\\(%s\\)\\'\\|\\(%s\\)\\'"
5653 shell-prompt-pattern tramp-shell-prompt-pattern
))
5654 (pop-to-buffer (buffer-name))
5656 (error "Couldn't find local shell prompt"))
5657 ;; Now do all the connections as specified.
5658 (while (< i num-hops
)
5659 (let* ((m (aref method i
))
5662 (entry (assoc m tramp-multi-connection-function-alist
))
5663 (multi-func (nth 1 entry
))
5664 (command (nth 2 entry
)))
5665 ;; The multi-funcs don't need to do save-match-data, as that
5667 (funcall multi-func p m u h command
)
5670 (tramp-open-connection-setup-interactive-shell
5671 p multi-method method user host
)
5672 (tramp-post-connection multi-method method user host
)))))
5674 ;; HHH: Changed. Multi method. Don't know how to handle this in the case
5675 ;; of no user name provided. Hack to make it work as it did before:
5676 ;; changed `user' to `(or user (user-login-name))' in the places where
5677 ;; the value is actually used.
5678 (defun tramp-multi-connect-telnet (p method user host command
)
5679 "Issue `telnet' command.
5680 Uses shell COMMAND to issue a `telnet' command to log in as USER to
5681 HOST. You can use percent escapes in COMMAND: `%h' is replaced with
5682 the host name, and `%n' is replaced with an end of line character, as
5683 set in `tramp-rsh-end-of-line'. Use `%%' if you want a literal percent
5686 If USER is nil, uses the return value of (user-login-name) instead."
5687 (let ((cmd (format-spec command
5688 `((?h .
,host
) (?n .
,tramp-rsh-end-of-line
))))
5689 (cmd1 (format-spec command
`((?h .
,host
) (?n .
""))))
5692 (tramp-message 9 "Sending telnet command `%s'" cmd1
)
5693 (process-send-string p cmd
)
5694 (tramp-process-multi-actions p method user host
5695 tramp-multi-actions
)))
5697 ;; HHH: Changed. Multi method. Don't know how to handle this in the case
5698 ;; of no user name provided. Hack to make it work as it did before:
5699 ;; changed `user' to `(or user (user-login-name))' in the places where
5700 ;; the value is actually used.
5701 (defun tramp-multi-connect-rlogin (p method user host command
)
5702 "Issue `rlogin' command.
5703 Uses shell COMMAND to issue an `rlogin' command to log in as USER to
5704 HOST. You can use percent escapes in COMMAND. `%u' will be replaced
5705 with the user name, `%h' will be replaced with the host name, and `%n'
5706 will be replaced with the value of `tramp-rsh-end-of-line'. You can use
5707 `%%' if you want to use a literal percent character.
5709 If USER is nil, uses the return value of (user-login-name) instead."
5710 (let ((cmd (format-spec command
`((?h .
,host
)
5711 (?u .
,(or user
(user-login-name)))
5712 (?n .
,tramp-rsh-end-of-line
))))
5713 (cmd1 (format-spec command
`((?h .
,host
)
5714 (?u .
,(or user
(user-login-name)))
5718 (tramp-message 9 "Sending rlogin command `%s'" cmd1
)
5719 (process-send-string p cmd
)
5720 (tramp-process-multi-actions p method user host
5721 tramp-multi-actions
)))
5723 ;; HHH: Changed. Multi method. Don't know how to handle this in the case
5724 ;; of no user name provided. Hack to make it work as it did before:
5725 ;; changed `user' to `(or user (user-login-name))' in the places where
5726 ;; the value is actually used.
5727 (defun tramp-multi-connect-su (p method user host command
)
5728 "Issue `su' command.
5729 Uses shell COMMAND to issue a `su' command to log in as USER on
5730 HOST. The HOST name is ignored, this just changes the user id on the
5731 host currently logged in to.
5733 If USER is nil, uses the return value of (user-login-name) instead.
5735 You can use percent escapes in the COMMAND. `%u' is replaced with the
5736 user name, and `%n' is replaced with the value of
5737 `tramp-rsh-end-of-line'. Use `%%' if you want a literal percent
5739 (let ((cmd (format-spec command
`((?u .
,(or user
(user-login-name)))
5740 (?n .
,tramp-rsh-end-of-line
))))
5741 (cmd1 (format-spec command
`((?u .
,(or user
(user-login-name)))
5745 (tramp-message 9 "Sending su command `%s'" cmd1
)
5746 (process-send-string p cmd
)
5747 (tramp-process-multi-actions p method user host
5748 tramp-multi-actions
)))
5750 ;; Utility functions.
5752 (defun tramp-accept-process-output
5753 (&optional process timeout timeout-msecs
)
5754 "Like `accept-process-output' for Tramp processes.
5755 This is needed in order to hide `last-coding-system-used', which is set
5756 for process communication also."
5757 (let (last-coding-system-used)
5758 (accept-process-output process timeout timeout-msecs
)))
5760 (defun tramp-wait-for-regexp (proc timeout regexp
)
5761 "Wait for a REGEXP to appear from process PROC within TIMEOUT seconds.
5762 Expects the output of PROC to be sent to the current buffer. Returns
5763 the string that matched, or nil. Waits indefinitely if TIMEOUT is
5766 (start-time (current-time)))
5768 ;; Work around a bug in XEmacs 21, where the timeout
5769 ;; expires faster than it should. This degenerates
5770 ;; to polling for buggy XEmacsen, but oh, well.
5771 (while (and (not found
)
5772 (< (tramp-time-diff (current-time) start-time
)
5774 (with-timeout (timeout)
5776 (tramp-accept-process-output proc
1)
5777 (unless (memq (process-status proc
) '(run open
))
5778 (error "Process has died"))
5779 (goto-char (point-min))
5780 (setq found
(re-search-forward regexp nil t
))))))
5783 (tramp-accept-process-output proc
1)
5784 (unless (memq (process-status proc
) '(run open
))
5785 (error "Process has died"))
5786 (goto-char (point-min))
5787 (setq found
(re-search-forward regexp nil t
)))))
5788 (when tramp-debug-buffer
5790 (tramp-get-debug-buffer tramp-current-multi-method tramp-current-method
5791 tramp-current-user tramp-current-host
)
5792 (point-min) (point-max))
5796 (tramp-get-debug-buffer tramp-current-multi-method tramp-current-method
5797 tramp-current-user tramp-current-host
))
5798 (goto-char (point-max))
5799 (insert "[[Regexp `" regexp
"' not found"
5800 (if timeout
(format " in %d secs" timeout
) "")
5804 (defun tramp-wait-for-shell-prompt (proc timeout
)
5805 "Wait for the shell prompt to appear from process PROC within TIMEOUT seconds.
5806 See `tramp-wait-for-regexp' for more details.
5807 Shell prompt pattern is determined by variables `shell-prompt-pattern'
5808 and `tramp-shell-prompt-pattern'."
5809 (tramp-wait-for-regexp
5811 (format "\\(%s\\|%s\\)\\'"
5812 shell-prompt-pattern tramp-shell-prompt-pattern
)))
5814 (defun tramp-barf-if-no-shell-prompt (proc timeout
&rest error-args
)
5815 "Wait for shell prompt and barf if none appears.
5816 Looks at process PROC to see if a shell prompt appears in TIMEOUT
5817 seconds. If not, it produces an error message with the given ERROR-ARGS."
5818 (unless (tramp-wait-for-shell-prompt proc timeout
)
5819 (pop-to-buffer (buffer-name))
5820 (apply 'error error-args
)))
5822 (defun tramp-enter-password (p prompt user host
)
5823 "Prompt for a password and send it to the remote end.
5824 Uses PROMPT as a prompt and sends the password to process P."
5825 (let ((pw (tramp-read-passwd user host prompt
)))
5827 (process-send-string
5829 (or (tramp-get-method-parameter
5830 tramp-current-multi-method
5831 tramp-current-method
5834 'tramp-password-end-of-line
)
5835 tramp-default-password-end-of-line
)))))
5837 ;; HHH: Not Changed. This might handle the case where USER is not
5838 ;; given in the "File name" very poorly. Then, the local
5839 ;; variable tramp-current-user will be set to nil.
5840 (defun tramp-pre-connection (multi-method method user host chunksize
)
5841 "Do some setup before actually logging in.
5842 METHOD, USER and HOST specify the connection."
5843 (set-buffer (tramp-get-buffer multi-method method user host
))
5844 (set (make-local-variable 'tramp-current-multi-method
) multi-method
)
5845 (set (make-local-variable 'tramp-current-method
) method
)
5846 (set (make-local-variable 'tramp-current-user
) user
)
5847 (set (make-local-variable 'tramp-current-host
) host
)
5848 (set (make-local-variable 'tramp-chunksize
) chunksize
)
5849 (set (make-local-variable 'inhibit-eol-conversion
) nil
)
5852 (defun tramp-open-connection-setup-interactive-shell
5853 (p multi-method method user host
)
5854 "Set up an interactive shell.
5855 Mainly sets the prompt and the echo correctly. P is the shell process
5856 to set up. METHOD, USER and HOST specify the connection."
5857 ;; Wait a bit in case the remote end feels like sending a little
5858 ;; junk first. It seems that fencepost.gnu.org does this when doing
5859 ;; a Kerberos login.
5861 (tramp-discard-garbage-erase-buffer p multi-method method user host
)
5862 (tramp-process-initial-commands p multi-method method user host
5863 tramp-initial-commands
)
5864 ;; It is useful to set the prompt in the following command because
5865 ;; some people have a setting for $PS1 which /bin/sh doesn't know
5866 ;; about and thus /bin/sh will display a strange prompt. For
5867 ;; example, if $PS1 has "${CWD}" in the value, then ksh will display
5868 ;; the current working directory but /bin/sh will display a dollar
5869 ;; sign. The following command line sets $PS1 to a sane value, and
5870 ;; works under Bourne-ish shells as well as csh-like shells. Daniel
5871 ;; Pittman reports that the unusual positioning of the single quotes
5872 ;; makes it work under `rc', too. We also unset the variable $ENV
5873 ;; because that is read by some sh implementations (eg, bash when
5874 ;; called as sh) on startup; this way, we avoid the startup file
5876 (tramp-send-command-internal
5877 multi-method method user host
5878 (format "exec env 'ENV=' 'PS1=$ ' %s"
5879 (tramp-get-method-parameter
5880 multi-method method user host
'tramp-remote-sh
))
5881 (format "remote `%s' to come up"
5882 (tramp-get-method-parameter
5883 multi-method method user host
'tramp-remote-sh
)))
5884 (tramp-barf-if-no-shell-prompt
5886 "Remote `%s' didn't come up. See buffer `%s' for details"
5887 (tramp-get-method-parameter multi-method method user host
'tramp-remote-sh
)
5889 (tramp-message 8 "Setting up remote shell environment")
5890 (tramp-discard-garbage-erase-buffer p multi-method method user host
)
5891 (tramp-send-command-internal multi-method method user host
5892 "stty -inlcr -echo kill '^U'")
5894 ;; Ignore garbage after stty command.
5895 (tramp-send-command-internal multi-method method user host
5898 (tramp-send-command-internal multi-method method user host
5899 "TERM=dumb; export TERM")
5901 ;; Check whether the remote host suffers from buggy `send-process-string'.
5902 ;; This is known for FreeBSD (see comment in `send_process', file process.c).
5903 ;; I've tested sending 624 bytes successfully, sending 625 bytes failed.
5904 ;; Emacs makes a hack when this host type is detected locally. It cannot
5905 ;; handle remote hosts, though.
5906 (when (or (not tramp-chunksize
) (zerop tramp-chunksize
))
5907 (tramp-message 9 "Checking remote host type for `send-process-string' bug")
5908 (tramp-send-command-internal multi-method method user host
5909 "(uname -sr) 2>/dev/null")
5910 (goto-char (point-min))
5911 (when (looking-at "FreeBSD")
5912 (setq tramp-chunksize
500)))
5914 ;; Try to set up the coding system correctly.
5915 ;; CCC this can't be the right way to do it. Hm.
5918 (tramp-message 9 "Determining coding system")
5919 (tramp-send-command-internal multi-method method user host
5920 "echo foo ; echo bar")
5921 (goto-char (point-min))
5922 (if (featurep 'mule
)
5923 ;; Use MULE to select the right EOL convention for communicating
5924 ;; with the process.
5925 (let* ((cs (or (process-coding-system p
) (cons 'undecided
'undecided
)))
5926 cs-decode cs-encode
)
5927 (when (symbolp cs
) (setq cs
(cons cs cs
)))
5928 (setq cs-decode
(car cs
))
5929 (setq cs-encode
(cdr cs
))
5930 (unless cs-decode
(setq cs-decode
'undecided
))
5931 (unless cs-encode
(setq cs-encode
'undecided
))
5932 (setq cs-encode
(tramp-coding-system-change-eol-conversion
5934 (when (search-forward "\r" nil t
)
5935 (setq cs-decode
(tramp-coding-system-change-eol-conversion
5937 (set-buffer-process-coding-system cs-decode cs-encode
))
5938 ;; Look for ^M and do something useful if found.
5939 (when (search-forward "\r" nil t
)
5940 ;; We have found a ^M but cannot frob the process coding system
5941 ;; because we're running on a non-MULE Emacs. Let's try
5944 (tramp-message 9 "Trying `stty -onlcr'")
5945 (tramp-send-command-internal multi-method method user host
5949 9 "Waiting 30s for `HISTFILE=$HOME/.tramp_history; HISTSIZE=1; export HISTFILE; export HISTSIZE'")
5950 (tramp-send-command-internal
5951 multi-method method user host
5952 "HISTFILE=$HOME/.tramp_history; HISTSIZE=1; export HISTFILE; export HISTSIZE")
5954 (tramp-message 9 "Waiting 30s for `set +o vi +o emacs'")
5955 (tramp-send-command-internal multi-method method user host
5956 "set +o vi +o emacs")
5958 (tramp-message 9 "Waiting 30s for `unset MAIL MAILCHECK MAILPATH'")
5959 (tramp-send-command-internal
5960 multi-method method user host
5961 "unset MAIL MAILCHECK MAILPATH 1>/dev/null 2>/dev/null")
5963 (tramp-message 9 "Waiting 30s for `unset CDPATH'")
5964 (tramp-send-command-internal multi-method method user host
5967 (tramp-message 9 "Setting shell prompt")
5968 ;; Douglas Gray Stephens <DGrayStephens@slb.com> says that we must
5969 ;; use "\n" here, not tramp-rsh-end-of-line. We also manually frob
5970 ;; the last time we sent a command, to avoid tramp-send-command to send
5971 ;; "echo are you awake".
5972 (setq tramp-last-cmd-time
(current-time))
5974 multi-method method user host
5975 (format "PS1='%s%s%s'; PS2=''; PS3=''"
5976 tramp-rsh-end-of-line
5978 tramp-rsh-end-of-line
))
5979 (tramp-wait-for-output))
5981 (defun tramp-post-connection (multi-method method user host
)
5982 "Prepare a remote shell before being able to work on it.
5983 METHOD, USER and HOST specify the connection.
5984 Among other things, this finds a shell which groks tilde expansion,
5985 tries to find an `ls' command which groks the `-n' option, sets the
5986 locale to C and sets up the remote shell search path."
5987 ;; Search for a good shell before searching for a command which
5988 ;; checks if a file exists. This is done because Tramp wants to use
5989 ;; "test foo; echo $?" to check if various conditions hold, and
5990 ;; there are buggy /bin/sh implementations which don't execute the
5991 ;; "echo $?" part if the "test" part has an error. In particular,
5992 ;; the Solaris /bin/sh is a problem. I'm betting that all systems
5993 ;; with buggy /bin/sh implementations will have a working bash or
5995 (tramp-find-shell multi-method method user host
)
5996 ;; Without (sit-for 0.1) at least, my machine will almost always blow
5997 ;; up on 'not numberp /root' - a race that causes the 'echo ~root'
5998 ;; output of (tramp-find-shell) to show up along with the output of
5999 ;; (tramp-find-ls-command) testing.
6001 ;; I can't work out why this is a problem though. The (tramp-wait-for-output)
6002 ;; call in (tramp-find-shell) *should* make this not happen, I thought.
6004 ;; After much debugging I couldn't find any problem with the implementation
6005 ;; of that function though. The workaround stays for me at least. :/
6007 ;; Daniel Pittman <daniel@danann.net>
6010 (tramp-find-file-exists-command multi-method method user host
)
6011 (make-local-variable 'tramp-ls-command
)
6012 (setq tramp-ls-command
(tramp-find-ls-command multi-method method user host
))
6013 (unless tramp-ls-command
6016 "Danger! Couldn't find ls which groks -n. Muddling through anyway")
6017 (setq tramp-ls-command
6018 (tramp-find-executable multi-method method user host
6019 "ls" tramp-remote-path nil
)))
6020 (unless tramp-ls-command
6021 (error "Fatal error: Couldn't find remote executable `ls'"))
6022 (tramp-message 5 "Using remote command `%s' for getting directory listings"
6024 (tramp-send-command multi-method method user host
6025 (concat "tramp_set_exit_status () {" tramp-rsh-end-of-line
6026 "return $1" tramp-rsh-end-of-line
6028 (tramp-wait-for-output)
6029 ;; Set remote PATH variable.
6030 (tramp-set-remote-path multi-method method user host
"PATH" tramp-remote-path
)
6031 ;; Tell remote shell to use standard time format, needed for
6032 ;; parsing `ls -l' output.
6033 (tramp-send-command multi-method method user host
6034 "LC_TIME=C; export LC_TIME; echo huhu")
6035 (tramp-wait-for-output)
6036 (tramp-send-command multi-method method user host
6037 "mesg n; echo huhu")
6038 (tramp-wait-for-output)
6039 (tramp-send-command multi-method method user host
6040 "biff n ; echo huhu")
6041 (tramp-wait-for-output)
6042 ;; Unalias ls(1) to work around issues with those silly people who make it
6043 ;; spit out ANSI escapes or whatever.
6044 (tramp-send-command multi-method method user host
6045 "unalias ls; echo huhu")
6046 (tramp-wait-for-output)
6047 ;; Does `test A -nt B' work? Use abominable `find' construct if it
6048 ;; doesn't. BSD/OS 4.0 wants the parentheses around the command,
6049 ;; for otherwise the shell crashes.
6051 (make-local-variable 'tramp-test-groks-nt
)
6052 (tramp-send-command multi-method method user host
6054 (tramp-wait-for-output)
6055 (goto-char (point-min))
6056 (setq tramp-test-groks-nt
6057 (looking-at (format "\n%s\r?\n" (regexp-quote tramp-end-of-output
))))
6058 (unless tramp-test-groks-nt
6060 multi-method method user host
6061 (concat "tramp_test_nt () {" tramp-rsh-end-of-line
6062 "test -n \"`find $1 -prune -newer $2 -print`\"" tramp-rsh-end-of-line
6064 (tramp-wait-for-output)
6065 ;; Send the fallback `uudecode' script.
6067 (tramp-send-string multi-method method user host tramp-uudecode
)
6068 (tramp-wait-for-output)
6071 (tramp-set-connection-property "perl-scripts" nil multi-method method user host
)
6072 (let ((tramp-remote-perl
6073 (or (tramp-find-executable multi-method method user host
6074 "perl5" tramp-remote-path nil
)
6075 (tramp-find-executable multi-method method user host
6076 "perl" tramp-remote-path nil
))))
6077 (when tramp-remote-perl
6078 (tramp-set-connection-property "perl" tramp-remote-perl
6079 multi-method method user host
)
6080 (unless (tramp-method-out-of-band-p multi-method method user host
)
6081 (tramp-message 5 "Sending the Perl `mime-encode' implementations.")
6083 multi-method method user host
6084 (concat "tramp_encode () {\n"
6085 (format tramp-perl-encode tramp-remote-perl
)
6088 (tramp-wait-for-output)
6090 multi-method method user host
6091 (concat "tramp_encode_with_module () {\n"
6092 (format tramp-perl-encode-with-module tramp-remote-perl
)
6095 (tramp-wait-for-output)
6096 (tramp-message 5 "Sending the Perl `mime-decode' implementations.")
6098 multi-method method user host
6099 (concat "tramp_decode () {\n"
6100 (format tramp-perl-decode tramp-remote-perl
)
6103 (tramp-wait-for-output)
6105 multi-method method user host
6106 (concat "tramp_decode_with_module () {\n"
6107 (format tramp-perl-decode-with-module tramp-remote-perl
)
6110 (tramp-wait-for-output))))
6113 (let ((ln (tramp-find-executable multi-method method user host
6114 "ln" tramp-remote-path nil
)))
6116 (tramp-set-connection-property "ln" ln multi-method method user host
)))
6118 ;; Find the right encoding/decoding commands to use.
6119 (unless (tramp-method-out-of-band-p multi-method method user host
)
6120 (tramp-find-inline-encoding multi-method method user host
))
6121 ;; If encoding/decoding command are given, test to see if they work.
6122 ;; CCC: Maybe it would be useful to run the encoder both locally and
6123 ;; remotely to see if they produce the same result.
6124 (let ((rem-enc (tramp-get-remote-encoding multi-method method user host
))
6125 (rem-dec (tramp-get-remote-decoding multi-method method user host
))
6126 (magic-string "xyzzy"))
6127 (when (and (or rem-dec rem-enc
) (not (and rem-dec rem-enc
)))
6128 (tramp-kill-process multi-method method user host
)
6129 ;; Improve error message and/or error check.
6131 "Must give both decoding and encoding command in method definition"))
6132 (when (and rem-enc rem-dec
)
6135 "Checking to see if encoding/decoding commands work on remote host...")
6137 multi-method method user host
6138 (format "echo %s | %s | %s"
6139 (tramp-shell-quote-argument magic-string
) rem-enc rem-dec
))
6140 (tramp-wait-for-output)
6141 (unless (looking-at (regexp-quote magic-string
))
6142 (tramp-kill-process multi-method method user host
)
6143 (error "Remote host cannot execute de/encoding commands. See buffer `%s' for details"
6147 5 "Checking to see if encoding/decoding commands work on remote host...done"))))
6149 ;; CCC: We should either implement a Perl version of base64 encoding
6150 ;; and decoding. Then we just use that in the last item. The other
6151 ;; alternative is to use the Perl version of UU encoding. But then
6152 ;; we need a Lisp version of uuencode.
6154 ;; Old text from documentation of tramp-methods:
6155 ;; Using a uuencode/uudecode inline method is discouraged, please use one
6156 ;; of the base64 methods instead since base64 encoding is much more
6157 ;; reliable and the commands are more standardized between the different
6158 ;; Unix versions. But if you can't use base64 for some reason, please
6159 ;; note that the default uudecode command does not work well for some
6160 ;; Unices, in particular AIX and Irix. For AIX, you might want to use
6161 ;; the following command for uudecode:
6163 ;; sed '/^begin/d;/^[` ]$/d;/^end/d' | iconv -f uucode -t ISO8859-1
6165 ;; For Irix, no solution is known yet.
6167 (defvar tramp-coding-commands
6168 '(("mimencode -b" "mimencode -u -b"
6169 base64-encode-region base64-decode-region
)
6170 ("mmencode -b" "mmencode -u -b"
6171 base64-encode-region base64-decode-region
)
6172 ("recode data..base64" "recode base64..data"
6173 base64-encode-region base64-decode-region
)
6174 ("uuencode xxx" "uudecode -o /dev/stdout"
6175 tramp-uuencode-region uudecode-decode-region
)
6176 ("uuencode xxx" "uudecode -o -"
6177 tramp-uuencode-region uudecode-decode-region
)
6178 ("uuencode xxx" "uudecode -p"
6179 tramp-uuencode-region uudecode-decode-region
)
6180 ("uuencode xxx" "tramp_uudecode"
6181 tramp-uuencode-region uudecode-decode-region
)
6182 ("tramp_encode_with_module" "tramp_decode_with_module"
6183 base64-encode-region base64-decode-region
)
6184 ("tramp_encode" "tramp_decode"
6185 base64-encode-region base64-decode-region
))
6186 "List of coding commands for inline transfer.
6187 Each item is a list that looks like this:
6189 \(REMOTE-ENCODING REMOTE-DECODING LOCAL-ENCODING LOCAL-DECODING)
6191 The REMOTE-ENCODING should be a string, giving a command accepting a
6192 plain file on standard input and writing the encoded file to standard
6193 output. The REMOTE-DECODING should also be a string, giving a command
6194 accepting an encoded file on standard input and writing the decoded
6195 file to standard output.
6197 LOCAL-ENCODING and LOCAL-DECODING can be strings, giving commands, or
6198 symbols, giving functions. If they are strings, then they can contain
6199 the \"%s\" format specifier. If that specifier is present, the input
6200 filename will be put into the command line at that spot. If the
6201 specifier is not present, the input should be read from standard
6204 If they are functions, they will be called with two arguments, start
6205 and end of region, and are expected to replace the region contents
6206 with the encoded or decoded results, respectively.")
6208 (defun tramp-find-inline-encoding (multi-method method user host
)
6209 "Find an inline transfer encoding that works.
6210 Goes through the list `tramp-coding-commands'."
6211 (let ((commands tramp-coding-commands
)
6214 (while (and commands
(null found
))
6215 (setq item
(pop commands
))
6217 (let ((rem-enc (nth 0 item
))
6218 (rem-dec (nth 1 item
))
6219 (loc-enc (nth 2 item
))
6220 (loc-dec (nth 3 item
)))
6221 ;; Check if remote encoding and decoding commands can be
6222 ;; called remotely with null input and output. This makes
6223 ;; sure there are no syntax errors and the command is really
6224 ;; found. Note that we do not redirect stdout to /dev/null,
6225 ;; for two reaons: when checking the decoding command, we
6226 ;; actually check the output it gives. And also, when
6227 ;; redirecting "mimencode" output to /dev/null, then as root
6228 ;; it might change the permissions of /dev/null!
6229 (tramp-message-for-buffer
6230 multi-method method user host
9
6231 "Checking remote encoding command `%s' for sanity" rem-enc
)
6232 (unless (zerop (tramp-send-command-and-check
6233 multi-method method user host
6234 (format "%s </dev/null" rem-enc
) t
))
6235 (throw 'wont-work nil
))
6236 (tramp-message-for-buffer
6237 multi-method method user host
9
6238 "Checking remote decoding command `%s' for sanity" rem-dec
)
6239 (unless (zerop (tramp-send-command-and-check
6240 multi-method method user host
6241 (format "echo %s | %s | %s"
6242 magic rem-enc rem-dec
) t
))
6243 (throw 'wont-work nil
))
6245 (goto-char (point-min))
6246 (unless (looking-at (regexp-quote magic
))
6247 (throw 'wont-work nil
)))
6248 ;; If the local encoder or decoder is a string, the
6249 ;; corresponding command has to work locally.
6250 (when (stringp loc-enc
)
6251 (tramp-message-for-buffer
6252 multi-method method user host
9
6253 "Checking local encoding command `%s' for sanity" loc-enc
)
6254 (unless (zerop (tramp-call-local-coding-command
6256 (throw 'wont-work nil
)))
6257 (when (stringp loc-dec
)
6258 (tramp-message-for-buffer
6259 multi-method method user host
9
6260 "Checking local decoding command `%s' for sanity" loc-dec
)
6261 (unless (zerop (tramp-call-local-coding-command
6263 (throw 'wont-work nil
)))
6264 ;; CCC: At this point, maybe we should check that the output
6265 ;; of the commands is correct. But for the moment we will
6266 ;; assume that commands working on empty input will also
6267 ;; work in practice.
6268 (setq found item
))))
6269 ;; Did we find something? If not, issue error. If so,
6270 ;; set connection properties.
6272 (error "Couldn't find an inline transfer encoding"))
6273 (let ((rem-enc (nth 0 found
))
6274 (rem-dec (nth 1 found
))
6275 (loc-enc (nth 2 found
))
6276 (loc-dec (nth 3 found
)))
6277 (tramp-message 10 "Using remote encoding %s" rem-enc
)
6278 (tramp-set-remote-encoding multi-method method user host rem-enc
)
6279 (tramp-message 10 "Using remote decoding %s" rem-dec
)
6280 (tramp-set-remote-decoding multi-method method user host rem-dec
)
6281 (tramp-message 10 "Using local encoding %s" loc-enc
)
6282 (tramp-set-local-encoding multi-method method user host loc-enc
)
6283 (tramp-message 10 "Using local decoding %s" loc-dec
)
6284 (tramp-set-local-decoding multi-method method user host loc-dec
))))
6286 (defun tramp-call-local-coding-command (cmd input output
)
6287 "Call the local encoding or decoding command.
6288 If CMD contains \"%s\", provide input file INPUT there in command.
6289 Otherwise, INPUT is passed via standard input.
6290 INPUT can also be nil which means `/dev/null'.
6291 OUTPUT can be a string (which specifies a filename), or t (which
6292 means standard output and thus the current buffer), or nil (which
6295 tramp-encoding-shell
;program
6296 (when (and input
(not (string-match "%s" cmd
)))
6298 (if (eq output t
) t nil
) ;output
6300 tramp-encoding-command-switch
6301 ;; actual shell command
6303 (if (string-match "%s" cmd
) (format cmd input
) cmd
)
6304 (if (stringp output
) (concat "> " output
) ""))))
6306 (defun tramp-maybe-open-connection (multi-method method user host
)
6307 "Maybe open a connection to HOST, logging in as USER, using METHOD.
6308 Does not do anything if a connection is already open, but re-opens the
6309 connection if a previous connection has died for some reason."
6310 (let ((p (get-buffer-process
6311 (tramp-get-buffer multi-method method user host
)))
6313 ;; If too much time has passed since last command was sent, look
6314 ;; whether process is still alive. If it isn't, kill it. When
6315 ;; using ssh, it can sometimes happen that the remote end has hung
6316 ;; up but the local ssh client doesn't recognize this until it
6317 ;; tries to send some data to the remote end. So that's why we
6318 ;; try to send a command from time to time, then look again
6319 ;; whether the process is really alive.
6321 (set-buffer (tramp-get-buffer multi-method method user host
))
6322 (when (and tramp-last-cmd-time
6323 (> (tramp-time-diff (current-time) tramp-last-cmd-time
) 60)
6324 p
(processp p
) (memq (process-status p
) '(run open
)))
6326 multi-method method user host
"echo are you awake" nil t
)
6327 (unless (tramp-wait-for-output 10)
6331 (unless (and p
(processp p
) (memq (process-status p
) '(run open
)))
6332 (when (and p
(processp p
))
6334 (let ((process-connection-type tramp-process-connection-type
))
6335 (funcall (tramp-get-method-parameter
6337 (tramp-find-method multi-method method user host
)
6338 user host
'tramp-connection-function
)
6339 multi-method method user host
)))))
6341 (defun tramp-send-command
6342 (multi-method method user host command
&optional noerase neveropen
)
6343 "Send the COMMAND to USER at HOST (logged in using METHOD).
6344 Erases temporary buffer before sending the command (unless NOERASE
6346 If optional seventh arg NEVEROPEN is non-nil, never try to open the
6347 connection. This is meant to be used from
6348 `tramp-maybe-open-connection' only."
6350 (tramp-maybe-open-connection multi-method method user host
))
6351 (setq tramp-last-cmd-time
(current-time))
6352 (setq tramp-last-cmd command
)
6353 (when tramp-debug-buffer
6355 (set-buffer (tramp-get-debug-buffer multi-method method user host
))
6356 (goto-char (point-max))
6357 (tramp-insert-with-face 'bold
(format "$ %s\n" command
))))
6359 (set-buffer (tramp-get-buffer multi-method method user host
))
6360 (unless noerase
(erase-buffer))
6361 (setq proc
(get-buffer-process (current-buffer)))
6362 (process-send-string proc
6363 (concat command tramp-rsh-end-of-line
))))
6365 (defun tramp-send-command-internal
6366 (multi-method method user host command
&optional msg
)
6367 "Send command to remote host and wait for success.
6368 Sends COMMAND, then waits 30 seconds for shell prompt."
6369 (tramp-send-command multi-method method user host command t t
)
6371 (tramp-message 9 "Waiting 30s for %s..." msg
))
6372 (tramp-barf-if-no-shell-prompt
6374 "Couldn't `%s', see buffer `%s'" command
(buffer-name)))
6376 (defun tramp-wait-for-output (&optional timeout
)
6377 "Wait for output from remote rsh command."
6378 (let ((proc (get-buffer-process (current-buffer)))
6380 (start-time (current-time))
6381 (start-point (point))
6382 (end-of-output (concat "^"
6383 (regexp-quote tramp-end-of-output
)
6385 ;; Algorithm: get waiting output. See if last line contains
6386 ;; end-of-output sentinel. If not, wait a bit and again get
6387 ;; waiting output. Repeat until timeout expires or end-of-output
6388 ;; sentinel is seen. Will hang if timeout is nil and
6389 ;; end-of-output sentinel never appears.
6392 ;; Work around an XEmacs bug, where the timeout expires
6393 ;; faster than it should. This degenerates into polling
6394 ;; for buggy XEmacsen, but oh, well.
6395 (while (and (not found
)
6396 (< (tramp-time-diff (current-time) start-time
)
6398 (with-timeout (timeout)
6400 (tramp-accept-process-output proc
1)
6401 (unless (memq (process-status proc
) '(run open
))
6402 (error "Process has died"))
6403 (goto-char (point-max))
6405 (setq found
(looking-at end-of-output
))))))
6408 (tramp-accept-process-output proc
1)
6409 (unless (memq (process-status proc
) '(run open
))
6410 (error "Process has died"))
6411 (goto-char (point-max))
6413 (setq found
(looking-at end-of-output
))))))
6414 ;; At this point, either the timeout has expired or we have found
6415 ;; the end-of-output sentinel.
6417 (goto-char (point-max))
6419 (delete-region (point) (point-max)))
6420 ;; If processing echoes, look for it in the first line and delete.
6421 (when tramp-process-echoes
6423 (goto-char start-point
)
6424 (when (looking-at (regexp-quote tramp-last-cmd
))
6425 (delete-region (point) (progn (forward-line 1) (point))))))
6426 ;; Add output to debug buffer if appropriate.
6427 (when tramp-debug-buffer
6429 (tramp-get-debug-buffer tramp-current-multi-method tramp-current-method
6430 tramp-current-user tramp-current-host
)
6431 (point-min) (point-max))
6435 (tramp-get-debug-buffer tramp-current-multi-method tramp-current-method
6436 tramp-current-user tramp-current-host
))
6437 (goto-char (point-max))
6438 (insert "[[Remote prompt `" end-of-output
"' not found"
6439 (if timeout
(format " in %d secs" timeout
) "")
6441 (goto-char (point-min))
6442 ;; Return value is whether end-of-output sentinel was found.
6445 (defun tramp-send-command-and-check (multi-method method user host command
6447 "Run COMMAND and check its exit status.
6448 MULTI-METHOD and METHOD specify how to log in (as USER) to the remote HOST.
6449 Sends `echo $?' along with the COMMAND for checking the exit status. If
6450 COMMAND is nil, just sends `echo $?'. Returns the exit status found.
6452 If the optional argument SUBSHELL is non-nil, the command is executed in
6453 a subshell, ie surrounded by parentheses."
6454 (tramp-send-command multi-method method user host
6455 (concat (if subshell
"( " "")
6457 (if command
" 2>/dev/null; " "")
6458 "echo tramp_exit_status $?"
6459 (if subshell
" )" " ")))
6460 (tramp-wait-for-output)
6461 (goto-char (point-max))
6462 (unless (search-backward "tramp_exit_status " nil t
)
6463 (error "Couldn't find exit status of `%s'" command
))
6464 (skip-chars-forward "^ ")
6465 (read (current-buffer)))
6467 (defun tramp-barf-unless-okay (multi-method method user host command subshell
6468 signal fmt
&rest args
)
6469 "Run COMMAND, check exit status, throw error if exit status not okay.
6470 Similar to `tramp-send-command-and-check' but accepts two more arguments
6471 FMT and ARGS which are passed to `error'."
6472 (unless (zerop (tramp-send-command-and-check
6473 multi-method method user host command subshell
))
6474 ;; CCC: really pop-to-buffer? Maybe it's appropriate to be more
6476 (pop-to-buffer (current-buffer))
6477 (funcall 'signal signal
(apply 'format fmt args
))))
6479 ;; It seems that Tru64 Unix does not like it if long strings are sent
6480 ;; to it in one go. (This happens when sending the Perl
6481 ;; `file-attributes' implementation, for instance.) Therefore, we
6482 ;; have this function which waits a bit at each line.
6483 (defun tramp-send-string
6484 (multi-method method user host string
)
6485 "Send the STRING to USER at HOST using METHOD.
6487 The STRING is expected to use Unix line-endings, but the lines sent to
6488 the remote host use line-endings as defined in the variable
6489 `tramp-rsh-end-of-line'."
6490 (let ((proc (get-buffer-process
6491 (tramp-get-buffer multi-method method user host
))))
6493 (error "Can't send string to remote host -- not logged in"))
6495 (when tramp-debug-buffer
6497 (set-buffer (tramp-get-debug-buffer multi-method method user host
))
6498 (goto-char (point-max))
6499 (tramp-insert-with-face 'bold
(format "$ %s\n" string
))))
6500 ;; replace "\n" by `tramp-rsh-end-of-line'
6502 (mapconcat 'identity
6503 (split-string string
"\n")
6504 tramp-rsh-end-of-line
))
6505 (unless (or (string= string
"")
6506 (string-equal (substring string -
1) tramp-rsh-end-of-line
))
6507 (setq string
(concat string tramp-rsh-end-of-line
)))
6509 (if (and tramp-chunksize
(not (zerop tramp-chunksize
)))
6511 (end (length string
)))
6513 (tramp-message-for-buffer
6514 multi-method method user host
10
6515 "Sending chunk from %s to %s"
6516 pos
(min (+ pos tramp-chunksize
) end
))
6517 (process-send-string
6518 proc
(substring string pos
(min (+ pos tramp-chunksize
) end
)))
6519 (setq pos
(+ pos tramp-chunksize
))
6521 (process-send-string proc string
))))
6523 (defun tramp-send-eof (multi-method method user host
)
6524 "Send EOF to the remote end.
6525 METHOD, HOST and USER specify the connection."
6526 (let ((proc (get-buffer-process
6527 (tramp-get-buffer multi-method method user host
))))
6529 (error "Can't send EOF to remote host -- not logged in"))
6530 (process-send-eof proc
)))
6531 ; (process-send-string proc "\^D")))
6533 (defun tramp-kill-process (multi-method method user host
)
6534 "Kill the connection process used by Tramp.
6535 MULTI-METHOD, METHOD, USER, and HOST specify the connection."
6536 (let ((proc (get-buffer-process
6537 (tramp-get-buffer multi-method method user host
))))
6538 (kill-process proc
)))
6540 (defun tramp-discard-garbage-erase-buffer (p multi-method method user host
)
6541 "Erase buffer, then discard subsequent garbage.
6542 If `tramp-discard-garbage' is nil, just erase buffer."
6543 (if (not tramp-discard-garbage
)
6545 (while (prog1 (erase-buffer) (tramp-accept-process-output p
0.25))
6546 (when tramp-debug-buffer
6548 (set-buffer (tramp-get-debug-buffer multi-method method user host
))
6549 (goto-char (point-max))
6550 (tramp-insert-with-face
6551 'bold
(format "Additional characters detected\n")))))))
6553 (defun tramp-mode-string-to-int (mode-string)
6554 "Converts a ten-letter `drwxrwxrwx'-style mode string into mode bits."
6555 (let* ((mode-chars (string-to-vector mode-string
))
6556 (owner-read (aref mode-chars
1))
6557 (owner-write (aref mode-chars
2))
6558 (owner-execute-or-setid (aref mode-chars
3))
6559 (group-read (aref mode-chars
4))
6560 (group-write (aref mode-chars
5))
6561 (group-execute-or-setid (aref mode-chars
6))
6562 (other-read (aref mode-chars
7))
6563 (other-write (aref mode-chars
8))
6564 (other-execute-or-sticky (aref mode-chars
9)))
6568 (?r
(tramp-octal-to-decimal "00400")) (?-
0)
6569 (t (error "Second char `%c' must be one of `r-'" owner-read
)))
6571 (?w
(tramp-octal-to-decimal "00200")) (?-
0)
6572 (t (error "Third char `%c' must be one of `w-'" owner-write
)))
6573 (case owner-execute-or-setid
6574 (?x
(tramp-octal-to-decimal "00100"))
6575 (?S
(tramp-octal-to-decimal "04000"))
6576 (?s
(tramp-octal-to-decimal "04100"))
6578 (t (error "Fourth char `%c' must be one of `xsS-'"
6579 owner-execute-or-setid
)))
6581 (?r
(tramp-octal-to-decimal "00040")) (?-
0)
6582 (t (error "Fifth char `%c' must be one of `r-'" group-read
)))
6584 (?w
(tramp-octal-to-decimal "00020")) (?-
0)
6585 (t (error "Sixth char `%c' must be one of `w-'" group-write
)))
6586 (case group-execute-or-setid
6587 (?x
(tramp-octal-to-decimal "00010"))
6588 (?S
(tramp-octal-to-decimal "02000"))
6589 (?s
(tramp-octal-to-decimal "02010"))
6591 (t (error "Seventh char `%c' must be one of `xsS-'"
6592 group-execute-or-setid
)))
6594 (?r
(tramp-octal-to-decimal "00004")) (?-
0)
6595 (t (error "Eighth char `%c' must be one of `r-'" other-read
)))
6597 (?w
(tramp-octal-to-decimal "00002")) (?-
0)
6598 (t (error "Nineth char `%c' must be one of `w-'" other-write
)))
6599 (case other-execute-or-sticky
6600 (?x
(tramp-octal-to-decimal "00001"))
6601 (?T
(tramp-octal-to-decimal "01000"))
6602 (?t
(tramp-octal-to-decimal "01001"))
6604 (t (error "Tenth char `%c' must be one of `xtT-'"
6605 other-execute-or-sticky
)))))))
6607 (defun tramp-convert-file-attributes (multi-method method user host attr
)
6608 "Convert file-attributes ATTR generated by perl script or ls.
6609 Convert file mode bits to string and set virtual device number.
6611 (unless (stringp (nth 8 attr
))
6612 ;; Convert file mode bits to string.
6613 (setcar (nthcdr 8 attr
) (tramp-file-mode-from-int (nth 8 attr
))))
6614 ;; Set virtual device number.
6615 (setcar (nthcdr 11 attr
)
6616 (tramp-get-device multi-method method user host
))
6619 (defun tramp-get-device (multi-method method user host
)
6620 "Returns the virtual device number.
6621 If it doesn't exist, generate a new one."
6622 (let ((string (tramp-make-tramp-file-name multi-method method user host
"")))
6623 (unless (assoc string tramp-devices
)
6624 (add-to-list 'tramp-devices
6625 (list string
(length tramp-devices
))))
6626 (list -
1 (nth 1 (assoc string tramp-devices
)))))
6628 (defun tramp-file-mode-from-int (mode)
6629 "Turn an integer representing a file mode into an ls(1)-like string."
6630 (let ((type (cdr (assoc (logand (lsh mode -
12) 15) tramp-file-mode-type-map
)))
6631 (user (logand (lsh mode -
6) 7))
6632 (group (logand (lsh mode -
3) 7))
6633 (other (logand (lsh mode -
0) 7))
6634 (suid (> (logand (lsh mode -
9) 4) 0))
6635 (sgid (> (logand (lsh mode -
9) 2) 0))
6636 (sticky (> (logand (lsh mode -
9) 1) 0)))
6637 (setq user
(tramp-file-mode-permissions user suid
"s"))
6638 (setq group
(tramp-file-mode-permissions group sgid
"s"))
6639 (setq other
(tramp-file-mode-permissions other sticky
"t"))
6640 (concat type user group other
)))
6643 (defun tramp-file-mode-permissions (perm suid suid-text
)
6644 "Convert a permission bitset into a string.
6645 This is used internally by `tramp-file-mode-from-int'."
6646 (let ((r (> (logand perm
4) 0))
6647 (w (> (logand perm
2) 0))
6648 (x (> (logand perm
1) 0)))
6649 (concat (or (and r
"r") "-")
6650 (or (and w
"w") "-")
6651 (or (and suid x suid-text
) ; suid, execute
6652 (and suid
(upcase suid-text
)) ; suid, !execute
6653 (and x
"x") "-")))) ; !suid
6656 (defun tramp-decimal-to-octal (i)
6657 "Return a string consisting of the octal digits of I.
6658 Not actually used. Use `(format \"%o\" i)' instead?"
6659 (cond ((< i
0) (error "Cannot convert negative number to octal"))
6660 ((not (integerp i
)) (error "Cannot convert non-integer to octal"))
6662 (t (concat (tramp-decimal-to-octal (/ i
8))
6663 (number-to-string (% i
8))))))
6666 ;;(defun tramp-octal-to-decimal (ostr)
6667 ;; "Given a string of octal digits, return a decimal number."
6668 ;; (cond ((null ostr) 0)
6669 ;; ((string= "" ostr) 0)
6670 ;; (t (let ((last (aref ostr (1- (length ostr))))
6671 ;; (rest (substring ostr 0 (1- (length ostr)))))
6672 ;; (unless (and (>= last ?0)
6674 ;; (error "Not an octal digit: %c" last))
6675 ;; (+ (- last ?0) (* 8 (tramp-octal-to-decimal rest)))))))
6676 ;; Kudos to Gerd Moellmann for this suggestion.
6677 (defun tramp-octal-to-decimal (ostr)
6678 "Given a string of octal digits, return a decimal number."
6679 (let ((x (or ostr
"")))
6680 ;; `save-match' is in `tramp-mode-string-to-int' which calls this.
6681 (unless (string-match "\\`[0-7]*\\'" x
)
6682 (error "Non-octal junk in string `%s'" x
))
6683 (string-to-number ostr
8)))
6685 (defun tramp-shell-case-fold (string)
6686 "Converts STRING to shell glob pattern which ignores case."
6689 (if (equal (downcase c
) (upcase c
))
6691 (format "[%c%c]" (downcase c
) (upcase c
))))
6696 ;; ------------------------------------------------------------
6697 ;; -- TRAMP file names --
6698 ;; ------------------------------------------------------------
6699 ;; Conversion functions between external representation and
6700 ;; internal data structure. Convenience functions for internal
6703 (defstruct tramp-file-name multi-method method user host localname
)
6705 (defun tramp-tramp-file-p (name)
6706 "Return t iff NAME is a tramp file."
6708 (string-match tramp-file-name-regexp name
)))
6710 ;; HHH: Changed. Used to assign the return value of (user-login-name)
6711 ;; to the `user' part of the structure if a user name was not
6712 ;; provided, now it assigns nil.
6713 (defun tramp-dissect-file-name (name)
6714 "Return an `tramp-file-name' structure.
6715 The structure consists of remote method, remote user, remote host and
6716 localname (file name on remote host)."
6718 (let* ((match (string-match (nth 0 tramp-file-name-structure
) name
))
6721 (if match
(match-string (nth 1 tramp-file-name-structure
) name
)
6724 (format (nth 0 tramp-multi-file-name-structure
)
6725 (nth 0 tramp-multi-file-name-hop-structure
)) name
)
6726 (match-string (nth 1 tramp-multi-file-name-structure
) name
))))
6727 (if (and method
(member method tramp-multi-methods
))
6728 ;; If it's a multi method, the file name structure contains
6729 ;; arrays of method, user and host.
6730 (tramp-dissect-multi-file-name name
)
6731 ;; Normal method. First, find out default method.
6732 (unless match
(error "Not a tramp file name: %s" name
))
6733 (let ((user (match-string (nth 2 tramp-file-name-structure
) name
))
6734 (host (match-string (nth 3 tramp-file-name-structure
) name
))
6735 (localname (match-string (nth 4 tramp-file-name-structure
) name
)))
6736 (make-tramp-file-name
6741 :localname localname
))))))
6743 (defun tramp-find-default-method (user host
)
6744 "Look up the right method to use in `tramp-default-method-alist'."
6745 (let ((choices tramp-default-method-alist
)
6746 (method tramp-default-method
)
6749 (setq item
(pop choices
))
6750 (when (and (string-match (nth 0 item
) (or host
""))
6751 (string-match (nth 1 item
) (or user
"")))
6752 (setq method
(nth 2 item
))
6753 (setq choices nil
)))
6756 (defun tramp-find-method (multi-method method user host
)
6757 "Return the right method string to use.
6758 This is MULTI-METHOD, if non-nil. Otherwise, it is METHOD, if non-nil.
6759 If both MULTI-METHOD and METHOD are nil, do a lookup in
6760 `tramp-default-method-alist'."
6761 (or multi-method method
(tramp-find-default-method user host
)))
6763 ;; HHH: Not Changed. Multi method. Will probably not handle the case where
6764 ;; a user name is not provided in the "file name" very well.
6765 (defun tramp-dissect-multi-file-name (name)
6766 "Not implemented yet."
6767 (let ((regexp (nth 0 tramp-multi-file-name-structure
))
6768 (method-index (nth 1 tramp-multi-file-name-structure
))
6769 (hops-index (nth 2 tramp-multi-file-name-structure
))
6770 (localname-index (nth 3 tramp-multi-file-name-structure
))
6771 (hop-regexp (nth 0 tramp-multi-file-name-hop-structure
))
6772 (hop-method-index (nth 1 tramp-multi-file-name-hop-structure
))
6773 (hop-user-index (nth 2 tramp-multi-file-name-hop-structure
))
6774 (hop-host-index (nth 3 tramp-multi-file-name-hop-structure
))
6775 method hops len hop-methods hop-users hop-hosts localname
)
6776 (unless (string-match (format regexp hop-regexp
) name
)
6777 (error "Not a multi tramp file name: %s" name
))
6778 (setq method
(match-string method-index name
))
6779 (setq hops
(match-string hops-index name
))
6780 (setq len
(/ (length (match-data t
)) 2))
6781 (when (< localname-index
0) (incf localname-index len
))
6782 (setq localname
(match-string localname-index name
))
6784 (while (string-match hop-regexp hops index
)
6785 (setq index
(match-end 0))
6787 (cons (match-string hop-method-index hops
) hop-methods
))
6789 (cons (match-string hop-user-index hops
) hop-users
))
6791 (cons (match-string hop-host-index hops
) hop-hosts
))))
6792 (make-tramp-file-name
6793 :multi-method method
6794 :method
(apply 'vector
(reverse hop-methods
))
6795 :user
(apply 'vector
(reverse hop-users
))
6796 :host
(apply 'vector
(reverse hop-hosts
))
6797 :localname localname
)))
6799 (defun tramp-make-tramp-file-name (multi-method method user host localname
)
6800 "Constructs a tramp file name from METHOD, USER, HOST and LOCALNAME."
6802 (tramp-make-tramp-multi-file-name multi-method method user host localname
)
6804 (concat tramp-prefix-format
6805 (when method
(concat "%m" tramp-postfix-single-method-format
))
6806 (when user
(concat "%u" tramp-postfix-user-format
))
6807 (when host
(concat "%h" tramp-postfix-host-format
))
6808 (when localname
(concat "%p")))
6809 `((?m .
,method
) (?u .
,user
) (?h .
,host
) (?p .
,localname
)))))
6811 ;; CCC: Henrik Holm: Not Changed. Multi Method. What should be done
6812 ;; with this when USER is nil?
6813 (defun tramp-make-tramp-multi-file-name (multi-method method user host localname
)
6814 "Constructs a tramp file name for a multi-hop method."
6815 (unless tramp-make-multi-tramp-file-format
6816 (error "`tramp-make-multi-tramp-file-format' is nil"))
6817 (let* ((prefix-format (nth 0 tramp-make-multi-tramp-file-format
))
6818 (hop-format (nth 1 tramp-make-multi-tramp-file-format
))
6819 (localname-format (nth 2 tramp-make-multi-tramp-file-format
))
6820 (prefix (format-spec prefix-format
`((?m .
,multi-method
))))
6822 (localname (format-spec localname-format
`((?p .
,localname
))))
6824 (len (length method
)))
6826 (let ((m (aref method i
)) (u (aref user i
)) (h (aref host i
)))
6827 (setq hops
(concat hops
(format-spec hop-format
6828 `((?m .
,m
) (?u .
,u
) (?h .
,h
)))))
6830 (concat prefix hops localname
)))
6832 (defun tramp-make-copy-program-file-name (user host localname
)
6833 "Create a file name suitable to be passed to `rcp' and workalikes."
6835 (format "%s@%s:%s" user host localname
)
6836 (format "%s:%s" host localname
)))
6838 (defun tramp-method-out-of-band-p (multi-method method user host
)
6839 "Return t if this is an out-of-band method, nil otherwise."
6840 (tramp-get-method-parameter
6842 (tramp-find-method multi-method method user host
)
6843 user host
'tramp-copy-program
))
6845 ;; Variables local to connection.
6847 (defun tramp-get-ls-command (multi-method method user host
)
6849 (tramp-maybe-open-connection multi-method method user host
)
6850 (set-buffer (tramp-get-buffer multi-method method user host
))
6853 (defun tramp-get-test-groks-nt (multi-method method user host
)
6855 (tramp-maybe-open-connection multi-method method user host
)
6856 (set-buffer (tramp-get-buffer multi-method method user host
))
6857 tramp-test-groks-nt
))
6859 (defun tramp-get-file-exists-command (multi-method method user host
)
6861 (tramp-maybe-open-connection multi-method method user host
)
6862 (set-buffer (tramp-get-buffer multi-method method user host
))
6863 tramp-file-exists-command
))
6865 (defun tramp-get-remote-perl (multi-method method user host
)
6866 (tramp-get-connection-property "perl" nil multi-method method user host
))
6868 (defun tramp-get-remote-ln (multi-method method user host
)
6869 (tramp-get-connection-property "ln" nil multi-method method user host
))
6871 ;; Get a property of a TRAMP connection.
6872 (defun tramp-get-connection-property
6873 (property default multi-method method user host
)
6874 "Get the named property for the connection.
6875 If the value is not set for the connection, return `default'"
6876 (tramp-maybe-open-connection multi-method method user host
)
6877 (with-current-buffer (tramp-get-buffer multi-method method user host
)
6880 (symbol-value (intern (concat "tramp-connection-property-" property
)))
6883 ;; Set a property of a TRAMP connection.
6884 (defun tramp-set-connection-property
6885 (property value multi-method method user host
)
6886 "Set the named property of a TRAMP connection."
6887 (tramp-maybe-open-connection multi-method method user host
)
6888 (with-current-buffer (tramp-get-buffer multi-method method user host
)
6889 (set (make-local-variable
6890 (intern (concat "tramp-connection-property-" property
)))
6893 ;; Some predefined connection properties.
6894 (defun tramp-set-remote-encoding (multi-method method user host rem-enc
)
6895 (tramp-set-connection-property "remote-encoding" rem-enc
6896 multi-method method user host
))
6897 (defun tramp-get-remote-encoding (multi-method method user host
)
6898 (tramp-get-connection-property "remote-encoding" nil
6899 multi-method method user host
))
6901 (defun tramp-set-remote-decoding (multi-method method user host rem-dec
)
6902 (tramp-set-connection-property "remote-decoding" rem-dec
6903 multi-method method user host
))
6904 (defun tramp-get-remote-decoding (multi-method method user host
)
6905 (tramp-get-connection-property "remote-decoding" nil
6906 multi-method method user host
))
6908 (defun tramp-set-local-encoding (multi-method method user host loc-enc
)
6909 (tramp-set-connection-property "local-encoding" loc-enc
6910 multi-method method user host
))
6911 (defun tramp-get-local-encoding (multi-method method user host
)
6912 (tramp-get-connection-property "local-encoding" nil
6913 multi-method method user host
))
6915 (defun tramp-set-local-decoding (multi-method method user host loc-dec
)
6916 (tramp-set-connection-property "local-decoding" loc-dec
6917 multi-method method user host
))
6918 (defun tramp-get-local-decoding (multi-method method user host
)
6919 (tramp-get-connection-property "local-decoding" nil
6920 multi-method method user host
))
6922 (defun tramp-get-method-parameter (multi-method method user host param
)
6923 "Return the method parameter PARAM.
6924 If the `tramp-methods' entry does not exist, use the variable PARAM
6926 (unless (boundp param
)
6927 (error "Non-existing method parameter `%s'" param
))
6928 (let ((entry (assoc param
6929 (assoc (tramp-find-method multi-method method user host
)
6933 (symbol-value param
))))
6936 ;; Auto saving to a special directory.
6938 (defun tramp-exists-file-name-handler (operation)
6939 (let ((file-name-handler-alist (list (cons "/" 'identity
))))
6940 (eq (find-file-name-handler "/" operation
) 'identity
)))
6942 (unless (tramp-exists-file-name-handler 'make-auto-save-file-name
)
6943 (defadvice make-auto-save-file-name
6944 (around tramp-advice-make-auto-save-file-name
() activate
)
6945 "Invoke `tramp-handle-make-auto-save-file-name' for tramp files."
6946 (if (and (buffer-file-name) (tramp-tramp-file-p (buffer-file-name)))
6947 (setq ad-return-value
(tramp-make-auto-save-file-name))
6950 ;; In Emacs < 22 and XEmacs < 21.5 autosaved remote files have
6951 ;; permission 0666 minus umask. This is a security threat.
6953 (defun tramp-set-auto-save-file-modes ()
6954 "Set permissions of autosaved remote files to the original permissions."
6955 (let ((bfn (buffer-file-name)))
6956 (when (and (stringp bfn
)
6957 (tramp-tramp-file-p bfn
)
6958 (stringp buffer-auto-save-file-name
)
6959 (not (equal bfn buffer-auto-save-file-name
)))
6960 (unless (file-exists-p buffer-auto-save-file-name
)
6961 (write-region "" nil buffer-auto-save-file-name
))
6962 ;; Permissions should be set always, because there might be an old
6963 ;; auto-saved file belonging to another original file. This could
6964 ;; be a security threat.
6965 (set-file-modes buffer-auto-save-file-name
6966 (or (file-modes bfn
) #o600
)))))
6968 (unless (or (> emacs-major-version
21)
6969 (and (featurep 'xemacs
)
6970 (= emacs-major-version
21)
6971 (> emacs-minor-version
4)))
6972 (add-hook 'auto-save-hook
'tramp-set-auto-save-file-modes
))
6974 (defun tramp-subst-strs-in-string (alist string
)
6975 "Replace all occurrences of the string FROM with TO in STRING.
6976 ALIST is of the form ((FROM . TO) ...)."
6979 (let* ((pr (car alist
))
6982 (while (string-match (regexp-quote from
) string
)
6983 (setq string
(replace-match to t t string
)))
6984 (setq alist
(cdr alist
))))
6987 (defun tramp-insert-with-face (face string
)
6988 "Insert text with a specific face."
6989 (let ((start (point)))
6991 (add-text-properties start
(point) (list 'face face
))))
6993 ;; ------------------------------------------------------------
6994 ;; -- Compatibility functions section --
6995 ;; ------------------------------------------------------------
6997 (defun tramp-temporary-file-directory ()
6998 "Return name of directory for temporary files (compat function).
6999 For Emacs, this is the variable `temporary-file-directory', for XEmacs
7000 this is the function `temp-directory'."
7001 (cond ((boundp 'temporary-file-directory
)
7002 (symbol-value 'temporary-file-directory
))
7003 ((fboundp 'temp-directory
)
7004 (funcall (symbol-function 'temp-directory
))) ;pacify byte-compiler
7005 ((let ((d (getenv "TEMP"))) (and d
(file-directory-p d
)))
7006 (file-name-as-directory (getenv "TEMP")))
7007 ((let ((d (getenv "TMP"))) (and d
(file-directory-p d
)))
7008 (file-name-as-directory (getenv "TMP")))
7009 ((let ((d (getenv "TMPDIR"))) (and d
(file-directory-p d
)))
7010 (file-name-as-directory (getenv "TMPDIR")))
7011 ((file-exists-p "c:/temp") (file-name-as-directory "c:/temp"))
7012 (t (message (concat "Neither `temporary-file-directory' nor "
7013 "`temp-directory' is defined -- using /tmp."))
7014 (file-name-as-directory "/tmp"))))
7016 (defun tramp-read-passwd (user host prompt
)
7017 "Read a password from user (compat function).
7018 Invokes `password-read' if available, `read-passwd' else."
7019 (if (functionp 'password-read
)
7020 (let* ((key (concat (or user
(user-login-name)) "@" host
))
7021 (password (apply #'password-read
(list prompt key
))))
7022 (apply #'password-cache-add
(list key password
))
7024 (read-passwd prompt
)))
7026 (defun tramp-clear-passwd (&optional user host
)
7027 "Clear password cache for connection related to current-buffer."
7029 (let ((filename (or buffer-file-name list-buffers-directory
"")))
7030 (when (and (functionp 'password-cache-remove
)
7031 (or (and user host
) (tramp-tramp-file-p filename
)))
7032 (let* ((v (when (tramp-tramp-file-p filename
)
7033 (tramp-dissect-file-name filename
)))
7034 (luser (or user
(tramp-file-name-user v
) (user-login-name)))
7035 (lhost (or host
(tramp-file-name-host v
) (system-name)))
7036 (key (concat luser
"@" lhost
)))
7037 (apply #'password-cache-remove
(list key
))))))
7039 (defun tramp-time-diff (t1 t2
)
7040 "Return the difference between the two times, in seconds.
7041 T1 and T2 are time values (as returned by `current-time' for example).
7043 NOTE: This function will fail if the time difference is too large to
7045 ;; Pacify byte-compiler with `symbol-function'.
7046 (cond ((and (fboundp 'subtract-time
)
7047 (fboundp 'float-time
))
7048 (funcall (symbol-function 'float-time
)
7049 (funcall (symbol-function 'subtract-time
) t1 t2
)))
7050 ((and (fboundp 'subtract-time
)
7051 (fboundp 'time-to-seconds
))
7052 (funcall (symbol-function 'time-to-seconds
)
7053 (funcall (symbol-function 'subtract-time
) t1 t2
)))
7054 ((fboundp 'itimer-time-difference
)
7056 (symbol-function 'itimer-time-difference
)
7057 (if (< (length t1
) 3) (append t1
'(0)) t1
)
7058 (if (< (length t2
) 3) (append t2
'(0)) t2
))))
7060 ;; snarfed from Emacs 21 time-date.el; combining
7061 ;; time-to-seconds and subtract-time
7062 (let ((time (let ((borrow (< (cadr t1
) (cadr t2
))))
7063 (list (- (car t1
) (car t2
) (if borrow
1 0))
7064 (- (+ (if borrow
65536 0) (cadr t1
)) (cadr t2
))))))
7065 (+ (* (car time
) 65536.0)
7067 (/ (or (nth 2 time
) 0) 1000000.0))))))
7069 (defun tramp-coding-system-change-eol-conversion (coding-system eol-type
)
7070 "Return a coding system like CODING-SYSTEM but with given EOL-TYPE.
7071 EOL-TYPE can be one of `dos', `unix', or `mac'."
7072 (cond ((fboundp 'coding-system-change-eol-conversion
)
7073 (apply #'coding-system-change-eol-conversion
7074 (list coding-system eol-type
)))
7075 ((fboundp 'subsidiary-coding-system
)
7077 #'subsidiary-coding-system
7079 (cond ((eq eol-type
'dos
) 'crlf
)
7080 ((eq eol-type
'unix
) 'lf
)
7081 ((eq eol-type
'mac
) 'cr
)
7083 (error "Unknown EOL-TYPE `%s', must be %s"
7085 "`dos', `unix', or `mac'"))))))
7086 (t (error "Can't change EOL conversion -- is MULE missing?"))))
7088 (defun tramp-split-string (string pattern
)
7089 "Like `split-string' but omit empty strings.
7090 In Emacs, (split-string \"/foo/bar\" \"/\") returns (\"foo\" \"bar\").
7091 This is, the first, empty, element is omitted. In XEmacs, the first
7092 element is not omitted.
7094 Note: this function has been written for `tramp-handle-file-truename'.
7095 If you want to use it for something else, you'll have to check whether
7096 it does the right thing."
7097 (delete "" (split-string string pattern
)))
7099 (defun tramp-set-process-query-on-exit-flag (process flag
)
7100 "Specify if query is needed for process when Emacs is exited.
7101 If the second argument flag is non-nil, Emacs will query the user before
7102 exiting if process is running."
7104 (if (fboundp 'set-process-query-on-exit-flag
)
7105 (symbol-function 'set-process-query-on-exit-flag
)
7106 (symbol-function 'process-kill-without-query
))
7110 ;; ------------------------------------------------------------
7111 ;; -- Kludges section --
7112 ;; ------------------------------------------------------------
7114 ;; Currently (as of Emacs 20.5), the function `shell-quote-argument'
7115 ;; does not deal well with newline characters. Newline is replaced by
7116 ;; backslash newline. But if, say, the string `a backslash newline b'
7117 ;; is passed to a shell, the shell will expand this into "ab",
7118 ;; completely omitting the newline. This is not what was intended.
7119 ;; It does not appear to be possible to make the function
7120 ;; `shell-quote-argument' work with newlines without making it
7121 ;; dependent on the shell used. But within this package, we know that
7122 ;; we will always use a Bourne-like shell, so we use an approach which
7125 ;; The approach is simple: we call `shell-quote-argument', then
7126 ;; massage the newline part of the result.
7128 ;; This function should produce a string which is grokked by a Unix
7129 ;; shell, even if the Emacs is running on Windows. Since this is the
7130 ;; kludges section, we bind `system-type' in such a way that
7131 ;; `shell-quote-arguments' behaves as if on Unix.
7133 ;; Thanks to Mario DeWeerd for the hint that it is sufficient for this
7134 ;; function to work with Bourne-like shells.
7136 ;; CCC: This function should be rewritten so that
7137 ;; `shell-quote-argument' is not used. This way, we are safe from
7138 ;; changes in `shell-quote-argument'.
7139 (defun tramp-shell-quote-argument (s)
7140 "Similar to `shell-quote-argument', but groks newlines.
7141 Only works for Bourne-like shells."
7142 (let ((system-type 'not-windows
))
7144 (let ((result (shell-quote-argument s
))
7145 (nl (regexp-quote (format "\\%s" tramp-rsh-end-of-line
))))
7146 (when (and (>= (length result
) 2)
7147 (string= (substring result
0 2) "\\~"))
7148 (setq result
(substring result
1)))
7149 (while (string-match nl result
)
7150 (setq result
(replace-match (format "'%s'" tramp-rsh-end-of-line
)
7154 ;; ;; EFS hooks itself into the file name handling stuff in more places
7155 ;; ;; than just `file-name-handler-alist'. The following tells EFS to stay
7156 ;; ;; away from tramp.el file names.
7158 ;; ;; This is needed because EFS installs (efs-dired-before-readin) into
7159 ;; ;; 'dired-before-readin-hook'. This prevents EFS from opening an FTP
7160 ;; ;; connection to help it's dired process. Not that I have any real
7161 ;; ;; idea *why* this is helpful to dired.
7163 ;; ;; Anyway, this advice fixes the problem (with a sledgehammer :)
7165 ;; ;; Daniel Pittman <daniel@danann.net>
7167 ;; ;; CCC: when the other defadvice calls have disappeared, make sure
7168 ;; ;; not to call defadvice unless it's necessary. How do we find out whether
7169 ;; ;; it is necessary? (featurep 'efs) is surely the wrong way --
7170 ;; ;; EFS might nicht be loaded yet.
7171 ;; (defadvice efs-ftp-path (around dont-match-tramp-localname activate protect)
7172 ;; "Cause efs-ftp-path to fail when the path is a TRAMP localname."
7173 ;; (if (tramp-tramp-file-p (ad-get-arg 0))
7177 ;; We currently (sometimes) use "[" and "]" in the filename format.
7178 ;; This means that Emacs wants to expand wildcards if
7179 ;; `find-file-wildcards' is non-nil, and then barfs because no
7180 ;; expansion could be found. We detect this situation and do
7181 ;; something really awful: we have `file-expand-wildcards' return the
7182 ;; original filename if it can't expand anything. Let's just hope
7183 ;; that this doesn't break anything else.
7184 ;; CCC: This check is now also really awful; we should search all
7185 ;; of the filename format, not just the prefix.
7186 (when (string-match "\\[" tramp-prefix-format
)
7187 (defadvice file-expand-wildcards
(around tramp-fix activate
)
7188 (let ((name (ad-get-arg 0)))
7189 (if (tramp-tramp-file-p name
)
7190 ;; If it's a Tramp file, dissect it and look if wildcards
7191 ;; need to be expanded at all.
7192 (let ((v (tramp-dissect-file-name name
)))
7193 (if (string-match "[[*?]" (tramp-file-name-localname v
))
7194 (let ((res ad-do-it
))
7195 (setq ad-return-value
(or res
(list name
))))
7196 (setq ad-return-value
(list name
))))
7197 ;; If it is not a Tramp file, just run the original function.
7198 (let ((res ad-do-it
))
7199 (setq ad-return-value
(or res
(list name
))))))))
7201 ;; Tramp version is useful in a number of situations.
7203 (defun tramp-version (arg)
7204 "Print version number of tramp.el in minibuffer or current buffer."
7206 (if arg
(insert tramp-version
) (message tramp-version
)))
7208 ;; Make the `reporter` functionality available for making bug reports about
7209 ;; the package. A most useful piece of code.
7211 (unless (fboundp 'reporter-submit-bug-report
)
7212 (autoload 'reporter-submit-bug-report
"reporter"))
7215 "Submit a bug report to the TRAMP developers."
7219 (let ((reporter-prompt-for-summary-p t
))
7220 (reporter-submit-bug-report
7221 tramp-bug-report-address
; to-address
7222 (format "tramp (%s)" tramp-version
) ; package name and version
7227 tramp-file-exists-command
7228 tramp-current-multi-method
7229 tramp-current-method
7234 tramp-auto-save-directory
; vars to dump
7235 tramp-default-method
7236 tramp-rsh-end-of-line
7237 tramp-default-password-end-of-line
7239 tramp-login-prompt-regexp
7240 ;; Mask non-7bit characters
7241 (tramp-password-prompt-regexp . tramp-reporter-dump-variable
)
7242 tramp-wrong-passwd-regexp
7243 tramp-yesno-prompt-regexp
7244 tramp-yn-prompt-regexp
7245 tramp-terminal-prompt-regexp
7246 tramp-temp-name-prefix
7247 tramp-file-name-structure
7248 tramp-file-name-regexp
7249 tramp-multi-file-name-structure
7250 tramp-multi-file-name-hop-structure
7252 tramp-multi-connection-function-alist
7255 tramp-coding-commands
7256 tramp-actions-before-shell
7257 tramp-actions-copy-out-of-band
7260 ;; Mask non-7bit characters
7261 (tramp-shell-prompt-pattern . tramp-reporter-dump-variable
)
7263 ,(when (boundp 'tramp-backup-directory-alist
)
7264 'tramp-backup-directory-alist
)
7265 ,(when (boundp 'tramp-bkup-backup-directory-info
)
7266 'tramp-bkup-backup-directory-info
)
7268 ;; Non-tramp variables of interest
7269 ;; Mask non-7bit characters
7270 (shell-prompt-pattern . tramp-reporter-dump-variable
)
7272 backup-by-copying-when-linked
7273 backup-by-copying-when-mismatch
7274 ,(when (boundp 'backup-by-copying-when-privileged-mismatch
)
7275 'backup-by-copying-when-privileged-mismatch
)
7276 ,(when (boundp 'password-cache
)
7278 ,(when (boundp 'password-cache-expiry
)
7279 'password-cache-expiry
)
7280 ,(when (boundp 'backup-directory-alist
)
7281 'backup-directory-alist
)
7282 ,(when (boundp 'bkup-backup-directory-info
)
7283 'bkup-backup-directory-info
)
7284 file-name-handler-alist
))
7286 'tramp-load-report-modules
; pre-hook
7287 'tramp-append-tramp-buffers
; post-hook
7289 Enter your bug report in this message, including as much detail as you
7290 possibly can about the problem, what you did to cause it and what the
7291 local and remote machines are.
7293 If you can give a simple set of instructions to make this bug happen
7294 reliably, please include those. Thank you for helping kill bugs in
7297 Another useful thing to do is to put (setq tramp-debug-buffer t) in
7298 the ~/.emacs file and to repeat the bug. Then, include the contents
7299 of the *tramp/foo* buffer and the *debug tramp/foo* buffer in your bug
7302 --bug report follows this line--
7305 (defun tramp-reporter-dump-variable (varsym mailbuf
)
7306 "Pretty-print the value of the variable in symbol VARSYM.
7307 Used for non-7bit chars in strings."
7308 (let* ((reporter-eval-buffer (symbol-value 'reporter-eval-buffer
))
7309 (val (with-current-buffer reporter-eval-buffer
7310 (symbol-value varsym
))))
7312 ;; There are characters to be masked.
7313 (when (and (boundp 'mm-7bit-chars
)
7315 (concat "[^" (symbol-value 'mm-7bit-chars
) "]") val
))
7316 (with-current-buffer reporter-eval-buffer
7317 (set varsym
(concat "(base64-decode-string \""
7318 (base64-encode-string val
)
7322 (funcall (symbol-function 'reporter-dump-variable
) varsym mailbuf
)
7324 ;; Remove string quotation.
7327 (concat "\\(^.*\\)" "\"" ;; \1 "
7328 "\\((base64-decode-string \\)" "\\\\" ;; \2 \
7329 "\\(\".*\\)" "\\\\" ;; \3 \
7330 "\\(\")\\)" "\"$")) ;; \4 "
7331 (replace-match "\\1\\2\\3\\4")
7333 (insert " ;; variable encoded due to non-printable characters\n"))
7336 ;; Reset VARSYM to old value.
7337 (with-current-buffer reporter-eval-buffer
7340 (defun tramp-load-report-modules ()
7341 "Load needed modules for reporting."
7343 ;; We load message.el and mml.el from Gnus.
7344 (if (featurep 'xemacs
)
7346 (load "message" 'noerror
)
7347 (load "mml" 'noerror
))
7348 (require 'message nil
'noerror
)
7349 (require 'mml nil
'noerror
))
7350 (when (functionp 'message-mode
)
7351 (funcall (symbol-function 'message-mode
)))
7352 (when (functionp 'mml-mode
)
7353 (funcall (symbol-function 'mml-mode
) t
)))
7355 (defun tramp-append-tramp-buffers ()
7356 "Append Tramp buffers into the bug report."
7359 (eq major-mode
'message-mode
)
7361 (symbol-value 'mml-mode
))
7363 (let* ((tramp-buf-regexp "\\*\\(debug \\)?tramp/")
7366 (mapcar '(lambda (b)
7367 (when (string-match tramp-buf-regexp
(buffer-name b
)) b
))
7369 (curbuf (current-buffer)))
7371 ;; There is at least one Tramp buffer.
7373 (switch-to-buffer (list-buffers-noselect nil
))
7374 (delete-other-windows)
7375 (setq buffer-read-only nil
)
7376 (goto-char (point-min))
7378 (if (re-search-forward tramp-buf-regexp
(tramp-point-at-eol) t
)
7381 (let ((start (point)))
7383 (kill-region start
(point)))))
7385 The buffer(s) above will be appended to this message. If you don't want
7386 to append a buffer because it contains sensible data, or because the buffer
7387 is too large, you should delete the respective buffer. The buffer(s) will
7388 contain user and host names. Passwords will never be included there.")
7390 (when (and tramp-debug-buffer
(> tramp-verbose
9))
7392 (let ((start (point)))
7394 Please note that you have set `tramp-verbose' to a value greater than 9.
7395 Therefore, the contents of files might be included in the debug buffer(s).")
7396 (add-text-properties start
(point) (list 'face
'italic
))))
7398 (set-buffer-modified-p nil
)
7399 (setq buffer-read-only t
)
7400 (goto-char (point-min))
7402 (if (y-or-n-p "Do you want to append the buffer(s)? ")
7403 ;; OK, let's send. First we delete the buffer list.
7406 (switch-to-buffer curbuf
)
7407 (goto-char (point-max))
7409 (dolist (buffer buffer-list
)
7410 (funcall (symbol-function 'mml-insert-empty-tag
)
7411 'part
'type
"text/plain" 'encoding
"base64"
7412 'disposition
"attachment" 'buffer
(buffer-name buffer
)
7413 'description
(buffer-name buffer
)))
7414 (set-buffer-modified-p nil
))
7416 ;; Don't send. Delete the message buffer.
7418 (set-buffer-modified-p nil
)
7420 (throw 'dont-send nil
))))))
7422 (defalias 'tramp-submit-bug
'tramp-bug
)
7426 ;; Make sure that we get integration with the VC package.
7427 ;; When it is loaded, we need to pull in the integration module.
7428 ;; This must come after (provide 'tramp) because tramp-vc.el
7430 (eval-after-load "vc"
7431 '(require 'tramp-vc
))
7435 ;; * Allow putting passwords in the filename.
7436 ;; This should be implemented via a general mechanism to add
7437 ;; parameters in filenames. There is currently a kludge for
7438 ;; putting the port number into the filename for ssh and ftp
7439 ;; files. This could be subsumed by the new mechanism as well.
7440 ;; Another approach is to read a netrc file like ~/.authinfo
7442 ;; * Handle nonlocal exits such as C-g.
7443 ;; * Autodetect if remote `ls' groks the "--dired" switch.
7444 ;; * Add fallback for inline encodings. This should be used
7445 ;; if the remote end doesn't support mimencode or a similar program.
7446 ;; For reading files from the remote host, we can just parse the output
7447 ;; of `od -b'. For writing files to the remote host, we construct
7448 ;; a shell program which contains only "safe" ascii characters
7449 ;; and which writes the right bytes to the file. We can use printf(1)
7450 ;; or "echo -e" or the printf function in awk and use octal escapes
7451 ;; for the "dangerous" characters. The null byte might be a problem.
7452 ;; On some systems, the octal escape doesn't work. So we try the following
7453 ;; two commands to write a null byte:
7454 ;; dd if=/dev/zero bs=1 count=1
7455 ;; echo | tr '\n' '\000'
7456 ;; * Separate local `tramp-coding-commands' from remote ones. Connect
7457 ;; the two via a format which can be `uu' or `b64'. Then we can search
7458 ;; for the right local commands and the right remote commands separately.
7459 ;; * Cooperate with PCL-CVS. It uses start-process, which doesn't
7460 ;; work for remote files.
7461 ;; * Rewrite `tramp-shell-quote-argument' to abstain from using
7462 ;; `shell-quote-argument'.
7463 ;; * Completion gets confused when you leave out the method name.
7464 ;; * In Emacs 21, `insert-directory' shows total number of bytes used
7465 ;; by the files in that directory. Add this here.
7466 ;; * Avoid screen blanking when hitting `g' in dired. (Eli Tziperman)
7467 ;; * Make ffap.el grok Tramp filenames. (Eli Tziperman)
7468 ;; * When logging in, keep looking for questions according to an alist
7469 ;; and then invoke the right function.
7470 ;; * Case-insensitive filename completion. (Norbert Goevert.)
7471 ;; * Running CVS remotely doesn't appear to work right. It thinks
7472 ;; files are locked by somebody else even if I'm the locking user.
7473 ;; Sometimes, one gets `No CVSROOT specified' errors from CVS.
7475 ;; * Don't use globbing for directories with many files, as this is
7476 ;; likely to produce long command lines, and some shells choke on
7477 ;; long command lines.
7478 ;; * Find out about the new auto-save mechanism in Emacs 21 and
7479 ;; do the right thing.
7480 ;; * `vc-directory' does not work. It never displays any files, even
7481 ;; if it does show files when run locally.
7482 ;; * Allow correction of passwords, if the remote end allows this.
7483 ;; (Mark Hershberger)
7484 ;; * How to deal with MULE in `insert-file-contents' and `write-region'?
7485 ;; * Do asynchronous `shell-command's.
7486 ;; * Grok `append' parameter for `write-region'.
7487 ;; * Test remote ksh or bash for tilde expansion in `tramp-find-shell'?
7488 ;; * abbreviate-file-name
7489 ;; * grok ~ in tramp-remote-path (Henrik Holm <henrikh@tele.ntnu.no>)
7490 ;; * Also allow to omit user names when doing multi-hop. Not sure yet
7491 ;; what the user names should default to, though.
7492 ;; * better error checking. At least whenever we see something
7493 ;; strange when doing zerop, we should kill the process and start
7494 ;; again. (Greg Stark)
7495 ;; * Add caching for filename completion. (Greg Stark)
7496 ;; Of course, this has issues with usability (stale cache bites)
7497 ;; -- <daniel@danann.net>
7498 ;; * Provide a local cache of old versions of remote files for the rsync
7499 ;; transfer method to use. (Greg Stark)
7500 ;; * Remove unneeded parameters from methods.
7501 ;; * Invoke rsync once for copying a whole directory hierarchy.
7502 ;; (Francesco Potort\e,Al\e(B)
7503 ;; * Should we set PATH ourselves or should we rely on the remote end
7505 ;; * Make it work for XEmacs 20, which is missing `with-timeout'.
7506 ;; * Make it work for different encodings, and for different file name
7507 ;; encodings, too. (Daniel Pittman)
7508 ;; * Change applicable functions to pass a struct tramp-file-name rather
7509 ;; than the individual items MULTI-METHOD, METHOD, USER, HOST, LOCALNAME.
7510 ;; * Implement asynchronous shell commands.
7511 ;; * Clean up unused *tramp/foo* buffers after a while. (Pete Forman)
7512 ;; * Progress reports while copying files. (Michael Kifer)
7513 ;; * `Smart' connection method that uses inline for small and out of
7514 ;; band for large files. (Michael Kifer)
7515 ;; * Don't search for perl5 and perl. Instead, only search for perl and
7516 ;; then look if it's the right version (with `perl -v').
7517 ;; * When editing a remote CVS controlled file as a different user, VC
7518 ;; gets confused about the file locking status. Try to find out why
7519 ;; the workaround doesn't work.
7520 ;; * Change `copy-file' to grok the case where the filename handler
7521 ;; for the source and the target file are different. Right now,
7522 ;; it looks at the source file and then calls that handler, if
7523 ;; there is one. But since ange-ftp, for instance, does not know
7524 ;; about Tramp, it does not do the right thing if the target file
7525 ;; name is a Tramp name.
7526 ;; * Username and hostname completion.
7527 ;; ** If `partial-completion-mode' isn't loaded, "/foo:bla" tries to
7528 ;; connect to host "blabla" already if that host is unique. No idea
7529 ;; how to suppress. Maybe not an essential problem.
7530 ;; ** Try to avoid usage of `last-input-event' in `tramp-completion-mode'.
7531 ;; ** Extend `tramp-get-completion-su' for NIS and shadow passwords.
7532 ;; ** Unify `tramp-parse-{rhosts,shosts,sconfig,hosts,passwd,netrc}'.
7533 ;; Code is nearly identical.
7534 ;; ** Decide whiche files to take for searching user/host names depending on
7535 ;; operating system (windows-nt) in `tramp-completion-function-alist'.
7536 ;; ** Enhance variables for debug.
7537 ;; ** Implement "/multi:" completion.
7538 ;; ** Add a learning mode for completion. Make results persistent.
7539 ;; * Allow out-of-band methods as _last_ multi-hop.
7541 ;; Functions for file-name-handler-alist:
7542 ;; diff-latest-backup-file -- in diff.el
7543 ;; dired-uncache -- this will be needed when we do insert-directory caching
7544 ;; file-name-as-directory -- use primitive?
7545 ;; file-name-sans-versions -- use primitive?
7546 ;; get-file-buffer -- use primitive
7549 ;;; arch-tag: 3a21a994-182b-48fa-b0cd-c1d9fede424a
7550 ;;; tramp.el ends here