* net/tramp.el (tramp-handle-insert-directory): Suppress error messages.
[bpt/emacs.git] / lisp / net / tramp-fish.el
CommitLineData
00d6fd04
MA
1;;; tramp-fish.el --- Tramp access functions for FISH protocol
2
ae940284 3;; Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
00d6fd04
MA
4
5;; Author: Michael Albinus <michael.albinus@gmx.de>
6;; Keywords: comm, processes
7
8;; This file is part of GNU Emacs.
9
874a927a 10;; GNU Emacs is free software: you can redistribute it and/or modify
00d6fd04 11;; it under the terms of the GNU General Public License as published by
874a927a
GM
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
00d6fd04
MA
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
874a927a 21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
00d6fd04
MA
22
23;;; Commentary:
24
25;; Access functions for FIles transferred over SHell protocol from Tramp.
26
27;; FISH is a protocol developped for the GNU Midnight Commander
28;; <https://savannah.gnu.org/projects/mc>. A client connects to a
29;; remote host via ssh (or rsh, shall be configurable), and starts
30;; there a fish server via the command "start_fish_server". All
31;; commands from the client have the form "#FISH_COMMAND\n" (always
32;; one line), followed by equivalent shell commands in case there is
33;; no fish server running.
34
35;; The fish server (or the equivalent shell commands) must return the
36;; response, which is finished by a line "### xxx <optional text>\n".
37;; "xxx" stands for 3 digits, representing a return code. Return
38;; codes "# 000" and "# 001" are reserved for fallback implementation
39;; with native shell commands; they are not used inside the server. See
40;; <http://cvs.savannah.gnu.org/viewcvs/mc/vfs/README.fish?root=mc&view=markup>
41;; for details of original specification.
42
43;; The GNU Midnight Commander implements the original fish protocol
44;; version 0.0.2. The KDE Konqueror has its own implementation, which
45;; can be found at
46;; <http://websvn.kde.org/branches/KDE/3.5/kdebase/kioslave/fish>. It
47;; implements an extended protocol version 0.0.3. Additionally, it
48;; provides a fish server implementation in Perl (which is the only
49;; implementation I've heard of). The following command reference is
50;; based on that implementation.
51
52;; All commands return either "### 2xx\n" (OK) or "### 5xx <optional text>\n"
53;; (NOK). Return codes are mentioned only if they are different from this.
54;; Spaces in any parameter must be escaped by "\ ".
55
56;; Command/Return Code Comment
57;;
58;; #FISH initial connection, not used
59;; in .fishsrv.pl
60;; ### 100 transfer fish server missing server, or wrong checksum
61;; version 0.0.3 only
62
63;; #VER a.b.c <commands requested>
64;; VER x.y.z <commands offered> .fishsrv.pl response is not uptodate
65
66;; #PWD
67;; /path/to/file
68
69;; #CWD /some/path
70
71;; #COPY /path/a /path/b version 0.0.3 only
72
73;; #RENAME /path/a /path/b
74
75;; #SYMLINK /path/a /path/b
76
77;; #LINK /path/a /path/b
78
79;; #DELE /some/path
80
81;; #MKD /some/path
82
83;; #RMD /some/path
84
85;; #CHOWN user /file/name
86
87;; #CHGRP group /file/name
88
89;; #CHMOD 1234 file
90
91;; #READ <offset> <size> /path/and/filename
92;; ### 291 successful exit when reading
93;; ended at eof
94;; ### 292 successful exit when reading
95;; did not end at eof
96
97;; #WRITE <offset> <size> /path/and/filename
98
99;; #APPEND <size> /path/and/filename version 0.0.3 only
100
101;; #LIST /directory
102;; <number of entries> version 0.0.3 only
103;; ### 100 version 0.0.3 only
104;; P<unix permissions> <owner>.<group>
105;; S<size>
106;; d<3-letters month name> <day> <year or HH:MM>
107;; D<year> <month> <day> <hour> <minute> <second>[.1234]
108;; E<major-of-device>,<minor>
109;; :<filename>
110;; L<filename symlink points to>
111;; M<mimetype> version 0.0.3 only
112;; <blank line to separate items>
113
114;; #STAT /file version 0.0.3 only
115;; like #LIST except for directories
116;; <number of entries>
117;; ### 100
118;; P<unix permissions> <owner>.<group>
119;; S<size>
120;; d<3-letters month name> <day> <year or HH:MM>
121;; D<year> <month> <day> <hour> <minute> <second>[.1234]
122;; E<major-of-device>,<minor>
123;; :<filename>
124;; L<filename symlink points to>
125;; <blank line to separate items>
126
127;; #RETR /some/name
128;; <filesize>
129;; ### 100
130;; <binary data> exactly filesize bytes
131;; ### 200 with no preceding newline
132
133;; #STOR <size> /file/name
134;; ### 100
135;; <data> exactly size bytes
136;; ### 001 partial success
137
138;; #EXEC <command> <tmpfile> version 0.0.3 only
139;; <tmpfile> must not exists. It contains the output of <command>.
140;; It can be retrieved afterwards. Last line is
141;; ###RESULT: <returncode>
142
143;; This implementation is meant as proof of the concept, whether there
144;; is a better performance compared with the native ssh method. It
145;; looks like the file information retrieval is slower, especially the
146;; #LIST command. On the other hand, the file contents transmission
147;; seems to perform better than other inline methods, because there is
148;; no need for data encoding/decoding, and it supports the APPEND
149;; parameter of `write-region'. Transfer of binary data fails due to
150;; Emacs' process input/output handling.
151
152
153;;; Code:
154
155(require 'tramp)
156(require 'tramp-cache)
9e6ab520 157(require 'tramp-compat)
00d6fd04 158
00d6fd04
MA
159;; Define FISH method ...
160(defcustom tramp-fish-method "fish"
161 "*Method to connect via FISH protocol."
162 :group 'tramp
163 :type 'string)
164
165;; ... and add it to the method list.
166(add-to-list 'tramp-methods (cons tramp-fish-method nil))
167
168;; Add a default for `tramp-default-user-alist'. Default is the local user.
169(add-to-list 'tramp-default-user-alist
170 `(,tramp-fish-method nil ,(user-login-name)))
171
172;; Add completion function for FISH method.
173(tramp-set-completion-function
174 tramp-fish-method tramp-completion-function-alist-ssh)
175
176(defconst tramp-fish-continue-prompt-regexp "^### 100.*\n"
177 "FISH return code OK.")
178
179;; It cannot be a defconst, occasionally we bind it locally.
180(defvar tramp-fish-ok-prompt-regexp "^### 200\n"
181 "FISH return code OK.")
182
183(defconst tramp-fish-error-prompt-regexp "^### \\(4\\|5\\)[0-9]+.*\n"
184 "Regexp for possible error strings of FISH servers.
185Used instead of analyzing error codes of commands.")
186
187(defcustom tramp-fish-start-fish-server-command
188 (concat "stty intr \"\" quit \"\" erase \"\" kill \"\" eof \"\" eol \"\" eol2 \"\" swtch \"\" start \"\" stop \"\" susp \"\" rprnt \"\" werase \"\" lnext \"\" flush \"\"; "
189 "perl .fishsrv.pl "
190 "`grep 'ARGV\\[0\\]' .fishsrv.pl | "
191 "sed -e 's/^[^\"]*\"//' -e 's/\"[^\"]*$//'`; "
192 "exit")
193 "*Command to connect via FISH protocol."
194 :group 'tramp
195 :type 'string)
196
197;; New handlers should be added here.
198(defconst tramp-fish-file-name-handler-alist
199 '(
200 ;; `access-file' performed by default handler
201 (add-name-to-file . tramp-fish-handle-add-name-to-file)
202 ;; `byte-compiler-base-file-name' performed by default handler
203 (copy-file . tramp-fish-handle-copy-file)
204 (delete-directory . tramp-fish-handle-delete-directory)
205 (delete-file . tramp-fish-handle-delete-file)
206 ;; `diff-latest-backup-file' performed by default handler
207 (directory-file-name . tramp-handle-directory-file-name)
208 (directory-files . tramp-handle-directory-files)
209 (directory-files-and-attributes . tramp-fish-handle-directory-files-and-attributes)
210 ;; `dired-call-process' performed by default handler
211 ;; `dired-compress-file' performed by default handler
d904dc86 212 (dired-uncache . tramp-handle-dired-uncache)
00d6fd04
MA
213 (expand-file-name . tramp-fish-handle-expand-file-name)
214 ;; `file-accessible-directory-p' performed by default handler
215 (file-attributes . tramp-fish-handle-file-attributes)
216 (file-directory-p . tramp-fish-handle-file-directory-p)
217 (file-executable-p . tramp-fish-handle-file-executable-p)
218 (file-exists-p . tramp-fish-handle-file-exists-p)
219 (file-local-copy . tramp-fish-handle-file-local-copy)
220 (file-remote-p . tramp-handle-file-remote-p)
221 (file-modes . tramp-handle-file-modes)
222 (file-name-all-completions . tramp-fish-handle-file-name-all-completions)
59c3a9ad 223 (file-name-as-directory . tramp-handle-file-name-as-directory)
00d6fd04
MA
224 (file-name-completion . tramp-handle-file-name-completion)
225 (file-name-directory . tramp-handle-file-name-directory)
226 (file-name-nondirectory . tramp-handle-file-name-nondirectory)
227 ;; `file-name-sans-versions' performed by default handler
228 (file-newer-than-file-p . tramp-fish-handle-file-newer-than-file-p)
229 (file-ownership-preserved-p . ignore)
230 (file-readable-p . tramp-fish-handle-file-readable-p)
231 (file-regular-p . tramp-handle-file-regular-p)
232 (file-symlink-p . tramp-handle-file-symlink-p)
233 ;; `file-truename' performed by default handler
234 (file-writable-p . tramp-fish-handle-file-writable-p)
235 (find-backup-file-name . tramp-handle-find-backup-file-name)
236 ;; `find-file-noselect' performed by default handler
237 ;; `get-file-buffer' performed by default handler
238 (insert-directory . tramp-fish-handle-insert-directory)
239 (insert-file-contents . tramp-fish-handle-insert-file-contents)
240 (load . tramp-handle-load)
241 (make-directory . tramp-fish-handle-make-directory)
242 (make-directory-internal . tramp-fish-handle-make-directory-internal)
243 (make-symbolic-link . tramp-fish-handle-make-symbolic-link)
244 (rename-file . tramp-fish-handle-rename-file)
245 (set-file-modes . tramp-fish-handle-set-file-modes)
ce3f516f 246 (set-file-times . tramp-fish-handle-set-file-times)
00d6fd04
MA
247 (set-visited-file-modtime . ignore)
248 (shell-command . tramp-handle-shell-command)
249 (substitute-in-file-name . tramp-handle-substitute-in-file-name)
250 (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory)
251 (vc-registered . ignore)
252 (verify-visited-file-modtime . ignore)
253 (write-region . tramp-fish-handle-write-region)
254 (executable-find . tramp-fish-handle-executable-find)
ce3f516f
MA
255 (start-file-process . ignore)
256 (process-file . tramp-fish-handle-process-file)
00d6fd04
MA
257)
258 "Alist of handler functions for Tramp FISH method.
259Operations not mentioned here will be handled by the default Emacs primitives.")
260
261(defun tramp-fish-file-name-p (filename)
262 "Check if it's a filename for FISH protocol."
263 (let ((v (tramp-dissect-file-name filename)))
264 (string= (tramp-file-name-method v) tramp-fish-method)))
265
266(defun tramp-fish-file-name-handler (operation &rest args)
267 "Invoke the FISH related OPERATION.
268First arg specifies the OPERATION, second arg is a list of arguments to
269pass to the OPERATION."
270 (let ((fn (assoc operation tramp-fish-file-name-handler-alist)))
271 (if fn
272 (save-match-data (apply (cdr fn) args))
273 (tramp-run-real-handler operation args))))
274
275(add-to-list 'tramp-foreign-file-name-handler-alist
276 (cons 'tramp-fish-file-name-p 'tramp-fish-file-name-handler))
277
278
279;; File name primitives
280
281(defun tramp-fish-handle-add-name-to-file
282 (filename newname &optional ok-if-already-exists)
283 "Like `add-name-to-file' for Tramp files."
284 (unless (tramp-equal-remote filename newname)
285 (with-parsed-tramp-file-name
286 (if (tramp-tramp-file-p filename) filename newname) nil
287 (tramp-error
288 v 'file-error
289 "add-name-to-file: %s"
290 "only implemented for same method, same user, same host")))
291 (with-parsed-tramp-file-name filename v1
292 (with-parsed-tramp-file-name newname v2
293 (when (and (not ok-if-already-exists)
294 (file-exists-p newname)
295 (not (numberp ok-if-already-exists))
296 (y-or-n-p
297 (format
298 "File %s already exists; make it a new name anyway? "
299 newname)))
300 (tramp-error
301 v2 'file-error
302 "add-name-to-file: file %s already exists" newname))
303 (tramp-flush-file-property v2 v2-localname)
304 (unless (tramp-fish-send-command-and-check
305 v1 (format "#LINK %s %s" v1-localname v2-localname))
306 (tramp-error
307 v1 'file-error "Error with add-name-to-file %s" newname)))))
308
309(defun tramp-fish-handle-copy-file
a4aeb9a4 310 (filename newname &optional ok-if-already-exists keep-date preserve-uid-gid)
00d6fd04
MA
311 "Like `copy-file' for Tramp files."
312 (tramp-fish-do-copy-or-rename-file
a4aeb9a4 313 'copy filename newname ok-if-already-exists keep-date preserve-uid-gid))
00d6fd04 314
ecacb4d6 315(defun tramp-fish-handle-delete-directory (directory &optional recursive)
00d6fd04
MA
316 "Like `delete-directory' for Tramp files."
317 (when (file-exists-p directory)
ecacb4d6
MA
318 (if recursive
319 (mapc
320 (lambda (file)
321 (if (file-directory-p file)
3426871b 322 (tramp-compat-delete-directory file recursive)
ecacb4d6
MA
323 (delete-file file)))
324 ;; We do not want to delete "." and "..".
325 (directory-files
326 directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")))
327 (with-parsed-tramp-file-name
00d6fd04
MA
328 (directory-file-name (expand-file-name directory)) nil
329 (tramp-flush-directory-property v localname)
330 (tramp-fish-send-command-and-check v (format "#RMD %s" localname)))))
331
332(defun tramp-fish-handle-delete-file (filename)
333 "Like `delete-file' for Tramp files."
334 (when (file-exists-p filename)
335 (with-parsed-tramp-file-name (expand-file-name filename) nil
336 (tramp-flush-file-property v localname)
337 (tramp-fish-send-command-and-check v (format "#DELE %s" localname)))))
338
339(defun tramp-fish-handle-directory-files-and-attributes
340 (directory &optional full match nosort id-format)
341 "Like `directory-files-and-attributes' for Tramp files."
342 (mapcar
343 (lambda (x)
344 ;; We cannot call `file-attributes' for backward compatibility reasons.
345 ;; Its optional parameter ID-FORMAT is introduced with Emacs 22.
346 (cons x (tramp-fish-handle-file-attributes
347 (if full x (expand-file-name x directory)) id-format)))
348 (directory-files directory full match nosort)))
349
350(defun tramp-fish-handle-expand-file-name (name &optional dir)
351 "Like `expand-file-name' for Tramp files."
352 ;; If DIR is not given, use DEFAULT-DIRECTORY or "/".
353 (setq dir (or dir default-directory "/"))
354 ;; Unless NAME is absolute, concat DIR and NAME.
355 (unless (file-name-absolute-p name)
356 (setq name (concat (file-name-as-directory dir) name)))
a4aeb9a4 357 ;; If NAME is not a Tramp file, run the real handler,
9ce8462a 358 (if (or (tramp-completion-mode-p) (not (tramp-tramp-file-p name)))
00d6fd04
MA
359 (tramp-drop-volume-letter
360 (tramp-run-real-handler 'expand-file-name (list name nil)))
361 ;; Dissect NAME.
362 (with-parsed-tramp-file-name name nil
87bdd2c7 363 (unless (tramp-run-real-handler 'file-name-absolute-p (list localname))
00d6fd04
MA
364 (setq localname (concat "~/" localname)))
365 ;; Tilde expansion if necessary.
366 (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname)
367 (let ((uname (match-string 1 localname))
368 (fname (match-string 2 localname)))
369 ;; We cannot apply "~user/", because this is not supported
370 ;; by the FISH protocol.
371 (unless (string-equal uname "~")
372 (tramp-error
373 v 'file-error "Tilde expansion not supported for %s" name))
374 (setq uname
375 (with-connection-property v uname
376 (tramp-fish-send-command-and-check v "#PWD")
377 (with-current-buffer (tramp-get-buffer v)
378 (goto-char (point-min))
9e6ab520 379 (buffer-substring (point) (tramp-compat-line-end-position)))))
00d6fd04
MA
380 (setq localname (concat uname fname))))
381 ;; There might be a double slash, for example when "~/"
382 ;; expands to "/". Remove this.
383 (while (string-match "//" localname)
384 (setq localname (replace-match "/" t t localname)))
385 ;; No tilde characters in file name, do normal
386 ;; expand-file-name (this does "/./" and "/../"). We bind
387 ;; `directory-sep-char' here for XEmacs on Windows, which
388 ;; would otherwise use backslash. `default-directory' is
389 ;; bound, because on Windows there would be problems with UNC
390 ;; shares or Cygwin mounts.
40f245a3
MA
391 (let ((directory-sep-char ?/)
392 (default-directory (tramp-compat-temporary-file-directory)))
393 (tramp-make-tramp-file-name
394 method user host
395 (tramp-drop-volume-letter
87bdd2c7
MA
396 (tramp-run-real-handler
397 'expand-file-name (list localname))))))))
00d6fd04
MA
398
399(defun tramp-fish-handle-file-attributes (filename &optional id-format)
400 "Like `file-attributes' for Tramp files."
401 (with-parsed-tramp-file-name (expand-file-name filename) nil
402 (with-file-property v localname (format "file-attributes-%s" id-format)
403 (cdr (car (tramp-fish-get-file-entries v localname nil))))))
404
405(defun tramp-fish-handle-file-directory-p (filename)
406 "Like `file-directory-p' for Tramp files."
407 (let ((attributes (file-attributes filename)))
408 (and attributes
409 (or (string-match "d" (nth 8 attributes))
410 (and (file-symlink-p filename)
411 (with-parsed-tramp-file-name filename nil
412 (file-directory-p
413 (tramp-make-tramp-file-name
414 method user host (nth 0 attributes))))))
415 t)))
416
417(defun tramp-fish-handle-file-exists-p (filename)
418 "Like `file-exists-p' for Tramp files."
419 (and (file-attributes filename) t))
420
421(defun tramp-fish-handle-file-executable-p (filename)
422 "Like `file-executable-p' for Tramp files."
423 (with-parsed-tramp-file-name (expand-file-name filename) nil
424 (with-file-property v localname "file-executable-p"
425 (when (file-exists-p filename)
426 (let ((mode-chars (string-to-vector (nth 8 (file-attributes filename))))
427 (home-directory
428 (tramp-make-tramp-file-name
429 method user host
430 (tramp-get-connection-property v "home-directory" nil))))
431 (or (and (char-equal (aref mode-chars 3) ?x)
432 (equal (nth 2 (file-attributes filename))
433 (nth 2 (file-attributes home-directory))))
434 (and (char-equal (aref mode-chars 6) ?x)
435 (equal (nth 3 (file-attributes filename))
436 (nth 3 (file-attributes home-directory))))
437 (char-equal (aref mode-chars 9) ?x)))))))
438
439(defun tramp-fish-handle-file-readable-p (filename)
440 "Like `file-readable-p' for Tramp files."
441 (with-parsed-tramp-file-name (expand-file-name filename) nil
442 (with-file-property v localname "file-readable-p"
443 (when (file-exists-p filename)
444 (let ((mode-chars (string-to-vector (nth 8 (file-attributes filename))))
445 (home-directory
446 (tramp-make-tramp-file-name
447 method user host
448 (tramp-get-connection-property v "home-directory" nil))))
449 (or (and (char-equal (aref mode-chars 1) ?r)
450 (equal (nth 2 (file-attributes filename))
451 (nth 2 (file-attributes home-directory))))
452 (and (char-equal (aref mode-chars 4) ?r)
453 (equal (nth 3 (file-attributes filename))
454 (nth 3 (file-attributes home-directory))))
455 (char-equal (aref mode-chars 7) ?r)))))))
456
457(defun tramp-fish-handle-file-writable-p (filename)
458 "Like `file-writable-p' for Tramp files."
459 (with-parsed-tramp-file-name (expand-file-name filename) nil
460 (with-file-property v localname "file-writable-p"
461 (if (not (file-exists-p filename))
462 ;; If file doesn't exist, check if directory is writable.
463 (and (file-directory-p (file-name-directory filename))
464 (file-writable-p (file-name-directory filename)))
465 ;; Existing files must be writable.
466 (let ((mode-chars (string-to-vector (nth 8 (file-attributes filename))))
467 (home-directory
468 (tramp-make-tramp-file-name
469 method user host
470 (tramp-get-connection-property v "home-directory" nil))))
471 (or (and (char-equal (aref mode-chars 2) ?w)
472 (equal (nth 2 (file-attributes filename))
473 (nth 2 (file-attributes home-directory))))
474 (and (char-equal (aref mode-chars 5) ?w)
475 (equal (nth 3 (file-attributes filename))
476 (nth 3 (file-attributes home-directory))))
477 (char-equal (aref mode-chars 8) ?w)))))))
478
479(defun tramp-fish-handle-file-local-copy (filename)
480 "Like `file-local-copy' for Tramp files."
481 (with-parsed-tramp-file-name (expand-file-name filename) nil
482 (unless (file-exists-p filename)
483 (tramp-error
484 v 'file-error
485 "Cannot make local copy of non-existing file `%s'" filename))
258800f8 486 (let ((tmpfile (tramp-compat-make-temp-file filename)))
94be87e8 487 (tramp-message v 4 "Fetching %s to tmp file %s..." filename tmpfile)
00d6fd04
MA
488 (when (tramp-fish-retrieve-data v)
489 ;; Save file
490 (with-current-buffer (tramp-get-buffer v)
94be87e8
MA
491 (write-region (point-min) (point-max) tmpfile))
492 (tramp-message v 4 "Fetching %s to tmp file %s...done" filename tmpfile)
493 tmpfile))))
00d6fd04
MA
494
495;; This function should return "foo/" for directories and "bar" for
496;; files.
497(defun tramp-fish-handle-file-name-all-completions (filename directory)
498 "Like `file-name-all-completions' for Tramp files."
499 (all-completions
500 filename
501 (with-parsed-tramp-file-name (expand-file-name directory) nil
502 (with-file-property v localname "file-name-all-completions"
503 (save-match-data
504 (let ((entries
505 (with-file-property v localname "file-entries"
506 (tramp-fish-get-file-entries v localname t))))
507 (mapcar
508 (lambda (x)
509 (list
510 (if (string-match "d" (nth 9 x))
511 (file-name-as-directory (nth 0 x))
512 (nth 0 x))))
513 entries)))))))
514
515(defun tramp-fish-handle-file-newer-than-file-p (file1 file2)
516 "Like `file-newer-than-file-p' for Tramp files."
517 (cond
518 ((not (file-exists-p file1)) nil)
519 ((not (file-exists-p file2)) t)
520 (t (tramp-time-less-p (nth 5 (file-attributes file2))
521 (nth 5 (file-attributes file1))))))
522
523(defun tramp-fish-handle-insert-directory
524 (filename switches &optional wildcard full-directory-p)
525 "Like `insert-directory' for Tramp files.
526WILDCARD and FULL-DIRECTORY-P are not handled."
527 (setq filename (expand-file-name filename))
528 (when (file-directory-p filename)
529 ;; This check is a little bit strange, but in `dired-add-entry'
530 ;; this function is called with a non-directory ...
531 (setq filename (file-name-as-directory filename)))
532
533 (with-parsed-tramp-file-name filename nil
534 (tramp-flush-file-property v localname)
535 (save-match-data
536 (let ((entries
537 (with-file-property v localname "file-entries"
538 (tramp-fish-get-file-entries v localname t))))
539
540 ;; Sort entries
541 (setq entries
542 (sort
543 entries
544 (lambda (x y)
545 (if (string-match "t" switches)
546 ;; Sort by date.
547 (tramp-time-less-p (nth 6 y) (nth 6 x))
548 ;; Sort by name.
549 (string-lessp (nth 0 x) (nth 0 y))))))
550
551 ;; Print entries.
552 (mapcar
553 (lambda (x)
554 (insert
555 (format
556 "%10s %3d %-8s %-8s %8s %s %s%s\n"
557 (nth 9 x) ; mode
558 1 ; hardlinks
559 (nth 3 x) ; uid
560 (nth 4 x) ; gid
561 (nth 8 x) ; size
562 (format-time-string
563 (if (tramp-time-less-p
564 (tramp-time-subtract (current-time) (nth 6 x))
565 tramp-half-a-year)
566 "%b %e %R"
567 "%b %e %Y")
568 (nth 6 x)) ; date
569 (nth 0 x) ; file name
570 (if (stringp (nth 1 x)) (format " -> %s" (nth 1 x)) "")))
571 (forward-line)
572 (beginning-of-line))
573 entries)))))
574
575(defun tramp-fish-handle-insert-file-contents
576 (filename &optional visit beg end replace)
577 "Like `insert-file-contents' for Tramp files."
578 (barf-if-buffer-read-only)
579 (when visit
580 (setq buffer-file-name (expand-file-name filename))
581 (set-visited-file-modtime)
582 (set-buffer-modified-p nil))
583
584 (with-parsed-tramp-file-name filename nil
585 (if (not (file-exists-p filename))
586 (tramp-error
587 v 'file-error "File %s not found on remote host" filename)
588
589 (let ((point (point))
590 size)
591 (tramp-message v 4 "Fetching file %s..." filename)
592 (when (tramp-fish-retrieve-data v)
593 ;; Insert file
594 (insert
595 (with-current-buffer (tramp-get-buffer v)
596 (let ((beg (or beg (point-min)))
597 (end (min (or end (point-max)) (point-max))))
598 (setq size (- end beg))
599 (buffer-substring beg end))))
600 (goto-char point))
601 (tramp-message v 4 "Fetching file %s...done" filename)
602
603 (list (expand-file-name filename) size)))))
604
605(defun tramp-fish-handle-make-directory (dir &optional parents)
606 "Like `make-directory' for Tramp files."
607 (setq dir (directory-file-name (expand-file-name dir)))
608 (unless (file-name-absolute-p dir)
609 (setq dir (expand-file-name dir default-directory)))
610 (with-parsed-tramp-file-name dir nil
611 (save-match-data
612 (let ((ldir (file-name-directory dir)))
613 ;; Make missing directory parts
614 (when (and parents (not (file-directory-p ldir)))
615 (make-directory ldir parents))
616 ;; Just do it
617 (when (file-directory-p ldir)
618 (make-directory-internal dir))
619 (unless (file-directory-p dir)
620 (tramp-error v 'file-error "Couldn't make directory %s" dir))))))
621
622(defun tramp-fish-handle-make-directory-internal (directory)
623 "Like `make-directory-internal' for Tramp files."
624 (setq directory (directory-file-name (expand-file-name directory)))
625 (unless (file-name-absolute-p directory)
626 (setq directory (expand-file-name directory default-directory)))
627 (when (file-directory-p (file-name-directory directory))
628 (with-parsed-tramp-file-name directory nil
629 (save-match-data
630 (unless
631 (tramp-fish-send-command-and-check v (format "#MKD %s" localname))
632 (tramp-error
633 v 'file-error "Couldn't make directory %s" directory))))))
634
635(defun tramp-fish-handle-make-symbolic-link
636 (filename linkname &optional ok-if-already-exists)
637 "Like `make-symbolic-link' for Tramp files.
638If LINKNAME is a non-Tramp file, it is used verbatim as the target of
639the symlink. If LINKNAME is a Tramp file, only the localname component is
640used as the target of the symlink.
641
642If LINKNAME is a Tramp file and the localname component is relative, then
643it is expanded first, before the localname component is taken. Note that
644this can give surprising results if the user/host for the source and
645target of the symlink differ."
646 (with-parsed-tramp-file-name linkname nil
647 ;; Do the 'confirm if exists' thing.
648 (when (file-exists-p linkname)
649 ;; What to do?
650 (if (or (null ok-if-already-exists) ; not allowed to exist
651 (and (numberp ok-if-already-exists)
652 (not (yes-or-no-p
653 (format
654 "File %s already exists; make it a link anyway? "
655 localname)))))
656 (tramp-error
657 v 'file-already-exists "File %s already exists" localname)
658 (delete-file linkname)))
659
660 ;; If FILENAME is a Tramp name, use just the localname component.
661 (when (tramp-tramp-file-p filename)
662 (setq filename (tramp-file-name-localname
663 (tramp-dissect-file-name (expand-file-name filename)))))
664
665 ;; Right, they are on the same host, regardless of user, method, etc.
666 ;; We now make the link on the remote machine. This will occur as the user
667 ;; that FILENAME belongs to.
668 (unless
669 (tramp-fish-send-command-and-check
670 v (format "#SYMLINK %s %s" filename localname))
671 (tramp-error v 'file-error "Error creating symbolic link %s" linkname))))
672
673(defun tramp-fish-handle-rename-file
674 (filename newname &optional ok-if-already-exists)
675 "Like `rename-file' for Tramp files."
676 (tramp-fish-do-copy-or-rename-file
677 'rename filename newname ok-if-already-exists t))
678
679(defun tramp-fish-handle-set-file-modes (filename mode)
680 "Like `set-file-modes' for Tramp files."
681 (with-parsed-tramp-file-name filename nil
682 (tramp-flush-file-property v localname)
683 (unless (tramp-fish-send-command-and-check
684 v (format "#CHMOD %s %s"
685 (tramp-decimal-to-octal mode)
686 (tramp-shell-quote-argument localname)))
687 (tramp-error
688 v 'file-error "Error while changing file's mode %s" filename))))
689
ce3f516f
MA
690(defun tramp-fish-handle-set-file-times (filename &optional time)
691 "Like `set-file-times' for Tramp files."
692 (with-parsed-tramp-file-name filename nil
693 (let ((time (if (or (null time) (equal time '(0 0))) (current-time) time)))
9e6ab520
MA
694 (zerop (process-file
695 "touch" nil nil nil "-t"
696 (format-time-string "%Y%m%d%H%M.%S" time)
697 (tramp-shell-quote-argument localname))))))
ce3f516f 698
00d6fd04
MA
699(defun tramp-fish-handle-write-region
700 (start end filename &optional append visit lockname confirm)
701 "Like `write-region' for Tramp files."
702 (setq filename (expand-file-name filename))
703 (with-parsed-tramp-file-name filename nil
704 ;; XEmacs takes a coding system as the seventh argument, not `confirm'
705 (when (and (not (featurep 'xemacs))
706 confirm (file-exists-p filename))
707 (unless (y-or-n-p (format "File %s exists; overwrite anyway? "
708 filename))
709 (tramp-error v 'file-error "File not overwritten")))
710
711 (tramp-flush-file-property v localname)
712
713 ;; Send command
714 (let ((tramp-fish-ok-prompt-regexp
715 (concat
716 tramp-fish-ok-prompt-regexp "\\|"
717 tramp-fish-continue-prompt-regexp)))
718 (tramp-fish-send-command
719 v (format "%s %d %s\n### 100"
720 (if append "#APPEND" "#STOR") (- end start) localname)))
721
722 ;; Send data, if there are any.
723 (when (> end start)
724 (tramp-fish-send-command v (buffer-substring-no-properties start end)))
725
726 (when (eq visit t)
727 (set-visited-file-modtime))))
728
729(defun tramp-fish-handle-executable-find (command)
730 "Like `executable-find' for Tramp files."
731 (with-temp-buffer
9e6ab520 732 (if (zerop (process-file "which" nil t nil command))
00d6fd04
MA
733 (progn
734 (goto-char (point-min))
9e6ab520 735 (buffer-substring (point-min) (tramp-compat-line-end-position))))))
00d6fd04 736
ce3f516f 737(defun tramp-fish-handle-process-file
00d6fd04 738 (program &optional infile destination display &rest args)
ce3f516f 739 "Like `process-file' for Tramp files."
00d6fd04
MA
740 ;; The implementation is not complete yet.
741 (when (and (numberp destination) (zerop destination))
742 (error "Implementation does not handle immediate return"))
743
744 (with-parsed-tramp-file-name default-directory nil
a6e96327
MA
745 (let (command input tmpinput output tmpoutput stderr tmpstderr
746 outbuf tmpfile ret)
00d6fd04
MA
747 ;; Compute command.
748 (setq command (mapconcat 'tramp-shell-quote-argument
749 (cons program args) " "))
750 ;; Determine input.
751 (if (null infile)
752 (setq input "/dev/null")
753 (setq infile (expand-file-name infile))
754 (if (tramp-equal-remote default-directory infile)
755 ;; INFILE is on the same remote host.
756 (setq input (with-parsed-tramp-file-name infile nil localname))
757 ;; INFILE must be copied to remote host.
a6e96327
MA
758 (setq input (tramp-make-tramp-temp-file v)
759 tmpinput (tramp-make-tramp-file-name method user host input))
760 (copy-file infile tmpinput t)))
00d6fd04
MA
761 (when input (setq command (format "%s <%s" command input)))
762
763 ;; Determine output.
a6e96327
MA
764 (setq output (tramp-make-tramp-temp-file v)
765 tmpoutput (tramp-make-tramp-file-name method user host output))
00d6fd04
MA
766 (cond
767 ;; Just a buffer
768 ((bufferp destination)
769 (setq outbuf destination))
770 ;; A buffer name
771 ((stringp destination)
772 (setq outbuf (get-buffer-create destination)))
773 ;; (REAL-DESTINATION ERROR-DESTINATION)
774 ((consp destination)
775 ;; output
776 (cond
777 ((bufferp (car destination))
778 (setq outbuf (car destination)))
779 ((stringp (car destination))
780 (setq outbuf (get-buffer-create (car destination)))))
781 ;; stderr
782 (cond
783 ((stringp (cadr destination))
784 (setcar (cdr destination) (expand-file-name (cadr destination)))
785 (if (tramp-equal-remote default-directory (cadr destination))
786 ;; stderr is on the same remote host.
787 (setq stderr (with-parsed-tramp-file-name
788 (cadr destination) nil localname))
789 ;; stderr must be copied to remote host. The temporary
790 ;; file must be deleted after execution.
a6e96327
MA
791 (setq stderr (tramp-make-tramp-temp-file v)
792 tmpstderr (tramp-make-tramp-file-name
793 method user host stderr))))
00d6fd04
MA
794 ;; stderr to be discarded
795 ((null (cadr destination))
796 (setq stderr "/dev/null"))))
797 ;; 't
798 (destination
799 (setq outbuf (current-buffer))))
800 (when stderr (setq command (format "%s 2>%s" command stderr)))
801
00d6fd04
MA
802 ;; Goto working directory.
803 (unless
804 (tramp-fish-send-command-and-check
805 v (format "#CWD %s" (tramp-shell-quote-argument localname)))
806 (tramp-error v 'file-error "No such directory: %s" default-directory))
807 ;; Send the command. It might not return in time, so we protect it.
808 (condition-case nil
809 (unwind-protect
810 (unless (tramp-fish-send-command-and-check
811 v (format
812 "#EXEC %s %s"
813 (tramp-shell-quote-argument command) output))
9ce8462a 814 (error nil))
00d6fd04 815 ;; Check return code.
94be87e8
MA
816 (setq tmpfile
817 (file-local-copy
818 (tramp-make-tramp-file-name method user host output)))
00d6fd04 819 (with-temp-buffer
94be87e8 820 (insert-file-contents tmpfile)
00d6fd04
MA
821 (goto-char (point-max))
822 (forward-line -1)
823 (looking-at "^###RESULT: \\([0-9]+\\)")
824 (setq ret (string-to-number (match-string 1)))
825 (delete-region (point) (point-max))
94be87e8 826 (write-region (point-min) (point-max) tmpfile))
00d6fd04
MA
827 ;; We should show the output anyway.
828 (when outbuf
94be87e8 829 (with-current-buffer outbuf (insert-file-contents tmpfile))
a6e96327 830 (when display (display-buffer outbuf))))
00d6fd04
MA
831 ;; When the user did interrupt, we should do it also.
832 (error (setq ret 1)))
a6e96327
MA
833
834 ;; Provide error file.
835 (when tmpstderr (rename-file tmpstderr (cadr destination) t))
836 ;; Cleanup.
837 (when tmpinput (delete-file tmpinput))
838 (when tmpoutput (delete-file tmpoutput))
00d6fd04
MA
839 ;; Return exit status.
840 ret)))
841
842
843;; Internal file name functions
844
845(defun tramp-fish-do-copy-or-rename-file
a4aeb9a4 846 (op filename newname &optional ok-if-already-exists keep-date preserve-uid-gid)
00d6fd04
MA
847 "Copy or rename a remote file.
848OP must be `copy' or `rename' and indicates the operation to
849perform. FILENAME specifies the file to copy or rename, NEWNAME
850is the name of the new file (for copy) or the new name of the
851file (for rename). OK-IF-ALREADY-EXISTS means don't barf if
852NEWNAME exists already. KEEP-DATE means to make sure that
853NEWNAME has the same timestamp as FILENAME.
854
855This function is invoked by `tramp-fish-handle-copy-file' and
856`tramp-fish-handle-rename-file'. It is an error if OP is neither
857of `copy' and `rename'. FILENAME and NEWNAME must be absolute
858file names."
859 (unless (memq op '(copy rename))
860 (error "Unknown operation `%s', must be `copy' or `rename'" op))
861 (let ((t1 (tramp-tramp-file-p filename))
862 (t2 (tramp-tramp-file-p newname)))
863
864 (unless ok-if-already-exists
865 (when (and t2 (file-exists-p newname))
866 (with-parsed-tramp-file-name newname nil
867 (tramp-error
868 v 'file-already-exists "File %s already exists" newname))))
869
870 (prog1
871 (cond
872 ;; Both are Tramp files.
873 ((and t1 t2)
874 (cond
875 ;; Shortcut: if method, host, user are the same for both
876 ;; files, we invoke `cp' or `mv' on the remote host
877 ;; directly.
878 ((tramp-equal-remote filename newname)
879 (tramp-fish-do-copy-or-rename-file-directly
a4aeb9a4 880 op filename newname keep-date preserve-uid-gid))
00d6fd04
MA
881 ;; No shortcut was possible. So we copy the
882 ;; file first. If the operation was `rename', we go
883 ;; back and delete the original file (if the copy was
884 ;; successful). The approach is simple-minded: we
885 ;; create a new buffer, insert the contents of the
886 ;; source file into it, then write out the buffer to
887 ;; the target file. The advantage is that it doesn't
888 ;; matter which filename handlers are used for the
889 ;; source and target file.
890 (t
891 (tramp-do-copy-or-rename-file-via-buffer
892 op filename newname keep-date))))
893
894 ;; One file is a Tramp file, the other one is local.
895 ((or t1 t2)
896 ;; Use the generic method via a Tramp buffer.
897 (tramp-do-copy-or-rename-file-via-buffer
898 op filename newname keep-date))
899
900 (t
901 ;; One of them must be a Tramp file.
902 (error "Tramp implementation says this cannot happen")))
903 ;; When newname did exist, we have wrong cached values.
904 (when t2
905 (with-parsed-tramp-file-name newname nil
906 (tramp-flush-file-property v localname)
907 (tramp-flush-file-property v (file-name-directory localname)))))))
908
909(defun tramp-fish-do-copy-or-rename-file-directly
a4aeb9a4 910 (op filename newname keep-date preserve-uid-gid)
00d6fd04
MA
911 "Invokes `COPY' or `RENAME' on the remote system.
912OP must be one of `copy' or `rename', indicating `cp' or `mv',
913respectively. VEC specifies the connection. LOCALNAME1 and
914LOCALNAME2 specify the two arguments of `cp' or `mv'. If
a4aeb9a4
MA
915KEEP-DATE is non-nil, preserve the time stamp when copying.
916PRESERVE-UID-GID is completely ignored."
00d6fd04
MA
917 (with-parsed-tramp-file-name filename v1
918 (with-parsed-tramp-file-name newname v2
919 (tramp-fish-send-command
920 v1
921 (format "%s %s %s"
922 (if (eq op 'copy) "#COPY" "#RENAME")
923 (tramp-shell-quote-argument v1-localname)
924 (tramp-shell-quote-argument v2-localname)))))
925 ;; KEEP-DATE handling.
ce3f516f 926 (when (and keep-date (functionp 'set-file-times))
9e6ab520 927 (set-file-times newname (nth 5 (file-attributes filename))))
00d6fd04 928 ;; Set the mode.
86a9be47 929 (set-file-modes newname (tramp-default-file-modes filename)))
00d6fd04
MA
930
931(defun tramp-fish-get-file-entries (vec localname list)
932 "Read entries returned by FISH server.
933When LIST is true, a #LIST command will be sent, including all entries
934of a directory. Otherwise, #STAT is sent for just one entry.
935Result is a list of (LOCALNAME LINK COUNT UID GID ATIME MTIME CTIME
936SIZE MODE WEIRD INODE DEVICE)."
937 (block nil
938 (with-current-buffer (tramp-get-buffer vec)
ce3f516f
MA
939 ;; #LIST does not work properly with trailing "/", at least in
940 ;; .fishsrv.pl.
00d6fd04
MA
941 (when (string-match "/$" localname)
942 (setq localname (concat localname ".")))
943
944 (let ((command (format "%s %s" (if list "#LIST" "#STAT") localname))
945 buffer-read-only num res)
946
947 ;; Send command
948 (tramp-fish-send-command vec command)
949
950 ;; Read number of entries
951 (goto-char (point-min))
952 (condition-case nil
9ce8462a 953 (unless (integerp (setq num (read (current-buffer)))) (error nil))
00d6fd04
MA
954 (error (return nil)))
955 (forward-line)
956 (delete-region (point-min) (point))
957
958 ;; Read return code
959 (goto-char (point-min))
960 (condition-case nil
9ce8462a 961 (unless (looking-at tramp-fish-continue-prompt-regexp) (error nil))
00d6fd04
MA
962 (error (return nil)))
963 (forward-line)
964 (delete-region (point-min) (point))
965
966 ;; Loop the listing
967 (dotimes (i num)
968 (let ((item (tramp-fish-read-file-entry)))
969 ;; Add inode and device.
970 (add-to-list
971 'res (append item
ce3f516f 972 (list (tramp-get-inode vec)
00d6fd04
MA
973 (tramp-get-device vec))))))
974
975 ;; Read return code
976 (goto-char (point-min))
977 (condition-case nil
9ce8462a 978 (unless (looking-at tramp-fish-ok-prompt-regexp) (error nil))
00d6fd04
MA
979 (error (tramp-error
980 vec 'file-error
981 "`%s' does not return a valid Lisp expression: `%s'"
982 command (buffer-string))))
983 (forward-line)
984 (delete-region (point-min) (point))
985
986 res))))
987
988(defun tramp-fish-read-file-entry ()
989 "Parse entry in output buffer.
990Result is the list (LOCALNAME LINK COUNT UID GID ATIME MTIME CTIME
991SIZE MODE WEIRD)."
992 ;; We are called from `tramp-fish-get-file-entries', which sets the
993 ;; current buffer.
994 (let (buffer-read-only localname link uid gid mtime size mode)
995 (block nil
996 (while t
997 (cond
998 ;; P<unix permissions> <owner>.<group>
999 ((looking-at "^P\\(.+\\)\\s-\\(.+\\)\\.\\(.+\\)$")
1000 (setq mode (match-string 1))
1001 (setq uid (match-string 2))
1002 (setq gid (match-string 3))
1003 (when (string-match "^d" mode) (setq link t)))
1004 ;; S<size>
1005 ((looking-at "^S\\([0-9]+\\)$")
1006 (setq size (string-to-number (match-string 1))))
1007 ;; D<year> <month> <day> <hour> <minute> <second>[.1234]
1008 ((looking-at
1009 "^D\\([0-9]+\\)\\s-\\([0-9]+\\)\\s-\\([0-9]+\\)\\s-\\([0-9]+\\)\\s-\\([0-9]+\\)\\s-\\(\\S-+\\)$")
1010 (setq mtime
1011 (encode-time
1012 (string-to-number (match-string 6))
1013 (string-to-number (match-string 5))
1014 (string-to-number (match-string 4))
1015 (string-to-number (match-string 3))
1016 (string-to-number (match-string 2))
1017 (string-to-number (match-string 1)))))
1018 ;; d<3-letters month name> <day> <year or HH:MM>
1019 ((looking-at "^d") nil)
1020 ;; E<major-of-device>,<minor>
1021 ((looking-at "^E") nil)
1022 ;; :<filename>
1023 ((looking-at "^:\\(.+\\)$")
1024 (setq localname (match-string 1)))
1025 ;; L<filename symlink points to>
1026 ((looking-at "^L\\(.+\\)$")
1027 (setq link (match-string 1)))
1028 ;; M<mimetype>
1029 ((looking-at "^M\\(.+\\)$") nil)
1030 ;; last line
1031 ((looking-at "^$")
1032 (return)))
1033 ;; delete line
1034 (forward-line)
1035 (delete-region (point-min) (point))))
1036
1037 ;; delete trailing empty line
1038 (forward-line)
1039 (delete-region (point-min) (point))
1040
1041 ;; Return entry in file-attributes format
1042 (list localname link -1 uid gid '(0 0) mtime '(0 0) size mode nil)))
1043
1044(defun tramp-fish-retrieve-data (vec)
1045 "Reads remote data for FISH protocol.
1046The data are left in the connection buffer of VEC for further processing.
1047Returns the size of the data."
1048 (block nil
1049 (with-current-buffer (tramp-get-buffer vec)
1050 ;; The retrieved data might be in binary format, without
1051 ;; trailing newline. Therefore, the OK prompt might not start
1052 ;; at the beginning of a line.
1053 (let ((tramp-fish-ok-prompt-regexp "### 200\n")
1054 size)
1055
1056 ;; Send command
1057 (tramp-fish-send-command
1058 vec (format "#RETR %s" (tramp-file-name-localname vec)))
1059
1060 ;; Read filesize
1061 (goto-char (point-min))
1062 (condition-case nil
9ce8462a 1063 (unless (integerp (setq size (read (current-buffer)))) (error nil))
00d6fd04
MA
1064 (error (return nil)))
1065 (forward-line)
1066 (delete-region (point-min) (point))
1067
1068 ;; Read return code
1069 (goto-char (point-min))
1070 (condition-case nil
9ce8462a 1071 (unless (looking-at tramp-fish-continue-prompt-regexp) (error nil))
00d6fd04
MA
1072 (error (return nil)))
1073 (forward-line)
1074 (delete-region (point-min) (point))
1075
1076 ;; The received data might contain the OK prompt already, so
1077 ;; there might be outstanding data.
1078 (while (/= (+ size (length tramp-fish-ok-prompt-regexp))
1079 (- (point-max) (point-min)))
1080 (tramp-wait-for-regexp
1081 (tramp-get-connection-process vec) nil
1082 (concat tramp-fish-ok-prompt-regexp "$")))
1083
1084 ;; Read return code
1085 (goto-char (+ (point-min) size))
1086 (condition-case nil
9ce8462a 1087 (unless (looking-at tramp-fish-ok-prompt-regexp) (error nil))
00d6fd04
MA
1088 (error (return nil)))
1089 (delete-region (+ (point-min) size) (point-max))
1090 size))))
1091
1092
1093;; Connection functions
1094
1095(defun tramp-fish-maybe-open-connection (vec)
1096 "Maybe open a connection VEC.
1097Does not do anything if a connection is already open, but re-opens the
1098connection if a previous connection has died for some reason."
1099 (let ((process-connection-type tramp-process-connection-type)
1100 (p (get-buffer-process (tramp-get-buffer vec))))
1101
1102 ;; New connection must be opened.
1103 (unless (and p (processp p) (memq (process-status p) '(run open)))
1104
1105 ;; Set variables for computing the prompt for reading password.
1106 (setq tramp-current-method (tramp-file-name-method vec)
1107 tramp-current-user (tramp-file-name-user vec)
1108 tramp-current-host (tramp-file-name-host vec))
1109
1110 ;; Start new process.
1111 (when (and p (processp p))
1112 (delete-process p))
1113 (setenv "TERM" tramp-terminal-type)
dab816a9 1114 (setenv "PS1" tramp-initial-end-of-output)
00d6fd04
MA
1115 (tramp-message
1116 vec 3 "Opening connection for %s@%s using %s..."
1117 tramp-current-user tramp-current-host tramp-current-method)
1118
1119 (let* ((process-connection-type tramp-process-connection-type)
1120 (inhibit-eol-conversion nil)
1121 (coding-system-for-read 'binary)
1122 (coding-system-for-write 'binary)
1123 ;; This must be done in order to avoid our file name handler.
9e6ab520
MA
1124 (p (let ((default-directory
1125 (tramp-compat-temporary-file-directory)))
00d6fd04
MA
1126 (start-process
1127 (or (tramp-get-connection-property vec "process-name" nil)
1128 (tramp-buffer-name vec))
1129 (tramp-get-connection-buffer vec)
1130 "ssh" "-l"
1131 (tramp-file-name-user vec)
1132 (tramp-file-name-host vec)))))
1133 (tramp-message vec 6 "%s" (mapconcat 'identity (process-command p) " "))
1134
1135 ;; Check whether process is alive.
00d6fd04
MA
1136 (tramp-set-process-query-on-exit-flag p nil)
1137
1138 (tramp-process-actions p vec tramp-actions-before-shell 60)
1139 (tramp-fish-send-command vec tramp-fish-start-fish-server-command)
1140 (tramp-message
1141 vec 3
1142 "Found remote shell prompt on `%s'" (tramp-file-name-host vec))))))
1143
1144(defun tramp-fish-send-command (vec command)
1145 "Send the COMMAND to connection VEC."
1146 (tramp-fish-maybe-open-connection vec)
1147 (tramp-message vec 6 "%s" command)
1148 (tramp-send-string vec command)
1149 (tramp-wait-for-regexp
1150 (tramp-get-connection-process vec) nil
1151 (concat tramp-fish-ok-prompt-regexp "\\|" tramp-fish-error-prompt-regexp)))
1152
1153(defun tramp-fish-send-command-and-check (vec command)
1154 "Send the COMMAND to connection VEC.
1155Returns nil if there has been an error message."
1156
1157 ;; Send command.
1158 (tramp-fish-send-command vec command)
1159
1160 ;; Read return code.
1161 (with-current-buffer (tramp-get-buffer vec)
1162 (goto-char (point-min))
1163 (looking-at tramp-fish-ok-prompt-regexp)))
1164
1165(provide 'tramp-fish)
1166;
1167;;;; TODO:
1168;
1169;; * Evaluate the MIME information with #LIST or #STAT.
1170;
69e4c7c4
MB
1171
1172;; arch-tag: a66df7df-5f29-42a7-a921-643ceb29db49
00d6fd04 1173;;;; tramp-fish.el ends here