Switch to recommended form of GPLv3 permissions notice.
[bpt/emacs.git] / lisp / net / tramp-fish.el
CommitLineData
00d6fd04
MA
1;;; tramp-fish.el --- Tramp access functions for FISH protocol
2
dcb8ac09 3;; Copyright (C) 2006, 2007, 2008 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
212 ;; `dired-uncache' performed by default handler
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)
223 ;; `file-name-as-directory' performed by default handler
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
MA
314
315(defun tramp-fish-handle-delete-directory (directory)
316 "Like `delete-directory' for Tramp files."
317 (when (file-exists-p directory)
318 (with-parsed-tramp-file-name
319 (directory-file-name (expand-file-name directory)) nil
320 (tramp-flush-directory-property v localname)
321 (tramp-fish-send-command-and-check v (format "#RMD %s" localname)))))
322
323(defun tramp-fish-handle-delete-file (filename)
324 "Like `delete-file' for Tramp files."
325 (when (file-exists-p filename)
326 (with-parsed-tramp-file-name (expand-file-name filename) nil
327 (tramp-flush-file-property v localname)
328 (tramp-fish-send-command-and-check v (format "#DELE %s" localname)))))
329
330(defun tramp-fish-handle-directory-files-and-attributes
331 (directory &optional full match nosort id-format)
332 "Like `directory-files-and-attributes' for Tramp files."
333 (mapcar
334 (lambda (x)
335 ;; We cannot call `file-attributes' for backward compatibility reasons.
336 ;; Its optional parameter ID-FORMAT is introduced with Emacs 22.
337 (cons x (tramp-fish-handle-file-attributes
338 (if full x (expand-file-name x directory)) id-format)))
339 (directory-files directory full match nosort)))
340
341(defun tramp-fish-handle-expand-file-name (name &optional dir)
342 "Like `expand-file-name' for Tramp files."
343 ;; If DIR is not given, use DEFAULT-DIRECTORY or "/".
344 (setq dir (or dir default-directory "/"))
345 ;; Unless NAME is absolute, concat DIR and NAME.
346 (unless (file-name-absolute-p name)
347 (setq name (concat (file-name-as-directory dir) name)))
a4aeb9a4 348 ;; If NAME is not a Tramp file, run the real handler,
9ce8462a 349 (if (or (tramp-completion-mode-p) (not (tramp-tramp-file-p name)))
00d6fd04
MA
350 (tramp-drop-volume-letter
351 (tramp-run-real-handler 'expand-file-name (list name nil)))
352 ;; Dissect NAME.
353 (with-parsed-tramp-file-name name nil
87bdd2c7 354 (unless (tramp-run-real-handler 'file-name-absolute-p (list localname))
00d6fd04
MA
355 (setq localname (concat "~/" localname)))
356 ;; Tilde expansion if necessary.
357 (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname)
358 (let ((uname (match-string 1 localname))
359 (fname (match-string 2 localname)))
360 ;; We cannot apply "~user/", because this is not supported
361 ;; by the FISH protocol.
362 (unless (string-equal uname "~")
363 (tramp-error
364 v 'file-error "Tilde expansion not supported for %s" name))
365 (setq uname
366 (with-connection-property v uname
367 (tramp-fish-send-command-and-check v "#PWD")
368 (with-current-buffer (tramp-get-buffer v)
369 (goto-char (point-min))
9e6ab520 370 (buffer-substring (point) (tramp-compat-line-end-position)))))
00d6fd04
MA
371 (setq localname (concat uname fname))))
372 ;; There might be a double slash, for example when "~/"
373 ;; expands to "/". Remove this.
374 (while (string-match "//" localname)
375 (setq localname (replace-match "/" t t localname)))
376 ;; No tilde characters in file name, do normal
377 ;; expand-file-name (this does "/./" and "/../"). We bind
378 ;; `directory-sep-char' here for XEmacs on Windows, which
379 ;; would otherwise use backslash. `default-directory' is
380 ;; bound, because on Windows there would be problems with UNC
381 ;; shares or Cygwin mounts.
40f245a3
MA
382 (let ((directory-sep-char ?/)
383 (default-directory (tramp-compat-temporary-file-directory)))
384 (tramp-make-tramp-file-name
385 method user host
386 (tramp-drop-volume-letter
87bdd2c7
MA
387 (tramp-run-real-handler
388 'expand-file-name (list localname))))))))
00d6fd04
MA
389
390(defun tramp-fish-handle-file-attributes (filename &optional id-format)
391 "Like `file-attributes' for Tramp files."
392 (with-parsed-tramp-file-name (expand-file-name filename) nil
393 (with-file-property v localname (format "file-attributes-%s" id-format)
394 (cdr (car (tramp-fish-get-file-entries v localname nil))))))
395
396(defun tramp-fish-handle-file-directory-p (filename)
397 "Like `file-directory-p' for Tramp files."
398 (let ((attributes (file-attributes filename)))
399 (and attributes
400 (or (string-match "d" (nth 8 attributes))
401 (and (file-symlink-p filename)
402 (with-parsed-tramp-file-name filename nil
403 (file-directory-p
404 (tramp-make-tramp-file-name
405 method user host (nth 0 attributes))))))
406 t)))
407
408(defun tramp-fish-handle-file-exists-p (filename)
409 "Like `file-exists-p' for Tramp files."
410 (and (file-attributes filename) t))
411
412(defun tramp-fish-handle-file-executable-p (filename)
413 "Like `file-executable-p' for Tramp files."
414 (with-parsed-tramp-file-name (expand-file-name filename) nil
415 (with-file-property v localname "file-executable-p"
416 (when (file-exists-p filename)
417 (let ((mode-chars (string-to-vector (nth 8 (file-attributes filename))))
418 (home-directory
419 (tramp-make-tramp-file-name
420 method user host
421 (tramp-get-connection-property v "home-directory" nil))))
422 (or (and (char-equal (aref mode-chars 3) ?x)
423 (equal (nth 2 (file-attributes filename))
424 (nth 2 (file-attributes home-directory))))
425 (and (char-equal (aref mode-chars 6) ?x)
426 (equal (nth 3 (file-attributes filename))
427 (nth 3 (file-attributes home-directory))))
428 (char-equal (aref mode-chars 9) ?x)))))))
429
430(defun tramp-fish-handle-file-readable-p (filename)
431 "Like `file-readable-p' for Tramp files."
432 (with-parsed-tramp-file-name (expand-file-name filename) nil
433 (with-file-property v localname "file-readable-p"
434 (when (file-exists-p filename)
435 (let ((mode-chars (string-to-vector (nth 8 (file-attributes filename))))
436 (home-directory
437 (tramp-make-tramp-file-name
438 method user host
439 (tramp-get-connection-property v "home-directory" nil))))
440 (or (and (char-equal (aref mode-chars 1) ?r)
441 (equal (nth 2 (file-attributes filename))
442 (nth 2 (file-attributes home-directory))))
443 (and (char-equal (aref mode-chars 4) ?r)
444 (equal (nth 3 (file-attributes filename))
445 (nth 3 (file-attributes home-directory))))
446 (char-equal (aref mode-chars 7) ?r)))))))
447
448(defun tramp-fish-handle-file-writable-p (filename)
449 "Like `file-writable-p' for Tramp files."
450 (with-parsed-tramp-file-name (expand-file-name filename) nil
451 (with-file-property v localname "file-writable-p"
452 (if (not (file-exists-p filename))
453 ;; If file doesn't exist, check if directory is writable.
454 (and (file-directory-p (file-name-directory filename))
455 (file-writable-p (file-name-directory filename)))
456 ;; Existing files must be writable.
457 (let ((mode-chars (string-to-vector (nth 8 (file-attributes filename))))
458 (home-directory
459 (tramp-make-tramp-file-name
460 method user host
461 (tramp-get-connection-property v "home-directory" nil))))
462 (or (and (char-equal (aref mode-chars 2) ?w)
463 (equal (nth 2 (file-attributes filename))
464 (nth 2 (file-attributes home-directory))))
465 (and (char-equal (aref mode-chars 5) ?w)
466 (equal (nth 3 (file-attributes filename))
467 (nth 3 (file-attributes home-directory))))
468 (char-equal (aref mode-chars 8) ?w)))))))
469
470(defun tramp-fish-handle-file-local-copy (filename)
471 "Like `file-local-copy' for Tramp files."
472 (with-parsed-tramp-file-name (expand-file-name filename) nil
473 (unless (file-exists-p filename)
474 (tramp-error
475 v 'file-error
476 "Cannot make local copy of non-existing file `%s'" filename))
258800f8 477 (let ((tmpfile (tramp-compat-make-temp-file filename)))
94be87e8 478 (tramp-message v 4 "Fetching %s to tmp file %s..." filename tmpfile)
00d6fd04
MA
479 (when (tramp-fish-retrieve-data v)
480 ;; Save file
481 (with-current-buffer (tramp-get-buffer v)
94be87e8
MA
482 (write-region (point-min) (point-max) tmpfile))
483 (tramp-message v 4 "Fetching %s to tmp file %s...done" filename tmpfile)
484 tmpfile))))
00d6fd04
MA
485
486;; This function should return "foo/" for directories and "bar" for
487;; files.
488(defun tramp-fish-handle-file-name-all-completions (filename directory)
489 "Like `file-name-all-completions' for Tramp files."
490 (all-completions
491 filename
492 (with-parsed-tramp-file-name (expand-file-name directory) nil
493 (with-file-property v localname "file-name-all-completions"
494 (save-match-data
495 (let ((entries
496 (with-file-property v localname "file-entries"
497 (tramp-fish-get-file-entries v localname t))))
498 (mapcar
499 (lambda (x)
500 (list
501 (if (string-match "d" (nth 9 x))
502 (file-name-as-directory (nth 0 x))
503 (nth 0 x))))
504 entries)))))))
505
506(defun tramp-fish-handle-file-newer-than-file-p (file1 file2)
507 "Like `file-newer-than-file-p' for Tramp files."
508 (cond
509 ((not (file-exists-p file1)) nil)
510 ((not (file-exists-p file2)) t)
511 (t (tramp-time-less-p (nth 5 (file-attributes file2))
512 (nth 5 (file-attributes file1))))))
513
514(defun tramp-fish-handle-insert-directory
515 (filename switches &optional wildcard full-directory-p)
516 "Like `insert-directory' for Tramp files.
517WILDCARD and FULL-DIRECTORY-P are not handled."
518 (setq filename (expand-file-name filename))
519 (when (file-directory-p filename)
520 ;; This check is a little bit strange, but in `dired-add-entry'
521 ;; this function is called with a non-directory ...
522 (setq filename (file-name-as-directory filename)))
523
524 (with-parsed-tramp-file-name filename nil
525 (tramp-flush-file-property v localname)
526 (save-match-data
527 (let ((entries
528 (with-file-property v localname "file-entries"
529 (tramp-fish-get-file-entries v localname t))))
530
531 ;; Sort entries
532 (setq entries
533 (sort
534 entries
535 (lambda (x y)
536 (if (string-match "t" switches)
537 ;; Sort by date.
538 (tramp-time-less-p (nth 6 y) (nth 6 x))
539 ;; Sort by name.
540 (string-lessp (nth 0 x) (nth 0 y))))))
541
542 ;; Print entries.
543 (mapcar
544 (lambda (x)
545 (insert
546 (format
547 "%10s %3d %-8s %-8s %8s %s %s%s\n"
548 (nth 9 x) ; mode
549 1 ; hardlinks
550 (nth 3 x) ; uid
551 (nth 4 x) ; gid
552 (nth 8 x) ; size
553 (format-time-string
554 (if (tramp-time-less-p
555 (tramp-time-subtract (current-time) (nth 6 x))
556 tramp-half-a-year)
557 "%b %e %R"
558 "%b %e %Y")
559 (nth 6 x)) ; date
560 (nth 0 x) ; file name
561 (if (stringp (nth 1 x)) (format " -> %s" (nth 1 x)) "")))
562 (forward-line)
563 (beginning-of-line))
564 entries)))))
565
566(defun tramp-fish-handle-insert-file-contents
567 (filename &optional visit beg end replace)
568 "Like `insert-file-contents' for Tramp files."
569 (barf-if-buffer-read-only)
570 (when visit
571 (setq buffer-file-name (expand-file-name filename))
572 (set-visited-file-modtime)
573 (set-buffer-modified-p nil))
574
575 (with-parsed-tramp-file-name filename nil
576 (if (not (file-exists-p filename))
577 (tramp-error
578 v 'file-error "File %s not found on remote host" filename)
579
580 (let ((point (point))
581 size)
582 (tramp-message v 4 "Fetching file %s..." filename)
583 (when (tramp-fish-retrieve-data v)
584 ;; Insert file
585 (insert
586 (with-current-buffer (tramp-get-buffer v)
587 (let ((beg (or beg (point-min)))
588 (end (min (or end (point-max)) (point-max))))
589 (setq size (- end beg))
590 (buffer-substring beg end))))
591 (goto-char point))
592 (tramp-message v 4 "Fetching file %s...done" filename)
593
594 (list (expand-file-name filename) size)))))
595
596(defun tramp-fish-handle-make-directory (dir &optional parents)
597 "Like `make-directory' for Tramp files."
598 (setq dir (directory-file-name (expand-file-name dir)))
599 (unless (file-name-absolute-p dir)
600 (setq dir (expand-file-name dir default-directory)))
601 (with-parsed-tramp-file-name dir nil
602 (save-match-data
603 (let ((ldir (file-name-directory dir)))
604 ;; Make missing directory parts
605 (when (and parents (not (file-directory-p ldir)))
606 (make-directory ldir parents))
607 ;; Just do it
608 (when (file-directory-p ldir)
609 (make-directory-internal dir))
610 (unless (file-directory-p dir)
611 (tramp-error v 'file-error "Couldn't make directory %s" dir))))))
612
613(defun tramp-fish-handle-make-directory-internal (directory)
614 "Like `make-directory-internal' for Tramp files."
615 (setq directory (directory-file-name (expand-file-name directory)))
616 (unless (file-name-absolute-p directory)
617 (setq directory (expand-file-name directory default-directory)))
618 (when (file-directory-p (file-name-directory directory))
619 (with-parsed-tramp-file-name directory nil
620 (save-match-data
621 (unless
622 (tramp-fish-send-command-and-check v (format "#MKD %s" localname))
623 (tramp-error
624 v 'file-error "Couldn't make directory %s" directory))))))
625
626(defun tramp-fish-handle-make-symbolic-link
627 (filename linkname &optional ok-if-already-exists)
628 "Like `make-symbolic-link' for Tramp files.
629If LINKNAME is a non-Tramp file, it is used verbatim as the target of
630the symlink. If LINKNAME is a Tramp file, only the localname component is
631used as the target of the symlink.
632
633If LINKNAME is a Tramp file and the localname component is relative, then
634it is expanded first, before the localname component is taken. Note that
635this can give surprising results if the user/host for the source and
636target of the symlink differ."
637 (with-parsed-tramp-file-name linkname nil
638 ;; Do the 'confirm if exists' thing.
639 (when (file-exists-p linkname)
640 ;; What to do?
641 (if (or (null ok-if-already-exists) ; not allowed to exist
642 (and (numberp ok-if-already-exists)
643 (not (yes-or-no-p
644 (format
645 "File %s already exists; make it a link anyway? "
646 localname)))))
647 (tramp-error
648 v 'file-already-exists "File %s already exists" localname)
649 (delete-file linkname)))
650
651 ;; If FILENAME is a Tramp name, use just the localname component.
652 (when (tramp-tramp-file-p filename)
653 (setq filename (tramp-file-name-localname
654 (tramp-dissect-file-name (expand-file-name filename)))))
655
656 ;; Right, they are on the same host, regardless of user, method, etc.
657 ;; We now make the link on the remote machine. This will occur as the user
658 ;; that FILENAME belongs to.
659 (unless
660 (tramp-fish-send-command-and-check
661 v (format "#SYMLINK %s %s" filename localname))
662 (tramp-error v 'file-error "Error creating symbolic link %s" linkname))))
663
664(defun tramp-fish-handle-rename-file
665 (filename newname &optional ok-if-already-exists)
666 "Like `rename-file' for Tramp files."
667 (tramp-fish-do-copy-or-rename-file
668 'rename filename newname ok-if-already-exists t))
669
670(defun tramp-fish-handle-set-file-modes (filename mode)
671 "Like `set-file-modes' for Tramp files."
672 (with-parsed-tramp-file-name filename nil
673 (tramp-flush-file-property v localname)
674 (unless (tramp-fish-send-command-and-check
675 v (format "#CHMOD %s %s"
676 (tramp-decimal-to-octal mode)
677 (tramp-shell-quote-argument localname)))
678 (tramp-error
679 v 'file-error "Error while changing file's mode %s" filename))))
680
ce3f516f
MA
681(defun tramp-fish-handle-set-file-times (filename &optional time)
682 "Like `set-file-times' for Tramp files."
683 (with-parsed-tramp-file-name filename nil
684 (let ((time (if (or (null time) (equal time '(0 0))) (current-time) time)))
9e6ab520
MA
685 (zerop (process-file
686 "touch" nil nil nil "-t"
687 (format-time-string "%Y%m%d%H%M.%S" time)
688 (tramp-shell-quote-argument localname))))))
ce3f516f 689
00d6fd04
MA
690(defun tramp-fish-handle-write-region
691 (start end filename &optional append visit lockname confirm)
692 "Like `write-region' for Tramp files."
693 (setq filename (expand-file-name filename))
694 (with-parsed-tramp-file-name filename nil
695 ;; XEmacs takes a coding system as the seventh argument, not `confirm'
696 (when (and (not (featurep 'xemacs))
697 confirm (file-exists-p filename))
698 (unless (y-or-n-p (format "File %s exists; overwrite anyway? "
699 filename))
700 (tramp-error v 'file-error "File not overwritten")))
701
702 (tramp-flush-file-property v localname)
703
704 ;; Send command
705 (let ((tramp-fish-ok-prompt-regexp
706 (concat
707 tramp-fish-ok-prompt-regexp "\\|"
708 tramp-fish-continue-prompt-regexp)))
709 (tramp-fish-send-command
710 v (format "%s %d %s\n### 100"
711 (if append "#APPEND" "#STOR") (- end start) localname)))
712
713 ;; Send data, if there are any.
714 (when (> end start)
715 (tramp-fish-send-command v (buffer-substring-no-properties start end)))
716
717 (when (eq visit t)
718 (set-visited-file-modtime))))
719
720(defun tramp-fish-handle-executable-find (command)
721 "Like `executable-find' for Tramp files."
722 (with-temp-buffer
9e6ab520 723 (if (zerop (process-file "which" nil t nil command))
00d6fd04
MA
724 (progn
725 (goto-char (point-min))
9e6ab520 726 (buffer-substring (point-min) (tramp-compat-line-end-position))))))
00d6fd04 727
ce3f516f 728(defun tramp-fish-handle-process-file
00d6fd04 729 (program &optional infile destination display &rest args)
ce3f516f 730 "Like `process-file' for Tramp files."
00d6fd04
MA
731 ;; The implementation is not complete yet.
732 (when (and (numberp destination) (zerop destination))
733 (error "Implementation does not handle immediate return"))
734
735 (with-parsed-tramp-file-name default-directory nil
a6e96327
MA
736 (let (command input tmpinput output tmpoutput stderr tmpstderr
737 outbuf tmpfile ret)
00d6fd04
MA
738 ;; Compute command.
739 (setq command (mapconcat 'tramp-shell-quote-argument
740 (cons program args) " "))
741 ;; Determine input.
742 (if (null infile)
743 (setq input "/dev/null")
744 (setq infile (expand-file-name infile))
745 (if (tramp-equal-remote default-directory infile)
746 ;; INFILE is on the same remote host.
747 (setq input (with-parsed-tramp-file-name infile nil localname))
748 ;; INFILE must be copied to remote host.
a6e96327
MA
749 (setq input (tramp-make-tramp-temp-file v)
750 tmpinput (tramp-make-tramp-file-name method user host input))
751 (copy-file infile tmpinput t)))
00d6fd04
MA
752 (when input (setq command (format "%s <%s" command input)))
753
754 ;; Determine output.
a6e96327
MA
755 (setq output (tramp-make-tramp-temp-file v)
756 tmpoutput (tramp-make-tramp-file-name method user host output))
00d6fd04
MA
757 (cond
758 ;; Just a buffer
759 ((bufferp destination)
760 (setq outbuf destination))
761 ;; A buffer name
762 ((stringp destination)
763 (setq outbuf (get-buffer-create destination)))
764 ;; (REAL-DESTINATION ERROR-DESTINATION)
765 ((consp destination)
766 ;; output
767 (cond
768 ((bufferp (car destination))
769 (setq outbuf (car destination)))
770 ((stringp (car destination))
771 (setq outbuf (get-buffer-create (car destination)))))
772 ;; stderr
773 (cond
774 ((stringp (cadr destination))
775 (setcar (cdr destination) (expand-file-name (cadr destination)))
776 (if (tramp-equal-remote default-directory (cadr destination))
777 ;; stderr is on the same remote host.
778 (setq stderr (with-parsed-tramp-file-name
779 (cadr destination) nil localname))
780 ;; stderr must be copied to remote host. The temporary
781 ;; file must be deleted after execution.
a6e96327
MA
782 (setq stderr (tramp-make-tramp-temp-file v)
783 tmpstderr (tramp-make-tramp-file-name
784 method user host stderr))))
00d6fd04
MA
785 ;; stderr to be discarded
786 ((null (cadr destination))
787 (setq stderr "/dev/null"))))
788 ;; 't
789 (destination
790 (setq outbuf (current-buffer))))
791 (when stderr (setq command (format "%s 2>%s" command stderr)))
792
00d6fd04
MA
793 ;; Goto working directory.
794 (unless
795 (tramp-fish-send-command-and-check
796 v (format "#CWD %s" (tramp-shell-quote-argument localname)))
797 (tramp-error v 'file-error "No such directory: %s" default-directory))
798 ;; Send the command. It might not return in time, so we protect it.
799 (condition-case nil
800 (unwind-protect
801 (unless (tramp-fish-send-command-and-check
802 v (format
803 "#EXEC %s %s"
804 (tramp-shell-quote-argument command) output))
9ce8462a 805 (error nil))
00d6fd04 806 ;; Check return code.
94be87e8
MA
807 (setq tmpfile
808 (file-local-copy
809 (tramp-make-tramp-file-name method user host output)))
00d6fd04 810 (with-temp-buffer
94be87e8 811 (insert-file-contents tmpfile)
00d6fd04
MA
812 (goto-char (point-max))
813 (forward-line -1)
814 (looking-at "^###RESULT: \\([0-9]+\\)")
815 (setq ret (string-to-number (match-string 1)))
816 (delete-region (point) (point-max))
94be87e8 817 (write-region (point-min) (point-max) tmpfile))
00d6fd04
MA
818 ;; We should show the output anyway.
819 (when outbuf
94be87e8 820 (with-current-buffer outbuf (insert-file-contents tmpfile))
a6e96327 821 (when display (display-buffer outbuf))))
00d6fd04
MA
822 ;; When the user did interrupt, we should do it also.
823 (error (setq ret 1)))
a6e96327
MA
824
825 ;; Provide error file.
826 (when tmpstderr (rename-file tmpstderr (cadr destination) t))
827 ;; Cleanup.
828 (when tmpinput (delete-file tmpinput))
829 (when tmpoutput (delete-file tmpoutput))
00d6fd04
MA
830 ;; Return exit status.
831 ret)))
832
833
834;; Internal file name functions
835
836(defun tramp-fish-do-copy-or-rename-file
a4aeb9a4 837 (op filename newname &optional ok-if-already-exists keep-date preserve-uid-gid)
00d6fd04
MA
838 "Copy or rename a remote file.
839OP must be `copy' or `rename' and indicates the operation to
840perform. FILENAME specifies the file to copy or rename, NEWNAME
841is the name of the new file (for copy) or the new name of the
842file (for rename). OK-IF-ALREADY-EXISTS means don't barf if
843NEWNAME exists already. KEEP-DATE means to make sure that
844NEWNAME has the same timestamp as FILENAME.
845
846This function is invoked by `tramp-fish-handle-copy-file' and
847`tramp-fish-handle-rename-file'. It is an error if OP is neither
848of `copy' and `rename'. FILENAME and NEWNAME must be absolute
849file names."
850 (unless (memq op '(copy rename))
851 (error "Unknown operation `%s', must be `copy' or `rename'" op))
852 (let ((t1 (tramp-tramp-file-p filename))
853 (t2 (tramp-tramp-file-p newname)))
854
855 (unless ok-if-already-exists
856 (when (and t2 (file-exists-p newname))
857 (with-parsed-tramp-file-name newname nil
858 (tramp-error
859 v 'file-already-exists "File %s already exists" newname))))
860
861 (prog1
862 (cond
863 ;; Both are Tramp files.
864 ((and t1 t2)
865 (cond
866 ;; Shortcut: if method, host, user are the same for both
867 ;; files, we invoke `cp' or `mv' on the remote host
868 ;; directly.
869 ((tramp-equal-remote filename newname)
870 (tramp-fish-do-copy-or-rename-file-directly
a4aeb9a4 871 op filename newname keep-date preserve-uid-gid))
00d6fd04
MA
872 ;; No shortcut was possible. So we copy the
873 ;; file first. If the operation was `rename', we go
874 ;; back and delete the original file (if the copy was
875 ;; successful). The approach is simple-minded: we
876 ;; create a new buffer, insert the contents of the
877 ;; source file into it, then write out the buffer to
878 ;; the target file. The advantage is that it doesn't
879 ;; matter which filename handlers are used for the
880 ;; source and target file.
881 (t
882 (tramp-do-copy-or-rename-file-via-buffer
883 op filename newname keep-date))))
884
885 ;; One file is a Tramp file, the other one is local.
886 ((or t1 t2)
887 ;; Use the generic method via a Tramp buffer.
888 (tramp-do-copy-or-rename-file-via-buffer
889 op filename newname keep-date))
890
891 (t
892 ;; One of them must be a Tramp file.
893 (error "Tramp implementation says this cannot happen")))
894 ;; When newname did exist, we have wrong cached values.
895 (when t2
896 (with-parsed-tramp-file-name newname nil
897 (tramp-flush-file-property v localname)
898 (tramp-flush-file-property v (file-name-directory localname)))))))
899
900(defun tramp-fish-do-copy-or-rename-file-directly
a4aeb9a4 901 (op filename newname keep-date preserve-uid-gid)
00d6fd04
MA
902 "Invokes `COPY' or `RENAME' on the remote system.
903OP must be one of `copy' or `rename', indicating `cp' or `mv',
904respectively. VEC specifies the connection. LOCALNAME1 and
905LOCALNAME2 specify the two arguments of `cp' or `mv'. If
a4aeb9a4
MA
906KEEP-DATE is non-nil, preserve the time stamp when copying.
907PRESERVE-UID-GID is completely ignored."
00d6fd04
MA
908 (with-parsed-tramp-file-name filename v1
909 (with-parsed-tramp-file-name newname v2
910 (tramp-fish-send-command
911 v1
912 (format "%s %s %s"
913 (if (eq op 'copy) "#COPY" "#RENAME")
914 (tramp-shell-quote-argument v1-localname)
915 (tramp-shell-quote-argument v2-localname)))))
916 ;; KEEP-DATE handling.
ce3f516f 917 (when (and keep-date (functionp 'set-file-times))
9e6ab520 918 (set-file-times newname (nth 5 (file-attributes filename))))
00d6fd04
MA
919 ;; Set the mode.
920 (set-file-modes newname (file-modes filename)))
921
922(defun tramp-fish-get-file-entries (vec localname list)
923 "Read entries returned by FISH server.
924When LIST is true, a #LIST command will be sent, including all entries
925of a directory. Otherwise, #STAT is sent for just one entry.
926Result is a list of (LOCALNAME LINK COUNT UID GID ATIME MTIME CTIME
927SIZE MODE WEIRD INODE DEVICE)."
928 (block nil
929 (with-current-buffer (tramp-get-buffer vec)
ce3f516f
MA
930 ;; #LIST does not work properly with trailing "/", at least in
931 ;; .fishsrv.pl.
00d6fd04
MA
932 (when (string-match "/$" localname)
933 (setq localname (concat localname ".")))
934
935 (let ((command (format "%s %s" (if list "#LIST" "#STAT") localname))
936 buffer-read-only num res)
937
938 ;; Send command
939 (tramp-fish-send-command vec command)
940
941 ;; Read number of entries
942 (goto-char (point-min))
943 (condition-case nil
9ce8462a 944 (unless (integerp (setq num (read (current-buffer)))) (error nil))
00d6fd04
MA
945 (error (return nil)))
946 (forward-line)
947 (delete-region (point-min) (point))
948
949 ;; Read return code
950 (goto-char (point-min))
951 (condition-case nil
9ce8462a 952 (unless (looking-at tramp-fish-continue-prompt-regexp) (error nil))
00d6fd04
MA
953 (error (return nil)))
954 (forward-line)
955 (delete-region (point-min) (point))
956
957 ;; Loop the listing
958 (dotimes (i num)
959 (let ((item (tramp-fish-read-file-entry)))
960 ;; Add inode and device.
961 (add-to-list
962 'res (append item
ce3f516f 963 (list (tramp-get-inode vec)
00d6fd04
MA
964 (tramp-get-device vec))))))
965
966 ;; Read return code
967 (goto-char (point-min))
968 (condition-case nil
9ce8462a 969 (unless (looking-at tramp-fish-ok-prompt-regexp) (error nil))
00d6fd04
MA
970 (error (tramp-error
971 vec 'file-error
972 "`%s' does not return a valid Lisp expression: `%s'"
973 command (buffer-string))))
974 (forward-line)
975 (delete-region (point-min) (point))
976
977 res))))
978
979(defun tramp-fish-read-file-entry ()
980 "Parse entry in output buffer.
981Result is the list (LOCALNAME LINK COUNT UID GID ATIME MTIME CTIME
982SIZE MODE WEIRD)."
983 ;; We are called from `tramp-fish-get-file-entries', which sets the
984 ;; current buffer.
985 (let (buffer-read-only localname link uid gid mtime size mode)
986 (block nil
987 (while t
988 (cond
989 ;; P<unix permissions> <owner>.<group>
990 ((looking-at "^P\\(.+\\)\\s-\\(.+\\)\\.\\(.+\\)$")
991 (setq mode (match-string 1))
992 (setq uid (match-string 2))
993 (setq gid (match-string 3))
994 (when (string-match "^d" mode) (setq link t)))
995 ;; S<size>
996 ((looking-at "^S\\([0-9]+\\)$")
997 (setq size (string-to-number (match-string 1))))
998 ;; D<year> <month> <day> <hour> <minute> <second>[.1234]
999 ((looking-at
1000 "^D\\([0-9]+\\)\\s-\\([0-9]+\\)\\s-\\([0-9]+\\)\\s-\\([0-9]+\\)\\s-\\([0-9]+\\)\\s-\\(\\S-+\\)$")
1001 (setq mtime
1002 (encode-time
1003 (string-to-number (match-string 6))
1004 (string-to-number (match-string 5))
1005 (string-to-number (match-string 4))
1006 (string-to-number (match-string 3))
1007 (string-to-number (match-string 2))
1008 (string-to-number (match-string 1)))))
1009 ;; d<3-letters month name> <day> <year or HH:MM>
1010 ((looking-at "^d") nil)
1011 ;; E<major-of-device>,<minor>
1012 ((looking-at "^E") nil)
1013 ;; :<filename>
1014 ((looking-at "^:\\(.+\\)$")
1015 (setq localname (match-string 1)))
1016 ;; L<filename symlink points to>
1017 ((looking-at "^L\\(.+\\)$")
1018 (setq link (match-string 1)))
1019 ;; M<mimetype>
1020 ((looking-at "^M\\(.+\\)$") nil)
1021 ;; last line
1022 ((looking-at "^$")
1023 (return)))
1024 ;; delete line
1025 (forward-line)
1026 (delete-region (point-min) (point))))
1027
1028 ;; delete trailing empty line
1029 (forward-line)
1030 (delete-region (point-min) (point))
1031
1032 ;; Return entry in file-attributes format
1033 (list localname link -1 uid gid '(0 0) mtime '(0 0) size mode nil)))
1034
1035(defun tramp-fish-retrieve-data (vec)
1036 "Reads remote data for FISH protocol.
1037The data are left in the connection buffer of VEC for further processing.
1038Returns the size of the data."
1039 (block nil
1040 (with-current-buffer (tramp-get-buffer vec)
1041 ;; The retrieved data might be in binary format, without
1042 ;; trailing newline. Therefore, the OK prompt might not start
1043 ;; at the beginning of a line.
1044 (let ((tramp-fish-ok-prompt-regexp "### 200\n")
1045 size)
1046
1047 ;; Send command
1048 (tramp-fish-send-command
1049 vec (format "#RETR %s" (tramp-file-name-localname vec)))
1050
1051 ;; Read filesize
1052 (goto-char (point-min))
1053 (condition-case nil
9ce8462a 1054 (unless (integerp (setq size (read (current-buffer)))) (error nil))
00d6fd04
MA
1055 (error (return nil)))
1056 (forward-line)
1057 (delete-region (point-min) (point))
1058
1059 ;; Read return code
1060 (goto-char (point-min))
1061 (condition-case nil
9ce8462a 1062 (unless (looking-at tramp-fish-continue-prompt-regexp) (error nil))
00d6fd04
MA
1063 (error (return nil)))
1064 (forward-line)
1065 (delete-region (point-min) (point))
1066
1067 ;; The received data might contain the OK prompt already, so
1068 ;; there might be outstanding data.
1069 (while (/= (+ size (length tramp-fish-ok-prompt-regexp))
1070 (- (point-max) (point-min)))
1071 (tramp-wait-for-regexp
1072 (tramp-get-connection-process vec) nil
1073 (concat tramp-fish-ok-prompt-regexp "$")))
1074
1075 ;; Read return code
1076 (goto-char (+ (point-min) size))
1077 (condition-case nil
9ce8462a 1078 (unless (looking-at tramp-fish-ok-prompt-regexp) (error nil))
00d6fd04
MA
1079 (error (return nil)))
1080 (delete-region (+ (point-min) size) (point-max))
1081 size))))
1082
1083
1084;; Connection functions
1085
1086(defun tramp-fish-maybe-open-connection (vec)
1087 "Maybe open a connection VEC.
1088Does not do anything if a connection is already open, but re-opens the
1089connection if a previous connection has died for some reason."
1090 (let ((process-connection-type tramp-process-connection-type)
1091 (p (get-buffer-process (tramp-get-buffer vec))))
1092
1093 ;; New connection must be opened.
1094 (unless (and p (processp p) (memq (process-status p) '(run open)))
1095
1096 ;; Set variables for computing the prompt for reading password.
1097 (setq tramp-current-method (tramp-file-name-method vec)
1098 tramp-current-user (tramp-file-name-user vec)
1099 tramp-current-host (tramp-file-name-host vec))
1100
1101 ;; Start new process.
1102 (when (and p (processp p))
1103 (delete-process p))
1104 (setenv "TERM" tramp-terminal-type)
1105 (setenv "PS1" "$ ")
1106 (tramp-message
1107 vec 3 "Opening connection for %s@%s using %s..."
1108 tramp-current-user tramp-current-host tramp-current-method)
1109
1110 (let* ((process-connection-type tramp-process-connection-type)
1111 (inhibit-eol-conversion nil)
1112 (coding-system-for-read 'binary)
1113 (coding-system-for-write 'binary)
1114 ;; This must be done in order to avoid our file name handler.
9e6ab520
MA
1115 (p (let ((default-directory
1116 (tramp-compat-temporary-file-directory)))
00d6fd04
MA
1117 (start-process
1118 (or (tramp-get-connection-property vec "process-name" nil)
1119 (tramp-buffer-name vec))
1120 (tramp-get-connection-buffer vec)
1121 "ssh" "-l"
1122 (tramp-file-name-user vec)
1123 (tramp-file-name-host vec)))))
1124 (tramp-message vec 6 "%s" (mapconcat 'identity (process-command p) " "))
1125
1126 ;; Check whether process is alive.
24f7320b 1127 (set-process-sentinel p 'tramp-process-sentinel)
00d6fd04
MA
1128 (tramp-set-process-query-on-exit-flag p nil)
1129
1130 (tramp-process-actions p vec tramp-actions-before-shell 60)
1131 (tramp-fish-send-command vec tramp-fish-start-fish-server-command)
1132 (tramp-message
1133 vec 3
1134 "Found remote shell prompt on `%s'" (tramp-file-name-host vec))))))
1135
1136(defun tramp-fish-send-command (vec command)
1137 "Send the COMMAND to connection VEC."
1138 (tramp-fish-maybe-open-connection vec)
1139 (tramp-message vec 6 "%s" command)
1140 (tramp-send-string vec command)
1141 (tramp-wait-for-regexp
1142 (tramp-get-connection-process vec) nil
1143 (concat tramp-fish-ok-prompt-regexp "\\|" tramp-fish-error-prompt-regexp)))
1144
1145(defun tramp-fish-send-command-and-check (vec command)
1146 "Send the COMMAND to connection VEC.
1147Returns nil if there has been an error message."
1148
1149 ;; Send command.
1150 (tramp-fish-send-command vec command)
1151
1152 ;; Read return code.
1153 (with-current-buffer (tramp-get-buffer vec)
1154 (goto-char (point-min))
1155 (looking-at tramp-fish-ok-prompt-regexp)))
1156
1157(provide 'tramp-fish)
1158;
1159;;;; TODO:
1160;
1161;; * Evaluate the MIME information with #LIST or #STAT.
1162;
69e4c7c4
MB
1163
1164;; arch-tag: a66df7df-5f29-42a7-a921-643ceb29db49
00d6fd04 1165;;;; tramp-fish.el ends here