comparison lisp/net/tramp.el @ 49612:407d6516031a

2003-02-05 Kai Gro?ohann <kai.grossjohann@uni-duisburg.de> Version 2.0.29 released. * net/tramp.el (tramp-send-region): Protect against tramp-chunksize being nil. 2003-02-04 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-handle-directory-file-name): Handle the case PATH is "". (tramp-completion-handle-file-name-all-completions): Define `tramp-current-user' locally. See `tramp-parse-passwd'. (tramp-parse-passwd): For su-alike methods it would be desirable to return "root@localhost" as default. Unfortunately, we have no information whether any user name has been typed already. So we (mis-)use tramp-current-user as indication, assuming it is set in `tramp-completion-handle-file-name-all-completions'. (tramp-send-region): Handle the case `tramp-chunksize' is equal 0. I did it accidently. Infinite loop ... * net/tramp-ftp.el (top-level): eval-after-load "ange-ftp" '(tramp-disable-ange-ftp). Suggested by Kai. (tramp-ftp-file-name-handler): `tramp-disable-ange-ftp' not needed any longer. * net/tramp-smb.el (tramp-smb-file-name-handler-alist): Apply `tramp-handle-directory-file-name' in order to profit from Kai's yesterday changes. 2003-02-03 Kai Gro?ohann <kai.grossjohann@uni-duisburg.de> * net/tramp.el (tramp-chunksize): Set default to 500 as workaround for some ssh connections. (tramp-handle-directory-file-name): New implementation. Not sure if it works. 2003-01-28 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-get-device): `tramp-make-tramp-file-name' must not be called with NIL path. It fails in case of multi-method. 2003-01-27 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-file-name-for-operation): Apply `expand-file-name' for relative file names only. Otherwise there might be problems if the default directory is another Tramp directory as the directory the file is based on. (tramp-find-foreign-file-name-handler): Check whether FILENAME is a Tramp file name. It isn't if it comes from an expanded file name (like "/xx:yy//zz"). 2003-01-25 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-devices): New variable. Keeps virtual device numbers. Devices must distinguish physical file systems. The device numbers provided by "lstat" aren't unique, because we operate on different hosts. So we use virtual device numbers, generated by `tramp-get-device'. Both Ange-FTP and EFS use device number -1. In order to be different, we use device number (-1 x), whereby "x" is unique for a given (multi-method method user host). Suggested by Kai. (tramp-perl-file-attributes): Always return device number -1. There will be a virtual device number set in `tramp-handle-file-attributes', which replaces this one. (tramp-handle-file-attributes): Set virtual device number. (tramp-get-device): New function. Returns the virtual device number. If it doesn't exist, generate a new one. (tramp-handle-file-regular-p): Use Emacs file name primitives instead of calling tramp-handle-* equivalents directly. Needed for tramp-smb. * net/tramp-smb.el (tramp-smb-devices, tramp-smb-get-device): Removed. Functionality moved to tramp.el. (tramp-smb-handle-file-attributes): Apply `tramp-get-device'. ATIME and CTIME are (0 0) now (= "don't know"), which is more honest. (tramp-smb-handle-make-directory): Use Emacs file name primitives instead of calling tramp-smb-handle-* equivalents directly. (tramp-smb-read-file-entry): Return size as a number but a string. 2003-01-24 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-function-alist-ssh): Add parsing of "/etc/ssh_config" and "~/.ssh/config". Suggested by Kai. (tramp-completion-function-alist, tramp-set-completion-function): Doc string update. (tramp-parse-sconfig, tramp-parse-sconfig-group): New functions. Provide parsing of "~/.ssh/config" style files. 2003-01-21 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-handle-expand-file-name): Apply `tramp-drop-volume-letter'. Otherwise, there are problems on W32 systems. 2003-01-21 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp-smb.el (tramp-smb-get-device, tramp-smb-get-inode): New functions. Device number and inode number don't exist for SMB files. Therefore we must generate virtual ones. (tramp-smb-devices, tramp-smb-inodes): New variables. Keep generated virtual device numbers and inodes numbers for SMB files. (tramp-smb-handle-file-attributes): Apply them. 2003-01-14 Kai Gro?ohann <kai.grossjohann@uni-duisburg.de> * net/tramp.el (tramp-md5-function): Require md5 before checking function md5. If using md5-encode, put wrapper around it that converts vector of bytes to ascii text. 2003-01-13 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-completion-mode): Perform check (integerp last-input-event) before (event-modifiers last-input-event) - there might be problems if `last-input-event' is a mouse event. 2003-01-12 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp.el (tramp-parse-rhosts, tramp-parse-shosts) (tramp-parse-hosts, tramp-parse-passwd, tramp-parse-netrc): Use `file-readable-p' instead of `file-exists-p'. Otherwise these functions might block. Reported by <kin@neoscale.com>. 2003-01-02 Michael Albinus <Michael.Albinus@alcatel.de> * net/tramp-ftp.el (top-level): Defaults for `tramp-default-method-alist' must be a list. * net/tramp-smb.el (top-level): Defaults for `tramp-default-method-alist' must be a list. 2003-01-02 Kai Gro?ohann <kai.grossjohann@uni-duisburg.de> * net/tramp.el (top-level): Avoid byte-compiler warnings of unused variables if the byte-compiler supports this. This is for the with-parsed-tramp-file-name macro which is wont to produce such stuff.
author Kai Großjohann <kgrossjo@eu.uu.net>
date Wed, 05 Feb 2003 21:03:36 +0000
parents 0d8b17d428b5
children a0e8a85259ed d7ddb3e565de
comparison
equal deleted inserted replaced
49611:c6104239711d 49612:407d6516031a
1 ;;; tramp.el --- Transparent Remote Access, Multiple Protocol -*- coding: iso-8859-1; -*- 1 ;;; tramp.el --- Transparent Remote Access, Multiple Protocol -*- coding: iso-8859-1; -*-
2 2
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. 3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4 4
5 ;; Author: Kai.Grossjohann@CS.Uni-Dortmund.DE 5 ;; Author: Kai.Grossjohann@CS.Uni-Dortmund.DE
6 ;; Keywords: comm, processes 6 ;; Keywords: comm, processes
7 7
8 ;; This file is part of GNU Emacs. 8 ;; This file is part of GNU Emacs.
70 ;;; Code: 70 ;;; Code:
71 71
72 ;; In the Tramp CVS repository, the version numer is auto-frobbed from 72 ;; In the Tramp CVS repository, the version numer is auto-frobbed from
73 ;; the Makefile, so you should edit the top-level Makefile to change 73 ;; the Makefile, so you should edit the top-level Makefile to change
74 ;; the version number. 74 ;; the version number.
75 (defconst tramp-version "2.0.28" 75 (defconst tramp-version "2.0.29"
76 "This version of tramp.") 76 "This version of tramp.")
77 77
78 (defconst tramp-bug-report-address "tramp-devel@mail.freesoftware.fsf.org" 78 (defconst tramp-bug-report-address "tramp-devel@mail.freesoftware.fsf.org"
79 "Email address to send bug reports to.") 79 "Email address to send bug reports to.")
80 80
122 (or (>= emacs-major-version 20) 122 (or (>= emacs-major-version 20)
123 (load "cl-seq"))) 123 (load "cl-seq")))
124 124
125 (unless (boundp 'custom-print-functions) 125 (unless (boundp 'custom-print-functions)
126 (defvar custom-print-functions nil)) ; not autoloaded before Emacs 20.4 126 (defvar custom-print-functions nil)) ; not autoloaded before Emacs 20.4
127
128 ;; Avoid bytecompiler warnings if the byte-compiler supports this.
129 ;; Currently, XEmacs supports this.
130 (eval-when-compile
131 (when (fboundp 'byte-compiler-options)
132 (byte-compiler-options (warnings (- unused-vars)))))
127 133
128 ;; XEmacs is distributed with few Lisp packages. Further packages are 134 ;; XEmacs is distributed with few Lisp packages. Further packages are
129 ;; installed using EFS. If we use a unified filename format, then 135 ;; installed using EFS. If we use a unified filename format, then
130 ;; Tramp is required in addition to EFS. (But why can't Tramp just 136 ;; Tramp is required in addition to EFS. (But why can't Tramp just
131 ;; disable EFS when Tramp is loaded? Then XEmacs can ship with EFS 137 ;; disable EFS when Tramp is loaded? Then XEmacs can ship with EFS
665 ) 671 )
666 672
667 ;; Default values for non-Unices seeked 673 ;; Default values for non-Unices seeked
668 (defconst tramp-completion-function-alist-ssh 674 (defconst tramp-completion-function-alist-ssh
669 (unless (memq system-type '(windows-nt)) 675 (unless (memq system-type '(windows-nt))
670 '((tramp-parse-rhosts "/etc/hosts.equiv") 676 '((tramp-parse-rhosts "/etc/hosts.equiv")
671 (tramp-parse-rhosts "/etc/shosts.equiv") 677 (tramp-parse-rhosts "/etc/shosts.equiv")
672 (tramp-parse-shosts "/etc/ssh_known_hosts") 678 (tramp-parse-shosts "/etc/ssh_known_hosts")
673 (tramp-parse-rhosts "~/.rhosts") 679 (tramp-parse-sconfig "/etc/ssh_config")
674 (tramp-parse-rhosts "~/.shosts") 680 (tramp-parse-rhosts "~/.rhosts")
675 (tramp-parse-shosts "~/.ssh/known_hosts"))) 681 (tramp-parse-rhosts "~/.shosts")
682 (tramp-parse-shosts "~/.ssh/known_hosts")
683 (tramp-parse-sconfig "~/.ssh/config")))
676 "Default list of (FUNCTION FILE) pairs to be examined for ssh methods." 684 "Default list of (FUNCTION FILE) pairs to be examined for ssh methods."
677 ) 685 )
678 686
679 ;; Default values for non-Unices seeked 687 ;; Default values for non-Unices seeked
680 (defconst tramp-completion-function-alist-telnet 688 (defconst tramp-completion-function-alist-telnet
719 This is a list of entries of the form (NAME PAIR1 PAIR2 ...). 727 This is a list of entries of the form (NAME PAIR1 PAIR2 ...).
720 Each NAME stands for a remote access method. Each PAIR is of the form 728 Each NAME stands for a remote access method. Each PAIR is of the form
721 \(FUNCTION FILE). FUNCTION is responsible to extract user names and host 729 \(FUNCTION FILE). FUNCTION is responsible to extract user names and host
722 names from FILE for completion. The following predefined FUNCTIONs exists: 730 names from FILE for completion. The following predefined FUNCTIONs exists:
723 731
724 * `tramp-parse-rhosts' for \".rhosts\" like files, 732 * `tramp-parse-rhosts' for \"~/.rhosts\" like files,
725 * `tramp-parse-shosts' for \"ssh_known_hosts\" like files, 733 * `tramp-parse-shosts' for \"~/.ssh/known_hosts\" like files,
726 * `tramp-parse-hosts' for \"/etc/hosts\" like files, and 734 * `tramp-parse-sconfig' for \"~/.ssh/config\" like files,
727 * `tramp-parse-passwd' for \"/etc/passwd\" like files. 735 * `tramp-parse-hosts' for \"/etc/hosts\" like files, and
728 * `tramp-parse-netrc' for \".netrc\" like files. 736 * `tramp-parse-passwd' for \"/etc/passwd\" like files.
737 * `tramp-parse-netrc' for \"~/.netrc\" like files.
729 738
730 FUNCTION can also see a customer defined function. For more details see 739 FUNCTION can also see a customer defined function. For more details see
731 the info pages." 740 the info pages."
732 :group 'tramp 741 :group 'tramp
733 :type '(repeat 742 :type '(repeat
1248 machine groks Perl. If it is used, it's used as an emulation for 1257 machine groks Perl. If it is used, it's used as an emulation for
1249 the visited file modtime.") 1258 the visited file modtime.")
1250 (make-variable-buffer-local 'tramp-buffer-file-attributes) 1259 (make-variable-buffer-local 'tramp-buffer-file-attributes)
1251 1260
1252 (defvar tramp-md5-function 1261 (defvar tramp-md5-function
1253 (cond ((fboundp 'md5) 'md5) 1262 (cond ((and (require 'md5) (fboundp 'md5)) 'md5)
1254 ((and (require 'md5) (fboundp 'md5-encode)) 'md5-encode) 1263 ((fboundp 'md5-encode)
1264 (lambda (x) (base64-encode-string (md5-encode x))))
1255 (t (error "Coulnd't find an `md5' function"))) 1265 (t (error "Coulnd't find an `md5' function")))
1256 "Function to call for running the MD5 algorithm.") 1266 "Function to call for running the MD5 algorithm.")
1257 1267
1258 (defvar tramp-end-of-output 1268 (defvar tramp-end-of-output
1259 (concat "///" 1269 (concat "///"
1394 1404
1395 ;; Perl script to implement `file-attributes' in a Lisp `read'able 1405 ;; Perl script to implement `file-attributes' in a Lisp `read'able
1396 ;; output. If you are hacking on this, note that you get *no* output 1406 ;; output. If you are hacking on this, note that you get *no* output
1397 ;; unless this spits out a complete line, including the '\n' at the 1407 ;; unless this spits out a complete line, including the '\n' at the
1398 ;; end. 1408 ;; end.
1409 ;; The device number is returned as "-1", because there will be a virtual
1410 ;; device number set in `tramp-handle-file-attributes'
1399 (defconst tramp-perl-file-attributes "\ 1411 (defconst tramp-perl-file-attributes "\
1400 $f = $ARGV[0]; 1412 $f = $ARGV[0];
1401 @s = lstat($f); 1413 @s = lstat($f);
1402 if (($s[2] & 0170000) == 0120000) { $l = readlink($f); $l = \"\\\"$l\\\"\"; } 1414 if (($s[2] & 0170000) == 0120000) { $l = readlink($f); $l = \"\\\"$l\\\"\"; }
1403 elsif (($s[2] & 0170000) == 040000) { $l = \"t\"; } 1415 elsif (($s[2] & 0170000) == 040000) { $l = \"t\"; }
1404 else { $l = \"nil\" }; 1416 else { $l = \"nil\" };
1405 printf(\"(%s %u %d %d (%u %u) (%u %u) (%u %u) %u %u t (%u . %u) (%u %u))\\n\", 1417 printf(\"(%s %u %d %d (%u %u) (%u %u) (%u %u) %u %u t (%u . %u) -1)\\n\",
1406 $l, $s[3], $s[4], $s[5], $s[8] >> 16 & 0xffff, $s[8] & 0xffff, 1418 $l, $s[3], $s[4], $s[5], $s[8] >> 16 & 0xffff, $s[8] & 0xffff,
1407 $s[9] >> 16 & 0xffff, $s[9] & 0xffff, $s[10] >> 16 & 0xffff, $s[10] & 0xffff, 1419 $s[9] >> 16 & 0xffff, $s[9] & 0xffff, $s[10] >> 16 & 0xffff, $s[10] & 0xffff,
1408 $s[7], $s[2], $s[1] >> 16 & 0xffff, $s[1] & 0xffff, $s[0] >> 16 & 0xffff, $s[0] & 0xffff);" 1420 $s[7], $s[2], $s[1] >> 16 & 0xffff, $s[1] & 0xffff);"
1409 "Perl script to produce output suitable for use with `file-attributes' 1421 "Perl script to produce output suitable for use with `file-attributes'
1410 on the remote file system.") 1422 on the remote file system.")
1411 1423
1412 ;; ;; These two use uu encoding. 1424 ;; ;; These two use uu encoding.
1413 ;; (defvar tramp-perl-encode "%s -e'\ 1425 ;; (defvar tramp-perl-encode "%s -e'\
1724 "Sets the list of completion functions for METHOD. 1736 "Sets the list of completion functions for METHOD.
1725 FUNCTION-LIST is a list of entries of the form (FUNCTION FILE). 1737 FUNCTION-LIST is a list of entries of the form (FUNCTION FILE).
1726 The FUNCTION is intended to parse FILE according its syntax. 1738 The FUNCTION is intended to parse FILE according its syntax.
1727 It might be a predefined FUNCTION, or a user defined FUNCTION. 1739 It might be a predefined FUNCTION, or a user defined FUNCTION.
1728 Predefined FUNCTIONs are `tramp-parse-rhosts', `tramp-parse-shosts', 1740 Predefined FUNCTIONs are `tramp-parse-rhosts', `tramp-parse-shosts',
1729 `tramp-parse-hosts', and `tramp-parse-passwd'. 1741 `tramp-parse-sconfig',`tramp-parse-hosts', `tramp-parse-passwd',
1742 and `tramp-parse-netrc'.
1743
1730 Example: 1744 Example:
1731 1745
1732 (tramp-set-completion-function 1746 (tramp-set-completion-function
1733 \"ssh\" 1747 \"ssh\"
1734 '((tramp-parse-shosts \"/etc/ssh_known_hosts\") 1748 '((tramp-parse-sconfig \"/etc/ssh_config\")
1735 (tramp-parse-shosts \"~/.ssh/known_hosts\")))" 1749 (tramp-parse-sconfig \"~/.ssh/config\")))"
1736 1750
1737 (let ((v (cdr (assoc method tramp-completion-function-alist)))) 1751 (let ((v (cdr (assoc method tramp-completion-function-alist))))
1738 (if v (setcdr v function-list) 1752 (if v (setcdr v function-list)
1739 (add-to-list 'tramp-completion-function-alist 1753 (add-to-list 'tramp-completion-function-alist
1740 (cons method function-list))))) 1754 (cons method function-list)))))
1942 multi-method method user host 1956 multi-method method user host
1943 (format 1957 (format
1944 (tramp-get-file-exists-command multi-method method user host) 1958 (tramp-get-file-exists-command multi-method method user host)
1945 (tramp-shell-quote-argument path))))))) 1959 (tramp-shell-quote-argument path)))))))
1946 1960
1961 ;; Devices must distinguish physical file systems. The device numbers
1962 ;; provided by "lstat" aren't unique, because we operate on different hosts.
1963 ;; So we use virtual device numbers, generated by Tramp. Both Ange-FTP and
1964 ;; EFS use device number "-1". In order to be different, we use device number
1965 ;; (-1 x), whereby "x" is unique for a given (multi-method method user host).
1966 (defvar tramp-devices nil
1967 "Keeps virtual device numbers.")
1968
1947 ;; CCC: This should check for an error condition and signal failure 1969 ;; CCC: This should check for an error condition and signal failure
1948 ;; when something goes wrong. 1970 ;; when something goes wrong.
1949 ;; Daniel Pittman <daniel@danann.net> 1971 ;; Daniel Pittman <daniel@danann.net>
1950 (defun tramp-handle-file-attributes (filename &optional nonnumeric) 1972 (defun tramp-handle-file-attributes (filename &optional nonnumeric)
1951 "Like `file-attributes' for tramp files. 1973 "Like `file-attributes' for tramp files.
1960 (setq result 1982 (setq result
1961 (tramp-handle-file-attributes-with-perl 1983 (tramp-handle-file-attributes-with-perl
1962 multi-method method user host path nonnumeric)) 1984 multi-method method user host path nonnumeric))
1963 (setq result 1985 (setq result
1964 (tramp-handle-file-attributes-with-ls 1986 (tramp-handle-file-attributes-with-ls
1965 multi-method method user host path nonnumeric)))))) 1987 multi-method method user host path nonnumeric)))
1988 ;; set virtual device number
1989 (setcar (nthcdr 11 result)
1990 (tramp-get-device multi-method method user host)))))
1966 result)) 1991 result))
1967
1968 1992
1969 (defun tramp-handle-file-attributes-with-ls 1993 (defun tramp-handle-file-attributes-with-ls
1970 (multi-method method user host path &optional nonnumeric) 1994 (multi-method method user host path &optional nonnumeric)
1971 "Implement `file-attributes' for tramp files using the ls(1) command." 1995 "Implement `file-attributes' for tramp files using the ls(1) command."
1972 (let (symlinkp dirp 1996 (let (symlinkp dirp
2045 ;; 9. t iff file's gid would change if file were deleted and 2069 ;; 9. t iff file's gid would change if file were deleted and
2046 ;; recreated. 2070 ;; recreated.
2047 nil ;hm? 2071 nil ;hm?
2048 ;; 10. inode number. 2072 ;; 10. inode number.
2049 res-inode 2073 res-inode
2050 ;; 11. Device number. 2074 ;; 11. Device number. Will be replaced by a virtual device number.
2051 -1 ;hm? 2075 -1
2052 ))) 2076 )))
2053 2077
2054 (defun tramp-handle-file-attributes-with-perl 2078 (defun tramp-handle-file-attributes-with-perl
2055 (multi-method method user host path &optional nonnumeric) 2079 (multi-method method user host path &optional nonnumeric)
2056 "Implement `file-attributes' for tramp files using a Perl script. 2080 "Implement `file-attributes' for tramp files using a Perl script.
2068 (tramp-wait-for-output) 2092 (tramp-wait-for-output)
2069 (let ((result (read (current-buffer)))) 2093 (let ((result (read (current-buffer))))
2070 (setcar (nthcdr 8 result) 2094 (setcar (nthcdr 8 result)
2071 (tramp-file-mode-from-int (nth 8 result))) 2095 (tramp-file-mode-from-int (nth 8 result)))
2072 result)) 2096 result))
2097
2098 (defun tramp-get-device (multi-method method user host)
2099 "Returns the virtual device number.
2100 If it doesn't exist, generate a new one."
2101 (let ((string (tramp-make-tramp-file-name multi-method method user host "")))
2102 (unless (assoc string tramp-devices)
2103 (add-to-list 'tramp-devices
2104 (list string (length tramp-devices))))
2105 (list -1 (nth 1 (assoc string tramp-devices)))))
2073 2106
2074 (defun tramp-handle-set-visited-file-modtime (&optional time-list) 2107 (defun tramp-handle-set-visited-file-modtime (&optional time-list)
2075 "Like `set-visited-file-modtime' for tramp files." 2108 "Like `set-visited-file-modtime' for tramp files."
2076 (unless (buffer-file-name) 2109 (unless (buffer-file-name)
2077 (error "Can't set-visited-file-modtime: buffer `%s' not visiting a file" 2110 (error "Can't set-visited-file-modtime: buffer `%s' not visiting a file"
2259 t))))) ;run command in subshell 2292 t))))) ;run command in subshell
2260 2293
2261 (defun tramp-handle-file-regular-p (filename) 2294 (defun tramp-handle-file-regular-p (filename)
2262 "Like `file-regular-p' for tramp files." 2295 "Like `file-regular-p' for tramp files."
2263 (with-parsed-tramp-file-name filename nil 2296 (with-parsed-tramp-file-name filename nil
2264 (and (tramp-handle-file-exists-p filename) 2297 (and (file-exists-p filename)
2265 (eq ?- (aref (nth 8 (tramp-handle-file-attributes filename)) 0))))) 2298 (eq ?- (aref (nth 8 (file-attributes filename)) 0)))))
2266 2299
2267 (defun tramp-handle-file-symlink-p (filename) 2300 (defun tramp-handle-file-symlink-p (filename)
2268 "Like `file-symlink-p' for tramp files." 2301 "Like `file-symlink-p' for tramp files."
2269 (with-parsed-tramp-file-name filename nil 2302 (with-parsed-tramp-file-name filename nil
2270 (let ((x (car (tramp-handle-file-attributes filename)))) 2303 (let ((x (car (tramp-handle-file-attributes filename))))
2297 ;; (if (and (eq (aref directory (- (length directory) 1)) ?/) 2330 ;; (if (and (eq (aref directory (- (length directory) 1)) ?/)
2298 ;; (not (eq (aref directory (- (length directory) 2)) ?:))) 2331 ;; (not (eq (aref directory (- (length directory) 2)) ?:)))
2299 ;; (substring directory 0 (- (length directory) 1)) 2332 ;; (substring directory 0 (- (length directory) 1))
2300 ;; directory)) 2333 ;; directory))
2301 2334
2302 ;; Philippe Troin <phil@fifi.org> 2335 ;; ;; Philippe Troin <phil@fifi.org>
2336 ;; (defun tramp-handle-directory-file-name (directory)
2337 ;; "Like `directory-file-name' for tramp files."
2338 ;; (with-parsed-tramp-file-name directory nil
2339 ;; (let ((directory-length-1 (1- (length directory))))
2340 ;; (save-match-data
2341 ;; (if (and (eq (aref directory directory-length-1) ?/)
2342 ;; (eq (string-match tramp-file-name-regexp directory) 0)
2343 ;; (/= (match-end 0) directory-length-1))
2344 ;; (substring directory 0 directory-length-1)
2345 ;; directory)))))
2346
2303 (defun tramp-handle-directory-file-name (directory) 2347 (defun tramp-handle-directory-file-name (directory)
2304 "Like `directory-file-name' for tramp files." 2348 "Like `directory-file-name' for tramp files."
2349 ;; If path component of filename is "/", leave it unchanged.
2350 ;; Otherwise, remove any trailing slash from path component.
2351 ;; Method, host, etc, are unchanged. Does it make sense to try
2352 ;; to avoid parsing the filename?
2305 (with-parsed-tramp-file-name directory nil 2353 (with-parsed-tramp-file-name directory nil
2306 (let ((directory-length-1 (1- (length directory)))) 2354 (if (and (not (zerop (length path)))
2307 (save-match-data 2355 (eq (aref path (1- (length path))) ?/)
2308 (if (and (eq (aref directory directory-length-1) ?/) 2356 (not (string= path "/")))
2309 (eq (string-match tramp-file-name-regexp directory) 0) 2357 (substring directory 0 -1)
2310 (/= (match-end 0) directory-length-1)) 2358 directory)))
2311 (substring directory 0 directory-length-1)
2312 directory)))))
2313 2359
2314 ;; Directory listings. 2360 ;; Directory listings.
2315 2361
2316 (defun tramp-handle-directory-files (directory 2362 (defun tramp-handle-directory-files (directory
2317 &optional full match nosort files-only) 2363 &optional full match nosort files-only)
3343 'dired-file-modtime 'dired-make-compressed-filename 3389 'dired-file-modtime 'dired-make-compressed-filename
3344 'dired-recursive-delete-directory 'dired-set-file-modtime 3390 'dired-recursive-delete-directory 'dired-set-file-modtime
3345 'dired-shell-unhandle-file-name 'dired-uucode-file 3391 'dired-shell-unhandle-file-name 'dired-uucode-file
3346 'insert-file-contents-literally 'recover-file 3392 'insert-file-contents-literally 'recover-file
3347 'vm-imap-check-mail 'vm-pop-check-mail 'vm-spool-check-mail)) 3393 'vm-imap-check-mail 'vm-pop-check-mail 'vm-spool-check-mail))
3348 (expand-file-name (nth 0 args))) 3394 (if (file-name-absolute-p (nth 0 args))
3395 (nth 0 args)
3396 (expand-file-name (nth 0 args))))
3349 ; FILE DIRECTORY resp FILE1 FILE2 3397 ; FILE DIRECTORY resp FILE1 FILE2
3350 ((member operation 3398 ((member operation
3351 (list 'add-name-to-file 'copy-file 'expand-file-name 3399 (list 'add-name-to-file 'copy-file 'expand-file-name
3352 'file-name-all-completions 'file-name-completion 3400 'file-name-all-completions 'file-name-completion
3353 'file-newer-than-file-p 'make-symbolic-link 'rename-file 3401 'file-newer-than-file-p 'make-symbolic-link 'rename-file
3378 ; unknown file primitive 3426 ; unknown file primitive
3379 (t (error "unknown file I/O primitive: %s" operation)))) 3427 (t (error "unknown file I/O primitive: %s" operation))))
3380 3428
3381 (defun tramp-find-foreign-file-name-handler (filename) 3429 (defun tramp-find-foreign-file-name-handler (filename)
3382 "Return foreign file name handler if exists." 3430 "Return foreign file name handler if exists."
3383 (let (elt res) 3431 (when (tramp-tramp-file-p filename)
3384 (dolist (elt tramp-foreign-file-name-handler-alist res) 3432 (let (elt res)
3385 (when (funcall (car elt) filename) 3433 (dolist (elt tramp-foreign-file-name-handler-alist res)
3386 (setq res (cdr elt)))) 3434 (when (funcall (car elt) filename)
3387 res)) 3435 (setq res (cdr elt))))
3436 res)))
3388 3437
3389 ;; Main function. 3438 ;; Main function.
3390 ;;;###autoload 3439 ;;;###autoload
3391 (defun tramp-file-name-handler (operation &rest args) 3440 (defun tramp-file-name-handler (operation &rest args)
3392 "Invoke tramp file name handler. 3441 "Invoke tramp file name handler.
3521 (concat tramp-prefix-regexp 3570 (concat tramp-prefix-regexp
3522 "\\(" tramp-method-regexp "\\)" tramp-postfix-single-method-regexp "$") 3571 "\\(" tramp-method-regexp "\\)" tramp-postfix-single-method-regexp "$")
3523 file) 3572 file)
3524 (member (match-string 1 file) (mapcar 'car tramp-methods))) 3573 (member (match-string 1 file) (mapcar 'car tramp-methods)))
3525 ((or (equal last-input-event 'tab) 3574 ((or (equal last-input-event 'tab)
3526 (and (not (event-modifiers last-input-event)) 3575 (and (integerp last-input-event)
3527 (integerp last-input-event) 3576 (not (event-modifiers last-input-event))
3528 (or (char-equal last-input-event ?\?) 3577 (or (char-equal last-input-event ?\?)
3529 (char-equal last-input-event ?\t) ; handled by 'tab already? 3578 (char-equal last-input-event ?\t) ; handled by 'tab already?
3530 (char-equal last-input-event ?\ )))) 3579 (char-equal last-input-event ?\ ))))
3531 t))) 3580 t)))
3532 3581
3576 (method (tramp-file-name-method car)) 3625 (method (tramp-file-name-method car))
3577 (user (tramp-file-name-user car)) 3626 (user (tramp-file-name-user car))
3578 (host (tramp-file-name-host car)) 3627 (host (tramp-file-name-host car))
3579 (path (tramp-file-name-path car)) 3628 (path (tramp-file-name-path car))
3580 (m (tramp-find-method multi-method method user host)) 3629 (m (tramp-find-method multi-method method user host))
3630 (tramp-current-user user) ; see `tramp-parse-passwd'
3581 all-user-hosts) 3631 all-user-hosts)
3582 3632
3583 (unless (or multi-method ;; Not handled (yet). 3633 (unless (or multi-method ;; Not handled (yet).
3584 path) ;; Nothing to complete 3634 path) ;; Nothing to complete
3585 3635
3783 (defun tramp-parse-rhosts (filename) 3833 (defun tramp-parse-rhosts (filename)
3784 "Return a list of (user host) tuples allowed to access. 3834 "Return a list of (user host) tuples allowed to access.
3785 Either user or host may be nil." 3835 Either user or host may be nil."
3786 3836
3787 (let (res) 3837 (let (res)
3788 (when (file-exists-p filename) 3838 (when (file-readable-p filename)
3789 (with-temp-buffer 3839 (with-temp-buffer
3790 (insert-file-contents filename) 3840 (insert-file-contents filename)
3791 (goto-char (point-min)) 3841 (goto-char (point-min))
3792 (while (not (eobp)) 3842 (while (not (eobp))
3793 (push (tramp-parse-rhosts-group) res)))) 3843 (push (tramp-parse-rhosts-group) res))))
3820 (defun tramp-parse-shosts (filename) 3870 (defun tramp-parse-shosts (filename)
3821 "Return a list of (user host) tuples allowed to access. 3871 "Return a list of (user host) tuples allowed to access.
3822 User is always nil." 3872 User is always nil."
3823 3873
3824 (let (res) 3874 (let (res)
3825 (when (file-exists-p filename) 3875 (when (file-readable-p filename)
3826 (with-temp-buffer 3876 (with-temp-buffer
3827 (insert-file-contents filename) 3877 (insert-file-contents filename)
3828 (goto-char (point-min)) 3878 (goto-char (point-min))
3829 (while (not (eobp)) 3879 (while (not (eobp))
3830 (push (tramp-parse-shosts-group) res)))) 3880 (push (tramp-parse-shosts-group) res))))
3844 (or 3894 (or
3845 (> (skip-chars-forward ",") 0) 3895 (> (skip-chars-forward ",") 0)
3846 (forward-line 1)) 3896 (forward-line 1))
3847 result)) 3897 result))
3848 3898
3899 (defun tramp-parse-sconfig (filename)
3900 "Return a list of (user host) tuples allowed to access.
3901 User is always nil."
3902
3903 (let (res)
3904 (when (file-readable-p filename)
3905 (with-temp-buffer
3906 (insert-file-contents filename)
3907 (goto-char (point-min))
3908 (while (not (eobp))
3909 (push (tramp-parse-sconfig-group) res))))
3910 res))
3911
3912 (defun tramp-parse-sconfig-group ()
3913 "Return a (user host) tuple allowed to access.
3914 User is always nil."
3915
3916 (let ((result)
3917 (regexp (concat "^[ \t]*Host[ \t]+" "\\(" tramp-host-regexp "\\)")))
3918
3919 (narrow-to-region (point) (tramp-point-at-eol))
3920 (when (re-search-forward regexp nil t)
3921 (setq result (list nil (match-string 1))))
3922 (widen)
3923 (or
3924 (> (skip-chars-forward ",") 0)
3925 (forward-line 1))
3926 result))
3927
3849 (defun tramp-parse-hosts (filename) 3928 (defun tramp-parse-hosts (filename)
3850 "Return a list of (user host) tuples allowed to access. 3929 "Return a list of (user host) tuples allowed to access.
3851 User is always nil." 3930 User is always nil."
3852 3931
3853 (let (res) 3932 (let (res)
3854 (when (file-exists-p filename) 3933 (when (file-readable-p filename)
3855 (with-temp-buffer 3934 (with-temp-buffer
3856 (insert-file-contents filename) 3935 (insert-file-contents filename)
3857 (goto-char (point-min)) 3936 (goto-char (point-min))
3858 (while (not (eobp)) 3937 (while (not (eobp))
3859 (push (tramp-parse-hosts-group) res)))) 3938 (push (tramp-parse-hosts-group) res))))
3874 (or 3953 (or
3875 (> (skip-chars-forward " \t") 0) 3954 (> (skip-chars-forward " \t") 0)
3876 (forward-line 1)) 3955 (forward-line 1))
3877 result)) 3956 result))
3878 3957
3958 ;; For su-alike methods it would be desirable to return "root@localhost"
3959 ;; as default. Unfortunately, we have no information whether any user name
3960 ;; has been typed already. So we (mis-)use tramp-current-user as indication,
3961 ;; assuming it is set in `tramp-completion-handle-file-name-all-completions'.
3879 (defun tramp-parse-passwd (filename) 3962 (defun tramp-parse-passwd (filename)
3880 "Return a list of (user host) tuples allowed to access. 3963 "Return a list of (user host) tuples allowed to access.
3881 Host is always \"localhost\"." 3964 Host is always \"localhost\"."
3882 3965
3883 (let (res) 3966 (let (res)
3884 (if (and (symbolp 'user) (zerop (length user))) 3967 (if (zerop (length tramp-current-user))
3885 '(("root" nil)) 3968 '(("root" nil))
3886 (when (file-exists-p filename) 3969 (when (file-readable-p filename)
3887 (with-temp-buffer 3970 (with-temp-buffer
3888 (insert-file-contents filename) 3971 (insert-file-contents filename)
3889 (goto-char (point-min)) 3972 (goto-char (point-min))
3890 (while (not (eobp)) 3973 (while (not (eobp))
3891 (push (tramp-parse-passwd-group) res)))) 3974 (push (tramp-parse-passwd-group) res))))
3908 (defun tramp-parse-netrc (filename) 3991 (defun tramp-parse-netrc (filename)
3909 "Return a list of (user host) tuples allowed to access. 3992 "Return a list of (user host) tuples allowed to access.
3910 User may be nil." 3993 User may be nil."
3911 3994
3912 (let (res) 3995 (let (res)
3913 (when (file-exists-p filename) 3996 (when (file-readable-p filename)
3914 (with-temp-buffer 3997 (with-temp-buffer
3915 (insert-file-contents filename) 3998 (insert-file-contents filename)
3916 (goto-char (point-min)) 3999 (goto-char (point-min))
3917 (while (not (eobp)) 4000 (while (not (eobp))
3918 (push (tramp-parse-netrc-group) res)))) 4001 (push (tramp-parse-netrc-group) res))))
3936 result)) 4019 result))
3937 4020
3938 (defun tramp-completion-handle-expand-file-name (name &optional dir) 4021 (defun tramp-completion-handle-expand-file-name (name &optional dir)
3939 "Like `expand-file-name' for tramp files." 4022 "Like `expand-file-name' for tramp files."
3940 (let ((fullname (concat (or dir default-directory) name))) 4023 (let ((fullname (concat (or dir default-directory) name)))
3941 (if (tramp-completion-mode fullname) 4024 (tramp-drop-volume-letter
3942 (tramp-run-real-handler 4025 (if (tramp-completion-mode fullname)
3943 'expand-file-name (list name dir)) 4026 (tramp-run-real-handler
3944 (tramp-completion-run-real-handler 4027 'expand-file-name (list name dir))
3945 'expand-file-name (list name dir))))) 4028 (tramp-completion-run-real-handler
4029 'expand-file-name (list name dir))))))
3946 4030
3947 ;;; Internal Functions: 4031 ;;; Internal Functions:
3948 4032
3949 (defun tramp-set-auto-save () 4033 (defun tramp-set-auto-save ()
3950 (when (and (buffer-file-name) 4034 (when (and (buffer-file-name)
5516 ;; CCC: really pop-to-buffer? Maybe it's appropriate to be more 5600 ;; CCC: really pop-to-buffer? Maybe it's appropriate to be more
5517 ;; silent. 5601 ;; silent.
5518 (pop-to-buffer (current-buffer)) 5602 (pop-to-buffer (current-buffer))
5519 (funcall 'signal signal (apply 'format fmt args)))) 5603 (funcall 'signal signal (apply 'format fmt args))))
5520 5604
5521 ;; Chunked sending kluge. 5605 ;; Chunked sending kluge. We set this to 500 just to be on the
5522 (defvar tramp-chunksize nil 5606 ;; safe side; some ssh connections appear to drop bytes when data
5607 ;; is sent too quickly.
5608 ;; This happens when using `ssh' method using GNU Emacs 20.7.1
5609 ;; (hppa1.1-hp-hpux10.20, Motif). (The connection is made to
5610 ;; localhost.)
5611 (defvar tramp-chunksize 500
5523 "If non-nil, chunksize for sending things to remote host.") 5612 "If non-nil, chunksize for sending things to remote host.")
5524 5613
5525 (defun tramp-send-region (multi-method method user host start end) 5614 (defun tramp-send-region (multi-method method user host start end)
5526 "Send the region from START to END to remote command 5615 "Send the region from START to END to remote command
5527 running as USER on HOST using METHOD." 5616 running as USER on HOST using METHOD."
5528 (let ((proc (get-buffer-process 5617 (let ((proc (get-buffer-process
5529 (tramp-get-buffer multi-method method user host)))) 5618 (tramp-get-buffer multi-method method user host))))
5530 (unless proc 5619 (unless proc
5531 (error "Can't send region to remote host -- not logged in")) 5620 (error "Can't send region to remote host -- not logged in"))
5532 (if tramp-chunksize 5621 (if (and tramp-chunksize (not (zerop tramp-chunksize)))
5533 (let ((pos start)) 5622 (let ((pos start))
5534 (while (< pos end) 5623 (while (< pos end)
5535 (tramp-message-for-buffer 5624 (tramp-message-for-buffer
5536 multi-method method user host 10 5625 multi-method method user host 10
5537 "Sending chunk from %s to %s" pos end) 5626 "Sending chunk from %s to %s" pos end)
6437 ;; ** If `partial-completion-mode' isn't loaded, "/foo:bla" tries to 6526 ;; ** If `partial-completion-mode' isn't loaded, "/foo:bla" tries to
6438 ;; connect to host "blabla" already if that host is unique. No idea 6527 ;; connect to host "blabla" already if that host is unique. No idea
6439 ;; how to suppress. Maybe not an essential problem. 6528 ;; how to suppress. Maybe not an essential problem.
6440 ;; ** Try to avoid usage of `last-input-event' in `tramp-completion-mode'. 6529 ;; ** Try to avoid usage of `last-input-event' in `tramp-completion-mode'.
6441 ;; ** Extend `tramp-get-completion-su' for NIS and shadow passwords. 6530 ;; ** Extend `tramp-get-completion-su' for NIS and shadow passwords.
6442 ;; ** Unify `tramp-parse-{rhosts,shosts,hosts,passwd,netrc}'. 6531 ;; ** Unify `tramp-parse-{rhosts,shosts,sconfig,hosts,passwd,netrc}'.
6443 ;; Code is nearly identical. 6532 ;; Code is nearly identical.
6444 ;; ** Decide whiche files to take for searching user/host names depending on 6533 ;; ** Decide whiche files to take for searching user/host names depending on
6445 ;; operating system (windows-nt) in `tramp-completion-function-alist'. 6534 ;; operating system (windows-nt) in `tramp-completion-function-alist'.
6446 ;; ** Enhance variables for debug. 6535 ;; ** Enhance variables for debug.
6447 ;; ** Implement "/multi:" completion. 6536 ;; ** Implement "/multi:" completion.