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