0
|
1 ;;; ange-ftp.el --- transparent FTP support for GNU Emacs
|
|
2 ;; Keywords: comm
|
|
3
|
|
4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
5 ;;
|
|
6 ;; File: ange-ftp.el
|
|
7 ;; RCS: Header: ange-ftp.el,v 4.20 92/08/14 17:04:34 ange Exp
|
|
8 ;; Description: transparent FTP support for GNU Emacs
|
|
9 ;; Author: Andy Norman, ange@hplb.hpl.hp.com
|
|
10 ;; Created: Thu Oct 12 14:00:05 1989
|
|
11 ;; Modified: Wed May 3 00:50:40 1995 (Andy Norman) ange@hplb.hpl.hp.com
|
|
12 ;; Modified for XEmacs by jwz
|
|
13 ;;
|
|
14 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
15
|
|
16 ;;; Copyright (C) 1989, 1990, 1991, 1992 Andy Norman.
|
|
17 ;;;
|
|
18 ;;; Author: Andy Norman (ange@hplb.hpl.hp.com)
|
|
19 ;;;
|
|
20 ;;; This program is free software; you can redistribute it and/or modify
|
|
21 ;;; it under the terms of the GNU General Public License as published by
|
|
22 ;;; the Free Software Foundation; either version 1, or (at your option)
|
|
23 ;;; any later version.
|
|
24 ;;;
|
|
25 ;;; This program is distributed in the hope that it will be useful,
|
|
26 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
27 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
28 ;;; GNU General Public License for more details.
|
|
29 ;;;
|
|
30 ;;; A copy of the GNU General Public License can be obtained from this
|
|
31 ;;; program's author (send electronic mail to ange@hplb.hpl.hp.com) or from
|
|
32 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
|
|
33 ;;; 02139, USA.
|
|
34
|
|
35 ;;; Synched up with: Not synched with FSF.
|
|
36
|
|
37 ;;; Description:
|
|
38 ;;;
|
|
39 ;;; This package attempts to make accessing files and directories using FTP
|
|
40 ;;; from within GNU Emacs as simple and transparent as possible. A subset of
|
|
41 ;;; the common file-handling routines are extended to interact with FTP.
|
|
42
|
|
43 ;;; Installation:
|
|
44 ;;;
|
|
45 ;;; Byte-compile ange-ftp.el to ange-ftp.elc and put them both in a directory
|
|
46 ;;; on your load-path. Load the package from your .emacs file with:
|
|
47 ;;;
|
|
48 ;;; (require 'ange-ftp).
|
|
49 ;;;
|
|
50 ;;; ange-ftp can't sensibly be auto-loaded; you are either using it, or you
|
|
51 ;;; ain't.
|
|
52
|
|
53 ;;; Usage:
|
|
54 ;;;
|
|
55 ;;; Some of the common GNU Emacs file-handling operations have been made
|
|
56 ;;; FTP-smart. If one of these routines is given a filename that matches
|
|
57 ;;; '/user@host:path' then it will spawn an FTP process connecting to machine
|
|
58 ;;; 'host' as account 'user' and perform its operation on the file 'path'.
|
|
59 ;;;
|
|
60 ;;; For example: if find-file is given a filename of:
|
|
61 ;;;
|
|
62 ;;; /ange@anorman:/tmp/notes
|
|
63 ;;;
|
|
64 ;;; then ange-ftp will spawn an FTP process, connect to the host 'anorman' as
|
|
65 ;;; user 'ange', get the file '/tmp/notes' and pop up a buffer containing the
|
|
66 ;;; contents of that file as if it were on the local filesystem. If ange-ftp
|
|
67 ;;; needed a password to connect then it would prompt the user in the
|
|
68 ;;; minibuffer.
|
|
69
|
|
70 ;;; Extended filename syntax:
|
|
71 ;;;
|
|
72 ;;; The default extended filename syntax is '/user@host:path', where the
|
|
73 ;;; 'user@' part may be omitted. This syntax can be customised to a certain
|
|
74 ;;; extent by changing ange-ftp-path-format. There are limitations.
|
|
75 ;;;
|
|
76 ;;; If the user part is omitted then ange-ftp will generate a default user
|
|
77 ;;; instead whose value depends on the variable ange-ftp-default-user.
|
|
78
|
|
79 ;;; Passwords:
|
|
80 ;;;
|
|
81 ;;; A password is required for each host / user pair. This will be prompted
|
|
82 ;;; for when needed, unless already set by calling ange-ftp-set-passwd, or
|
|
83 ;;; specified in a *valid* ~/.netrc file.
|
|
84
|
|
85 ;;; Passwords for user "anonymous":
|
|
86 ;;;
|
|
87 ;;; Passwords for the user "anonymous" (or "ftp") are handled specially. The
|
|
88 ;;; variable ange-ftp-generate-anonymous-password controls what happens: if
|
|
89 ;;; the value of this variable is a string, then this is used as the password;
|
|
90 ;;; if non-nil, then a password is created from the name of the user and the
|
|
91 ;;; hostname of the machine on which GNU Emacs is running; if nil (the
|
|
92 ;;; default) then the user is prompted for a password as normal.
|
|
93
|
|
94 ;;; "Dumb" UNIX hosts:
|
|
95 ;;;
|
|
96 ;;; The FTP servers on some UNIX machines have problems if the 'ls' command is
|
|
97 ;;; used.
|
|
98 ;;;
|
|
99 ;;; The routine ange-ftp-add-dumb-unix-host can be called to tell ange-ftp to
|
|
100 ;;; limit itself to the DIR command and not 'ls' for a given UNIX host. Note
|
|
101 ;;; that this change will take effect for the current GNU Emacs session only.
|
|
102 ;;; See below for a discussion of non-UNIX hosts. If a large number of
|
|
103 ;;; machines with similar hostnames have this problem then it is easier to set
|
|
104 ;;; the value of ange-ftp-dumb-unix-host-regexp in your .emacs file. ange-ftp
|
|
105 ;;; is unable to automatically recognize dumb unix hosts.
|
|
106
|
|
107 ;;; File name completion:
|
|
108 ;;;
|
|
109 ;;; Full file-name completion is supported on UNIX, VMS, CMS, and MTS hosts.
|
|
110 ;;; To do filename completion, ange-ftp needs a listing from the remote host.
|
|
111 ;;; Therefore, for very slow connections, it might not save any time.
|
|
112
|
|
113 ;;; FTP processes:
|
|
114 ;;;
|
|
115 ;;; When ange-ftp starts up an FTP process, it leaves it running for speed
|
|
116 ;;; purposes. Some FTP servers will close the connection after a period of
|
|
117 ;;; time, but ange-ftp should be able to quietly reconnect the next time that
|
|
118 ;;; the process is needed.
|
|
119 ;;;
|
|
120 ;;; The FTP process will be killed should the associated "*ftp user@host*"
|
|
121 ;;; buffer be deleted. This should not cause ange-ftp any grief.
|
|
122
|
|
123 ;;; Binary file transfers:
|
|
124 ;;;
|
|
125 ;;; By default ange-ftp will transfer files in ASCII mode. If a file being
|
|
126 ;;; transferred matches the value of ange-ftp-binary-file-name-regexp then the
|
|
127 ;;; FTP process will be toggled into BINARY mode before the transfer and back
|
|
128 ;;; to ASCII mode after the transfer.
|
|
129
|
|
130 ;;; Account passwords:
|
|
131 ;;;
|
|
132 ;;; Some FTP servers require an additional password which is sent by the
|
|
133 ;;; ACCOUNT command. ange-ftp partially supports this by allowing the user to
|
|
134 ;;; specify an account password by either calling ange-ftp-set-account, or by
|
|
135 ;;; specifying an account token in the .netrc file. If the account password
|
|
136 ;;; is set by either of these methods then ange-ftp will issue an ACCOUNT
|
|
137 ;;; command upon starting the FTP process.
|
|
138
|
|
139 ;;; Preloading:
|
|
140 ;;;
|
|
141 ;;; ange-ftp can be preloaded, but must be put in the site-init.el file and
|
|
142 ;;; not the site-load.el file in order for the documentation strings for the
|
|
143 ;;; functions being overloaded to be available.
|
|
144
|
|
145 ;;; Status reports:
|
|
146 ;;;
|
|
147 ;;; Most ange-ftp commands that talk to the FTP process output a status
|
|
148 ;;; message on what they are doing. In addition, ange-ftp can take advantage
|
|
149 ;;; of the FTP client's HASH command to display the status of transferring
|
|
150 ;;; files and listing directories. See the documentation for the variables
|
|
151 ;;; ange-ftp-{ascii,binary}-hash-mark-size, ange-ftp-send-hash and
|
|
152 ;;; ange-ftp-process-verbose for more details.
|
|
153
|
|
154 ;;; Gateways:
|
|
155 ;;;
|
|
156 ;;; Sometimes it is neccessary for the FTP process to be run on a different
|
|
157 ;;; machine than the machine running GNU Emacs. This can happen when the
|
|
158 ;;; local machine has restrictions on what hosts it can access.
|
|
159 ;;;
|
|
160 ;;; ange-ftp has support for running the ftp process on a different (gateway)
|
|
161 ;;; machine. The way it works is as follows:
|
|
162 ;;;
|
|
163 ;;; 1) Set the variable 'ange-ftp-gateway-host' to the name of a machine
|
|
164 ;;; that doesn't have the access restrictions.
|
|
165 ;;;
|
|
166 ;;; 2) Set the variable 'ange-ftp-local-host-regexp' to a regular expression
|
|
167 ;;; that matches hosts that can be contacted from running a local ftp
|
|
168 ;;; process, but fails to match hosts that can't be accessed locally. For
|
|
169 ;;; example:
|
|
170 ;;;
|
|
171 ;;; "\\.hp\\.com$\\|^[^.]*$"
|
|
172 ;;;
|
|
173 ;;; will match all hosts that are in the .hp.com domain, or don't have an
|
|
174 ;;; explicit domain in their name, but will fail to match hosts with
|
|
175 ;;; explicit domains or that are specified by their ip address.
|
|
176 ;;;
|
|
177 ;;; 3) Using NFS and symlinks, make sure that there is a shared directory with
|
|
178 ;;; the *same* name between the local machine and the gateway machine.
|
|
179 ;;; This directory is neccessary for temporary files created by ange-ftp.
|
|
180 ;;;
|
|
181 ;;; 4) Set the variable 'ange-ftp-gateway-tmp-name-template' to the name of
|
|
182 ;;; this directory plus an identifying filename prefix. For example:
|
|
183 ;;;
|
|
184 ;;; "/nfs/hplose/ange/ange-ftp"
|
|
185 ;;;
|
|
186 ;;; where /nfs/hplose/ange is a directory that is shared between the
|
|
187 ;;; gateway machine and the local machine.
|
|
188 ;;;
|
|
189 ;;; The simplest way of getting a ftp process running on the gateway machine
|
|
190 ;;; is if you can spawn a remote shell using either 'rsh' or 'remsh'. If you
|
|
191 ;;; can't do this for some reason such as security then points 7 onwards will
|
|
192 ;;; discuss an alternative approach.
|
|
193 ;;;
|
|
194 ;;; 5) Set the variable ange-ftp-gateway-program to the name of the remote
|
|
195 ;;; shell process such as 'remsh' or 'rsh' if the default isn't correct.
|
|
196 ;;;
|
|
197 ;;; 6) Set the variable ange-ftp-gateway-program-interactive to nil if it
|
|
198 ;;; isn't already. This tells ange-ftp that you are using a remote shell
|
|
199 ;;; rather than logging in using telnet or rlogin.
|
|
200 ;;;
|
|
201 ;;; That should be all you need to allow ange-ftp to spawn a ftp process on
|
|
202 ;;; the gateway machine. If you have to use telnet or rlogin to get to the
|
|
203 ;;; gateway machine then follow the instructions below.
|
|
204 ;;;
|
|
205 ;;; 7) Set the variable ange-ftp-gateway-program to the name of the program
|
|
206 ;;; that lets you log onto the gateway machine. This may be something like
|
|
207 ;;; telnet or rlogin.
|
|
208 ;;;
|
|
209 ;;; 8) Set the variable ange-ftp-gateway-prompt-pattern to a regular
|
|
210 ;;; expression that matches the prompt you get when you login to the
|
|
211 ;;; gateway machine. Be very specific here; this regexp must not match
|
|
212 ;;; *anything* in your login banner except this prompt.
|
|
213 ;;; shell-prompt-pattern is far too general as it appears to match some
|
|
214 ;;; login banners from Sun machines. For example:
|
|
215 ;;;
|
|
216 ;;; "^$*$ *"
|
|
217 ;;;
|
|
218 ;;; 9) Set the variable ange-ftp-gateway-program-interactive to 't' to let
|
|
219 ;;; ange-ftp know that it has to "hand-hold" the login to the gateway
|
|
220 ;;; machine.
|
|
221 ;;;
|
|
222 ;;; 10) Set the variable ange-ftp-gateway-setup-term-command to a UNIX command
|
|
223 ;;; that will put the pty connected to the gateway machine into a
|
|
224 ;;; no-echoing mode, and will strip off carriage-returns from output from
|
|
225 ;;; the gateway machine. For example:
|
|
226 ;;;
|
|
227 ;;; "stty -onlcr -echo"
|
|
228 ;;;
|
|
229 ;;; will work on HP-UX machines, whereas:
|
|
230 ;;;
|
|
231 ;;; "stty -echo nl"
|
|
232 ;;;
|
|
233 ;;; appears to work for some Sun machines.
|
|
234 ;;;
|
|
235 ;;; That's all there is to it.
|
|
236
|
|
237 ;;; Smart gateways:
|
|
238 ;;;
|
|
239 ;;; If you have a "smart" ftp program that allows you to issue commands like
|
|
240 ;;; "USER foo@bar" which do nice proxy things, then look at the variables
|
|
241 ;;; ange-ftp-smart-gateway and ange-ftp-smart-gateway-port.
|
|
242
|
|
243 ;;; Tips for using ange-ftp:
|
|
244 ;;;
|
|
245 ;;; 1. For dired to work on a host which marks symlinks with a trailing @ in
|
|
246 ;;; an ls -alF listing, you need to (setq dired-ls-F-marks-symlinks t).
|
|
247 ;;; Most UNIX systems do not do this, but ULTRIX does. If you think that
|
|
248 ;;; there is a chance you might connect to an ULTRIX machine (such as
|
|
249 ;;; prep.ai.mit.edu), then set this variable accordingly. This will have
|
|
250 ;;; the side effect that dired will have problems with symlinks whose names
|
|
251 ;;; end in an @. If you get youself into this situation then editing
|
|
252 ;;; dired's ls-switches to remove "F", will temporarily fix things.
|
|
253 ;;;
|
|
254 ;;; 2. If you know that you are connecting to a certain non-UNIX machine
|
|
255 ;;; frequently, and ange-ftp seems to be unable to guess its host-type,
|
|
256 ;;; then setting the appropriate host-type regexp
|
|
257 ;;; (ange-ftp-vms-host-regexp, ange-ftp-mts-host-regexp, or
|
|
258 ;;; ange-ftp-cms-host-regexp) accordingly should help. Also, please report
|
|
259 ;;; ange-ftp's inability to recognize the host-type as a bug.
|
|
260 ;;;
|
|
261 ;;; 3. For slow connections, you might get "listing unreadable" error
|
|
262 ;;; messages, or get an empty buffer for a file that you know has something
|
|
263 ;;; in it. The solution is to increase the value of ange-ftp-retry-time.
|
|
264 ;;; Its default value is 5 which is plenty for reasonable connections.
|
|
265 ;;; However, for some transatlantic connections I set this to 20.
|
|
266 ;;;
|
|
267 ;;; 4. Beware of compressing files on non-UNIX hosts. Ange-ftp will do it by
|
|
268 ;;; copying the file to the local machine, compressing it there, and then
|
|
269 ;;; sending it back. Binary file transfers between machines of different
|
|
270 ;;; architectures can be a risky business. Test things out first on some
|
|
271 ;;; test files. See "Bugs" below. Also, note that ange-ftp copies files by
|
|
272 ;;; moving them through the local machine. Again, be careful when doing
|
|
273 ;;; this with binary files on non-Unix machines.
|
|
274 ;;;
|
|
275 ;;; 5. Beware that dired over ftp will use your setting of dired-no-confirm
|
|
276 ;;; (list of dired commands for which confirmation is not asked). You
|
|
277 ;;; might want to reconsider your setting of this variable, because you
|
|
278 ;;; might want confirmation for more commands on remote direds than on
|
|
279 ;;; local direds. For example, I strongly recommend that you not include
|
|
280 ;;; compress and uncompress in this list. If there is enough demand it
|
|
281 ;;; might be a good idea to have an alist ange-ftp-dired-no-confirm of
|
|
282 ;;; pairs ( TYPE . LIST ), where TYPE is an operating system type and LIST
|
|
283 ;;; is a list of commands for which confirmation would be suppressed. Then
|
|
284 ;;; remote dired listings would take their (buffer-local) value of
|
|
285 ;;; dired-no-confirm from this alist. Who votes for this?
|
|
286
|
|
287 ;;; ---------------------------------------------------------------------
|
|
288 ;;; Non-UNIX support:
|
|
289 ;;; ---------------------------------------------------------------------
|
|
290
|
|
291 ;;; VMS support:
|
|
292 ;;;
|
|
293 ;;; Ange-ftp has full support for VMS hosts, including tree dired support. It
|
|
294 ;;; should be able to automatically recognize any VMS machine. However, if it
|
|
295 ;;; fails to do this, you can use the command ange-ftp-add-vms-host. As well,
|
|
296 ;;; you can set the variable ange-ftp-vms-host-regexp in your .emacs file. We
|
|
297 ;;; would be grateful if you would report any failures to automatically
|
|
298 ;;; recognize a VMS host as a bug.
|
|
299 ;;;
|
|
300 ;;; Filename Syntax:
|
|
301 ;;;
|
|
302 ;;; For ease of *implementation*, the user enters the VMS filename syntax in a
|
|
303 ;;; UNIX-y way. For example:
|
|
304 ;;; PUB$:[ANONYMOUS.SDSCPUB.NEXT]README.TXT;1
|
|
305 ;;; would be entered as:
|
|
306 ;;; /PUB$$:/ANONYMOUS/SDSCPUB/NEXT/README.TXT;1
|
|
307 ;;; i.e. to log in as anonymous on ymir.claremont.edu and grab the file:
|
|
308 ;;; [.CSV.POLICY]RULES.MEM
|
|
309 ;;; you would type:
|
|
310 ;;; C-x C-f /anonymous@ymir.claremont.edu:CSV/POLICY/RULES.MEM
|
|
311 ;;;
|
|
312 ;;; A legal VMS filename is of the form: FILE.TYPE;##
|
|
313 ;;; where FILE can be up to 39 characters
|
|
314 ;;; TYPE can be up to 39 characters
|
|
315 ;;; ## is a version number (an integer between 1 and 32,767)
|
|
316 ;;; Valid characters in FILE and TYPE are A-Z 0-9 _ - $
|
|
317 ;;; $ cannot begin a filename, and - cannot be used as the first or last
|
|
318 ;;; character.
|
|
319 ;;;
|
|
320 ;;; Tips:
|
|
321 ;;; 1. Although VMS is not case sensitive, EMACS running under UNIX is.
|
|
322 ;;; Therefore, to access a VMS file, you must enter the filename with upper
|
|
323 ;;; case letters.
|
|
324 ;;; 2. To access the latest version of file under VMS, you use the filename
|
|
325 ;;; without the ";" and version number. You should always edit the latest
|
|
326 ;;; version of a file. If you want to edit an earlier version, copy it to a
|
|
327 ;;; new file first. This has nothing to do with ange-ftp, but is simply
|
|
328 ;;; good VMS operating practice. Therefore, to edit FILE.TXT;3 (say 3 is
|
|
329 ;;; latest version), do C-x C-f /ymir.claremont.edu:FILE.TXT. If you
|
|
330 ;;; inadvertently do C-x C-f /ymir.claremont.edu:FILE.TXT;3, you will find
|
|
331 ;;; that VMS will not allow you to save the file because it will refuse to
|
|
332 ;;; overwrite FILE.TXT;3, but instead will want to create FILE.TXT;4, and
|
|
333 ;;; attach the buffer to this file. To get out of this situation, M-x
|
|
334 ;;; write-file /ymir.claremont.edu:FILE.TXT will attach the buffer to
|
|
335 ;;; latest version of the file. For this reason, in tree dired "f"
|
|
336 ;;; (dired-find-file), always loads the file sans version, whereas "v",
|
|
337 ;;; (dired-view-file), always loads the explicit version number. The
|
|
338 ;;; reasoning being that it reasonable to view old versions of a file, but
|
|
339 ;;; not to edit them.
|
|
340 ;;; 3. EMACS has a feature in which it does environment variable substitution
|
|
341 ;;; in filenames. Therefore, to enter a $ in a filename, you must quote it
|
|
342 ;;; by typing $$. There is a bug in EMACS, in that it neglects to quote the
|
|
343 ;;; $'s in the default directory when it writes it in the minibuffer. You
|
|
344 ;;; must edit the minibuffer to quote the $'s manually. Hopefully, this bug
|
|
345 ;;; will be fixed in EMACS 19. If you use Sebastian Kremer's gmhist (V 4.26
|
|
346 ;;; or newer), you will not have this problem.
|
|
347
|
|
348 ;;; MTS support:
|
|
349 ;;;
|
|
350 ;;; Ange-ftp has full support, including tree dired support, for hosts running
|
|
351 ;;; the Michigan terminal system. It should be able to automatically
|
|
352 ;;; recognize any MTS machine. However, if it fails to do this, you can use
|
|
353 ;;; the command ange-ftp-add-mts-host. As well, you can set the variable
|
|
354 ;;; ange-ftp-mts-host-regexp in your .emacs file. We would be grateful if you
|
|
355 ;;; would report any failures to automatically recognize a MTS host as a bug.
|
|
356 ;;;
|
|
357 ;;; Filename syntax:
|
|
358 ;;;
|
|
359 ;;; MTS filenames are entered in a UNIX-y way. For example, if your account
|
|
360 ;;; was YYYY, the file FILE in the account XXXX: on mtsg.ubc.ca would be
|
|
361 ;;; entered as
|
|
362 ;;; /YYYY@mtsg.ubc.ca:/XXXX:/FILE
|
|
363 ;;; In other words, MTS accounts are treated as UNIX directories. Of course,
|
|
364 ;;; to access a file in another account, you must have access permission for
|
|
365 ;;; it. If FILE were in your own account, then you could enter it in a
|
|
366 ;;; relative path fashion as
|
|
367 ;;; /YYYY@mtsg.ubc.ca:FILE
|
|
368 ;;; MTS filenames can be up to 12 characters. Like UNIX, the structure of the
|
|
369 ;;; filename does not contain a TYPE (i.e. it can have as many "."'s as you
|
|
370 ;;; like.) MTS filenames are always in upper case, and hence be sure to enter
|
|
371 ;;; them as such! MTS is not case sensitive, but an EMACS running under UNIX
|
|
372 ;;; is.
|
|
373
|
|
374 ;;; CMS support:
|
|
375 ;;;
|
|
376 ;;; Ange-ftp has full support, including tree dired support, for hosts running
|
|
377 ;;; CMS. It should be able to automatically recognize any CMS machine.
|
|
378 ;;; However, if it fails to do this, you can use the command
|
|
379 ;;; ange-ftp-add-cms-host. As well, you can set the variable
|
|
380 ;;; ange-ftp-cms-host-regexp in your .emacs file. We would be grateful if you
|
|
381 ;;; would report any failures to automatically recognize a CMS host as a bug.
|
|
382 ;;;
|
|
383 ;;; Filename syntax:
|
|
384 ;;;
|
|
385 ;;; CMS filenames are entered in a UNIX-y way. In otherwords, minidisks are
|
|
386 ;;; treated as UNIX directories. For example to access the file READ.ME in
|
|
387 ;;; minidisk *.311 on cuvmb.cc.columbia.edu, you would enter
|
|
388 ;;; /anonymous@cuvmb.cc.columbia.edu:/*.311/READ.ME
|
|
389 ;;; If *.301 is the default minidisk for this account, you could access
|
|
390 ;;; FOO.BAR on this minidisk as
|
|
391 ;;; /anonymous@cuvmb.cc.columbia.edu:FOO.BAR
|
|
392 ;;; CMS filenames are of the form FILE.TYPE, where both FILE and TYPE can be
|
|
393 ;;; up to 8 characters. Again, beware that CMS filenames are always upper
|
|
394 ;;; case, and hence must be entered as such.
|
|
395 ;;;
|
|
396 ;;; Tips:
|
|
397 ;;; 1. CMS machines, with the exception of anonymous accounts, nearly always
|
|
398 ;;; need an account password. To have ange-ftp send an account password,
|
|
399 ;;; you can either include it in your .netrc file, or use
|
|
400 ;;; ange-ftp-set-account.
|
|
401 ;;; 2. Ange-ftp cannot send "write passwords" for a minidisk. Hopefully, we
|
|
402 ;;; can fix this.
|
|
403 ;;;
|
|
404 ;;; ------------------------------------------------------------------
|
|
405 ;;; Bugs:
|
|
406 ;;; ------------------------------------------------------------------
|
|
407 ;;;
|
|
408 ;;; 1. Umask problems:
|
|
409 ;;; Be warned that files created by using ange-ftp will take account of the
|
|
410 ;;; umask of the ftp daemon process rather than the umask of the creating
|
|
411 ;;; user. This is particulary important when logging in as the root user.
|
|
412 ;;; The way that I tighten up the ftp daemon's umask under HP-UX is to make
|
|
413 ;;; sure that the umask is changed to 027 before I spawn /etc/inetd. I
|
|
414 ;;; suspect that there is something similar on other systems.
|
|
415 ;;;
|
|
416 ;;; 2. Some combinations of FTP clients and servers break and get out of sync
|
|
417 ;;; when asked to list a non-existent directory. Some of the ai.mit.edu
|
|
418 ;;; machines cause this problem for some FTP clients. Using
|
|
419 ;;; ange-ftp-kill-process can be used to restart the ftp process, which
|
|
420 ;;; should get things back in synch.
|
|
421 ;;;
|
|
422 ;;; 3. Ange-ftp does not check to make sure that when creating a new file,
|
|
423 ;;; you provide a valid filename for the remote operating system.
|
|
424 ;;; If you do not, then the remote FTP server will most likely
|
|
425 ;;; translate your filename in some way. This may cause ange-ftp to
|
|
426 ;;; get confused about what exactly is the name of the file. The
|
|
427 ;;; most common causes of this are using lower case filenames on systems
|
|
428 ;;; which support only upper case, and using filenames which are too
|
|
429 ;;; long.
|
|
430 ;;;
|
|
431 ;;; 4. Null (blank) passwords confuse both ange-ftp and some FTP daemons.
|
|
432 ;;;
|
|
433 ;;; 5. Ange-ftp likes to use pty's to talk to its FTP processes. If GNU Emacs
|
|
434 ;;; for some reason creates a FTP process that only talks via pipes then
|
|
435 ;;; ange-ftp won't be getting the information it requires at the time that
|
|
436 ;;; it wants it since pipes flush at different times to pty's. One
|
|
437 ;;; disgusting way around this problem is to talk to the FTP process via
|
|
438 ;;; rlogin which does the 'right' things with pty's.
|
|
439 ;;;
|
|
440 ;;; 6. For CMS support, we send too many cd's. Since cd's are cheap, I haven't
|
|
441 ;;; worried about this too much. Eventually, we should have some caching
|
|
442 ;;; of the current minidisk.
|
|
443 ;;;
|
|
444 ;;; 7. Some CMS machines do not assign a default minidisk when you ftp them as
|
|
445 ;;; anonymous. It is then necessary to guess a valid minidisk name, and cd
|
|
446 ;;; to it. This is (understandably) beyond ange-ftp.
|
|
447 ;;;
|
|
448 ;;; 8. Remote to remote copying of files on non-Unix machines can be risky.
|
|
449 ;;; Depending on the variable ange-ftp-binary-file-name-regexp, ange-ftp
|
|
450 ;;; will use binary mode for the copy. Between systems of different
|
|
451 ;;; architecture, this still may not be enough to guarantee the integrity
|
|
452 ;;; of binary files. Binary file transfers from VMS machines are
|
|
453 ;;; particularly problematical. Should ange-ftp-binary-file-name-regexp be
|
|
454 ;;; an alist of OS type, regexp pairs?
|
|
455 ;;;
|
|
456 ;;; 9. The code to do compression of files over ftp is not as careful as it
|
|
457 ;;; should be. It deletes the old remote version of the file, before
|
|
458 ;;; actually checking if the local to remote transfer of the compressed
|
|
459 ;;; file succeeds. Of course to delete the original version of the file
|
|
460 ;;; after transferring the compressed version back is also dangerous,
|
|
461 ;;; because some OS's have severe restrictions on the length of filenames,
|
|
462 ;;; and when the compressed version is copied back the "-Z" or ".Z" may be
|
|
463 ;;; truncated. Then, ange-ftp would delete the only remaining version of
|
|
464 ;;; the file. Maybe ange-ftp should make backups when it compresses files
|
|
465 ;;; (of course, the backup "~" could also be truncated off, sigh...).
|
|
466 ;;; Suggestions?
|
|
467 ;;;
|
|
468
|
|
469 ;;; 10. If a dir listing is attempted for an empty directory on (at least
|
|
470 ;;; some) VMS hosts, an ftp error is given. This is really an ftp bug, and
|
|
471 ;;; I don't know how to get ange-ftp work to around it.
|
|
472 ;;;
|
|
473 ;;; 11. Bombs on filenames that start with a space. Deals well with filenames
|
|
474 ;;; containing spaces, but beware that the remote ftpd may not like them
|
|
475 ;;; much.
|
|
476 ;;;
|
|
477 ;;; 12. No classic dired support for non-UNIX systems. Tree dired was enough.
|
|
478 ;;;
|
|
479 ;;; 13. The famous @ bug. As mentioned above in TIPS, ULTRIX marks symlinks
|
|
480 ;;; with a trailing @ in a ls -alF listing. In order to account for this
|
|
481 ;;; ange-ftp looks to chop trailing @'s off of symlink names when it is
|
|
482 ;;; parsing a listing with the F switch. This will cause ange-ftp to
|
|
483 ;;; incorrectly get the name of a symlink on a non-ULTRIX host if its name
|
|
484 ;;; ends in an @. ange-ftp will correct itself if you take F out of the
|
|
485 ;;; dired ls switches (C-u s will allow you to edit the switches). The
|
|
486 ;;; dired buffer will be automatically reverted, which will allow ange-ftp
|
|
487 ;;; to fix its files hashtable. A cookie to anyone who can think of a
|
|
488 ;;; fast, sure-fire way to recognize ULTRIX over ftp.
|
|
489
|
|
490 ;;; If you find any bugs or problems with this package, PLEASE either e-mail
|
|
491 ;;; the above author, or send a message to the ange-ftp-lovers mailing list
|
|
492 ;;; below. Ideas and constructive comments are especially welcome.
|
|
493
|
|
494 ;;; ange-ftp-lovers:
|
|
495 ;;;
|
|
496 ;;; ange-ftp has its own mailing list modestly called ange-ftp-lovers. All
|
|
497 ;;; users of ange-ftp are welcome to subscribe (see below) and to discuss
|
|
498 ;;; aspects of ange-ftp. New versions of ange-ftp are posted periodically to
|
|
499 ;;; the mailing list.
|
|
500 ;;;
|
|
501 ;;; To [un]subscribe to ange-ftp-lovers, or to report mailer problems with the
|
|
502 ;;; list, please mail one of the following addresses:
|
|
503 ;;;
|
|
504 ;;; ange-ftp-lovers-request@anorman.hpl.hp.com
|
|
505 ;;; or
|
|
506 ;;; ange-ftp-lovers-request%anorman.hpl.hp.com@hplb.hpl.hp.com
|
|
507 ;;;
|
|
508 ;;; Please don't forget the -request part.
|
|
509 ;;;
|
|
510 ;;; For mail to be posted directly to ange-ftp-lovers, send to one of the
|
|
511 ;;; following addresses:
|
|
512 ;;;
|
|
513 ;;; ange-ftp-lovers@anorman.hpl.hp.com
|
|
514 ;;; or
|
|
515 ;;; ange-ftp-lovers%anorman.hpl.hp.com@hplb.hpl.hp.com
|
|
516 ;;;
|
|
517 ;;; Alternatively, there is a mailing list that only gets announcements of new
|
|
518 ;;; ange-ftp releases. This is called ange-ftp-lovers-announce, and can be
|
|
519 ;;; subscribed to by e-mailing to the -request address as above. Please make
|
|
520 ;;; it clear in the request which mailing list you wish to join.
|
|
521
|
|
522 ;;; The latest version of ange-ftp can usually be obtained via anonymous ftp
|
|
523 ;;; from:
|
|
524 ;;; alpha.gnu.ai.mit.edu:ange-ftp/ange-ftp.tar.Z
|
|
525 ;;; or:
|
|
526 ;;; ugle.unit.no:/pub/gnu/emacs-lisp/ange-ftp.tar.Z
|
|
527 ;;; or:
|
|
528 ;;; archive.cis.ohio-state.edu:pub/gnu/emacs/elisp-archive/packages/ange-ftp.tar.Z
|
|
529
|
|
530 ;;; The archives for ange-ftp-lovers can be found via anonymous ftp under:
|
|
531 ;;;
|
|
532 ;;; ftp.reed.edu:pub/mailing-lists/ange-ftp/
|
|
533
|
|
534 ;;; -----------------------------------------------------------
|
|
535 ;;; Technical information on this package:
|
|
536 ;;; -----------------------------------------------------------
|
|
537
|
|
538 ;;; The following GNU Emacs functions are replaced by this package:
|
|
539 ;;;
|
|
540 ;;; write-region
|
|
541 ;;; insert-file-contents
|
|
542 ;;; dired-readin
|
|
543 ;;; dired-revert
|
|
544 ;;; dired-call-process
|
|
545 ;;; diff
|
|
546 ;;; delete-file
|
|
547 ;;; read-file-name-internal
|
|
548 ;;; verify-visited-file-modtime
|
|
549 ;;; directory-files
|
|
550 ;;; backup-buffer
|
|
551 ;;; file-directory-p
|
|
552 ;;; file-writable-p
|
|
553 ;;; file-exists-p
|
|
554 ;;; file-readable-p
|
|
555 ;;; file-symlink-p
|
|
556 ;;; file-attributes
|
|
557 ;;; copy-file
|
|
558 ;;; rename-file
|
|
559 ;;; file-name-as-directory
|
|
560 ;;; file-name-directory
|
|
561 ;;; file-name-nondirectory
|
|
562 ;;; file-name-completion
|
|
563 ;;; directory-file-name
|
|
564 ;;; expand-file-name
|
|
565 ;;; file-name-all-completions
|
|
566
|
|
567 ;;; LISPDIR ENTRY for the Elisp Archive
|
|
568 ;;;
|
|
569 ;;; LCD Archive Entry:
|
|
570 ;;; ange-ftp|Andy Norman|ange@hplb.hpl.hp.com
|
|
571 ;;; |transparent FTP Support for GNU Emacs
|
|
572 ;;; |Date: 92/08/14 17:04:34 |Revision: 4.20 |
|
|
573
|
|
574 ;;; Checklist for adding non-UNIX support for TYPE
|
|
575 ;;;
|
|
576 ;;; The following functions may need TYPE versions:
|
|
577 ;;; (not all functions will be needed for every OS)
|
|
578 ;;;
|
|
579 ;;; ange-ftp-fix-path-for-TYPE
|
|
580 ;;; ange-ftp-fix-dir-path-for-TYPE
|
|
581 ;;; ange-ftp-TYPE-host
|
|
582 ;;; ange-ftp-TYPE-add-host
|
|
583 ;;; ange-ftp-parse-TYPE-listing
|
|
584 ;;; ange-ftp-TYPE-delete-file-entry
|
|
585 ;;; ange-ftp-TYPE-add-file-entry
|
|
586 ;;; ange-ftp-TYPE-file-name-as-directory
|
|
587 ;;;
|
|
588 ;;; Variables:
|
|
589 ;;;
|
|
590 ;;; ange-ftp-TYPE-host-regexp
|
|
591 ;;; May need to add TYPE to ange-ftp-dumb-host-types
|
|
592 ;;;
|
|
593 ;;; Check the following functions for OS dependent coding:
|
|
594 ;;;
|
|
595 ;;; ange-ftp-host-type
|
|
596 ;;; ange-ftp-guess-host-type
|
|
597 ;;; ange-ftp-allow-child-lookup
|
|
598 ;;;
|
|
599 ;;; For Tree Dired support:
|
|
600 ;;;
|
|
601 ;;; ange-ftp-dired-TYPE-insert-headerline
|
|
602 ;;; ange-ftp-dired-TYPE-move-to-filename
|
|
603 ;;; ange-ftp-dired-TYPE-move-to-end-of-filename
|
|
604 ;;; ange-ftp-dired-TYPE-get-filename
|
|
605 ;;; ange-ftp-dired-TYPE-between-files
|
|
606 ;;; ange-ftp-TYPE-make-compressed-filename
|
|
607 ;;; ange-ftp-dired-TYPE-ls-trim
|
|
608 ;;; ange-ftp-TYPE-bob-version
|
|
609 ;;; ange-ftp-dired-TYPE-clean-directory
|
|
610 ;;; ange-ftp-dired-TYPE-flag-backup-files
|
|
611 ;;; ange-ftp-dired-TYPE-backup-diff
|
|
612 ;;;
|
|
613 ;;; Variables for dired:
|
|
614 ;;;
|
|
615 ;;; ange-ftp-dired-TYPE-re-exe
|
|
616 ;;; ange-ftp-dired-TYPE-re-dir
|
|
617
|
|
618 ;;; Host type conventions:
|
|
619 ;;;
|
|
620 ;;; The function ange-ftp-host-type and the variable ange-ftp-dired-host-type
|
|
621 ;;; (mostly) follow the following conventions for remote host types. At
|
|
622 ;;; least, I think that future code should try to follow these conventions,
|
|
623 ;;; and the current code should eventually be made compliant.
|
|
624 ;;;
|
|
625 ;;; nil = local host type, whatever that is (probably unix).
|
|
626 ;;; Think nil as in "not a remote host". This value is used by
|
|
627 ;;; ange-ftp-dired-host-type for local buffers.
|
|
628 ;;;
|
|
629 ;;; t = a remote host of unknown type. Think t is in true, it's remote.
|
|
630 ;;; Currently, 'unix is used as the default remote host type.
|
|
631 ;;; Maybe we should use t.
|
|
632 ;;;
|
|
633 ;;; 'type = a remote host of TYPE type.
|
|
634 ;;;
|
|
635 ;;; 'type:list = a remote host of TYPE type, using a specialized ftp listing
|
|
636 ;;; program called list. This is currently only used for Unix
|
|
637 ;;; dl (descriptive listings), when ange-ftp-dired-host-type
|
|
638 ;;; is set to 'unix:dl.
|
|
639
|
|
640 ;;; Bug report codes:
|
|
641 ;;;
|
|
642 ;;; Because of their naive faith in this code, there are certain situations
|
|
643 ;;; which the writers of this program believe could never happen. However,
|
|
644 ;;; being realists they have put calls to 'error in the program at these
|
|
645 ;;; points. These errors provide a code, which is an integer, greater than 1.
|
|
646 ;;; To aid debugging. the error codes, and the functions in which they reside
|
|
647 ;;; are listed below.
|
|
648 ;;;
|
|
649 ;;; 1: See ange-ftp-ls
|
|
650 ;;;
|
|
651
|
|
652 ;;; XEmacs changes from 4.20
|
|
653 ;;;
|
|
654 ;;; - added gzip support
|
|
655 ;;; - added "lazy" messages
|
|
656 ;;; - fixed completion list in the root dir (nil vs (nil))
|
|
657 ;;; - use (message nil) to repaint minibuf instead of that awful kludge
|
|
658 ;;; - call compute-buffer-file-truename to set truenames properly for
|
|
659 ;;; when find-file-compare-truenames is set
|
|
660 ;;; - make-directory takes a second optional argument
|
|
661 ;;; - made ange-ftp-overwrite-fn use the 19.8 interface to byte-code objects
|
|
662 ;;; - made ange-ftp-shell-mode work better with the latest comint
|
|
663 ;;; - insert-file-contents takes 2-5 args in v19
|
|
664 ;;; - moved invocation of shell-mode to get along with the latest shell-font.el
|
|
665 ;;; - implemented ange-ftp-read-passwd in terms of read-passwd (from passwd.el)
|
|
666 ;;; - initialize all buffer-local variables to nil
|
|
667 ;;; - Apollo stuff from Bob Weiner
|
|
668
|
|
669
|
|
670 ;;; -----------------------------------------------------------
|
|
671 ;;; Hall of fame:
|
|
672 ;;; -----------------------------------------------------------
|
|
673 ;;;
|
|
674 ;;; Thanks to Roland McGrath for improving the filename syntax handling,
|
|
675 ;;; for suggesting many enhancements and for numerous cleanups to the code.
|
|
676 ;;;
|
|
677 ;;; Thanks to Jamie Zawinski for bugfixes and for ideas such as gateways.
|
|
678 ;;;
|
|
679 ;;; Thanks to Ken Laprade for improved .netrc parsing, password reading, and
|
|
680 ;;; dired / shell auto-loading.
|
|
681 ;;;
|
|
682 ;;; Thanks to Sebastian Kremer for tree dired support and for many ideas and
|
|
683 ;;; bugfixes.
|
|
684 ;;;
|
|
685 ;;; Thanks to Joe Wells for bugfixes, the original non-UNIX system support,
|
|
686 ;;; VOS support, and hostname completion.
|
|
687 ;;;
|
|
688 ;;; Thanks to Nakagawa Takayuki for many good ideas, filename-completion, help
|
|
689 ;;; with file-name expansion, efficiency worries, stylistic concerns and many
|
|
690 ;;; bugfixes.
|
|
691 ;;;
|
|
692 ;;; Thanks to Sandy Rutherford who re-wrote most of ange-ftp to support VMS,
|
|
693 ;;; MTS, CMS and UNIX-dls. Sandy also added dired-support for non-UNIX OS and
|
|
694 ;;; auto-recognition of the host type.
|
|
695 ;;;
|
|
696 ;;; Thanks to Dave Smith who wrote the info file for ange-ftp.
|
|
697 ;;;
|
|
698 ;;; Finally, thanks to Keith Waclena, Mark D. Baushke, Terence Kelleher, Ping
|
|
699 ;;; Zhou, Edward Vielmetti, Jack Repenning, Mike Balenger, Todd Kaufmann,
|
|
700 ;;; Kjetil Svarstad, Tom Wurgler, Linus Tolke, Niko Makila, Carl Edman, Bill
|
|
701 ;;; Trost, Dave Brennan, Dan Jacobson, Andy Scott, Steve Anderson, Sanjay
|
|
702 ;;; Mathur, the folks on the ange-ftp-lovers mailing list and many others
|
|
703 ;;; whose names I've forgotten who have helped to debug and fix problems with
|
|
704 ;;; ange-ftp.el.
|
|
705
|
|
706 ;;;; ------------------------------------------------------------
|
|
707 ;;;; User customization variables.
|
|
708 ;;;; ------------------------------------------------------------
|
|
709
|
|
710 ;;;###autoload
|
|
711 (defvar ange-ftp-path-format
|
|
712 '("^/\\(\\([^@/:]*\\)@\\)?\\([^@/:]*\\):\\(.*\\)" . (3 2 4))
|
|
713 "*Format of a fully expanded remote pathname. This is a cons
|
|
714 \(REGEXP . \(HOST USER PATH\)\), where REGEXP is a regular expression matching
|
|
715 the full remote pathname, and HOST, USER, and PATH are the numbers of
|
|
716 parenthesized expressions in REGEXP for the components (in that order).")
|
|
717
|
|
718 ;; ange-ftp-multi-skip-msgs should only match ###-, where ### is one of
|
|
719 ;; the number codes corresponding to ange-ftp-good-msgs or ange-ftp-fatal-msgs.
|
|
720 ;; Otherwise, ange-ftp will go into multi-skip mode, and never come out.
|
|
721
|
|
722 ;; XEmacs patch from Bob Weiner
|
|
723 (defvar ange-ftp-multi-msgs
|
|
724 "^331-\\|^220-\\|^230-\\|^226\\|^25.-\\|^221-\\|^200-\\|^530-\\|^4[25]1-"
|
|
725 "*Regular expression matching messages from the ftp process that start
|
|
726 a multiline reply.")
|
|
727
|
|
728 (defvar ange-ftp-good-msgs
|
|
729 "^220 \\|^230 \\|^226 \\|^25. \\|^221 \\|^200 \\|^[Hh]ash mark"
|
|
730 "*Regular expression matching messages from the ftp process that indicate
|
|
731 that the action that was initiated has completed successfully.")
|
|
732
|
|
733 ;; CMS and the odd VMS machine say 200 Port rather than 200 PORT.
|
|
734 ;; Also CMS machines use a multiline 550- reply to say that you
|
|
735 ;; don't have write permission. ange-ftp gets into multi-line skip
|
|
736 ;; mode and hangs. Have it ignore 550- instead. It will then barf
|
|
737 ;; when it gets the 550 line, as it should.
|
|
738
|
|
739 (defvar ange-ftp-skip-msgs
|
|
740 (concat "^200 \\(PORT\\|Port\\) \\|^331 \\|^150 \\|^350 \\|^[0-9]+ bytes \\|"
|
|
741 "^Connected \\|^$\\|^Remote system\\|^Using\\|^ \\|Password:\\|"
|
|
742 "^local:\\|^Trying\\|^125 \\|^550-\\|^221 .*oodbye")
|
|
743 "*Regular expression matching messages from the ftp process that can be
|
|
744 ignored.")
|
|
745
|
|
746 (defvar ange-ftp-fatal-msgs
|
|
747 (concat "^ftp: \\|^Not connected\\|^530 \\|^4[25]1 \\|rcmd: \\|"
|
|
748 "^No control connection\\|unknown host\\|^lost connection")
|
|
749 "*Regular expression matching messages from the FTP process that indicate
|
|
750 something has gone drastically wrong attempting the action that was
|
|
751 initiated and that the FTP process should (or already has) been killed.")
|
|
752
|
|
753 (defvar ange-ftp-gateway-fatal-msgs
|
|
754 "No route to host\\|Connection closed\\|No such host\\|Login incorrect"
|
|
755 "*Regular expression matching messages from the rlogin / telnet process that
|
|
756 indicates that logging in to the gateway machine has gone wrong.")
|
|
757
|
|
758 (defvar ange-ftp-xfer-size-msgs
|
|
759 "^150 .* connection for .* (\\([0-9]+\\) bytes)"
|
|
760 "*Regular expression used to determine the number of bytes in a FTP transfer.")
|
|
761
|
|
762 (defvar ange-ftp-tmp-name-template "/tmp/ange-ftp"
|
|
763 "*Template used to create temporary files.")
|
|
764
|
|
765 (defvar ange-ftp-gateway-tmp-name-template "/tmp/ange-ftp"
|
|
766 "*Template used to create temporary files when ftp-ing through a gateway.
|
|
767 Files starting with this prefix need to be accessible from BOTH the local
|
|
768 machine and the gateway machine, and need to have the SAME name on both
|
|
769 machines, that is, /tmp is probably NOT what you want, since that is rarely
|
|
770 cross-mounted.")
|
|
771
|
|
772 (defvar ange-ftp-netrc-filename "~/.netrc"
|
|
773 "*File in .netrc format to search for passwords.")
|
|
774
|
|
775 (defvar ange-ftp-disable-netrc-security-check nil
|
|
776 "*If non-nil avoid checking permissions on the .netrc file.")
|
|
777
|
|
778 (defvar ange-ftp-default-user "anonymous"
|
|
779 "*User name to use when none is specied in a pathname.
|
|
780 If nil, then the name under which the user is logged in is used.
|
|
781 If non-nil but not a string, the user is prompted for the name.")
|
|
782
|
|
783 (defvar ange-ftp-default-password nil
|
|
784 "*Password to use when the user is the same as ange-ftp-default-user.")
|
|
785
|
|
786 (defvar ange-ftp-default-account nil
|
|
787 "*Account password to use when the user is the same as ange-ftp-default-user.")
|
|
788
|
|
789 (defvar ange-ftp-generate-anonymous-password t ;; changed wing@666.com
|
|
790 "*If t, use a password of user@host when logging in as the anonymous user.
|
|
791 If a string then use that as the password.
|
|
792 If nil then prompt the user for a password.")
|
|
793
|
|
794 (defvar ange-ftp-dumb-unix-host-regexp nil
|
|
795 "*If non-nil, if the host being ftp'd to matches this regexp then the FTP
|
|
796 process uses the \'dir\' command to get directory information.")
|
|
797
|
|
798 (defvar ange-ftp-binary-file-name-regexp
|
|
799 (concat "\\.g?z$\\|\\.Z$\\|\\.lzh$\\|\\.arc$\\|\\.zip$\\|\\.zoo$\\|\\.tar$\\|"
|
|
800 "\\.dvi$\\|\\.ps$\\|\\.elc$\\|TAGS$\\|\\.gif$\\|"
|
|
801 "\\.EXE\\(;[0-9]+\\)?$\\|\\.g?z-part-..$\\|\\.Z-part-..$")
|
|
802 "*If a file matches this regexp then it is transferred in binary mode.")
|
|
803
|
|
804 (defvar ange-ftp-gateway-host nil
|
|
805 "*Name of host to use as gateway machine when local FTP isn't possible.")
|
|
806
|
|
807 (defvar ange-ftp-local-host-regexp ".*"
|
|
808 "*If a host being FTP'd to matches this regexp then the ftp process is started
|
|
809 locally, otherwise the FTP process is started on \`ange-ftp-gateway-host\'
|
|
810 instead.")
|
|
811
|
|
812 (defvar ange-ftp-gateway-program-interactive nil
|
|
813 "*If non-nil then the gateway program is expected to connect to the gateway
|
|
814 machine and eventually give a shell prompt. Both telnet and rlogin do something
|
|
815 like this.")
|
|
816
|
|
817 (defvar ange-ftp-gateway-program (if (eq system-type 'hpux) "remsh" "rsh")
|
|
818 "*Name of program to spawn a shell on the gateway machine. Valid candidates
|
|
819 are rsh (remsh on hp-ux), telnet and rlogin. See also the gateway variable
|
|
820 above.")
|
|
821
|
|
822 (defvar ange-ftp-gateway-prompt-pattern "^[^#$%>;]*[#$%>;] *"
|
|
823 "*Regexp used to detect that the logging-in sequence is completed on the
|
|
824 gateway machine and that the shell is now awaiting input. Make this regexp as
|
|
825 strict as possible; it shouldn't match *anything* at all except the user's
|
|
826 initial prompt. The above string will fail under most SUN-3's since it
|
|
827 matches the login banner.")
|
|
828
|
|
829 (defvar ange-ftp-gateway-setup-term-command
|
|
830 (if (eq system-type 'hpux)
|
|
831 "stty -onlcr -echo\n"
|
|
832 "stty -echo nl\n")
|
|
833 "*Command to use after logging in to the gateway machine to stop the terminal
|
|
834 echoing each command and to strip out trailing ^M characters.")
|
|
835
|
|
836 (defvar ange-ftp-smart-gateway nil
|
|
837 "*If the gateway FTP is smart enough to use proxy server, then don't bother
|
|
838 telnetting etc, just issue a user@host command instead.")
|
|
839
|
|
840 (defvar ange-ftp-smart-gateway-port "21"
|
|
841 "*Port on gateway machine to use when smart gateway is in operation.")
|
|
842
|
|
843 (defvar ange-ftp-send-hash t
|
|
844 "*If non-nil, send the HASH command to the FTP client.")
|
|
845
|
|
846 (defvar ange-ftp-binary-hash-mark-size nil
|
|
847 "*Default size, in bytes, between hash-marks when transferring a binary file.
|
|
848 If NIL, this variable will be locally overridden if the FTP client outputs a
|
|
849 suitable response to the HASH command. If non-NIL then this value takes
|
|
850 precedence over the local value.")
|
|
851
|
|
852 (defvar ange-ftp-ascii-hash-mark-size 1024
|
|
853 "*Default size, in bytes, between hash-marks when transferring an ASCII file.
|
|
854 This variable is buffer-local and will be locally overridden if the FTP client
|
|
855 outputs a suitable response to the HASH command.")
|
|
856
|
|
857 (defvar ange-ftp-process-verbose t
|
|
858 "*If non-NIL then be chatty about interaction with the FTP process.")
|
|
859
|
|
860 (defvar ange-ftp-ftp-program-name "ftp"
|
|
861 "*Name of FTP program to run.")
|
|
862
|
|
863 (defvar ange-ftp-gateway-ftp-program-name "ftp"
|
|
864 "*Name of FTP program to run on gateway machine.
|
|
865 Some AT&T folks claim to use something called `pftp' here.")
|
|
866
|
|
867 (defvar ange-ftp-ftp-program-args '("-i" "-n" "-g" "-v")
|
|
868 "*A list of arguments passed to the FTP program when started.")
|
|
869
|
|
870 (defvar ange-ftp-nslookup-program nil
|
|
871 "*If non-NIL then a string naming nslookup program." )
|
|
872
|
|
873 (defvar ange-ftp-make-backup-files ()
|
|
874 "*A list of operating systems for which ange-ftp will make Emacs backup
|
2
|
875 files on the remote host. For example, '\(unix\) makes sense, but
|
0
|
876 '\(unix vms\) or '\(vms\) would be silly, since vms makes its own backups.")
|
|
877
|
|
878 (defvar ange-ftp-retry-time 5
|
|
879 "*Number of seconds to wait before retrying if a file or listing
|
|
880 doesn't arrive. This might need to be increased for very slow connections.")
|
|
881
|
|
882 (defvar ange-ftp-auto-save 0
|
|
883 "If 1, allows ange-ftp files to be auto-saved.
|
|
884 If 0, suppresses auto-saving of ange-ftp files.
|
|
885 Don't use any other value.")
|
|
886
|
|
887 ;;;; ------------------------------------------------------------
|
|
888 ;;;; Hash table support.
|
|
889 ;;;; ------------------------------------------------------------
|
|
890
|
|
891 (require 'backquote)
|
|
892
|
|
893 (defun ange-ftp-make-hashtable (&optional size)
|
|
894 "Make an obarray suitable for use as a hashtable.
|
|
895 SIZE, if supplied, should be a prime number."
|
|
896 (make-vector (or size 31) 0))
|
|
897
|
|
898 (defun ange-ftp-map-hashtable (fun tbl)
|
|
899 "Call FUNCTION on each key and value in HASHTABLE."
|
|
900 (mapatoms
|
|
901 (function
|
|
902 (lambda (sym)
|
|
903 (funcall fun (get sym 'key) (get sym 'val))))
|
|
904 tbl))
|
|
905
|
|
906 (defmacro ange-ftp-make-hash-key (key)
|
|
907 "Convert KEY into a suitable key for a hashtable."
|
|
908 (` (if (stringp (, key))
|
|
909 (, key)
|
|
910 (prin1-to-string (, key)))))
|
|
911
|
|
912 (defun ange-ftp-get-hash-entry (key tbl)
|
|
913 "Return the value associated with KEY in HASHTABLE."
|
|
914 (let ((sym (intern-soft (ange-ftp-make-hash-key key) tbl)))
|
|
915 (and sym (get sym 'val))))
|
|
916
|
|
917 (defun ange-ftp-put-hash-entry (key val tbl)
|
|
918 "Record an association between KEY and VALUE in HASHTABLE."
|
|
919 (let ((sym (intern (ange-ftp-make-hash-key key) tbl)))
|
|
920 (put sym 'val val)
|
|
921 (put sym 'key key)))
|
|
922
|
|
923 (defun ange-ftp-del-hash-entry (key tbl)
|
|
924 "Copy all symbols except KEY in HASHTABLE and return modified hashtable."
|
|
925 (let* ((len (length tbl))
|
|
926 (new-tbl (ange-ftp-make-hashtable len))
|
|
927 (i (1- len)))
|
|
928 (ange-ftp-map-hashtable
|
|
929 (function
|
|
930 (lambda (k v)
|
|
931 (or (equal k key)
|
|
932 (ange-ftp-put-hash-entry k v new-tbl))))
|
|
933 tbl)
|
|
934 (while (>= i 0)
|
|
935 (aset tbl i (aref new-tbl i))
|
|
936 (setq i (1- i)))
|
|
937 tbl))
|
|
938
|
|
939 (defun ange-ftp-hash-entry-exists-p (key tbl)
|
|
940 "Return whether there is an association for KEY in TABLE."
|
|
941 (intern-soft (ange-ftp-make-hash-key key) tbl))
|
|
942
|
|
943 (defun ange-ftp-hash-table-keys (tbl)
|
|
944 "Return a sorted list of all the active keys in the hashtable, as strings."
|
|
945 (sort (all-completions "" tbl)
|
|
946 (function string-lessp)))
|
|
947
|
|
948 ;;;; ------------------------------------------------------------
|
|
949 ;;;; Internal variables.
|
|
950 ;;;; ------------------------------------------------------------
|
|
951
|
|
952 (defconst ange-ftp-version "Revision: 4.20.XEmacs")
|
|
953
|
|
954 (defvar ange-ftp-data-buffer-name " *ftp data*"
|
|
955 "Buffer name to hold directory listing data received from ftp process.")
|
|
956
|
|
957 (defvar ange-ftp-netrc-modtime nil
|
|
958 "Last modified time of the netrc file from file-attributes.")
|
|
959
|
|
960 (defvar ange-ftp-user-hashtable (ange-ftp-make-hashtable)
|
|
961 "Hash table holding associations between HOST, USER pairs.")
|
|
962
|
|
963 (defvar ange-ftp-passwd-hashtable (ange-ftp-make-hashtable)
|
|
964 "Mapping between a HOST, USER pair and a PASSWORD for them.")
|
|
965
|
|
966 (defvar ange-ftp-account-hashtable (ange-ftp-make-hashtable)
|
|
967 "Mapping between a HOST, USER pair and a ACCOUNT password for them.")
|
|
968
|
|
969 (defvar ange-ftp-files-hashtable (ange-ftp-make-hashtable 97)
|
|
970 "Hash table for storing directories and their respective files.")
|
|
971
|
|
972 (defvar ange-ftp-ls-cache-lsargs nil
|
|
973 "Last set of args used by ange-ftp-ls.")
|
|
974
|
|
975 (defvar ange-ftp-ls-cache-file nil
|
|
976 "Last file passed to ange-ftp-ls.")
|
|
977
|
|
978 (defvar ange-ftp-ls-cache-res nil
|
|
979 "Last result returned from ange-ftp-ls.")
|
|
980
|
|
981 ;; New error symbols.
|
|
982 ;; XEmacs change
|
|
983 (define-error 'ftp-error "FTP error" 'file-error)
|
|
984
|
|
985 ;;; ------------------------------------------------------------
|
|
986 ;;; Match-data support (stolen from Kyle I think)
|
|
987 ;;; ------------------------------------------------------------
|
|
988
|
|
989 (defmacro ange-ftp-save-match-data (&rest body)
|
|
990 "Execute the BODY forms, restoring the global value of the match data.
|
|
991 Before executing BODY, case-fold-search is locally bound to nil."
|
|
992 (let ((original (make-symbol "match-data"))
|
|
993 case-fold-search)
|
|
994 (list
|
|
995 'let (list (list original '(match-data)))
|
|
996 (list 'unwind-protect
|
|
997 (cons 'progn body)
|
|
998 (list 'store-match-data original)))))
|
|
999
|
|
1000 (put 'ange-ftp-save-match-data 'lisp-indent-hook 0)
|
|
1001 (put 'ange-ftp-save-match-data 'edebug-form-hook '(&rest form))
|
|
1002
|
|
1003 ;;; ------------------------------------------------------------
|
|
1004 ;;; Enhanced message support.
|
|
1005 ;;; ------------------------------------------------------------
|
|
1006
|
|
1007 (defun ange-ftp-message (fmt &rest args)
|
|
1008 "Output the given message, but truncate to the size of the minibuffer
|
|
1009 window."
|
|
1010 (let ((msg (apply (function format) fmt args))
|
|
1011 (max (window-width (minibuffer-window))))
|
|
1012 (if (>= (length msg) max)
|
|
1013 (setq msg (concat "> " (substring msg (- 3 max)))))
|
|
1014 (message "%s" msg)))
|
|
1015
|
|
1016 (defvar ange-ftp-lazy-message-time 0)
|
|
1017 (defun ange-ftp-lazy-message (fmt &rest args)
|
|
1018 "Output the given message, but truncate to the size of the minibuffer
|
|
1019 window, and don't print the message if we've printed another message
|
|
1020 less than one second ago."
|
|
1021 (if (= ange-ftp-lazy-message-time
|
|
1022 (setq ange-ftp-lazy-message-time (nth 1 (current-time))))
|
|
1023 nil
|
|
1024 (apply 'ange-ftp-message fmt args)))
|
|
1025
|
|
1026 (or (fboundp 'current-time) (fset 'ange-ftp-lazy-message 'ange-ftp-message))
|
|
1027
|
|
1028
|
|
1029 (defun ange-ftp-abbreviate-filename (file &optional new)
|
|
1030 "Abbreviate the given filename relative to the default-directory. If the
|
|
1031 optional parameter NEW is given and the non-directory parts match, only return
|
|
1032 the directory part of the file."
|
|
1033 (ange-ftp-save-match-data
|
|
1034 (if (and default-directory
|
|
1035 (string-match (concat "^"
|
|
1036 (regexp-quote default-directory)
|
|
1037 ".") file))
|
|
1038 (setq file (substring file (1- (match-end 0)))))
|
|
1039 (if (and new
|
|
1040 (string-equal (file-name-nondirectory file)
|
|
1041 (file-name-nondirectory new)))
|
|
1042 (setq file (file-name-directory file)))
|
|
1043 (or file "./")))
|
|
1044
|
|
1045 ;;;; ------------------------------------------------------------
|
|
1046 ;;;; User / Host mapping support.
|
|
1047 ;;;; ------------------------------------------------------------
|
|
1048
|
|
1049 (defun ange-ftp-set-user (host user)
|
|
1050 "For a given HOST, set or change the default USER."
|
|
1051 (interactive "sHost: \nsUser: ")
|
|
1052 (ange-ftp-put-hash-entry host user ange-ftp-user-hashtable))
|
|
1053
|
|
1054 (defun ange-ftp-get-user (host)
|
|
1055 "Given a HOST, return the default USER."
|
|
1056 (ange-ftp-parse-netrc)
|
|
1057 (let ((user (ange-ftp-get-hash-entry host ange-ftp-user-hashtable)))
|
|
1058 (or user
|
|
1059 (prog1
|
|
1060 (setq user
|
|
1061 (cond ((stringp ange-ftp-default-user)
|
|
1062 ;; We have a default name. Use it.
|
|
1063 ange-ftp-default-user)
|
|
1064 (ange-ftp-default-user
|
|
1065 ;; Ask the user.
|
|
1066 (let ((enable-recursive-minibuffers t))
|
|
1067 (read-string (format "User for %s: " host)
|
|
1068 (user-login-name))))
|
|
1069 ;; Default to the user's login name.
|
|
1070 (t
|
|
1071 (user-login-name))))
|
|
1072 (ange-ftp-set-user host user)))))
|
|
1073
|
|
1074 ;;;; ------------------------------------------------------------
|
|
1075 ;;;; Password support.
|
|
1076 ;;;; ------------------------------------------------------------
|
|
1077
|
|
1078 (defun ange-ftp-read-passwd (prompt &optional default)
|
|
1079 "Read a password from the user.
|
|
1080 See documentation of `read-passwd' for more info."
|
|
1081 (read-passwd prompt nil default))
|
|
1082
|
|
1083 ;(defun ange-ftp-read-passwd (prompt &optional default)
|
|
1084 ; "Read a password from the user. Echos a . for each character typed.
|
|
1085 ;End with RET, LFD, or ESC. DEL or C-h rubs out. ^U kills line.
|
|
1086 ;Optional DEFAULT is password to start with."
|
|
1087 ; (let ((pass (if default default ""))
|
|
1088 ; (c 0)
|
|
1089 ; (echo-keystrokes 0)
|
|
1090 ; (cursor-in-echo-area t))
|
|
1091 ; (while (and (/= c ?\r) (/= c ?\n) (/= c ?\e))
|
|
1092 ; (message "%s%s"
|
|
1093 ; prompt
|
|
1094 ; (make-string (length pass) ?.))
|
|
1095 ; (setq c (read-char))
|
|
1096 ; (if (= c ?\C-u)
|
|
1097 ; (setq pass "")
|
|
1098 ; (if (and (/= c ?\b) (/= c ?\177))
|
|
1099 ; (setq pass (concat pass (char-to-string c)))
|
|
1100 ; (if (> (length pass) 0)
|
|
1101 ; (setq pass (substring pass 0 -1))))))
|
|
1102 ; (ange-ftp-repaint-minibuffer)
|
|
1103 ; (substring pass 0 -1)))
|
|
1104
|
|
1105 (defmacro ange-ftp-generate-passwd-key (host user)
|
|
1106 (` (concat (, host) "/" (, user))))
|
|
1107
|
|
1108 (defmacro ange-ftp-lookup-passwd (host user)
|
|
1109 (` (ange-ftp-get-hash-entry (ange-ftp-generate-passwd-key (, host) (, user))
|
|
1110 ange-ftp-passwd-hashtable)))
|
|
1111
|
|
1112 (defun ange-ftp-set-passwd (host user passwd)
|
|
1113 "For a given HOST and USER, set or change the associated PASSWORD."
|
|
1114 (interactive (list (read-string "Host: ")
|
|
1115 (read-string "User: ")
|
|
1116 (ange-ftp-read-passwd "Password: ")))
|
|
1117 (ange-ftp-put-hash-entry (ange-ftp-generate-passwd-key host user)
|
|
1118 passwd
|
|
1119 ange-ftp-passwd-hashtable))
|
|
1120
|
|
1121 (defun ange-ftp-get-host-with-passwd (user)
|
|
1122 "Given a USER, return a host we know the password for."
|
|
1123 (ange-ftp-parse-netrc)
|
|
1124 (catch 'found-one
|
|
1125 (ange-ftp-map-hashtable
|
|
1126 (function (lambda (host val)
|
|
1127 (if (ange-ftp-lookup-passwd host user)
|
|
1128 (throw 'found-one host))))
|
|
1129 ange-ftp-user-hashtable)
|
|
1130 (ange-ftp-save-match-data
|
|
1131 (ange-ftp-map-hashtable
|
|
1132 (function
|
|
1133 (lambda (key value)
|
|
1134 (if (string-match "^[^/]*\\(/\\).*$" key)
|
|
1135 (let ((host (substring key 0 (match-beginning 1))))
|
|
1136 (if (and (string-equal user (substring key (match-end 1)))
|
|
1137 value)
|
|
1138 (throw 'found-one host))))))
|
|
1139 ange-ftp-passwd-hashtable))
|
|
1140 nil))
|
|
1141
|
|
1142 (defun ange-ftp-get-passwd (host user)
|
|
1143 "Given a HOST and USER, return the FTP password, prompting if it was not
|
|
1144 previously set."
|
|
1145 (ange-ftp-parse-netrc)
|
|
1146
|
|
1147 ;; look up password in the hash table first; user might have overriden the
|
|
1148 ;; defaults.
|
|
1149 (cond ((ange-ftp-lookup-passwd host user))
|
|
1150
|
|
1151 ;; see if default user and password set from the .netrc file.
|
|
1152 ((and (stringp ange-ftp-default-user)
|
|
1153 ange-ftp-default-password
|
|
1154 (string-equal user ange-ftp-default-user))
|
|
1155 ange-ftp-default-password)
|
|
1156
|
|
1157 ;; anonymous ftp password is handled specially since there is an
|
|
1158 ;; unwritten rule about how that is used on the Internet.
|
|
1159 ((and (or (string-equal user "anonymous")
|
|
1160 (string-equal user "ftp"))
|
|
1161 ange-ftp-generate-anonymous-password)
|
|
1162 (if (stringp ange-ftp-generate-anonymous-password)
|
|
1163 ange-ftp-generate-anonymous-password
|
|
1164 (concat (user-login-name) "@" (system-name))))
|
|
1165
|
|
1166 ;; see if same user has logged in to other hosts; if so then prompt
|
|
1167 ;; with the password that was used there.
|
|
1168 (t
|
|
1169 (let* ((other (ange-ftp-get-host-with-passwd user))
|
|
1170 (passwd (if other
|
|
1171
|
|
1172 ;; found another machine with the same user.
|
|
1173 ;; Try that account.
|
|
1174 (ange-ftp-read-passwd
|
|
1175 (format "passwd for %s@%s (same as %s@%s): "
|
|
1176 user host user other)
|
|
1177 (ange-ftp-lookup-passwd other user))
|
|
1178
|
|
1179 ;; I give up. Ask the user for the password.
|
|
1180 (ange-ftp-read-passwd
|
|
1181 (format "Password for %s@%s: " user host)))))
|
|
1182 (ange-ftp-set-passwd host user passwd)
|
|
1183 passwd))))
|
|
1184
|
|
1185 ;;;; ------------------------------------------------------------
|
|
1186 ;;;; Account support
|
|
1187 ;;;; ------------------------------------------------------------
|
|
1188
|
|
1189 ;; Account passwords must be either specified in the .netrc file, or set
|
|
1190 ;; manually by calling ange-ftp-set-account. For the moment, ange-ftp doesn't
|
|
1191 ;; check to see whether the FTP process is actually prompting for an account
|
|
1192 ;; password.
|
|
1193
|
|
1194 (defun ange-ftp-set-account (host user account)
|
|
1195 "For a given HOST and USER, set or change the associated ACCOUNT password."
|
|
1196 (interactive (list (read-string "Host: ")
|
|
1197 (read-string "User: ")
|
|
1198 (ange-ftp-read-passwd "Account password: ")))
|
|
1199 (ange-ftp-put-hash-entry (ange-ftp-generate-passwd-key host user)
|
|
1200 account
|
|
1201 ange-ftp-account-hashtable))
|
|
1202
|
|
1203 (defun ange-ftp-get-account (host user)
|
|
1204 "Given a HOST and USER, return the FTP account."
|
|
1205 (ange-ftp-parse-netrc)
|
|
1206 (or (ange-ftp-get-hash-entry (ange-ftp-generate-passwd-key host user)
|
|
1207 ange-ftp-account-hashtable)
|
|
1208 (and (stringp ange-ftp-default-user)
|
|
1209 (string-equal user ange-ftp-default-user)
|
|
1210 ange-ftp-default-account)))
|
|
1211
|
|
1212 ;;;; ------------------------------------------------------------
|
|
1213 ;;;; ~/.netrc support
|
|
1214 ;;;; ------------------------------------------------------------
|
|
1215
|
|
1216 (defun ange-ftp-chase-symlinks (file)
|
|
1217 "Return the filename that FILENAME references, following all symbolic links."
|
|
1218 (let (temp)
|
|
1219 (while (setq temp (ange-ftp-real-file-symlink-p file))
|
|
1220 (setq file
|
|
1221 (if (file-name-absolute-p temp)
|
|
1222 temp
|
|
1223 (concat (file-name-directory file) temp)))))
|
|
1224 file)
|
|
1225
|
|
1226 (defun ange-ftp-parse-netrc-token (token limit)
|
|
1227 "Move along current line looking for the value of the TOKEN. Valid
|
|
1228 separators between TOKEN and its value are commas and whitespace.
|
|
1229 Second arg LIMIT is a limit for the search."
|
|
1230 (if (search-forward token limit t)
|
|
1231 (let (beg)
|
|
1232 (skip-chars-forward ", \t\r\n" limit)
|
|
1233 (if (eq (following-char) ?\") ;quoted token value
|
|
1234 (progn (forward-char 1)
|
|
1235 (setq beg (point))
|
|
1236 (skip-chars-forward "^\"" limit)
|
|
1237 (forward-char 1)
|
|
1238 (buffer-substring beg (1- (point))))
|
|
1239 (setq beg (point))
|
|
1240 (skip-chars-forward "^, \t\r\n" limit)
|
|
1241 (buffer-substring beg (point))))))
|
|
1242
|
|
1243 (defun ange-ftp-parse-netrc-group ()
|
|
1244 "Extract the values for the tokens \`machine\', \`login\', \`password\'
|
|
1245 and \`account\' in the current buffer. If successful, record the information
|
|
1246 found."
|
|
1247 (beginning-of-line)
|
|
1248 (let ((start (point))
|
|
1249 (end (progn (re-search-forward "machine\\|default"
|
|
1250 (point-max) 'end 2) (point)))
|
|
1251 machine login password account)
|
|
1252 (goto-char start)
|
|
1253 (setq machine (ange-ftp-parse-netrc-token "machine" end)
|
|
1254 login (ange-ftp-parse-netrc-token "login" end)
|
|
1255 password (ange-ftp-parse-netrc-token "password" end)
|
|
1256 account (ange-ftp-parse-netrc-token "account" end))
|
|
1257 (if (and machine login)
|
|
1258 ;; found a `machine` token.
|
|
1259 (progn
|
|
1260 (ange-ftp-set-user machine login)
|
|
1261 (ange-ftp-set-passwd machine login password)
|
|
1262 (and account
|
|
1263 (ange-ftp-set-account machine login account)))
|
|
1264 (goto-char start)
|
|
1265 (if (search-forward "default" end t)
|
|
1266 ;; found a `default' token
|
|
1267 (progn
|
|
1268 (setq login (ange-ftp-parse-netrc-token "login" end)
|
|
1269 password (ange-ftp-parse-netrc-token "password" end)
|
|
1270 account (ange-ftp-parse-netrc-token "account" end))
|
|
1271 (and login
|
|
1272 (setq ange-ftp-default-user login))
|
|
1273 (and password
|
|
1274 (setq ange-ftp-default-password password))
|
|
1275 (and account
|
|
1276 (setq ange-ftp-default-account account)))))
|
|
1277 (goto-char end)))
|
|
1278
|
|
1279 (defun ange-ftp-parse-netrc ()
|
|
1280 "If ~/.netrc file exists and has the correct permissions then extract the
|
|
1281 \`machine\', \`login\', \`password\' and \`account\' information from within."
|
|
1282
|
|
1283 ;; We set this before actually doing it to avoid the possibility
|
|
1284 ;; of an infinite loop if ange-ftp-netrc-filename is an FTP file.
|
|
1285 (interactive)
|
|
1286 (let* ((file (ange-ftp-chase-symlinks
|
|
1287 (ange-ftp-real-expand-file-name ange-ftp-netrc-filename)))
|
|
1288 (attr (ange-ftp-real-file-attributes file)))
|
|
1289 (if (and attr ; file exists.
|
|
1290 (not (equal (nth 5 attr) ange-ftp-netrc-modtime))) ; file changed
|
|
1291 (ange-ftp-save-match-data
|
|
1292 (if (or ange-ftp-disable-netrc-security-check
|
|
1293 (and (eq (nth 2 attr) (user-uid)) ; Same uids.
|
|
1294 (string-match ".r..------" (nth 8 attr))))
|
|
1295 (save-excursion
|
|
1296 ;; we are cheating a bit here. I'm trying to do the equivalent
|
|
1297 ;; of find-file on the .netrc file, but then nuke it afterwards.
|
|
1298 ;; with the bit of logic below we should be able to have
|
|
1299 ;; encrypted .netrc files.
|
|
1300 (set-buffer (generate-new-buffer "*ftp-.netrc*"))
|
|
1301 (ange-ftp-real-insert-file-contents file)
|
|
1302 (setq buffer-file-name file)
|
|
1303 (setq default-directory (file-name-directory file))
|
|
1304 (normal-mode t)
|
|
1305 (mapcar 'funcall find-file-hooks)
|
|
1306 (setq buffer-file-name nil)
|
|
1307 (goto-char (point-min))
|
|
1308 (while (not (eobp))
|
|
1309 (ange-ftp-parse-netrc-group))
|
|
1310 (kill-buffer (current-buffer)))
|
|
1311 (ange-ftp-message "%s either not owned by you or badly protected."
|
|
1312 ange-ftp-netrc-filename)
|
|
1313 (sit-for 1))
|
|
1314 (setq ange-ftp-netrc-modtime (nth 5 attr))))))
|
|
1315
|
|
1316 (defun ange-ftp-generate-root-prefixes ()
|
|
1317 "Return a list of prefixes of the form 'user@host:' to be used when
|
|
1318 completion is done in the root directory."
|
|
1319 (ange-ftp-parse-netrc)
|
|
1320 (ange-ftp-save-match-data
|
|
1321 (let (res)
|
|
1322 (ange-ftp-map-hashtable
|
|
1323 (function
|
|
1324 (lambda (key value)
|
|
1325 (if (string-match "^[^/]*\\(/\\).*$" key)
|
|
1326 (let ((host (substring key 0 (match-beginning 1)))
|
|
1327 (user (substring key (match-end 1))))
|
|
1328 (setq res (cons (list (concat user "@" host ":"))
|
|
1329 res))))))
|
|
1330 ange-ftp-passwd-hashtable)
|
|
1331 (ange-ftp-map-hashtable
|
|
1332 (function (lambda (host user)
|
|
1333 (setq res (cons (list (concat host ":"))
|
|
1334 res))))
|
|
1335 ange-ftp-user-hashtable)
|
|
1336 ;; (or res (list nil))
|
|
1337 res
|
|
1338 )))
|
|
1339
|
|
1340 ;;;; ------------------------------------------------------------
|
|
1341 ;;;; Remote pathname syntax support.
|
|
1342 ;;;; ------------------------------------------------------------
|
|
1343
|
|
1344 (defmacro ange-ftp-ftp-path-component (n ns path)
|
|
1345 "Extract the Nth ftp path component from NS."
|
|
1346 (` (let ((elt (nth (, n) (, ns))))
|
|
1347 (if (match-beginning elt)
|
|
1348 (substring (, path) (match-beginning elt) (match-end elt))))))
|
|
1349
|
|
1350 (defvar ange-ftp-ftp-path-arg "")
|
|
1351 (defvar ange-ftp-ftp-path-res nil)
|
|
1352
|
|
1353 (defun ange-ftp-ftp-path (path)
|
|
1354 "Parse PATH according to ange-ftp-path-format (which see).
|
|
1355 Returns a list (HOST USER PATH), or nil if PATH does not match the format."
|
|
1356 (if (string-equal path ange-ftp-ftp-path-arg)
|
|
1357 ange-ftp-ftp-path-res
|
|
1358 (setq ange-ftp-ftp-path-arg path
|
|
1359 ange-ftp-ftp-path-res
|
|
1360 (ange-ftp-save-match-data
|
|
1361 (if (string-match (car ange-ftp-path-format) path)
|
|
1362 (let* ((ns (cdr ange-ftp-path-format))
|
|
1363 (host (ange-ftp-ftp-path-component 0 ns path))
|
|
1364 (user (ange-ftp-ftp-path-component 1 ns path))
|
|
1365 (path (ange-ftp-ftp-path-component 2 ns path)))
|
|
1366 (if (zerop (length user))
|
|
1367 (setq user (ange-ftp-get-user host)))
|
|
1368 (list host user path))
|
|
1369 nil)))))
|
|
1370
|
|
1371 (defun ange-ftp-replace-path-component (fullpath path)
|
|
1372 "Take a FULLPATH that matches according to ange-ftp-path-format and
|
|
1373 replace the path component with PATH."
|
|
1374 (ange-ftp-save-match-data
|
|
1375 (if (string-match (car ange-ftp-path-format) fullpath)
|
|
1376 (let* ((ns (cdr ange-ftp-path-format))
|
|
1377 (elt (nth 2 ns)))
|
|
1378 (concat (substring fullpath 0 (match-beginning elt))
|
|
1379 path
|
|
1380 (substring fullpath (match-end elt)))))))
|
|
1381
|
|
1382 ;;;; ------------------------------------------------------------
|
|
1383 ;;;; Miscellaneous utils.
|
|
1384 ;;;; ------------------------------------------------------------
|
|
1385
|
|
1386 (setq ange-ftp-tmp-keymap (make-sparse-keymap))
|
|
1387 (define-key ange-ftp-tmp-keymap "\C-m" 'exit-minibuffer)
|
|
1388
|
|
1389 (defun ange-ftp-repaint-minibuffer ()
|
|
1390 "Gross hack to set minibuf_message = 0, so that the contents of the
|
|
1391 minibuffer will show."
|
|
1392 (if (eq (selected-window) (minibuffer-window))
|
|
1393 (if (string-match "XEmacs" emacs-version)
|
|
1394 (message nil)
|
|
1395 ;; v18 GNU Emacs
|
|
1396 (let ((unread-command-char ?\C-m)
|
|
1397 (enable-recursive-minibuffers t))
|
|
1398 (read-from-minibuffer "" nil ange-ftp-tmp-keymap nil)))))
|
|
1399
|
|
1400 (defun ange-ftp-ftp-process-buffer (host user)
|
|
1401 "Return the name of the buffer that collects output from the ftp process
|
|
1402 connected to the given HOST and USER pair."
|
|
1403 (concat "*ftp " user "@" host "*"))
|
|
1404
|
|
1405 (defun ange-ftp-error (host user msg)
|
|
1406 "Display the last chunk of output from the ftp process for the given HOST
|
|
1407 USER pair, and signal an error including MSG in the text."
|
|
1408 (let ((cur (selected-window))
|
|
1409 (pop-up-windows t))
|
|
1410 (pop-to-buffer
|
|
1411 (get-buffer-create
|
|
1412 (ange-ftp-ftp-process-buffer host user)))
|
|
1413 (goto-char (point-max))
|
|
1414 (select-window cur))
|
|
1415 (signal 'ftp-error (list (format "FTP Error: %s" msg))))
|
|
1416
|
|
1417 (defun ange-ftp-set-buffer-mode ()
|
|
1418 "Set the correct modes for the current buffer if it is visiting a remote
|
|
1419 file."
|
|
1420 (if (and (stringp buffer-file-name)
|
|
1421 (ange-ftp-ftp-path buffer-file-name))
|
|
1422 (progn
|
|
1423 (auto-save-mode ange-ftp-auto-save)
|
|
1424 (make-variable-buffer-local 'revert-buffer-function)
|
|
1425 (setq revert-buffer-function 'ange-ftp-revert-buffer))))
|
|
1426
|
|
1427 (defun ange-ftp-kill-ftp-process (buffer)
|
|
1428 "If the BUFFER's visited filename or default-directory is an ftp filename
|
|
1429 then kill the related ftp process."
|
|
1430 (interactive "bKill FTP process associated with buffer: ")
|
|
1431 (if (null buffer)
|
|
1432 (setq buffer (current-buffer)))
|
|
1433 (let ((file (or (buffer-file-name) default-directory)))
|
|
1434 (if file
|
|
1435 (let ((parsed (ange-ftp-ftp-path (expand-file-name file))))
|
|
1436 (if parsed
|
|
1437 (let ((host (nth 0 parsed))
|
|
1438 (user (nth 1 parsed)))
|
|
1439 (kill-buffer (ange-ftp-ftp-process-buffer host user))))))))
|
|
1440
|
|
1441 (defun ange-ftp-quote-string (string)
|
|
1442 "Quote any characters in STRING that may confuse the ftp process."
|
|
1443 (apply (function concat)
|
|
1444 (mapcar (function
|
|
1445 (lambda (char)
|
|
1446 (if (or (<= char ? )
|
|
1447 (> char ?\~)
|
|
1448 (= char ?\")
|
|
1449 (= char ?\\))
|
|
1450 (vector ?\\ char)
|
|
1451 (vector char))))
|
|
1452 string)))
|
|
1453
|
|
1454 (defun ange-ftp-barf-if-not-directory (directory)
|
|
1455 (or (file-directory-p directory)
|
|
1456 (signal 'file-error
|
|
1457 (list "Opening directory"
|
|
1458 (if (file-exists-p directory)
|
|
1459 "not a directory"
|
|
1460 "no such file or directory")
|
|
1461 directory))))
|
|
1462
|
|
1463 ;;;; ------------------------------------------------------------
|
4
|
1464 ;;;; Remote file name syntax support.
|
|
1465 ;;;; ------------------------------------------------------------
|
|
1466 (defvar ange-ftp-name-format
|
|
1467 '("^/\\(\\([^@/:]*\\)@\\)?\\([^@/:]*[^@/:.]\\):\\(.*\\)" . (3 2 4))
|
|
1468 "*Format of a fully expanded remote file name.
|
|
1469 This is a list of the form \(REGEXP HOST USER NAME\),
|
|
1470 where REGEXP is a regular expression matching
|
|
1471 the full remote name, and HOST, USER, and NAME are the numbers of
|
|
1472 parenthesized expressions in REGEXP for the components (in that order).")
|
|
1473
|
|
1474 (defun ange-ftp-real-load (&rest args)
|
|
1475 (ange-ftp-run-real-handler 'load args))
|
|
1476
|
|
1477 (defmacro ange-ftp-ftp-name-component (n ns name)
|
|
1478 "Extract the Nth ftp file name component from NS."
|
|
1479 (` (let ((elt (nth (, n) (, ns))))
|
|
1480 (if (match-beginning elt)
|
|
1481 (substring (, name) (match-beginning elt) (match-end elt))))))
|
|
1482
|
|
1483 (defvar ange-ftp-ftp-name-arg "")
|
|
1484 (defvar ange-ftp-ftp-name-res nil)
|
|
1485
|
|
1486 ;; Parse NAME according to `ange-ftp-name-format' (which see).
|
|
1487 ;; Returns a list (HOST USER NAME), or nil if NAME does not match the format.
|
|
1488 (defun ange-ftp-ftp-name (name)
|
|
1489 (if (string-equal name ange-ftp-ftp-name-arg)
|
|
1490 ange-ftp-ftp-name-res
|
|
1491 (setq ange-ftp-ftp-name-arg name
|
|
1492 ange-ftp-ftp-name-res
|
|
1493 (save-match-data
|
|
1494 (if (posix-string-match (car ange-ftp-name-format) name)
|
|
1495 (let* ((ns (cdr ange-ftp-name-format))
|
|
1496 (host (ange-ftp-ftp-name-component 0 ns name))
|
|
1497 (user (ange-ftp-ftp-name-component 1 ns name))
|
|
1498 (name (ange-ftp-ftp-name-component 2 ns name)))
|
|
1499 (if (zerop (length user))
|
|
1500 (setq user (ange-ftp-get-user host)))
|
|
1501 (list host user name))
|
|
1502 nil)))))
|
|
1503
|
|
1504 ;; Take a FULLNAME that matches according to ange-ftp-name-format and
|
|
1505 ;; replace the name component with NAME.
|
|
1506 (defun ange-ftp-replace-name-component (fullname name)
|
|
1507 (save-match-data
|
|
1508 (if (posix-string-match (car ange-ftp-name-format) fullname)
|
|
1509 (let* ((ns (cdr ange-ftp-name-format))
|
|
1510 (elt (nth 2 ns)))
|
|
1511 (concat (substring fullname 0 (match-beginning elt))
|
|
1512 name
|
|
1513 (substring fullname (match-end elt)))))))
|
|
1514
|
|
1515 (defun ange-ftp-file-local-copy (file)
|
|
1516 (let* ((fn1 (expand-file-name file))
|
|
1517 (pa1 (ange-ftp-ftp-name fn1)))
|
|
1518 (if pa1
|
|
1519 (let ((tmp1 (ange-ftp-make-tmp-name (car pa1))))
|
|
1520 (ange-ftp-copy-file-internal fn1 tmp1 t nil
|
|
1521 (format "Getting %s" fn1))
|
|
1522 tmp1))))
|
|
1523
|
|
1524 (defun ange-ftp-load (file &optional noerror nomessage nosuffix)
|
|
1525 (if (ange-ftp-ftp-name file)
|
|
1526 (let ((tryfiles (if nosuffix
|
|
1527 (list file)
|
|
1528 (list (concat file ".elc") (concat file ".el") file)))
|
|
1529 copy)
|
|
1530 (while (and tryfiles (not copy))
|
|
1531 (condition-case error
|
|
1532 (setq copy (ange-ftp-file-local-copy (car tryfiles)))
|
|
1533 (ftp-error nil))
|
|
1534 (setq tryfiles (cdr tryfiles)))
|
|
1535 (if copy
|
|
1536 (unwind-protect
|
|
1537 (funcall 'load copy noerror nomessage nosuffix)
|
|
1538 (delete-file copy))
|
|
1539 (or noerror
|
|
1540 (signal 'file-error (list "Cannot open load file" file)))))
|
|
1541 (ange-ftp-real-load file noerror nomessage nosuffix)))
|
|
1542 (put 'load 'ange-ftp 'ange-ftp-load)
|
|
1543
|
|
1544 ;;;; ------------------------------------------------------------
|
0
|
1545 ;;;; FTP process filter support.
|
|
1546 ;;;; ------------------------------------------------------------
|
|
1547
|
|
1548 (defun ange-ftp-process-handle-line (line proc)
|
|
1549 "Look at the given LINE from the ftp process PROC. Try to catagorize it
|
|
1550 into one of four categories: good, skip, fatal, or unknown."
|
|
1551 (cond ((string-match ange-ftp-xfer-size-msgs line)
|
|
1552 (setq ange-ftp-xfer-size
|
|
1553 (ash (string-to-int (substring line
|
|
1554 (match-beginning 1)
|
|
1555 (match-end 1)))
|
|
1556 -10)))
|
|
1557 ((string-match ange-ftp-skip-msgs line)
|
|
1558 (setq ange-ftp-process-multi-skip nil) ;; XEmacs patch (Bob Weiner)
|
|
1559 t)
|
|
1560 ((string-match ange-ftp-good-msgs line)
|
|
1561 (setq ange-ftp-process-busy nil
|
|
1562 ange-ftp-process-result t
|
|
1563 ange-ftp-process-result-line line))
|
|
1564 ((string-match ange-ftp-fatal-msgs line)
|
|
1565 (delete-process proc)
|
|
1566 (setq ange-ftp-process-busy nil
|
|
1567 ange-ftp-process-result-line line))
|
|
1568 ((string-match ange-ftp-multi-msgs line)
|
|
1569 (setq ange-ftp-process-multi-skip t))
|
|
1570 (ange-ftp-process-multi-skip
|
|
1571 t)
|
|
1572 (t
|
|
1573 (setq ange-ftp-process-busy nil
|
|
1574 ange-ftp-process-result-line line))))
|
|
1575
|
|
1576 (defun ange-ftp-process-log-string (proc str)
|
|
1577 "For a given PROCESS, log the given STRING at the end of its
|
|
1578 associated buffer."
|
|
1579 (let ((old-buffer (current-buffer)))
|
|
1580 (unwind-protect
|
|
1581 (let (moving)
|
|
1582 (set-buffer (process-buffer proc))
|
|
1583 (setq moving (= (point) (process-mark proc)))
|
|
1584 (save-excursion
|
|
1585 ;; Insert the text, moving the process-marker.
|
|
1586 (goto-char (process-mark proc))
|
|
1587 (insert str)
|
|
1588 (set-marker (process-mark proc) (point)))
|
|
1589 (if moving (goto-char (process-mark proc))))
|
|
1590 (set-buffer old-buffer))))
|
|
1591
|
|
1592 (defun ange-ftp-set-xfer-size (host user bytes)
|
|
1593 "Set the size of the next FTP transfer in bytes."
|
|
1594 (let ((proc (ange-ftp-get-process host user)))
|
|
1595 (if proc
|
|
1596 (let ((buf (process-buffer proc)))
|
|
1597 (if buf
|
|
1598 (save-excursion
|
|
1599 (set-buffer buf)
|
|
1600 (setq ange-ftp-xfer-size (ash bytes -10))))))))
|
|
1601
|
|
1602 (defun ange-ftp-process-handle-hash (str)
|
|
1603 "Remove hash marks from STRING and display count so far."
|
|
1604 (setq str (concat (substring str 0 (match-beginning 0))
|
|
1605 (substring str (match-end 0)))
|
|
1606 ange-ftp-hash-mark-count (+ (- (match-end 0)
|
|
1607 (match-beginning 0))
|
|
1608 ange-ftp-hash-mark-count))
|
|
1609 (and ange-ftp-process-msg
|
|
1610 ange-ftp-process-verbose
|
|
1611 (not (eq (selected-window) (minibuffer-window)))
|
|
1612 (not (boundp 'search-message)) ;screws up isearch otherwise
|
|
1613 (not cursor-in-echo-area) ;screws up y-or-n-p otherwise
|
|
1614 (let ((kbytes (ash (* ange-ftp-hash-mark-unit
|
|
1615 ange-ftp-hash-mark-count)
|
|
1616 -6)))
|
|
1617 (if (zerop ange-ftp-xfer-size)
|
|
1618 (ange-ftp-lazy-message "%s...%dk" ange-ftp-process-msg kbytes)
|
|
1619 (let ((percent (/ (* 100 kbytes) ange-ftp-xfer-size)))
|
|
1620 ;; cut out the redisplay of identical %-age messages.
|
|
1621 (if (not (eq percent ange-ftp-last-percent))
|
|
1622 (progn
|
|
1623 (setq ange-ftp-last-percent percent)
|
|
1624 (ange-ftp-lazy-message "%s...%d%%"
|
|
1625 ange-ftp-process-msg percent)))))))
|
|
1626 str)
|
|
1627
|
|
1628 (defun ange-ftp-call-cont (cont result line)
|
|
1629 "Call the function specified by CONT. CONT can be either a function or a
|
|
1630 list of a function and some args. The first two parameters passed to the
|
|
1631 function will be RESULT and LINE. The remaining args will be taken from CONT
|
|
1632 if a list was passed."
|
|
1633 (if cont
|
|
1634 (if (and (listp cont)
|
|
1635 (not (eq (car cont) 'lambda)))
|
|
1636 (apply (car cont) result line (cdr cont))
|
|
1637 (funcall cont result line))))
|
|
1638
|
|
1639 (defun ange-ftp-process-filter (proc str)
|
|
1640 "Build up a complete line of output from the ftp PROCESS and pass it
|
|
1641 on to ange-ftp-process-handle-line to deal with."
|
|
1642 (let ((buffer (process-buffer proc))
|
|
1643 (old-buffer (current-buffer)))
|
|
1644
|
|
1645 ;; see if the buffer is still around... it could have been deleted.
|
|
1646 (if (buffer-name buffer)
|
|
1647 (unwind-protect
|
|
1648 (ange-ftp-save-match-data
|
|
1649 (set-buffer (process-buffer proc))
|
|
1650
|
|
1651 ;; handle hash mark printing
|
|
1652 (and ange-ftp-hash-mark-unit
|
|
1653 ange-ftp-process-busy
|
|
1654 (string-match "^#+$" str)
|
|
1655 (setq str (ange-ftp-process-handle-hash str)))
|
|
1656 (ange-ftp-process-log-string proc str)
|
|
1657 (if ange-ftp-process-busy
|
|
1658 (progn
|
|
1659 (setq ange-ftp-process-string (concat ange-ftp-process-string
|
|
1660 str))
|
|
1661
|
|
1662 ;; if we gave an empty password to the USER command earlier
|
|
1663 ;; then we should send a null password now.
|
|
1664 (if (string-match "Password: *$" ange-ftp-process-string)
|
|
1665 (send-string proc "\n"))))
|
|
1666 (while (and ange-ftp-process-busy
|
|
1667 (string-match "\n" ange-ftp-process-string))
|
|
1668 (let ((line (substring ange-ftp-process-string
|
|
1669 0
|
|
1670 (match-beginning 0))))
|
|
1671 (setq ange-ftp-process-string (substring ange-ftp-process-string
|
|
1672 (match-end 0)))
|
|
1673 (while (string-match "^ftp> *" line)
|
|
1674 (setq line (substring line (match-end 0))))
|
|
1675 (ange-ftp-process-handle-line line proc)))
|
|
1676
|
|
1677 ;; has the ftp client finished? if so then do some clean-up
|
|
1678 ;; actions.
|
|
1679 (if (not ange-ftp-process-busy)
|
|
1680 (progn
|
|
1681 ;; reset the xfer size
|
|
1682 (setq ange-ftp-xfer-size 0)
|
|
1683
|
|
1684 ;; issue the "done" message since we've finished.
|
|
1685 (if (and ange-ftp-process-msg
|
|
1686 ange-ftp-process-verbose
|
|
1687 ange-ftp-process-result)
|
|
1688 (progn
|
|
1689 (ange-ftp-message "%s...done" ange-ftp-process-msg)
|
|
1690 (ange-ftp-repaint-minibuffer)
|
|
1691 (setq ange-ftp-process-msg nil)))
|
|
1692
|
|
1693 ;; is there a continuation we should be calling? if so,
|
|
1694 ;; we'd better call it, making sure we only call it once.
|
|
1695 (if ange-ftp-process-continue
|
|
1696 (let ((cont ange-ftp-process-continue))
|
|
1697 (setq ange-ftp-process-continue nil)
|
|
1698 (ange-ftp-call-cont cont
|
|
1699 ange-ftp-process-result
|
|
1700 ange-ftp-process-result-line))))))
|
|
1701 (set-buffer old-buffer)))))
|
|
1702
|
|
1703 (defun ange-ftp-process-sentinel (proc str)
|
|
1704 "When ftp process changes state, nuke all file-entries in cache."
|
|
1705 (ange-ftp-save-match-data
|
|
1706 (let ((name (process-name proc)))
|
|
1707 (if (string-match "\\*ftp \\([^@]+\\)@\\([^*]+\\)*" name)
|
|
1708 (let ((user (substring name (match-beginning 1) (match-end 1)))
|
|
1709 (host (substring name (match-beginning 2) (match-end 2))))
|
|
1710 (ange-ftp-wipe-file-entries host user))))
|
|
1711 (setq ange-ftp-ls-cache-file nil)))
|
|
1712
|
|
1713 ;;;; ------------------------------------------------------------
|
|
1714 ;;;; Gateway support.
|
|
1715 ;;;; ------------------------------------------------------------
|
|
1716
|
|
1717 (defun ange-ftp-use-gateway-p (host)
|
|
1718 "Returns whether to access this host via a normal (non-smart) gateway."
|
|
1719 ;; yes, I know that I could simplify the following expression, but it is
|
|
1720 ;; clearer (to me at least) this way.
|
|
1721 (and (not ange-ftp-smart-gateway)
|
|
1722 (ange-ftp-save-match-data
|
|
1723 (not (string-match ange-ftp-local-host-regexp host)))))
|
|
1724
|
|
1725 (defun ange-ftp-use-smart-gateway-p (host)
|
|
1726 "Returns whether to access this host via a smart gateway."
|
|
1727 (and ange-ftp-smart-gateway
|
|
1728 (ange-ftp-save-match-data
|
|
1729 (not (string-match ange-ftp-local-host-regexp host)))))
|
|
1730
|
|
1731
|
|
1732 ;;; ------------------------------------------------------------
|
|
1733 ;;; Temporary file location and deletion...
|
|
1734 ;;; ------------------------------------------------------------
|
|
1735
|
|
1736 (defvar ange-ftp-tmp-name-files ())
|
|
1737 (defvar ange-ftp-tmp-name-hashtable (ange-ftp-make-hashtable 10))
|
|
1738 (defvar ange-ftp-pid nil)
|
|
1739
|
|
1740 (defun ange-ftp-get-pid ()
|
|
1741 "Half-hearted attempt to get the current process's id."
|
|
1742 (setq ange-ftp-pid (substring (make-temp-name "") 1)))
|
|
1743
|
|
1744 (defun ange-ftp-make-tmp-name (host)
|
|
1745 "This routine will return the name of a new file."
|
|
1746 (let* ((template (if (ange-ftp-use-gateway-p host)
|
|
1747 ange-ftp-gateway-tmp-name-template
|
|
1748 ange-ftp-tmp-name-template))
|
|
1749 (pid (or ange-ftp-pid (ange-ftp-get-pid)))
|
|
1750 (start ?a)
|
|
1751 file entry)
|
|
1752 (while
|
|
1753 (progn
|
|
1754 (setq file (format "%s%c%s" template start pid))
|
|
1755 (setq entry (intern file ange-ftp-tmp-name-hashtable))
|
|
1756 (or (memq entry ange-ftp-tmp-name-files)
|
|
1757 (ange-ftp-real-file-exists-p file)))
|
|
1758 (if (> (setq start (1+ start)) ?z)
|
|
1759 (progn
|
|
1760 (setq template (concat template "X"))
|
|
1761 (setq start ?a))))
|
|
1762 (setq ange-ftp-tmp-name-files
|
|
1763 (cons entry ange-ftp-tmp-name-files))
|
|
1764 file))
|
|
1765
|
|
1766 (defun ange-ftp-del-tmp-name (temp)
|
|
1767 (setq ange-ftp-tmp-name-files
|
|
1768 (delq (intern temp ange-ftp-tmp-name-hashtable)
|
|
1769 ange-ftp-tmp-name-files))
|
|
1770 (condition-case ()
|
|
1771 (ange-ftp-real-delete-file temp)
|
|
1772 (error nil)))
|
|
1773
|
|
1774 ;;;; ------------------------------------------------------------
|
|
1775 ;;;; Interactive gateway program support.
|
|
1776 ;;;; ------------------------------------------------------------
|
|
1777
|
|
1778 (defvar ange-ftp-gwp-running t)
|
|
1779 (defvar ange-ftp-gwp-status nil)
|
|
1780
|
|
1781 (defun ange-ftp-gwp-sentinel (proc str)
|
|
1782 (setq ange-ftp-gwp-running nil))
|
|
1783
|
|
1784 (defun ange-ftp-gwp-filter (proc str)
|
|
1785 (ange-ftp-save-match-data
|
|
1786 (ange-ftp-process-log-string proc str)
|
|
1787 (cond ((string-match "login: *$" str)
|
|
1788 (send-string proc
|
|
1789 (concat
|
|
1790 (let ((ange-ftp-default-user t))
|
|
1791 (ange-ftp-get-user ange-ftp-gateway-host))
|
|
1792 "\n")))
|
|
1793 ((string-match "Password: *$" str)
|
|
1794 (send-string proc
|
|
1795 (concat
|
|
1796 (ange-ftp-get-passwd ange-ftp-gateway-host
|
|
1797 (ange-ftp-get-user
|
|
1798 ange-ftp-gateway-host))
|
|
1799 "\n")))
|
|
1800 ((string-match ange-ftp-gateway-fatal-msgs str)
|
|
1801 (delete-process proc)
|
|
1802 (setq ange-ftp-gwp-running nil))
|
|
1803 ((string-match ange-ftp-gateway-prompt-pattern str)
|
|
1804 (setq ange-ftp-gwp-running nil
|
|
1805 ange-ftp-gwp-status t)))))
|
|
1806
|
|
1807 (defun ange-ftp-gwp-start (host user name args)
|
|
1808 "Login to the gateway machine and fire up an ftp process."
|
|
1809 (let* ((gw-user (ange-ftp-get-user ange-ftp-gateway-host))
|
|
1810 (proc (start-process name name
|
|
1811 ange-ftp-gateway-program
|
|
1812 ange-ftp-gateway-host))
|
|
1813 (ftp (mapconcat (function identity) args " ")))
|
|
1814 (process-kill-without-query proc)
|
|
1815 (set-process-sentinel proc (function ange-ftp-gwp-sentinel))
|
|
1816 (set-process-filter proc (function ange-ftp-gwp-filter))
|
|
1817 (set-marker (process-mark proc) (point))
|
|
1818 (setq ange-ftp-gwp-running t
|
|
1819 ange-ftp-gwp-status nil)
|
|
1820 (ange-ftp-message "Connecting to gateway %s..." ange-ftp-gateway-host)
|
|
1821 (while ange-ftp-gwp-running ;perform login sequence
|
|
1822 (accept-process-output proc))
|
|
1823 (if (not ange-ftp-gwp-status)
|
|
1824 (ange-ftp-error host user "unable to login to gateway"))
|
|
1825 (ange-ftp-message "Connecting to gateway %s...done" ange-ftp-gateway-host)
|
|
1826 (setq ange-ftp-gwp-running t
|
|
1827 ange-ftp-gwp-status nil)
|
|
1828 (process-send-string proc ange-ftp-gateway-setup-term-command)
|
|
1829 (while ange-ftp-gwp-running ;zap ^M's and double echoing.
|
|
1830 (accept-process-output proc))
|
|
1831 (if (not ange-ftp-gwp-status)
|
|
1832 (ange-ftp-error host user "unable to set terminal modes on gateway"))
|
|
1833 (setq ange-ftp-gwp-running t
|
|
1834 ange-ftp-gwp-status nil)
|
|
1835 (process-send-string proc (concat "exec " ftp "\n")) ;spawn ftp process
|
|
1836 proc))
|
|
1837
|
|
1838 ;;;; ------------------------------------------------------------
|
|
1839 ;;;; Support for sending commands to the ftp process.
|
|
1840 ;;;; ------------------------------------------------------------
|
|
1841
|
|
1842 (defun ange-ftp-raw-send-cmd (proc cmd &optional msg cont nowait)
|
|
1843 "Low-level routine to send the given ftp CMD to the ftp PROCESS.
|
|
1844 MSG is an optional message to output before and after the command.
|
|
1845 If CONT is non-NIL then it is either a function or a list of function and
|
|
1846 some arguments. The function will be called when the ftp command has completed.
|
|
1847 If CONT is NIL then this routine will return \( RESULT . LINE \) where RESULT
|
|
1848 is whether the command was successful, and LINE is the line from the FTP
|
|
1849 process that caused the command to complete.
|
|
1850 If NOWAIT is given then the routine will return immediately the command has
|
|
1851 been queued with no result. CONT will still be called, however."
|
|
1852 (if (memq (process-status proc) '(run open))
|
|
1853 (save-excursion
|
|
1854 (set-buffer (process-buffer proc))
|
|
1855 (while ange-ftp-process-busy
|
|
1856 (accept-process-output))
|
|
1857 (setq ange-ftp-process-string ""
|
|
1858 ange-ftp-process-result-line ""
|
|
1859 ange-ftp-process-busy t
|
|
1860 ange-ftp-process-result nil
|
|
1861 ange-ftp-process-multi-skip nil
|
|
1862 ange-ftp-process-msg msg
|
|
1863 ange-ftp-process-continue cont
|
|
1864 ange-ftp-hash-mark-count 0
|
|
1865 ange-ftp-last-percent -1
|
|
1866 cmd (concat cmd "\n"))
|
|
1867 (and msg ange-ftp-process-verbose (ange-ftp-message "%s..." msg))
|
|
1868 (goto-char (point-max))
|
|
1869 ; (move-marker last-input-start (point))
|
|
1870 ;; don't insert the password into the buffer on the USER command.
|
|
1871 (ange-ftp-save-match-data
|
|
1872 (if (string-match "^user \"[^\"]*\"" cmd)
|
|
1873 (insert (substring cmd 0 (match-end 0)) " Turtle Power!\n")
|
|
1874 (insert cmd)))
|
|
1875 ; (move-marker last-input-end (point))
|
|
1876 (send-string proc cmd)
|
|
1877 (set-marker (process-mark proc) (point))
|
|
1878 (if nowait
|
|
1879 nil
|
|
1880 ;; hang around for command to complete
|
|
1881 (while ange-ftp-process-busy
|
|
1882 (accept-process-output proc))
|
|
1883 (if cont
|
|
1884 nil ;cont has already been called
|
|
1885 (cons ange-ftp-process-result ange-ftp-process-result-line))))))
|
|
1886
|
|
1887 (defun ange-ftp-nslookup-host (host)
|
|
1888 "Attempt to resolve the given HOSTNAME using nslookup if possible."
|
|
1889 (interactive "sHost: ")
|
|
1890 (if ange-ftp-nslookup-program
|
|
1891 (let ((proc (start-process " *nslookup*" " *nslookup*"
|
|
1892 ange-ftp-nslookup-program host))
|
|
1893 (res host))
|
|
1894 (process-kill-without-query proc)
|
|
1895 (save-excursion
|
|
1896 (set-buffer (process-buffer proc))
|
|
1897 (while (memq (process-status proc) '(run open))
|
|
1898 (accept-process-output proc))
|
|
1899 (goto-char (point-min))
|
|
1900 (if (re-search-forward "Name:.*\nAddress: *\\(.*\\)$" nil t)
|
|
1901 (setq res (buffer-substring (match-beginning 1)
|
|
1902 (match-end 1))))
|
|
1903 (kill-buffer (current-buffer)))
|
|
1904 res)
|
|
1905 host))
|
|
1906
|
|
1907 (defun ange-ftp-start-process (host user name)
|
|
1908 "Spawn a new ftp process ready to connect to machine HOST and give it NAME.
|
|
1909 If HOST is only ftp-able through a gateway machine then spawn a shell
|
|
1910 on the gateway machine to do the ftp instead."
|
|
1911 (let* ((use-gateway (ange-ftp-use-gateway-p host))
|
|
1912 (ftp-prog (if use-gateway
|
|
1913 ange-ftp-gateway-ftp-program-name
|
|
1914 ange-ftp-ftp-program-name))
|
|
1915 (args (append (list ftp-prog) ange-ftp-ftp-program-args))
|
|
1916 (saved-term-var (getenv "TERM"))
|
|
1917 proc)
|
|
1918 ;; fix problems in losing Linux FTP's, which like to output
|
|
1919 ;; ESC sequences to highlight the ftp prompt, which messes things up
|
|
1920 (unwind-protect
|
|
1921 (progn
|
|
1922 (setenv "TERM" "dumb")
|
|
1923 (if use-gateway
|
|
1924 (if ange-ftp-gateway-program-interactive
|
|
1925 (setq proc (ange-ftp-gwp-start host user name args))
|
|
1926 (setq proc (apply 'start-process name name
|
|
1927 (append (list ange-ftp-gateway-program
|
|
1928 ange-ftp-gateway-host)
|
|
1929 args))))
|
|
1930 (setq proc (apply 'start-process name name args)))
|
|
1931 (process-kill-without-query proc)
|
|
1932 (set-process-sentinel proc (function ange-ftp-process-sentinel))
|
|
1933 (set-process-filter proc (function ange-ftp-process-filter)))
|
|
1934 (setenv "TERM" saved-term-var))
|
|
1935 ;; jwz: turn on shell mode after setting the proc filter for the
|
|
1936 ;; benefit of shell-font.
|
|
1937 (require 'shell)
|
|
1938 (save-excursion
|
|
1939 (set-buffer (process-buffer proc))
|
|
1940 (ange-ftp-shell-mode))
|
|
1941 (accept-process-output proc) ;wait for ftp startup message
|
|
1942 proc))
|
|
1943
|
|
1944 (defun ange-ftp-smart-login (host user pass account proc)
|
|
1945 "Connect to the FTP-server on HOST as USER using PASSWORD and ACCOUNT.
|
|
1946 PROC is the FTP-client's process. This routine uses the smart-gateway
|
|
1947 host specified in ``ange-ftp-gateway-host''."
|
|
1948 (let ((result (ange-ftp-raw-send-cmd
|
|
1949 proc
|
|
1950 (format "open %s %s"
|
|
1951 (ange-ftp-nslookup-host ange-ftp-gateway-host)
|
|
1952 ange-ftp-smart-gateway-port)
|
|
1953 (format "Opening FTP connection to %s via %s"
|
|
1954 host
|
|
1955 ange-ftp-gateway-host))))
|
|
1956 (or (car result)
|
|
1957 (ange-ftp-error host user
|
|
1958 (concat "OPEN request failed: "
|
|
1959 (cdr result))))
|
|
1960 (setq result (ange-ftp-raw-send-cmd
|
|
1961 proc (format "user \"%s\"@%s %s %s"
|
|
1962 user
|
|
1963 (ange-ftp-nslookup-host host)
|
|
1964 pass
|
|
1965 account)
|
|
1966 (format "Logging in as user %s@%s"
|
|
1967 user host)))
|
|
1968 (or (car result)
|
|
1969 (progn
|
|
1970 (ange-ftp-set-passwd host user nil) ; reset password
|
|
1971 (ange-ftp-set-account host user nil) ; reset account
|
|
1972 (ange-ftp-error host user
|
|
1973 (concat "USER request failed: "
|
|
1974 (cdr result)))))))
|
|
1975
|
|
1976 (defun ange-ftp-normal-login (host user pass account proc)
|
|
1977 "Connect to the FTP-server on HOST as USER using PASSWORD and ACCOUNT.
|
|
1978 PROC is the process to the FTP-client."
|
|
1979 (let ((result (ange-ftp-raw-send-cmd
|
|
1980 proc
|
|
1981 (format "open %s" (ange-ftp-nslookup-host host))
|
|
1982 (format "Opening FTP connection to %s" host))))
|
|
1983 (or (car result)
|
|
1984 (ange-ftp-error host user
|
|
1985 (concat "OPEN request failed: "
|
|
1986 (cdr result))))
|
|
1987 (setq result (ange-ftp-raw-send-cmd
|
|
1988 proc
|
|
1989 (format "user \"%s\" %s %s" user pass account)
|
|
1990 (format "Logging in as user %s@%s" user host)))
|
|
1991 (or (car result)
|
|
1992 (progn
|
|
1993 (ange-ftp-set-passwd host user nil) ;reset password.
|
|
1994 (ange-ftp-set-account host user nil) ;reset account.
|
|
1995 (ange-ftp-error host user
|
|
1996 (concat "USER request failed: "
|
|
1997 (cdr result)))))))
|
|
1998
|
|
1999 (defvar ange-ftp-hash-mark-msgs
|
|
2000 "[hH]ash mark [^0-9]*\\([0-9]+\\)"
|
|
2001 "*Regexp matching the FTP client's output upon doing a HASH command.")
|
|
2002
|
|
2003 (defun ange-ftp-guess-hash-mark-size (proc)
|
|
2004 (if ange-ftp-send-hash
|
|
2005 (save-excursion
|
|
2006 (set-buffer (process-buffer proc))
|
|
2007 (let* ((status (ange-ftp-raw-send-cmd proc "hash"))
|
|
2008 (result (car status))
|
|
2009 (line (cdr status)))
|
|
2010 (ange-ftp-save-match-data
|
|
2011 (if (string-match ange-ftp-hash-mark-msgs line)
|
|
2012 (let ((size (string-to-int
|
|
2013 (substring line
|
|
2014 (match-beginning 1)
|
|
2015 (match-end 1)))))
|
|
2016 (setq ange-ftp-ascii-hash-mark-size size
|
|
2017 ange-ftp-hash-mark-unit (ash size -4))
|
|
2018
|
|
2019 ;; if a default value for this is set, use that value.
|
|
2020 (or ange-ftp-binary-hash-mark-size
|
|
2021 (setq ange-ftp-binary-hash-mark-size size)))))))))
|
|
2022
|
|
2023 (defun ange-ftp-get-process (host user)
|
|
2024 "Return the process object for a FTP process connected to HOST and
|
|
2025 logged in as USER. Create a new process if needed."
|
|
2026 (let* ((name (ange-ftp-ftp-process-buffer host user))
|
|
2027 (proc (get-process name)))
|
|
2028 (if (and proc (memq (process-status proc) '(run open)))
|
|
2029 proc
|
|
2030 (let ((pass (ange-ftp-quote-string
|
|
2031 (ange-ftp-get-passwd host user)))
|
|
2032 (account (ange-ftp-quote-string
|
|
2033 (ange-ftp-get-account host user))))
|
|
2034 ;; grab a suitable process.
|
|
2035 (setq proc (ange-ftp-start-process host user name))
|
|
2036
|
|
2037 ;; login to FTP server.
|
|
2038 (if (ange-ftp-use-smart-gateway-p host)
|
|
2039 (ange-ftp-smart-login host user pass account proc)
|
|
2040 (ange-ftp-normal-login host user pass account proc))
|
|
2041
|
|
2042 ;; Tell client to send back hash-marks as progress. It isn't usually
|
|
2043 ;; fatal if this command fails.
|
|
2044 (ange-ftp-guess-hash-mark-size proc)
|
|
2045
|
|
2046 ;; Guess at the host type.
|
|
2047 (ange-ftp-guess-host-type host user)
|
|
2048
|
|
2049 ;; Run any user-specified hooks. Note that proc, host and user are
|
|
2050 ;; dynamically bound at this point.
|
|
2051 (run-hooks 'ange-ftp-process-startup-hook))
|
|
2052 proc)))
|
|
2053
|
|
2054 ;; Variables for caching host and host-type
|
|
2055 (defvar ange-ftp-host-cache nil)
|
|
2056 (defvar ange-ftp-host-type-cache nil)
|
|
2057
|
|
2058 ;; If ange-ftp-host-type is called with the optional user
|
|
2059 ;; argument, it will attempt to guess the host type by connecting
|
|
2060 ;; as user, if necessary. For efficiency, I have tried to give this
|
|
2061 ;; optional second argument only when necessary. Have I missed any calls
|
|
2062 ;; to ange-ftp-host-type where it should have been supplied?
|
|
2063
|
|
2064 (defun ange-ftp-host-type (host &optional user)
|
|
2065 "Return a symbol which represents the type of the HOST given.
|
|
2066 If the optional argument USER is given, attempts to guess the
|
|
2067 host-type by logging in as USER."
|
|
2068 (if (eq host ange-ftp-host-cache)
|
|
2069 ange-ftp-host-type-cache
|
|
2070 ;; Trigger an ftp connection, in case we need to guess at the host type.
|
|
2071 (if (and user (ange-ftp-get-process host user) (eq host ange-ftp-host-cache))
|
|
2072 ange-ftp-host-type-cache
|
|
2073 (setq ange-ftp-host-cache host
|
|
2074 ange-ftp-host-type-cache
|
|
2075 (cond ((ange-ftp-dumb-unix-host host)
|
|
2076 'dumb-unix)
|
|
2077 ((and (fboundp 'ange-ftp-vos-host)
|
|
2078 (ange-ftp-vos-host host))
|
|
2079 'vos)
|
|
2080 ((and (fboundp 'ange-ftp-vms-host)
|
|
2081 (ange-ftp-vms-host host))
|
|
2082 'vms)
|
|
2083 ((and (fboundp 'ange-ftp-mts-host)
|
|
2084 (ange-ftp-mts-host host))
|
|
2085 'mts)
|
|
2086 ((and (fboundp 'ange-ftp-cms-host)
|
|
2087 (ange-ftp-cms-host host))
|
|
2088 'cms)
|
|
2089 (t
|
|
2090 'unix))))))
|
|
2091
|
|
2092 ;; It would be nice to abstract the functions ange-ftp-TYPE-host and
|
|
2093 ;; ange-ftp-add-TYPE-host. The trick is to abstract these functions
|
|
2094 ;; without sacrificing speed. Also, having separate variables
|
|
2095 ;; ange-ftp-TYPE-regexp is more user friendly then requiring the user to
|
|
2096 ;; set an alist to indicate that a host is of a given type. Even with
|
|
2097 ;; automatic host type recognition, setting a regexp is still a good idea
|
|
2098 ;; (for efficiency) if you log into a particular non-UNIX host frequently.
|
|
2099
|
|
2100 (defvar ange-ftp-fix-path-func-alist nil
|
|
2101 "Association list of \( TYPE \. FUNC \) pairs, where FUNC is a routine
|
|
2102 which can change a UNIX path into a path more suitable for a host of type
|
|
2103 TYPE.")
|
|
2104
|
|
2105 (defvar ange-ftp-fix-dir-path-func-alist nil
|
|
2106 "Association list of \( TYPE \. FUNC \) pairs, where FUNC is a routine
|
|
2107 which can change UNIX directory path into a directory path more suitable
|
|
2108 for a host of type TYPE.")
|
|
2109
|
|
2110 ;; *** Perhaps the sense of this variable should be inverted, since there
|
|
2111 ;; *** is only 1 host type that can take ls-style listing options.
|
|
2112 (defvar ange-ftp-dumb-host-types '(dumb-unix)
|
|
2113 "List of host types that can't take UNIX ls-style listing options.")
|
|
2114
|
|
2115 (defun ange-ftp-send-cmd (host user cmd &optional msg cont nowait)
|
|
2116 "Find an ftp process connected to HOST logged in as USER and send it CMD.
|
|
2117 MSG is an optional status message to be output before and after issuing the
|
|
2118 command.
|
|
2119 See the documentation for ange-ftp-raw-send-cmd for a description of CONT
|
|
2120 and NOWAIT."
|
|
2121 ;; Handle conversion to remote pathname syntax and remote ls option
|
|
2122 ;; capability.
|
|
2123 (let ((cmd0 (car cmd))
|
|
2124 (cmd1 (nth 1 cmd))
|
|
2125 cmd2 cmd3 host-type fix-pathname-func)
|
|
2126
|
|
2127 (cond
|
|
2128
|
|
2129 ;; pwd case (We don't care what host-type.)
|
|
2130 ((null cmd1))
|
|
2131
|
|
2132 ;; cmd == 'dir "remote-path" "local-path" "ls-switches"
|
|
2133 ((progn
|
|
2134 (setq cmd2 (nth 2 cmd)
|
|
2135 host-type (ange-ftp-host-type host user))
|
|
2136 ;; This will trigger an FTP login, if one doesn't exist
|
|
2137 (eq cmd0 'dir))
|
|
2138 (setq cmd1 (funcall
|
|
2139 (or (cdr (assq host-type ange-ftp-fix-dir-path-func-alist))
|
|
2140 'identity)
|
|
2141 cmd1)
|
|
2142 cmd3 (nth 3 cmd))
|
|
2143 ;; Need to deal with the HP-UX ftp bug. This should also allow
|
|
2144 ;; us to resolve symlinks to directories on SysV machines. (Sebastian will
|
|
2145 ;; be happy.)
|
|
2146 (and (eq host-type 'unix)
|
|
2147 (string-match "/$" cmd1)
|
|
2148 (not (string-match "R" cmd3))
|
|
2149 (setq cmd1 (concat cmd1 ".")))
|
|
2150 ;; If the remote ls can take switches, put them in
|
|
2151 (or (memq host-type ange-ftp-dumb-host-types)
|
|
2152 (setq cmd0 'ls
|
|
2153 cmd1 (format "\"%s %s\"" cmd3 cmd1))))
|
|
2154
|
|
2155 ;; First argument is the remote pathname
|
|
2156 ((progn
|
|
2157 (setq fix-pathname-func (or (cdr (assq host-type
|
|
2158 ange-ftp-fix-path-func-alist))
|
|
2159 'identity))
|
|
2160 (memq cmd0 '(get delete mkdir rmdir cd)))
|
|
2161 (setq cmd1 (funcall fix-pathname-func cmd1)))
|
|
2162
|
|
2163 ;; Second argument is the remote pathname
|
|
2164 ((memq cmd0 '(append put chmod))
|
|
2165 (setq cmd2 (funcall fix-pathname-func cmd2)))
|
|
2166
|
|
2167 ;; Both arguments are remote pathnames
|
|
2168 ((eq cmd0 'rename)
|
|
2169 (setq cmd1 (funcall fix-pathname-func cmd1)
|
|
2170 cmd2 (funcall fix-pathname-func cmd2))))
|
|
2171
|
|
2172 ;; Turn the command into one long string
|
|
2173 (setq cmd0 (symbol-name cmd0))
|
|
2174 (setq cmd (concat cmd0
|
|
2175 (and cmd1 (concat " " cmd1))
|
|
2176 (and cmd2 (concat " " cmd2))))
|
|
2177
|
|
2178 ;; Actually send the resulting command.
|
|
2179 (let (afsc-result
|
|
2180 afsc-line)
|
|
2181 (ange-ftp-raw-send-cmd
|
|
2182 (ange-ftp-get-process host user)
|
|
2183 cmd
|
|
2184 msg
|
|
2185 (list
|
|
2186 (function (lambda (result line host user
|
|
2187 cmd msg cont nowait)
|
|
2188 (or cont
|
|
2189 (setq afsc-result result
|
|
2190 afsc-line line))
|
|
2191 (if result
|
|
2192 (ange-ftp-call-cont cont result line)
|
|
2193 (ange-ftp-raw-send-cmd
|
|
2194 (ange-ftp-get-process host user)
|
|
2195 cmd
|
|
2196 msg
|
|
2197 (list
|
|
2198 (function (lambda (result line cont)
|
|
2199 (or cont
|
|
2200 (setq afsc-result result
|
|
2201 afsc-line line))
|
|
2202 (ange-ftp-call-cont cont result line)))
|
|
2203 cont)
|
|
2204 nowait))))
|
|
2205 host user cmd msg cont nowait)
|
|
2206 nowait)
|
|
2207
|
|
2208 (if nowait
|
|
2209 nil
|
|
2210 (if cont
|
|
2211 nil
|
|
2212 (cons afsc-result afsc-line))))))
|
|
2213
|
|
2214 ;; It might be nice to message users about the host type identified,
|
|
2215 ;; but there is so much other messaging going on, it would not be
|
|
2216 ;; seen. No point in slowing things down just so users can read
|
|
2217 ;; a host type message.
|
|
2218
|
|
2219 (defconst ange-ftp-cms-path-template
|
|
2220 (concat
|
|
2221 "^[-A-Z0-9$*][-A-Z0-9$*]?[-A-Z0-9$*]?[-A-Z0-9$*]?[-A-Z0-9$*]?"
|
|
2222 "[-A-Z0-9$*]?[-A-Z0-9$*]?[-A-Z0-9$*]?\\.[0-9][0-9][0-9A-Z]$"))
|
|
2223 (defconst ange-ftp-vms-path-template
|
|
2224 "^[-A-Z0-9_$]+:\\[[-A-Z0-9_$]+\\(\\.[-A-Z0-9_$]+\\)*\\]$")
|
|
2225 (defconst ange-ftp-mts-path-template
|
|
2226 "^[A-Z0-9._][A-Z0-9._][A-Z0-9._][A-Z0-9._]:$")
|
|
2227
|
|
2228 (defun ange-ftp-guess-host-type (host user)
|
2
|
2229 "Guess at the host type of HOST by doing a pwd, and examining
|
0
|
2230 the directory syntax."
|
|
2231 (let ((host-type (ange-ftp-host-type host))
|
|
2232 (key (concat host "/" user "/~")))
|
|
2233 (if (eq host-type 'unix)
|
|
2234 ;; Note that ange-ftp-host-type returns unix as the default value.
|
|
2235 (ange-ftp-save-match-data
|
|
2236 (let* ((result (ange-ftp-get-pwd host user))
|
|
2237 (dir (car result))
|
|
2238 fix-path-func)
|
|
2239 (cond ((null dir)
|
|
2240 (message "Warning! Unable to get home directory")
|
|
2241 (sit-for 1)
|
|
2242 (if (string-match
|
|
2243 "^450 No current working directory defined$"
|
|
2244 (cdr result))
|
|
2245
|
|
2246 ;; We'll assume that if pwd bombs with this
|
|
2247 ;; error message, then it's CMS.
|
|
2248 (progn
|
|
2249 (ange-ftp-add-cms-host host)
|
|
2250 (setq ange-ftp-host-cache host
|
|
2251 ange-ftp-host-type-cache 'cms))))
|
|
2252
|
|
2253 ;; try for VMS
|
|
2254 ((string-match ange-ftp-vms-path-template dir)
|
|
2255 (ange-ftp-add-vms-host host)
|
|
2256 ;; The add-host functions clear the host type cache.
|
|
2257 ;; Therefore, need to set the cache afterwards.
|
|
2258 (setq ange-ftp-host-cache host
|
|
2259 ange-ftp-host-type-cache 'vms))
|
|
2260
|
|
2261 ;; try for MTS
|
|
2262 ((string-match ange-ftp-mts-path-template dir)
|
|
2263 (ange-ftp-add-mts-host host)
|
|
2264 (setq ange-ftp-host-cache host
|
|
2265 ange-ftp-host-type-cache 'mts))
|
|
2266
|
|
2267 ;; try for CMS
|
|
2268 ((string-match ange-ftp-cms-path-template dir)
|
|
2269 (ange-ftp-add-cms-host host)
|
|
2270 (setq ange-ftp-host-cache host
|
|
2271 ange-ftp-host-type-cache 'cms))
|
|
2272
|
|
2273 ;; assume UN*X
|
|
2274 (t
|
|
2275 (setq ange-ftp-host-cache host
|
|
2276 ange-ftp-host-type-cache 'unix)))
|
|
2277
|
|
2278 ;; Now that we have done a pwd, might as well put it in
|
|
2279 ;; the expand-dir hashtable.
|
|
2280 (setq fix-path-func (cdr (assq ange-ftp-host-type-cache
|
|
2281 ange-ftp-fix-path-func-alist)))
|
|
2282 (if fix-path-func
|
|
2283 (setq dir (funcall fix-path-func dir 'reverse)))
|
|
2284 (ange-ftp-put-hash-entry key dir
|
|
2285 ange-ftp-expand-dir-hashtable))))
|
|
2286
|
|
2287 ;; In the special case of CMS make sure that know the
|
|
2288 ;; expansion of the home minidisk now, because we will
|
|
2289 ;; be doing a lot of cd's.
|
|
2290 (if (and (eq host-type 'cms)
|
|
2291 (not (ange-ftp-hash-entry-exists-p
|
|
2292 key ange-ftp-expand-dir-hashtable)))
|
|
2293 (let ((dir (car (ange-ftp-get-pwd host user))))
|
|
2294 (if dir
|
|
2295 (ange-ftp-put-hash-entry key (concat "/" dir)
|
|
2296 ange-ftp-expand-dir-hashtable)
|
|
2297 (message "Warning! Unable to get home directory")
|
|
2298 (sit-for 1))))))
|
|
2299
|
|
2300
|
|
2301 ;;;; ------------------------------------------------------------
|
|
2302 ;;;; Simple FTP process shell support.
|
|
2303 ;;;; ------------------------------------------------------------
|
|
2304
|
|
2305 (defvar ange-ftp-shell-mode-map nil)
|
|
2306
|
|
2307 (defun ange-ftp-shell-mode ()
|
|
2308 "Major mode for interacting with an FTP process.
|
|
2309 Return at end of buffer sends line as input.
|
|
2310 Return not at end copies rest of line to end and sends it.
|
|
2311
|
|
2312 The following commands imitate the usual Unix interrupt and editing
|
|
2313 control characters:
|
|
2314 \\{ange-ftp-shell-mode-map}
|
|
2315 Runs ange-ftp-shell-mode-hook if not nil."
|
|
2316 (interactive)
|
|
2317 (let ((proc (get-buffer-process (current-buffer))))
|
|
2318 (kill-all-local-variables)
|
|
2319 (shell-mode)
|
|
2320 (if (null ange-ftp-shell-mode-map)
|
|
2321 (progn
|
|
2322 (setq ange-ftp-shell-mode-map (make-sparse-keymap))
|
|
2323 (set-keymap-parent ange-ftp-shell-mode-map shell-mode-map)
|
|
2324 (set-keymap-name ange-ftp-shell-mode-map 'ange-ftp-shell-mode-map)))
|
|
2325 (use-local-map ange-ftp-shell-mode-map)
|
|
2326 (setq major-mode 'ange-ftp-shell-mode)
|
|
2327 (setq mode-name "ange-ftp")
|
|
2328 (goto-char (point-max))
|
|
2329 (set-marker (process-mark proc) (point))
|
|
2330 (set (make-local-variable 'ange-ftp-process-string) nil)
|
|
2331 (setq ange-ftp-process-string "")
|
|
2332 (set (make-local-variable 'ange-ftp-process-busy) nil)
|
|
2333 (set (make-local-variable 'ange-ftp-process-result) nil)
|
|
2334 (set (make-local-variable 'ange-ftp-process-msg) nil)
|
|
2335 (set (make-local-variable 'ange-ftp-process-multi-skip) nil)
|
|
2336 (set (make-local-variable 'ange-ftp-process-result-line) nil)
|
|
2337 (set (make-local-variable 'ange-ftp-process-continue) nil)
|
|
2338 (set (make-local-variable 'ange-ftp-hash-mark-count) nil)
|
|
2339 (set (make-local-variable 'ange-ftp-binary-hash-mark-size) nil)
|
|
2340 (set (make-local-variable 'ange-ftp-ascii-hash-mark-size) nil)
|
|
2341 (set (make-local-variable 'ange-ftp-hash-mark-unit) nil)
|
|
2342 (set (make-local-variable 'ange-ftp-xfer-size) nil)
|
|
2343 (set (make-local-variable 'ange-ftp-last-percent) nil)
|
|
2344 (setq ange-ftp-hash-mark-count 0)
|
|
2345 (setq ange-ftp-xfer-size 0)
|
|
2346 (setq ange-ftp-process-result-line "")
|
|
2347 (run-hooks 'ange-ftp-shell-mode-hook)))
|
|
2348
|
|
2349 ;;;; ------------------------------------------------------------
|
|
2350 ;;;; Remote file and directory listing support.
|
|
2351 ;;;; ------------------------------------------------------------
|
|
2352
|
|
2353 (defun ange-ftp-dumb-unix-host (host)
|
|
2354 "Returns whether HOST's FTP server doesn't like \'ls\' or \'dir\' commands
|
|
2355 to take switch arguments."
|
|
2356 (and ange-ftp-dumb-unix-host-regexp
|
|
2357 (ange-ftp-save-match-data
|
|
2358 (string-match ange-ftp-dumb-unix-host-regexp host))))
|
|
2359
|
|
2360 (defun ange-ftp-add-dumb-unix-host (host)
|
|
2361 "Interactively adds a given HOST to ange-ftp-dumb-unix-host-regexp."
|
|
2362 (interactive
|
|
2363 (list (read-string "Host: "
|
|
2364 (let ((name (or (buffer-file-name)
|
|
2365 (and (eq major-mode 'dired-mode)
|
|
2366 dired-directory))))
|
|
2367 (and name (car (ange-ftp-ftp-path name)))))))
|
|
2368 (if (not (ange-ftp-dumb-unix-host host))
|
|
2369 (setq ange-ftp-dumb-unix-host-regexp
|
|
2370 (concat "^" (regexp-quote host) "$"
|
|
2371 (and ange-ftp-dumb-unix-host-regexp "\\|")
|
|
2372 ange-ftp-dumb-unix-host-regexp)
|
|
2373 ange-ftp-host-cache nil)))
|
|
2374
|
|
2375 (defvar ange-ftp-parse-list-func-alist nil
|
|
2376 "Association list of \( TYPE \. FUNC \) pairs. The FUNC is a routine
|
|
2377 which can parse the output from a DIR listing for a host of type TYPE.")
|
|
2378
|
|
2379 ;; With no-error nil, this function returns:
|
|
2380 ;; an error if file is not an ange-ftp-path
|
|
2381 ;; (This should never happen.)
|
|
2382 ;; an error if either the listing is unreadable or there is an ftp error.
|
|
2383 ;; the listing (a string), if everything works.
|
|
2384 ;;
|
|
2385 ;; With no-error t, it returns:
|
|
2386 ;; an error if not an ange-ftp-path
|
|
2387 ;; error if listing is unreable (most likely caused by a slow connection)
|
|
2388 ;; nil if ftp error (this is because although asking to list a nonexistent
|
|
2389 ;; directory on a remote unix machine usually (except
|
|
2390 ;; maybe for dumb hosts) returns an ls error, but no
|
|
2391 ;; ftp error, if the same is done on a VMS machine,
|
|
2392 ;; an ftp error is returned. Need to trap the error
|
|
2393 ;; so we can go on and try to list the parent.)
|
|
2394 ;; the listing, if everything works.
|
|
2395
|
|
2396 (defun ange-ftp-ls (file lsargs parse &optional no-error)
|
|
2397 "Return the output of an `DIR' or `ls' command done over ftp.
|
|
2398 FILE is the full name of the remote file, LSARGS is any args to pass to the
|
|
2399 `ls' command, and PARSE specifies that the output should be parsed and stored
|
|
2400 away in the internal cache."
|
|
2401 ;; If parse is t, we assume that file is a directory. i.e. we only parse
|
|
2402 ;; full directory listings.
|
|
2403 (setq file (ange-ftp-expand-file-name file))
|
|
2404 (let ((parsed (ange-ftp-ftp-path file)))
|
|
2405 (if parsed
|
|
2406 (let* ((host (nth 0 parsed))
|
|
2407 (user (nth 1 parsed))
|
|
2408 (path (ange-ftp-quote-string (nth 2 parsed)))
|
|
2409 (key (directory-file-name file))
|
|
2410 (host-type (ange-ftp-host-type host user))
|
|
2411 (dumb (memq host-type ange-ftp-dumb-host-types))
|
|
2412 result
|
|
2413 temp
|
|
2414 lscmd parse-func)
|
|
2415 (if (string-equal path "")
|
|
2416 (setq path
|
|
2417 (ange-ftp-real-file-name-as-directory
|
|
2418 (ange-ftp-expand-dir host user "~"))))
|
|
2419 (if (and ange-ftp-ls-cache-file
|
|
2420 (string-equal key ange-ftp-ls-cache-file)
|
|
2421 ;; Don't care about lsargs for dumb hosts.
|
|
2422 (or dumb (string-equal lsargs ange-ftp-ls-cache-lsargs)))
|
|
2423 ange-ftp-ls-cache-res
|
|
2424 (setq temp (ange-ftp-make-tmp-name host))
|
|
2425 (setq lscmd (list 'dir path temp lsargs))
|
|
2426 (unwind-protect
|
|
2427 (if (car (setq result (ange-ftp-send-cmd
|
|
2428 host
|
|
2429 user
|
|
2430 lscmd
|
|
2431 (format "Listing %s"
|
|
2432 (ange-ftp-abbreviate-filename
|
|
2433 file)))))
|
|
2434 (save-excursion
|
|
2435 (set-buffer (get-buffer-create
|
|
2436 ange-ftp-data-buffer-name))
|
|
2437 (erase-buffer)
|
|
2438 (if (ange-ftp-real-file-readable-p temp)
|
|
2439 (ange-ftp-real-insert-file-contents temp)
|
|
2440 (sleep-for ange-ftp-retry-time)
|
|
2441 ;wait for file to possibly appear
|
|
2442 (if (ange-ftp-real-file-readable-p temp)
|
|
2443 ;; Try again.
|
|
2444 (ange-ftp-real-insert-file-contents temp)
|
|
2445 (ange-ftp-error host user
|
|
2446 (format
|
|
2447 "list data file %s not readable"
|
|
2448 temp))))
|
|
2449 (if parse
|
|
2450 (ange-ftp-set-files
|
|
2451 file
|
|
2452 (if (setq
|
|
2453 parse-func
|
|
2454 (cdr (assq host-type
|
|
2455 ange-ftp-parse-list-func-alist)))
|
|
2456 (funcall parse-func)
|
|
2457 (ange-ftp-parse-dired-listing lsargs))))
|
|
2458 (setq ange-ftp-ls-cache-file key
|
|
2459 ange-ftp-ls-cache-lsargs lsargs
|
|
2460 ; For dumb hosts-types this is
|
|
2461 ; meaningless but harmless.
|
|
2462 ange-ftp-ls-cache-res (buffer-string))
|
|
2463 ;; (kill-buffer (current-buffer))
|
|
2464 ange-ftp-ls-cache-res)
|
|
2465 (if no-error
|
|
2466 nil
|
|
2467 (ange-ftp-error host user
|
|
2468 (concat "DIR failed: " (cdr result)))))
|
|
2469 (ange-ftp-del-tmp-name temp))))
|
|
2470 (error "Should never happen. Please report. Bug ref. no.: 1"))))
|
|
2471
|
|
2472 ;;;; ------------------------------------------------------------
|
|
2473 ;;;; Directory information caching support.
|
|
2474 ;;;; ------------------------------------------------------------
|
|
2475
|
|
2476 (defconst ange-ftp-date-regexp
|
|
2477 (concat
|
|
2478 " \\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|Aug\\|Sep\\|Oct"
|
|
2479 "\\|Nov\\|Dec\\) +[0-3]?[0-9] "))
|
|
2480
|
|
2481 (defvar ange-ftp-add-file-entry-alist nil
|
|
2482 "Association list of pairs \( TYPE \. FUNC \), where FUNC
|
|
2483 is a function to be used to add a file entry for the OS TYPE. The
|
|
2484 main reason for this alist is to deal with file versions in VMS.")
|
|
2485
|
|
2486 (defvar ange-ftp-delete-file-entry-alist nil
|
|
2487 "Association list of pairs \( TYPE \. FUNC \), where FUNC
|
|
2488 is a function to be used to delete a file entry for the OS TYPE.
|
|
2489 The main reason for this alist is to deal with file versions in
|
|
2490 VMS.")
|
|
2491
|
|
2492 (defun ange-ftp-add-file-entry (path &optional dir-p)
|
|
2493 "Given a PATH, add the file entry for it, if its directory
|
|
2494 info exists."
|
|
2495 (funcall (or (cdr (assq (ange-ftp-host-type
|
|
2496 (car (ange-ftp-ftp-path path)))
|
|
2497 ange-ftp-add-file-entry-alist))
|
|
2498 'ange-ftp-internal-add-file-entry)
|
|
2499 path dir-p)
|
|
2500 (setq ange-ftp-ls-cache-file nil))
|
|
2501
|
|
2502 (defun ange-ftp-delete-file-entry (path &optional dir-p)
|
|
2503 "Given a PATH, delete the file entry for it, if its directory
|
|
2504 info exists."
|
|
2505 (funcall (or (cdr (assq (ange-ftp-host-type
|
|
2506 (car (ange-ftp-ftp-path path)))
|
|
2507 ange-ftp-delete-file-entry-alist))
|
|
2508 'ange-ftp-internal-delete-file-entry)
|
|
2509 path dir-p)
|
|
2510 (setq ange-ftp-ls-cache-file nil))
|
|
2511
|
|
2512 (defmacro ange-ftp-parse-filename ()
|
|
2513 ;;Extract the filename from the current line of a dired-like listing.
|
|
2514 (` (let ((eol (progn (end-of-line) (point))))
|
|
2515 (beginning-of-line)
|
|
2516 (if (re-search-forward ange-ftp-date-regexp eol t)
|
|
2517 (progn
|
|
2518 (skip-chars-forward " ")
|
|
2519 (skip-chars-forward "^ " eol)
|
|
2520 (skip-chars-forward " " eol)
|
|
2521 ;; We bomb on filenames starting with a space.
|
|
2522 (buffer-substring (point) eol))))))
|
|
2523
|
|
2524 ;; This deals with the F switch. Should also do something about
|
|
2525 ;; unquoting names obtained with the SysV b switch and the GNU Q
|
|
2526 ;; switch. See Sebastian's dired-get-filename.
|
|
2527
|
|
2528 (defmacro ange-ftp-ls-parser ()
|
|
2529 ;; Note that switches is dynamically bound.
|
|
2530 ;; Meant to be called by ange-ftp-parse-dired-listing
|
|
2531 (` (let ((tbl (ange-ftp-make-hashtable))
|
|
2532 (used-F (and (stringp switches)
|
|
2533 (string-match "F" switches)))
|
|
2534 file-type symlink directory file)
|
|
2535 (while (setq file (ange-ftp-parse-filename))
|
|
2536 (beginning-of-line)
|
|
2537 (skip-chars-forward "\t 0-9")
|
|
2538 (setq file-type (following-char)
|
|
2539 directory (eq file-type ?d))
|
|
2540 (if (eq file-type ?l)
|
|
2541 (if (string-match " -> " file)
|
|
2542 (setq symlink (substring file (match-end 0))
|
|
2543 file (substring file 0 (match-beginning 0)))
|
|
2544 ;; Shouldn't happen
|
|
2545 (setq symlink ""))
|
|
2546 (setq symlink nil))
|
|
2547 ;; Only do a costly regexp search if the F switch was used.
|
|
2548 (if (and used-F
|
|
2549 (not (string-equal file ""))
|
|
2550 (looking-at
|
|
2551 ".[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)"))
|
|
2552 (let ((socket (eq file-type ?s))
|
|
2553 (executable
|
|
2554 (and (not symlink) ; x bits don't mean a thing for symlinks
|
|
2555 (string-match "[xst]"
|
|
2556 (concat
|
|
2557 (buffer-substring
|
|
2558 (match-beginning 1)
|
|
2559 (match-end 1))
|
|
2560 (buffer-substring
|
|
2561 (match-beginning 2)
|
|
2562 (match-end 2))
|
|
2563 (buffer-substring
|
|
2564 (match-beginning 3)
|
|
2565 (match-end 3)))))))
|
|
2566 ;; Some ls's with the F switch mark symlinks with an @ (ULTRIX)
|
|
2567 ;; and others don't. (sigh...) Beware, that some Unix's don't
|
|
2568 ;; seem to believe in the F-switch
|
|
2569 (if (or (and symlink (string-match "@$" file))
|
|
2570 (and directory (string-match "/$" file))
|
|
2571 (and executable (string-match "*$" file))
|
|
2572 (and socket (string-match "=$" file)))
|
|
2573 (setq file (substring file 0 -1)))))
|
|
2574 (ange-ftp-put-hash-entry file (or symlink directory) tbl)
|
|
2575 (forward-line 1))
|
|
2576 (ange-ftp-put-hash-entry "." t tbl)
|
|
2577 (ange-ftp-put-hash-entry ".." t tbl)
|
|
2578 tbl)))
|
|
2579
|
|
2580 ;;; The dl stuff for descriptive listings
|
|
2581
|
|
2582 (defvar ange-ftp-dl-dir-regexp nil
|
|
2583 "Regexp matching directories which are listed in dl format. This regexp
|
|
2584 shouldn't be anchored with a trailing $ so that it will match subdirectories
|
|
2585 as well.")
|
|
2586
|
|
2587 (defun ange-ftp-add-dl-dir (dir)
|
|
2588 "Interactively adds a given directory to ange-ftp-dl-dir-regexp."
|
|
2589 (interactive
|
|
2590 (list (read-string "Directory: "
|
|
2591 (let ((name (or (buffer-file-name)
|
|
2592 (and (eq major-mode 'dired-mode)
|
|
2593 dired-directory))))
|
|
2594 (and name (ange-ftp-ftp-path name)
|
|
2595 (file-name-directory name))))))
|
|
2596 (if (not (and ange-ftp-dl-dir-regexp
|
|
2597 (string-match ange-ftp-dl-dir-regexp dir)))
|
|
2598 (setq ange-ftp-dl-dir-regexp
|
|
2599 (concat "^" (regexp-quote dir)
|
|
2600 (and ange-ftp-dl-dir-regexp "\\|")
|
|
2601 ange-ftp-dl-dir-regexp))))
|
|
2602
|
|
2603 (defmacro ange-ftp-dl-parser ()
|
|
2604 ;; Parse the current buffer, which is assumed to be a descriptive
|
|
2605 ;; listing, and return a hashtable.
|
|
2606 (` (let ((tbl (ange-ftp-make-hashtable)))
|
|
2607 (while (not (eobp))
|
|
2608 (ange-ftp-put-hash-entry
|
|
2609 (buffer-substring (point)
|
|
2610 (progn
|
|
2611 (skip-chars-forward "^ /\n")
|
|
2612 (point)))
|
|
2613 (eq (following-char) ?/)
|
|
2614 tbl)
|
|
2615 (forward-line 1))
|
|
2616 (ange-ftp-put-hash-entry "." t tbl)
|
|
2617 (ange-ftp-put-hash-entry ".." t tbl)
|
|
2618 tbl)))
|
|
2619
|
|
2620 (defun ange-ftp-parse-dired-listing (&optional switches)
|
|
2621 "Parse the current buffer which is assumed to be in a dired-like listing
|
|
2622 format, and return a hashtable as the result. If the listing is not really
|
|
2623 a listing, then return nil."
|
|
2624 (ange-ftp-save-match-data
|
|
2625 (cond
|
|
2626 ((looking-at "^total [0-9]+$")
|
|
2627 (forward-line 1)
|
|
2628 (ange-ftp-ls-parser))
|
|
2629 ((looking-at "[^\n]+\\( not found\\|: Not a directory\\)\n\\'")
|
|
2630 ;; It's an ls error message.
|
|
2631 nil)
|
|
2632 ((eobp) ; i.e. (zerop (buffer-size))
|
|
2633 ;; This could be one of:
|
|
2634 ;; (1) An Ultrix ls error message
|
|
2635 ;; (2) A listing with the A switch of an empty directory
|
|
2636 ;; on a machine which doesn't give a total line.
|
|
2637 ;; (3) The twilight zone.
|
|
2638 ;; We'll assume (1) for now.
|
|
2639 nil)
|
|
2640 ((re-search-forward ange-ftp-date-regexp nil t)
|
|
2641 (beginning-of-line)
|
|
2642 (ange-ftp-ls-parser))
|
|
2643 ((re-search-forward "^[^ \n\t]+ +\\([0-9]+\\|-\\|=\\) " nil t)
|
|
2644 ;; It's a dl listing (I hope).
|
|
2645 ;; file is bound by the call to ange-ftp-ls
|
|
2646 (ange-ftp-add-dl-dir file)
|
|
2647 (beginning-of-line)
|
|
2648 (ange-ftp-dl-parser))
|
|
2649 (t nil))))
|
|
2650
|
|
2651 (defun ange-ftp-set-files (directory files)
|
|
2652 "For a given DIRECTORY, set or change the associated FILES hashtable."
|
|
2653 (and files (ange-ftp-put-hash-entry (file-name-as-directory directory)
|
|
2654 files ange-ftp-files-hashtable)))
|
|
2655
|
|
2656 (defun ange-ftp-get-files (directory &optional no-error)
|
|
2657 "Given a given DIRECTORY, return a hashtable of file entries.
|
|
2658 This will give an error or return nil, depending on the value of
|
|
2659 NO-ERROR, if a listing for DIRECTORY cannot be obtained."
|
|
2660 (setq directory (file-name-as-directory directory)) ;normalize
|
|
2661 (or (ange-ftp-get-hash-entry directory ange-ftp-files-hashtable)
|
|
2662 (ange-ftp-save-match-data
|
|
2663 (and (ange-ftp-ls directory
|
|
2664 ;; This is an efficiency hack. We try to
|
|
2665 ;; anticipate what sort of listing dired
|
|
2666 ;; might want, and cache just such a listing.
|
|
2667 (if (and (boundp 'dired-actual-switches)
|
|
2668 (stringp dired-actual-switches)
|
|
2669 ;; We allow the A switch, which lists
|
|
2670 ;; all files except "." and "..".
|
|
2671 ;; This is OK because we manually
|
|
2672 ;; insert these entries
|
|
2673 ;; in the hash table.
|
|
2674 (string-match
|
|
2675 "[aA]" dired-actual-switches)
|
|
2676 (string-match
|
|
2677 "l" dired-actual-switches)
|
|
2678 (not (string-match
|
|
2679 "R" dired-actual-switches)))
|
|
2680 dired-actual-switches
|
|
2681 (if (and (boundp 'dired-listing-switches)
|
|
2682 (stringp dired-listing-switches)
|
|
2683 (string-match
|
|
2684 "[aA]" dired-listing-switches)
|
|
2685 (string-match
|
|
2686 "l" dired-listing-switches)
|
|
2687 (not (string-match
|
|
2688 "R" dired-listing-switches)))
|
|
2689 dired-listing-switches
|
|
2690 "-al"))
|
|
2691 t no-error)
|
|
2692 (ange-ftp-get-hash-entry
|
|
2693 directory ange-ftp-files-hashtable)))))
|
|
2694
|
|
2695 (defmacro ange-ftp-get-file-part (path)
|
|
2696 "Given PATH, return the file part that can be used for looking up the
|
|
2697 file's entry in a hashtable."
|
|
2698 (` (let ((file (file-name-nondirectory (, path))))
|
|
2699 (if (string-equal file "")
|
|
2700 "."
|
|
2701 file))))
|
|
2702
|
|
2703 (defmacro ange-ftp-allow-child-lookup (dir file)
|
|
2704 "Return whether ange-ftp-file-entry-p and ange-ftp-get-file-entry are
|
|
2705 allowed to determine if PATH is a sub-directory by listing it directly,
|
|
2706 rather than listing its parent directory. This is used for efficiency so
|
|
2707 that a wasted listing is not done:
|
|
2708 1. When looking for a .dired file in dired-x.el.
|
|
2709 2. The syntax of FILE and DIR make it impossible that FILE could be a valid
|
|
2710 subdirectory. This is of course an OS dependent judgement."
|
|
2711 (` (not
|
|
2712 (let* ((efile (, file)) ; expand once.
|
|
2713 (edir (, dir))
|
|
2714 (parsed (ange-ftp-ftp-path edir))
|
|
2715 (host-type (ange-ftp-host-type
|
|
2716 (car parsed))))
|
|
2717 (or
|
|
2718 ;; Deal with dired
|
|
2719 (and (boundp 'dired-local-variables-file)
|
|
2720 (stringp dired-local-variables-file)
|
|
2721 (string-equal dired-local-variables-file efile))
|
|
2722 ;; No dots in dir names in vms.
|
|
2723 (and (eq host-type 'vms)
|
|
2724 (string-match "\\." efile))
|
|
2725 ;; No subdirs in mts of cms.
|
|
2726 (and (memq host-type '(mts cms))
|
|
2727 (not (string-equal "/" (nth 2 parsed)))))))))
|
|
2728
|
|
2729 (defun ange-ftp-file-entry-p (path)
|
|
2730 "Given PATH, return whether there is a file entry for it."
|
|
2731 (let* ((path (directory-file-name path))
|
|
2732 (dir (file-name-directory path))
|
|
2733 (ent (ange-ftp-get-hash-entry dir ange-ftp-files-hashtable))
|
|
2734 (file (ange-ftp-get-file-part path)))
|
|
2735 (if ent
|
|
2736 (ange-ftp-hash-entry-exists-p file ent)
|
|
2737 (or (and (ange-ftp-allow-child-lookup dir file)
|
|
2738 (setq ent (ange-ftp-get-files path t))
|
|
2739 ;; Try a child lookup. i.e. try to list file as a
|
|
2740 ;; subdirectory of dir. This is a good idea because
|
|
2741 ;; we may not have read permission for file's parent. Also,
|
|
2742 ;; people tend to work down directory trees anyway. We use
|
|
2743 ;; no-error ;; because if file does not exist as a subdir.,
|
|
2744 ;; then dumb hosts will give an ftp error. Smart unix hosts
|
|
2745 ;; will simply send back the ls
|
|
2746 ;; error message.
|
|
2747 (ange-ftp-get-hash-entry "." ent))
|
|
2748 ;; Child lookup failed. Try the parent. If this bombs,
|
|
2749 ;; we are at wits end -- signal an error.
|
|
2750 ;; Problem: If this signals an error, the error message
|
|
2751 ;; may not have a lot to do with what went wrong.
|
|
2752 (ange-ftp-hash-entry-exists-p file
|
|
2753 (ange-ftp-get-files dir))))))
|
|
2754
|
|
2755 (defun ange-ftp-get-file-entry (path)
|
|
2756 "Given PATH, return the given file entry which will be either t for a
|
|
2757 directory, nil for a normal file, or a string for a symlink. If the file
|
|
2758 isn't in the hashtable, this also returns nil."
|
|
2759 (let* ((path (directory-file-name path))
|
|
2760 (dir (file-name-directory path))
|
|
2761 (ent (ange-ftp-get-hash-entry dir ange-ftp-files-hashtable))
|
|
2762 (file (ange-ftp-get-file-part path)))
|
|
2763 (if ent
|
|
2764 (ange-ftp-get-hash-entry file ent)
|
|
2765 (or (and (ange-ftp-allow-child-lookup dir file)
|
|
2766 (setq ent (ange-ftp-get-files path t))
|
|
2767 (ange-ftp-get-hash-entry "." ent))
|
|
2768 ;; i.e. it's a directory by child lookup
|
|
2769 (ange-ftp-get-hash-entry file
|
|
2770 (ange-ftp-get-files dir))))))
|
|
2771
|
|
2772 (defun ange-ftp-internal-delete-file-entry (path &optional dir-p)
|
|
2773 (if dir-p
|
|
2774 (progn
|
|
2775 (setq path (file-name-as-directory path))
|
|
2776 (ange-ftp-del-hash-entry path ange-ftp-files-hashtable)
|
|
2777 (setq path (directory-file-name path))))
|
|
2778 ;; Note that file-name-as-directory followed by directory-file-name
|
|
2779 ;; serves to canonicalize directory file names to their unix form.
|
|
2780 ;; i.e. in VMS, FOO.DIR -> FOO/ -> FOO
|
|
2781 (let ((files (ange-ftp-get-hash-entry (file-name-directory path)
|
|
2782 ange-ftp-files-hashtable)))
|
|
2783 (if files
|
|
2784 (ange-ftp-del-hash-entry (ange-ftp-get-file-part path)
|
|
2785 files))))
|
|
2786
|
|
2787 (defun ange-ftp-internal-add-file-entry (path &optional dir-p)
|
|
2788 (and dir-p
|
|
2789 (setq path (directory-file-name path)))
|
|
2790 (let ((files (ange-ftp-get-hash-entry (file-name-directory path)
|
|
2791 ange-ftp-files-hashtable)))
|
|
2792 (if files
|
|
2793 (ange-ftp-put-hash-entry (ange-ftp-get-file-part path)
|
|
2794 dir-p
|
|
2795 files))))
|
|
2796
|
|
2797 (defun ange-ftp-wipe-file-entries (host user)
|
|
2798 "Replace the file entry information hashtable with one that doesn't have any
|
|
2799 entries for the given HOST, USER pair."
|
|
2800 (let ((new-tbl (ange-ftp-make-hashtable (length ange-ftp-files-hashtable))))
|
|
2801 (ange-ftp-map-hashtable
|
|
2802 (function
|
|
2803 (lambda (key val)
|
|
2804 (let ((parsed (ange-ftp-ftp-path key)))
|
|
2805 (if parsed
|
|
2806 (let ((h (nth 0 parsed))
|
|
2807 (u (nth 1 parsed)))
|
|
2808 (or (and (equal host h) (equal user u))
|
|
2809 (ange-ftp-put-hash-entry key val new-tbl)))))))
|
|
2810 ange-ftp-files-hashtable)
|
|
2811 (setq ange-ftp-files-hashtable new-tbl)))
|
|
2812
|
|
2813 ;;;; ------------------------------------------------------------
|
|
2814 ;;;; File transfer mode support.
|
|
2815 ;;;; ------------------------------------------------------------
|
|
2816
|
|
2817 (defun ange-ftp-set-binary-mode (host user)
|
|
2818 "Tell the ftp process for the given HOST & USER to switch to binary mode."
|
|
2819 (let ((result (ange-ftp-send-cmd host user '(type "binary"))))
|
|
2820 (if (not (car result))
|
|
2821 (ange-ftp-error host user (concat "BINARY failed: " (cdr result)))
|
|
2822 (save-excursion
|
|
2823 (set-buffer (process-buffer (ange-ftp-get-process host user)))
|
|
2824 (and ange-ftp-binary-hash-mark-size
|
|
2825 (setq ange-ftp-hash-mark-unit (ash ange-ftp-binary-hash-mark-size -4)))))))
|
|
2826
|
|
2827 (defun ange-ftp-set-ascii-mode (host user)
|
|
2828 "Tell the ftp process for the given HOST & USER to switch to ascii mode."
|
|
2829 (let ((result (ange-ftp-send-cmd host user '(type "ascii"))))
|
|
2830 (if (not (car result))
|
|
2831 (ange-ftp-error host user (concat "ASCII failed: " (cdr result)))
|
|
2832 (save-excursion
|
|
2833 (set-buffer (process-buffer (ange-ftp-get-process host user)))
|
|
2834 (and ange-ftp-ascii-hash-mark-size
|
|
2835 (setq ange-ftp-hash-mark-unit (ash ange-ftp-ascii-hash-mark-size -4)))))))
|
|
2836
|
|
2837 ;;; ------------------------------------------------------------
|
|
2838 ;;; expand-file-name and friends...
|
|
2839 ;;; ------------------------------------------------------------
|
|
2840
|
|
2841 (defun ange-ftp-cd (host user dir)
|
|
2842 (let ((result (ange-ftp-send-cmd host user (list 'cd dir) "Doing CD")))
|
|
2843 (or (car result)
|
|
2844 (ange-ftp-error host user (concat "CD failed: " (cdr result))))))
|
|
2845
|
|
2846 (defun ange-ftp-get-pwd (host user)
|
|
2847 "Attempts to get the current working directory for the given HOST/USER pair.
|
|
2848 Returns \( DIR . LINE \) where DIR is either the directory or NIL if not found,
|
|
2849 and LINE is the relevant success or fail line from the FTP-client."
|
|
2850 (let* ((result (ange-ftp-send-cmd host user '(pwd) "Getting PWD"))
|
|
2851 (line (cdr result))
|
|
2852 dir)
|
|
2853 (if (car result)
|
|
2854 (ange-ftp-save-match-data
|
|
2855 (and (or (string-match "\"\\([^\"]*\\)\"" line)
|
|
2856 (string-match " \\([^ ]+\\) " line)) ; stone-age VMS servers!
|
|
2857 (setq dir (substring line
|
|
2858 (match-beginning 1)
|
|
2859 (match-end 1))))))
|
|
2860 (cons dir line)))
|
|
2861
|
|
2862 (defconst ange-ftp-expand-dir-hashtable (ange-ftp-make-hashtable))
|
|
2863
|
|
2864 (defconst ange-ftp-expand-dir-regexp "^5.0 \\([^: ]+\\):")
|
|
2865
|
|
2866 (defun ange-ftp-expand-dir (host user dir)
|
|
2867 "Return the result of doing a PWD in the current FTP session to machine HOST
|
|
2868 logged in as user USER and cd'd to directory DIR."
|
|
2869 (let* ((host-type (ange-ftp-host-type host user))
|
|
2870 ;; It is more efficient to call ange-ftp-host-type
|
|
2871 ;; before binding res, because ange-ftp-host-type sometimes
|
|
2872 ;; adds to the info in the expand-dir-hashtable.
|
|
2873 (fix-pathname-func
|
|
2874 (cdr (assq host-type ange-ftp-fix-path-func-alist)))
|
|
2875 (key (concat host "/" user "/" dir))
|
|
2876 (res (ange-ftp-get-hash-entry key ange-ftp-expand-dir-hashtable)))
|
|
2877 (or res
|
|
2878 (progn
|
|
2879 (or
|
|
2880 (string-equal user "anonymous")
|
|
2881 (string-equal user "ftp")
|
|
2882 (not (eq host-type 'unix))
|
|
2883 (let* ((ange-ftp-good-msgs (concat ange-ftp-expand-dir-regexp
|
|
2884 "\\|"
|
|
2885 ange-ftp-good-msgs))
|
|
2886 (result (ange-ftp-send-cmd host user
|
|
2887 (list 'get dir "/dev/null")
|
|
2888 (format "expanding %s" dir)))
|
|
2889 (line (cdr result)))
|
|
2890 (setq res
|
|
2891 (if (string-match ange-ftp-expand-dir-regexp line)
|
|
2892 (substring line
|
|
2893 (match-beginning 1)
|
|
2894 (match-end 1))))))
|
|
2895 (or res
|
|
2896 (if (string-equal dir "~")
|
|
2897 (setq res (car (ange-ftp-get-pwd host user)))
|
|
2898 (let ((home (ange-ftp-expand-dir host user "~")))
|
|
2899 (unwind-protect
|
|
2900 (and (ange-ftp-cd host user dir)
|
|
2901 (setq res (car (ange-ftp-get-pwd host user))))
|
|
2902 (ange-ftp-cd host user home)))))
|
|
2903 (if res
|
|
2904 (progn
|
|
2905 (if fix-pathname-func
|
|
2906 (setq res (funcall fix-pathname-func res 'reverse)))
|
|
2907 (ange-ftp-put-hash-entry
|
|
2908 key res ange-ftp-expand-dir-hashtable)))
|
|
2909 res))))
|
|
2910
|
|
2911 (defun ange-ftp-canonize-filename (n)
|
|
2912 "Take a string and short-circuit //, /. and /.."
|
|
2913 (if (string-match "[^:]+//" n) ;don't upset Apollo users
|
|
2914 (setq n (substring n (1- (match-end 0)))))
|
|
2915 (let ((parsed (ange-ftp-ftp-path n)))
|
|
2916 (if parsed
|
|
2917 (let ((host (car parsed))
|
|
2918 (user (nth 1 parsed))
|
|
2919 (path (nth 2 parsed)))
|
|
2920
|
|
2921 ;; See if remote path is absolute. If so then just expand it and
|
|
2922 ;; replace the path component of the overall path.
|
|
2923 (cond ((string-match "^/" path)
|
|
2924 path)
|
|
2925
|
|
2926 ;; Path starts with ~ or ~user. Resolve that part of the path
|
|
2927 ;; making it absolute then re-expand it.
|
|
2928 ((string-match "^~[^/]*" path)
|
|
2929 (let* ((tilda (substring path
|
|
2930 (match-beginning 0)
|
|
2931 (match-end 0)))
|
|
2932 (rest (substring path (match-end 0)))
|
|
2933 (dir (ange-ftp-expand-dir host user tilda)))
|
|
2934 (if dir
|
|
2935 (setq path (concat dir rest))
|
|
2936 (error "User \"%s\" is not known"
|
|
2937 (substring tilda 1)))))
|
|
2938
|
|
2939 ;; relative path. Tack on homedir and re-expand.
|
|
2940 (t
|
|
2941 (let ((dir (ange-ftp-expand-dir host user "~")))
|
|
2942 (if dir
|
|
2943 (setq path (concat
|
|
2944 (ange-ftp-real-file-name-as-directory dir)
|
|
2945 path))
|
|
2946 (error "Unable to obtain CWD")))))
|
|
2947
|
|
2948 (if (not (string-match "^//" path))
|
|
2949 (progn
|
|
2950 (setq path (ange-ftp-real-expand-file-name path))
|
|
2951
|
|
2952 (if (string-match "^//" path)
|
|
2953 (setq path (substring path 1)))))
|
|
2954
|
|
2955 ;; Now substitute the expanded path back into the overall filename.
|
|
2956 (ange-ftp-replace-path-component n path))
|
|
2957
|
|
2958 ;; non-ange-ftp path. Just expand normally.
|
|
2959 (if (eq (string-to-char n) ?/)
|
|
2960 (ange-ftp-real-expand-file-name n)
|
|
2961 (ange-ftp-real-expand-file-name
|
|
2962 (ange-ftp-real-file-name-nondirectory n)
|
|
2963 (ange-ftp-real-file-name-directory n))))))
|
|
2964
|
|
2965 (defun ange-ftp-expand-file-name (name &optional default)
|
|
2966 "Documented as original."
|
|
2967 (ange-ftp-save-match-data
|
|
2968 (if (eq (string-to-char name) ?/)
|
|
2969 (while (cond ((string-match "[^:]+//" name) ;don't upset Apollo users
|
|
2970 (setq name (substring name (1- (match-end 0)))))
|
|
2971 ((string-match "/~" name)
|
|
2972 (setq name (substring name (1- (match-end 0))))))))
|
|
2973 (cond ((eq (string-to-char name) ?~)
|
|
2974 (ange-ftp-real-expand-file-name name))
|
|
2975 ((eq (string-to-char name) ?/)
|
|
2976 (ange-ftp-canonize-filename name))
|
|
2977 ((zerop (length name))
|
|
2978 (ange-ftp-canonize-filename (or default default-directory)))
|
|
2979 ((ange-ftp-canonize-filename
|
|
2980 (concat (file-name-as-directory (or default default-directory))
|
|
2981 name))))))
|
|
2982
|
|
2983 ;;;; ------------------------------------------------------------
|
|
2984 ;;;; Redefinitions of standard GNU Emacs functions.
|
|
2985 ;;;; ------------------------------------------------------------
|
|
2986
|
|
2987 (defvar ange-ftp-file-name-as-directory-alist nil
|
|
2988 "Association list of \( TYPE \. FUNC \) pairs, where
|
|
2989 FUNC converts a filename to a directory name for the operating
|
|
2990 system TYPE.")
|
|
2991
|
|
2992 (defun ange-ftp-file-name-as-directory (name)
|
|
2993 "Documented as original."
|
|
2994 (let ((parsed (ange-ftp-ftp-path name)))
|
|
2995 (if parsed
|
|
2996 (if (string-equal (nth 2 parsed) "")
|
|
2997 name
|
|
2998 (funcall (or (cdr (assq
|
|
2999 (ange-ftp-host-type (car parsed))
|
|
3000 ange-ftp-file-name-as-directory-alist))
|
|
3001 'ange-ftp-real-file-name-as-directory)
|
|
3002 name))
|
|
3003 (ange-ftp-real-file-name-as-directory name))))
|
|
3004
|
|
3005 (defun ange-ftp-file-name-directory (name)
|
|
3006 "Documented as original."
|
|
3007 (let ((parsed (ange-ftp-ftp-path name)))
|
|
3008 (if parsed
|
|
3009 (let ((path (nth 2 parsed)))
|
|
3010 (if (ange-ftp-save-match-data
|
|
3011 (string-match "^~[^/]*$" path))
|
|
3012 name
|
|
3013 (ange-ftp-replace-path-component
|
|
3014 name
|
|
3015 (ange-ftp-real-file-name-directory path))))
|
|
3016 (ange-ftp-real-file-name-directory name))))
|
|
3017
|
|
3018 (defun ange-ftp-file-name-nondirectory (name)
|
|
3019 "Documented as original."
|
|
3020 (let ((parsed (ange-ftp-ftp-path name)))
|
|
3021 (if parsed
|
|
3022 (let ((path (nth 2 parsed)))
|
|
3023 (if (ange-ftp-save-match-data
|
|
3024 (string-match "^~[^/]*$" path))
|
|
3025 ""
|
|
3026 (ange-ftp-real-file-name-nondirectory path)))
|
|
3027 (ange-ftp-real-file-name-nondirectory name))))
|
|
3028
|
|
3029 (defun ange-ftp-directory-file-name (dir)
|
|
3030 "Documented as original."
|
|
3031 (let ((parsed (ange-ftp-ftp-path dir)))
|
|
3032 (if parsed
|
|
3033 (ange-ftp-replace-path-component
|
|
3034 dir
|
|
3035 (ange-ftp-real-directory-file-name (nth 2 parsed)))
|
|
3036 (ange-ftp-real-directory-file-name dir))))
|
|
3037
|
|
3038 (defun ange-ftp-binary-file (file)
|
|
3039 "Returns whether the given FILE is to be considered as a binary file for
|
|
3040 ftp transfers."
|
|
3041 (ange-ftp-save-match-data
|
|
3042 (string-match ange-ftp-binary-file-name-regexp file)))
|
|
3043
|
|
3044 (defun ange-ftp-write-region (start end filename &optional append visit
|
|
3045 lockname)
|
|
3046 "Documented as original."
|
|
3047 (interactive "r\nFWrite region to file: ")
|
|
3048 (setq filename (expand-file-name filename))
|
|
3049 (let ((parsed (ange-ftp-ftp-path filename)))
|
|
3050 (if parsed
|
|
3051 (let* ((host (nth 0 parsed))
|
|
3052 (user (nth 1 parsed))
|
|
3053 (path (ange-ftp-quote-string (nth 2 parsed)))
|
|
3054 (temp (ange-ftp-make-tmp-name host))
|
|
3055 (binary (ange-ftp-binary-file filename))
|
|
3056 (cmd (if append 'append 'put))
|
|
3057 (abbr (ange-ftp-abbreviate-filename filename)))
|
|
3058 (unwind-protect
|
|
3059 (progn
|
|
3060 (let ((executing-macro t)
|
|
3061 (filename (buffer-file-name))
|
|
3062 (mod-p (buffer-modified-p)))
|
|
3063 (unwind-protect
|
|
3064 (ange-ftp-real-write-region start end temp nil
|
|
3065 visit lockname)
|
|
3066 ;; cleanup forms
|
|
3067 (setq buffer-file-name filename)
|
|
3068 (if (fboundp 'compute-buffer-file-truename)
|
|
3069 (compute-buffer-file-truename))
|
|
3070 (set-buffer-modified-p mod-p)))
|
|
3071 (if binary
|
|
3072 (ange-ftp-set-binary-mode host user))
|
|
3073
|
|
3074 ;; tell the process filter what size the transfer will be.
|
|
3075 (let ((attr (file-attributes temp)))
|
|
3076 (if attr
|
|
3077 (ange-ftp-set-xfer-size host user (nth 7 attr))))
|
|
3078
|
|
3079 ;; put or append the file.
|
|
3080 (let ((result (ange-ftp-send-cmd host user
|
|
3081 (list cmd temp path)
|
|
3082 (format "Writing %s" abbr))))
|
|
3083 (or (car result)
|
|
3084 (signal 'ftp-error
|
|
3085 (list
|
|
3086 "Opening output file"
|
|
3087 (format "FTP Error: \"%s\"" (cdr result))
|
|
3088 filename)))))
|
|
3089 (ange-ftp-del-tmp-name temp)
|
|
3090 (if binary
|
|
3091 (ange-ftp-set-ascii-mode host user)))
|
|
3092 (if (eq visit t)
|
|
3093 (progn
|
|
3094 (ange-ftp-set-buffer-mode)
|
|
3095 (setq buffer-file-name filename)
|
|
3096 (if (fboundp 'compute-buffer-file-truename)
|
|
3097 (compute-buffer-file-truename))
|
|
3098 (set-buffer-modified-p nil)))
|
|
3099 (ange-ftp-message "Wrote %s" abbr)
|
|
3100 (ange-ftp-add-file-entry filename))
|
|
3101 (ange-ftp-real-write-region start end filename append visit lockname))))
|
|
3102
|
|
3103 (defun ange-ftp-insert-file-contents (filename &optional visit beg end replace)
|
|
3104 "Documented as original."
|
|
3105 (barf-if-buffer-read-only)
|
|
3106 (setq filename (expand-file-name filename))
|
|
3107 (let ((parsed (ange-ftp-ftp-path filename)))
|
|
3108 (if parsed
|
|
3109 (progn
|
|
3110 (if visit
|
|
3111 (progn
|
|
3112 (setq buffer-file-name filename)
|
|
3113 (if (fboundp 'compute-buffer-file-truename)
|
|
3114 (compute-buffer-file-truename))))
|
|
3115 (if (or (file-exists-p filename)
|
|
3116 (progn
|
|
3117 (setq ange-ftp-ls-cache-file nil)
|
|
3118 (ange-ftp-del-hash-entry (file-name-directory filename)
|
|
3119 ange-ftp-files-hashtable)
|
|
3120 (file-exists-p filename)))
|
|
3121 (let* ((host (nth 0 parsed))
|
|
3122 (user (nth 1 parsed))
|
|
3123 (path (ange-ftp-quote-string (nth 2 parsed)))
|
|
3124 (temp (ange-ftp-make-tmp-name host))
|
|
3125 (binary (ange-ftp-binary-file filename))
|
|
3126 (abbr (ange-ftp-abbreviate-filename filename))
|
|
3127 size)
|
|
3128 (unwind-protect
|
|
3129 (progn
|
|
3130 (if binary
|
|
3131 (ange-ftp-set-binary-mode host user))
|
|
3132 (let ((result (ange-ftp-send-cmd host user
|
|
3133 (list 'get path temp)
|
|
3134 (format "Retrieving %s" abbr))))
|
|
3135 (or (car result)
|
|
3136 (signal 'ftp-error
|
|
3137 (list
|
|
3138 "Opening input file"
|
|
3139 (format "FTP Error: \"%s\"" (cdr result))
|
|
3140 filename))))
|
|
3141 (if (or (ange-ftp-real-file-readable-p temp)
|
|
3142 (sleep-for ange-ftp-retry-time)
|
|
3143 ;; Wait for file to hopefully appear.
|
|
3144 (ange-ftp-real-file-readable-p temp))
|
|
3145 (setq
|
|
3146 size
|
|
3147 (nth 1 (progn
|
|
3148 (if replace ; kludge...
|
|
3149 (delete-region (point-min)
|
|
3150 (point-max)))
|
|
3151 (ange-ftp-real-insert-file-contents
|
|
3152 temp visit beg end nil))))
|
|
3153 (signal 'ftp-error
|
|
3154 (list
|
|
3155 "Opening input file:"
|
|
3156 (format
|
|
3157 "FTP Error: %s not arrived or readable"
|
|
3158 filename)))))
|
|
3159 (if binary
|
|
3160 (ange-ftp-set-ascii-mode host user))
|
|
3161 (ange-ftp-del-tmp-name temp))
|
|
3162 (if visit
|
|
3163 (progn
|
|
3164 (setq buffer-file-name filename)
|
|
3165 (if (fboundp 'compute-buffer-file-truename)
|
|
3166 (compute-buffer-file-truename))))
|
|
3167 (list filename size))
|
|
3168 (signal 'file-error
|
|
3169 (list
|
|
3170 "Opening input file"
|
|
3171 filename))))
|
|
3172 (ange-ftp-real-insert-file-contents filename visit beg end replace))))
|
|
3173
|
|
3174 (defun ange-ftp-revert-buffer (arg noconfirm)
|
|
3175 "Revert this buffer from a remote file using ftp."
|
|
3176 (let ((opoint (point)))
|
|
3177 (cond ((null buffer-file-name)
|
|
3178 (error "Buffer does not seem to be associated with any file"))
|
|
3179 ((or noconfirm
|
|
3180 (yes-or-no-p (format "Revert buffer from file %s? "
|
|
3181 buffer-file-name)))
|
|
3182 (let ((buffer-read-only nil))
|
|
3183 ;; Set buffer-file-name to nil
|
|
3184 ;; so that we don't try to lock the file.
|
|
3185 (let ((buffer-file-name nil))
|
|
3186 (unlock-buffer)
|
|
3187 (erase-buffer))
|
|
3188 (insert-file-contents buffer-file-name t))
|
|
3189 (goto-char (min opoint (point-max)))
|
|
3190 (after-find-file nil)
|
|
3191 t))))
|
|
3192
|
|
3193 (defun ange-ftp-expand-symlink (file dir)
|
|
3194 (if (file-name-absolute-p file)
|
|
3195 (ange-ftp-replace-path-component dir file)
|
|
3196 (expand-file-name file dir)))
|
|
3197
|
|
3198 (defun ange-ftp-file-symlink-p (file)
|
|
3199 "Documented as original."
|
|
3200 ;; call ange-ftp-expand-file-name rather than the normal
|
|
3201 ;; expand-file-name to stop loops when using a package that
|
|
3202 ;; redefines both file-symlink-p and expand-file-name.
|
|
3203 (setq file (ange-ftp-expand-file-name file))
|
|
3204 (if (ange-ftp-ftp-path file)
|
|
3205 (let ((file-ent
|
|
3206 (ange-ftp-get-hash-entry
|
|
3207 (ange-ftp-get-file-part file)
|
|
3208 (ange-ftp-get-files (file-name-directory file)))))
|
|
3209 (if (stringp file-ent)
|
|
3210 (if (file-name-absolute-p file-ent)
|
|
3211 (ange-ftp-replace-path-component
|
|
3212 (file-name-directory file) file-ent)
|
|
3213 file-ent)))
|
|
3214 (ange-ftp-real-file-symlink-p file)))
|
|
3215
|
|
3216 (defun ange-ftp-file-exists-p (path)
|
|
3217 "Documented as original."
|
|
3218 (setq path (expand-file-name path))
|
|
3219 (if (ange-ftp-ftp-path path)
|
|
3220 (if (ange-ftp-file-entry-p path)
|
|
3221 (let ((file-ent (ange-ftp-get-file-entry path)))
|
|
3222 (if (stringp file-ent)
|
|
3223 (file-exists-p
|
|
3224 (ange-ftp-expand-symlink file-ent
|
|
3225 (file-name-directory
|
|
3226 (directory-file-name path))))
|
|
3227 t)))
|
|
3228 (ange-ftp-real-file-exists-p path)))
|
|
3229
|
|
3230 (defun ange-ftp-file-directory-p (path)
|
|
3231 "Documented as original."
|
|
3232 (setq path (expand-file-name path))
|
|
3233 (if (ange-ftp-ftp-path path)
|
|
3234 ;; We do a file-name-as-directory on path here because some
|
|
3235 ;; machines (VMS) use a .DIR to indicate the filename associated
|
|
3236 ;; with a directory. This needs to be canonicalized.
|
|
3237 (let ((file-ent (ange-ftp-get-file-entry
|
|
3238 (ange-ftp-file-name-as-directory path))))
|
|
3239 (if (stringp file-ent)
|
|
3240 (file-directory-p
|
|
3241 (ange-ftp-expand-symlink file-ent
|
|
3242 (file-name-directory
|
|
3243 (directory-file-name path))))
|
|
3244 file-ent))
|
|
3245 (ange-ftp-real-file-directory-p path)))
|
|
3246
|
|
3247 (defun ange-ftp-directory-files (directory &optional full match
|
|
3248 &rest v19-args)
|
|
3249 "Documented as original."
|
|
3250 (setq directory (expand-file-name directory))
|
|
3251 (if (ange-ftp-ftp-path directory)
|
|
3252 (progn
|
|
3253 (ange-ftp-barf-if-not-directory directory)
|
|
3254 (let ((tail (ange-ftp-hash-table-keys
|
|
3255 (ange-ftp-get-files directory)))
|
|
3256 files f)
|
|
3257 (setq directory (file-name-as-directory directory))
|
|
3258 (ange-ftp-save-match-data
|
|
3259 (while tail
|
|
3260 (setq f (car tail)
|
|
3261 tail (cdr tail))
|
|
3262 (if (or (not match) (string-match match f))
|
|
3263 (setq files
|
|
3264 (cons (if full (concat directory f) f) files)))))
|
|
3265 (nreverse files)))
|
|
3266 (apply 'ange-ftp-real-directory-files directory full match v19-args)))
|
|
3267
|
|
3268 (defun ange-ftp-file-attributes (file)
|
|
3269 "Documented as original."
|
|
3270 (setq file (expand-file-name file))
|
|
3271 (let ((parsed (ange-ftp-ftp-path file)))
|
|
3272 (if parsed
|
|
3273 (let ((part (ange-ftp-get-file-part file))
|
|
3274 (files (ange-ftp-get-files (file-name-directory file))))
|
|
3275 (if (ange-ftp-hash-entry-exists-p part files)
|
|
3276 (let ((host (nth 0 parsed))
|
|
3277 (user (nth 1 parsed))
|
|
3278 (path (nth 2 parsed))
|
|
3279 (dirp (ange-ftp-get-hash-entry part files)))
|
|
3280 (list (if (and (stringp dirp) (file-name-absolute-p dirp))
|
|
3281 (ange-ftp-expand-symlink dirp
|
|
3282 (file-name-directory file))
|
|
3283 dirp) ;0 file type
|
|
3284 -1 ;1 link count
|
|
3285 -1 ;2 uid
|
|
3286 -1 ;3 gid
|
|
3287 '(0 0) ;4 atime
|
|
3288 '(0 0) ;5 mtime
|
|
3289 '(0 0) ;6 ctime
|
|
3290 -1 ;7 size
|
|
3291 (concat (if (stringp dirp) "l" (if dirp "d" "-"))
|
|
3292 "?????????") ;8 mode
|
|
3293 nil ;9 gid weird
|
|
3294 ;; Hack to give remote files a unique "inode number".
|
|
3295 ;; It's actually the sum of the characters in its name.
|
|
3296 (apply '+ (nconc (mapcar 'identity host)
|
|
3297 (mapcar 'identity user)
|
|
3298 (mapcar 'identity
|
|
3299 (directory-file-name path))))
|
|
3300 -1 ;11 device number [v19 only]
|
|
3301 ))))
|
|
3302 (ange-ftp-real-file-attributes file))))
|
|
3303
|
|
3304 (defun ange-ftp-file-writable-p (file)
|
|
3305 "Documented as original."
|
|
3306 (setq file (expand-file-name file))
|
|
3307 (if (ange-ftp-ftp-path file)
|
|
3308 (or (file-exists-p file) ;guess here for speed
|
|
3309 (file-directory-p (file-name-directory file)))
|
|
3310 (ange-ftp-real-file-writable-p file)))
|
|
3311
|
|
3312 (defun ange-ftp-file-readable-p (file)
|
|
3313 "Documented as original."
|
|
3314 (setq file (expand-file-name file))
|
|
3315 (if (ange-ftp-ftp-path file)
|
|
3316 (file-exists-p file)
|
|
3317 (ange-ftp-real-file-readable-p file)))
|
|
3318
|
|
3319 (defun ange-ftp-delete-file (file)
|
|
3320 "Documented as original."
|
|
3321 (interactive "fDelete file: ")
|
|
3322 (setq file (expand-file-name file))
|
|
3323 (let ((parsed (ange-ftp-ftp-path file)))
|
|
3324 (if parsed
|
|
3325 (let* ((host (nth 0 parsed))
|
|
3326 (user (nth 1 parsed))
|
|
3327 (path (ange-ftp-quote-string (nth 2 parsed)))
|
|
3328 (abbr (ange-ftp-abbreviate-filename file))
|
|
3329 (result (ange-ftp-send-cmd host user
|
|
3330 (list 'delete path)
|
|
3331 (format "Deleting %s" abbr))))
|
|
3332 (or (car result)
|
|
3333 (signal 'ftp-error
|
|
3334 (list
|
|
3335 "Removing old name"
|
|
3336 (format "FTP Error: \"%s\"" (cdr result))
|
|
3337 file)))
|
|
3338 (ange-ftp-delete-file-entry file))
|
|
3339 (ange-ftp-real-delete-file file))))
|
|
3340
|
|
3341 (defun ange-ftp-verify-visited-file-modtime (buf)
|
|
3342 "Documented as original."
|
|
3343 (let ((name (buffer-file-name buf)))
|
|
3344 (if (and (stringp name) (ange-ftp-ftp-path name))
|
|
3345 t
|
|
3346 (ange-ftp-real-verify-visited-file-modtime buf))))
|
|
3347
|
|
3348 (defun ange-ftp-backup-buffer ()
|
|
3349 "Documented as original."
|
|
3350 (let (parsed)
|
|
3351 (if (and
|
|
3352 (listp ange-ftp-make-backup-files)
|
|
3353 (stringp buffer-file-name)
|
|
3354 (setq parsed (ange-ftp-ftp-path buffer-file-name))
|
|
3355 (or
|
|
3356 (null ange-ftp-make-backup-files)
|
|
3357 (not
|
|
3358 (memq
|
|
3359 (ange-ftp-host-type
|
|
3360 (car parsed))
|
|
3361 ange-ftp-make-backup-files))))
|
|
3362 nil
|
|
3363 (ange-ftp-real-backup-buffer))))
|
|
3364
|
|
3365 ;;;; ------------------------------------------------------------
|
|
3366 ;;;; File copying support... totally re-written 6/24/92.
|
|
3367 ;;;; ------------------------------------------------------------
|
|
3368
|
|
3369 (defun ange-ftp-barf-or-query-if-file-exists (absname querystring interactive)
|
|
3370 (if (file-exists-p absname)
|
|
3371 (if (not interactive)
|
|
3372 (signal 'file-already-exists (list absname))
|
|
3373 (if (not (yes-or-no-p (format "File %s already exists; %s anyway? "
|
|
3374 absname querystring)))
|
|
3375 (signal 'file-already-exists (list absname))))))
|
|
3376
|
|
3377 ;; async local copy commented out for now since I don't seem to get
|
|
3378 ;; the process sentinel called for some processes.
|
|
3379 ;;
|
|
3380 ;; (defun ange-ftp-copy-file-locally (filename newname ok-if-already-exists
|
|
3381 ;; keep-date cont)
|
|
3382 ;; "Kludge to copy a local file and call a continuation when the copy
|
|
3383 ;; finishes."
|
|
3384 ;; ;; check to see if we can overwrite
|
|
3385 ;; (if (or (not ok-if-already-exists)
|
|
3386 ;; (numberp ok-if-already-exists))
|
|
3387 ;; (ange-ftp-barf-or-query-if-file-exists newname "copy to it"
|
|
3388 ;; (numberp ok-if-already-exists)))
|
|
3389 ;; (let ((proc (start-process " *copy*"
|
|
3390 ;; (generate-new-buffer "*copy*")
|
|
3391 ;; "cp"
|
|
3392 ;; filename
|
|
3393 ;; newname))
|
|
3394 ;; res)
|
|
3395 ;; (set-process-sentinel proc (function ange-ftp-copy-file-locally-sentinel))
|
|
3396 ;; (process-kill-without-query proc)
|
|
3397 ;; (save-excursion
|
|
3398 ;; (set-buffer (process-buffer proc))
|
|
3399 ;; (make-variable-buffer-local 'copy-cont)
|
|
3400 ;; (setq copy-cont cont))))
|
|
3401 ;;
|
|
3402 ;; (defun ange-ftp-copy-file-locally-sentinel (proc status)
|
|
3403 ;; (save-excursion
|
|
3404 ;; (set-buffer (process-buffer proc))
|
|
3405 ;; (let ((cont copy-cont)
|
|
3406 ;; (result (buffer-string)))
|
|
3407 ;; (unwind-protect
|
|
3408 ;; (if (and (string-equal status "finished\n")
|
|
3409 ;; (zerop (length result)))
|
|
3410 ;; (ange-ftp-call-cont cont t nil)
|
|
3411 ;; (ange-ftp-call-cont cont
|
|
3412 ;; nil
|
|
3413 ;; (if (zerop (length result))
|
|
3414 ;; (substring status 0 -1)
|
|
3415 ;; (substring result 0 -1))))
|
|
3416 ;; (kill-buffer (current-buffer))))))
|
|
3417
|
|
3418 ;; this is the extended version of ange-ftp-copy-file-internal that works
|
|
3419 ;; asyncronously if asked nicely.
|
|
3420 (defun ange-ftp-copy-file-internal (filename newname ok-if-already-exists
|
|
3421 keep-date &optional msg cont nowait)
|
|
3422 (setq filename (expand-file-name filename)
|
|
3423 newname (expand-file-name newname))
|
|
3424
|
|
3425 ;; canonicalize newname if a directory.
|
|
3426 (if (file-directory-p newname)
|
|
3427 (setq newname (expand-file-name (file-name-nondirectory filename) newname)))
|
|
3428
|
|
3429 (let ((f-parsed (ange-ftp-ftp-path filename))
|
|
3430 (t-parsed (ange-ftp-ftp-path newname)))
|
|
3431
|
|
3432 ;; local file to local file copy?
|
|
3433 (if (and (not f-parsed) (not t-parsed))
|
|
3434 (progn
|
|
3435 (ange-ftp-real-copy-file filename newname ok-if-already-exists
|
|
3436 keep-date)
|
|
3437 (if cont
|
|
3438 (ange-ftp-call-cont cont t "Copied locally")))
|
|
3439 ;; one or both files are remote.
|
|
3440 (let* ((f-host (and f-parsed (nth 0 f-parsed)))
|
|
3441 (f-user (and f-parsed (nth 1 f-parsed)))
|
|
3442 (f-path (and f-parsed (ange-ftp-quote-string (nth 2 f-parsed))))
|
|
3443 (f-abbr (ange-ftp-abbreviate-filename filename))
|
|
3444 (t-host (and t-parsed (nth 0 t-parsed)))
|
|
3445 (t-user (and t-parsed (nth 1 t-parsed)))
|
|
3446 (t-path (and t-parsed (ange-ftp-quote-string (nth 2 t-parsed))))
|
|
3447 (t-abbr (ange-ftp-abbreviate-filename newname filename))
|
|
3448 (binary (or (ange-ftp-binary-file filename)
|
|
3449 (ange-ftp-binary-file newname)))
|
|
3450 temp1
|
|
3451 temp2)
|
|
3452
|
|
3453 ;; check to see if we can overwrite
|
|
3454 (if (or (not ok-if-already-exists)
|
|
3455 (numberp ok-if-already-exists))
|
|
3456 (ange-ftp-barf-or-query-if-file-exists newname "copy to it"
|
|
3457 (numberp ok-if-already-exists)))
|
|
3458
|
|
3459 ;; do the copying.
|
|
3460 (if f-parsed
|
|
3461
|
|
3462 ;; filename was remote.
|
|
3463 (progn
|
|
3464 (if (or (ange-ftp-use-gateway-p f-host)
|
|
3465 t-parsed)
|
|
3466 ;; have to use intermediate file if we are getting via
|
|
3467 ;; gateway machine or we are doing a remote to remote copy.
|
|
3468 (setq temp1 (ange-ftp-make-tmp-name f-host)))
|
|
3469
|
|
3470 (if binary
|
|
3471 (ange-ftp-set-binary-mode f-host f-user))
|
|
3472
|
|
3473 (ange-ftp-send-cmd
|
|
3474 f-host
|
|
3475 f-user
|
|
3476 (list 'get f-path (or temp1 newname))
|
|
3477 (or msg
|
|
3478 (if (and temp1 t-parsed)
|
|
3479 (format "Getting %s" f-abbr)
|
|
3480 (format "Copying %s to %s" f-abbr t-abbr)))
|
|
3481 (list (function ange-ftp-cf1)
|
|
3482 filename newname binary msg
|
|
3483 f-parsed f-host f-user f-path f-abbr
|
|
3484 t-parsed t-host t-user t-path t-abbr
|
|
3485 temp1 temp2 cont nowait)
|
|
3486 nowait))
|
|
3487
|
|
3488 ;; filename wasn't remote. newname must be remote. call the
|
|
3489 ;; function which does the remainder of the copying work.
|
|
3490 (ange-ftp-cf1 t nil
|
|
3491 filename newname binary msg
|
|
3492 f-parsed f-host f-user f-path f-abbr
|
|
3493 t-parsed t-host t-user t-path t-abbr
|
|
3494 nil nil cont nowait))))))
|
|
3495
|
|
3496 ;; next part of copying routine.
|
|
3497 (defun ange-ftp-cf1 (result line
|
|
3498 filename newname binary msg
|
|
3499 f-parsed f-host f-user f-path f-abbr
|
|
3500 t-parsed t-host t-user t-path t-abbr
|
|
3501 temp1 temp2 cont nowait)
|
|
3502 (if line
|
|
3503 ;; filename must have been remote, and we must have just done a GET.
|
|
3504 (unwind-protect
|
|
3505 (or result
|
|
3506 ;; GET failed for some reason. Clean up and get out.
|
|
3507 (progn
|
|
3508 (and temp1 (ange-ftp-del-tmp-name temp1))
|
|
3509 (or cont
|
|
3510 (signal 'ftp-error (list "Opening input file"
|
|
3511 (format "FTP Error: \"%s\"" line)
|
|
3512 filename)))))
|
|
3513 ;; cleanup
|
|
3514 (if binary
|
|
3515 (ange-ftp-set-ascii-mode f-host f-user))))
|
|
3516
|
|
3517 (if result
|
|
3518 ;; We now have to copy either temp1 or filename to newname.
|
|
3519 (if t-parsed
|
|
3520
|
|
3521 ;; newname was remote.
|
|
3522 (progn
|
|
3523 (if (ange-ftp-use-gateway-p t-host)
|
|
3524 (setq temp2 (ange-ftp-make-tmp-name t-host)))
|
|
3525
|
|
3526 ;; make sure data is moved into the right place for the
|
|
3527 ;; outgoing transfer. gateway temporary files complicate
|
|
3528 ;; things nicely.
|
|
3529 (if temp1
|
|
3530 (if temp2
|
|
3531 (if (string-equal temp1 temp2)
|
|
3532 (setq temp1 nil)
|
|
3533 (ange-ftp-real-copy-file temp1 temp2 t))
|
|
3534 (setq temp2 temp1 temp1 nil))
|
|
3535 (if temp2
|
|
3536 (ange-ftp-real-copy-file filename temp2 t)))
|
|
3537
|
|
3538 (if binary
|
|
3539 (ange-ftp-set-binary-mode t-host t-user))
|
|
3540
|
|
3541 ;; tell the process filter what size the file is.
|
|
3542 (let ((attr (file-attributes (or temp2 filename))))
|
|
3543 (if attr
|
|
3544 (ange-ftp-set-xfer-size t-host t-user (nth 7 attr))))
|
|
3545
|
|
3546 (ange-ftp-send-cmd
|
|
3547 t-host
|
|
3548 t-user
|
|
3549 (list 'put (or temp2 filename) t-path)
|
|
3550 (or msg
|
|
3551 (if (and temp2 f-parsed)
|
|
3552 (format "Putting %s" newname)
|
|
3553 (format "Copying %s to %s" f-abbr t-abbr)))
|
|
3554 (list (function ange-ftp-cf2)
|
|
3555 newname t-host t-user binary temp1 temp2 cont)
|
|
3556 nowait))
|
|
3557
|
|
3558 ;; newname wasn't remote.
|
|
3559 (ange-ftp-cf2 t nil newname t-host t-user binary temp1 temp2 cont))
|
|
3560
|
|
3561 ;; first copy failed, tell caller
|
|
3562 (ange-ftp-call-cont cont result line)))
|
|
3563
|
|
3564 ;; last part of copying routine.
|
|
3565 (defun ange-ftp-cf2 (result line newname t-host t-user binary temp1 temp2 cont)
|
|
3566 (unwind-protect
|
|
3567 (if line
|
|
3568 ;; result from doing a local to remote copy.
|
|
3569 (unwind-protect
|
|
3570 (progn
|
|
3571 (or result
|
|
3572 (or cont
|
|
3573 (signal 'ftp-error
|
|
3574 (list "Opening output file"
|
|
3575 (format "FTP Error: \"%s\"" line)
|
|
3576 newname))))
|
|
3577
|
|
3578 (ange-ftp-add-file-entry newname))
|
|
3579
|
|
3580 ;; cleanup.
|
|
3581 (if binary
|
|
3582 (ange-ftp-set-ascii-mode t-host t-user)))
|
|
3583
|
|
3584 ;; newname was local.
|
|
3585 (if temp1
|
|
3586 (ange-ftp-real-copy-file temp1 newname t)))
|
|
3587
|
|
3588 ;; clean up
|
|
3589 (and temp1 (ange-ftp-del-tmp-name temp1))
|
|
3590 (and temp2 (ange-ftp-del-tmp-name temp2))
|
|
3591 (ange-ftp-call-cont cont result line)))
|
|
3592
|
|
3593 (defun ange-ftp-copy-file (filename newname &optional ok-if-already-exists
|
|
3594 keep-date)
|
|
3595 "Documented as original."
|
|
3596 (interactive "fCopy file: \nFCopy %s to file: \np")
|
|
3597 (ange-ftp-copy-file-internal filename
|
|
3598 newname
|
|
3599 ok-if-already-exists
|
|
3600 keep-date
|
|
3601 nil
|
|
3602 nil
|
|
3603 (interactive-p)))
|
|
3604
|
|
3605 ;;;; ------------------------------------------------------------
|
|
3606 ;;;; File renaming support.
|
|
3607 ;;;; ------------------------------------------------------------
|
|
3608
|
|
3609 (defun ange-ftp-rename-remote-to-remote (filename newname f-parsed t-parsed
|
|
3610 binary)
|
|
3611 "Rename remote file FILE to remote file NEWNAME."
|
|
3612 (let ((f-host (nth 0 f-parsed))
|
|
3613 (f-user (nth 1 f-parsed))
|
|
3614 (t-host (nth 0 t-parsed))
|
|
3615 (t-user (nth 1 t-parsed)))
|
|
3616 (if (and (string-equal f-host t-host)
|
|
3617 (string-equal f-user t-user))
|
|
3618 (let* ((f-path (ange-ftp-quote-string (nth 2 f-parsed)))
|
|
3619 (t-path (ange-ftp-quote-string (nth 2 t-parsed)))
|
|
3620 (cmd (list 'rename f-path t-path))
|
|
3621 (fabbr (ange-ftp-abbreviate-filename filename))
|
|
3622 (nabbr (ange-ftp-abbreviate-filename newname filename))
|
|
3623 (result (ange-ftp-send-cmd f-host f-user cmd
|
|
3624 (format "Renaming %s to %s"
|
|
3625 fabbr
|
|
3626 nabbr))))
|
|
3627 (or (car result)
|
|
3628 (signal 'ftp-error
|
|
3629 (list
|
|
3630 "Renaming"
|
|
3631 (format "FTP Error: \"%s\"" (cdr result))
|
|
3632 filename
|
|
3633 newname)))
|
|
3634 (ange-ftp-add-file-entry newname)
|
|
3635 (ange-ftp-delete-file-entry filename))
|
|
3636 (ange-ftp-copy-file-internal filename newname t nil)
|
|
3637 (delete-file filename))))
|
|
3638
|
|
3639 (defun ange-ftp-rename-local-to-remote (filename newname)
|
|
3640 "Rename local FILE to remote file NEWNAME."
|
|
3641 (let* ((fabbr (ange-ftp-abbreviate-filename filename))
|
|
3642 (nabbr (ange-ftp-abbreviate-filename newname filename))
|
|
3643 (msg (format "Renaming %s to %s" fabbr nabbr)))
|
|
3644 (ange-ftp-copy-file-internal filename newname t nil msg)
|
|
3645 (let (ange-ftp-process-verbose)
|
|
3646 (delete-file filename))))
|
|
3647
|
|
3648 (defun ange-ftp-rename-remote-to-local (filename newname)
|
|
3649 "Rename remote file FILE to local file NEWNAME."
|
|
3650 (let* ((fabbr (ange-ftp-abbreviate-filename filename))
|
|
3651 (nabbr (ange-ftp-abbreviate-filename newname filename))
|
|
3652 (msg (format "Renaming %s to %s" fabbr nabbr)))
|
|
3653 (ange-ftp-copy-file-internal filename newname t nil msg)
|
|
3654 (let (ange-ftp-process-verbose)
|
|
3655 (delete-file filename))))
|
|
3656
|
|
3657 (defun ange-ftp-rename-file (filename newname &optional ok-if-already-exists)
|
|
3658 "Documented as original."
|
|
3659 (interactive "fRename file: \nFRename %s to file: \np")
|
|
3660 (setq filename (expand-file-name filename))
|
|
3661 (setq newname (expand-file-name newname))
|
|
3662 (let* ((f-parsed (ange-ftp-ftp-path filename))
|
|
3663 (t-parsed (ange-ftp-ftp-path newname))
|
|
3664 (binary (if (or f-parsed t-parsed) (ange-ftp-binary-file filename))))
|
|
3665 (if (and (or f-parsed t-parsed)
|
|
3666 (or (not ok-if-already-exists)
|
|
3667 (numberp ok-if-already-exists)))
|
|
3668 (ange-ftp-barf-or-query-if-file-exists
|
|
3669 newname
|
|
3670 "rename to it"
|
|
3671 (numberp ok-if-already-exists)))
|
|
3672 (if f-parsed
|
|
3673 (if t-parsed
|
|
3674 (ange-ftp-rename-remote-to-remote filename newname f-parsed
|
|
3675 t-parsed binary)
|
|
3676 (ange-ftp-rename-remote-to-local filename newname))
|
|
3677 (if t-parsed
|
|
3678 (ange-ftp-rename-local-to-remote filename newname)
|
|
3679 (ange-ftp-real-rename-file filename newname ok-if-already-exists)))))
|
|
3680
|
|
3681 ;;;; ------------------------------------------------------------
|
|
3682 ;;;; Classic Dired support.
|
|
3683 ;;;; ------------------------------------------------------------
|
|
3684
|
|
3685 (defvar ange-ftp-dired-host-type nil
|
|
3686 "The host type associated with a dired buffer. (buffer local)")
|
|
3687 (make-variable-buffer-local 'ange-ftp-dired-host-type)
|
|
3688
|
|
3689 (defun ange-ftp-dired-readin (dirname buffer)
|
|
3690 "Documented as original."
|
|
3691 (let ((file (ange-ftp-abbreviate-filename dirname))
|
|
3692 (parsed (ange-ftp-ftp-path dirname)))
|
|
3693 (save-excursion
|
|
3694 (ange-ftp-message "Reading directory %s..." file)
|
|
3695 (set-buffer buffer)
|
|
3696 (let ((buffer-read-only nil))
|
|
3697 (widen)
|
|
3698 (erase-buffer)
|
|
3699 (setq dirname (expand-file-name dirname))
|
|
3700 (if parsed
|
|
3701 (let ((host-type (ange-ftp-host-type (car parsed))))
|
|
3702 (setq ange-ftp-dired-host-type host-type)
|
|
3703 (insert (ange-ftp-ls dirname dired-listing-switches t)))
|
|
3704 (if (ange-ftp-real-file-directory-p dirname)
|
|
3705 (call-process "ls" nil buffer nil
|
|
3706 dired-listing-switches dirname)
|
|
3707 (let ((default-directory
|
|
3708 (ange-ftp-real-file-name-directory dirname)))
|
|
3709 (call-process
|
|
3710 shell-file-name nil buffer nil
|
|
3711 "-c" (concat
|
|
3712 "ls " dired-listing-switches " "
|
|
3713 (ange-ftp-real-file-name-nondirectory dirname))))))
|
|
3714 (goto-char (point-min))
|
|
3715 (while (not (eobp))
|
|
3716 (insert " ")
|
|
3717 (forward-line 1))
|
|
3718 (goto-char (point-min))))
|
|
3719 (ange-ftp-message "Reading directory %s...done" file)))
|
|
3720
|
|
3721 (defun ange-ftp-dired-revert (&optional arg noconfirm)
|
|
3722 "Documented as original."
|
|
3723 (if (and dired-directory
|
|
3724 (ange-ftp-ftp-path (expand-file-name dired-directory)))
|
|
3725 (setq ange-ftp-ls-cache-file nil))
|
|
3726 (ange-ftp-real-dired-revert arg noconfirm))
|
|
3727
|
|
3728 ;;;; ------------------------------------------------------------
|
|
3729 ;;;; Tree Dired support (ange & Sebastian Kremer)
|
|
3730 ;;;; ------------------------------------------------------------
|
|
3731
|
|
3732 (defvar ange-ftp-dired-re-exe-alist nil
|
|
3733 "Association list of regexps \(strings\) which match file lines of
|
|
3734 executable files.")
|
|
3735
|
|
3736 (defvar ange-ftp-dired-re-dir-alist nil
|
|
3737 "Association list of regexps \(strings\) which match file lines of
|
|
3738 subdirectories.")
|
|
3739
|
|
3740 (defvar ange-ftp-dired-insert-headerline-alist nil
|
|
3741 "Association list of \(TYPE \. FUNC \) pairs, where FUNC is
|
|
3742 the function to be used by dired to insert the headerline of
|
|
3743 the dired buffer.")
|
|
3744
|
|
3745 (defvar ange-ftp-dired-move-to-filename-alist nil
|
|
3746 "Association list of \(TYPE \. FUNC \) pairs, where FUNC is
|
|
3747 the function to be used by dired to move to the beginning of a
|
|
3748 filename.")
|
|
3749
|
|
3750 (defvar ange-ftp-dired-move-to-end-of-filename-alist nil
|
|
3751 "Association list of \(TYPE \. FUNC \) pairs, where FUNC is
|
|
3752 the function to be used by dired to move to the end of a
|
|
3753 filename.")
|
|
3754
|
|
3755 (defvar ange-ftp-dired-get-filename-alist nil
|
|
3756 "Association list of \(TYPE \. FUNC \) pairs, where FUNC is
|
|
3757 the function to be used by dired to get a filename from the
|
|
3758 current line.")
|
|
3759
|
|
3760 (defvar ange-ftp-dired-between-files-alist nil
|
|
3761 "Association list of \(TYPE \. FUNC \) pairs, where FUNC is
|
|
3762 the function to be used by dired to determine when the point
|
|
3763 is on a line between files.")
|
|
3764
|
|
3765 (defvar ange-ftp-dired-ls-trim-alist nil
|
|
3766 "Association list of \( TYPE \. FUNC \) pairs, where FUNC is
|
|
3767 a function which trims extraneous lines from a directory listing.")
|
|
3768
|
|
3769 (defvar ange-ftp-dired-clean-directory-alist nil
|
|
3770 "Association list of \( TYPE \. FUNC \) pairs, where FUNC is
|
|
3771 a function which cleans out old versions of files in the OS TYPE.")
|
|
3772
|
|
3773 (defvar ange-ftp-dired-flag-backup-files-alist nil
|
|
3774 "Association list of \( TYPE \. FUNC \) pairs, where FUNC is
|
|
3775 a functions which flags the backup files for deletion in the OS TYPE.")
|
|
3776
|
|
3777 (defvar ange-ftp-dired-backup-diff-alist nil
|
|
3778 "Association list of \( TYPE \. FUNC \) pairs, where FUNC diffs
|
|
3779 a file with its backup. The backup file is determined according to
|
|
3780 the OS TYPE.")
|
|
3781
|
|
3782 ;; Could use dired-before-readin-hook here, instead of overloading
|
|
3783 ;; dired-readin. However, if people change this hook after ange-ftp
|
|
3784 ;; is loaded, they'll break things.
|
|
3785 ;; Also, why overload dired-readin rather than dired-mode?
|
|
3786 ;; Because I don't want to muck up virtual dired (see dired-x.el).
|
|
3787
|
|
3788 (defun ange-ftp-tree-dired-readin (dirname buffer)
|
|
3789 "Documented as original."
|
|
3790 (let ((parsed (ange-ftp-ftp-path dirname)))
|
|
3791 (if parsed
|
|
3792 (save-excursion
|
|
3793 (set-buffer buffer)
|
|
3794 (setq ange-ftp-dired-host-type
|
|
3795 (ange-ftp-host-type (car parsed)))
|
|
3796 (and ange-ftp-dl-dir-regexp
|
|
3797 (eq ange-ftp-dired-host-type 'unix)
|
|
3798 (string-match ange-ftp-dl-dir-regexp dirname)
|
|
3799 (setq ange-ftp-dired-host-type 'unix:dl))
|
|
3800 (let ((eentry (assq ange-ftp-dired-host-type
|
|
3801 ange-ftp-dired-re-exe-alist))
|
|
3802 (dentry (assq ange-ftp-dired-host-type
|
|
3803 ange-ftp-dired-re-dir-alist)))
|
|
3804 (if eentry
|
|
3805 (set (make-local-variable 'dired-re-exe) (cdr eentry)))
|
|
3806 (if dentry
|
|
3807 (set (make-local-variable 'dired-re-dir) (cdr dentry)))
|
|
3808 ;; No switches are sent to dumb hosts, so don't confuse dired.
|
|
3809 ;; I hope that dired doesn't get excited if it doesn't see the l
|
|
3810 ;; switch. If it does, then maybe fake things by setting this to
|
|
3811 ;; "-Al".
|
|
3812 (if (memq ange-ftp-dired-host-type ange-ftp-dumb-host-types)
|
|
3813 (setq dired-actual-switches "-Al"))))))
|
|
3814 (ange-ftp-real-dired-readin dirname buffer))
|
|
3815
|
|
3816 (defun ange-ftp-dired-insert-headerline (dir)
|
|
3817 "Documented as original."
|
|
3818 (funcall (or (and ange-ftp-dired-host-type
|
|
3819 (cdr (assq ange-ftp-dired-host-type
|
|
3820 ange-ftp-dired-insert-headerline-alist)))
|
|
3821 'ange-ftp-real-dired-insert-headerline)
|
|
3822 dir))
|
|
3823
|
|
3824 (defun ange-ftp-dired-move-to-filename (&optional raise-error eol)
|
|
3825 "Documented as original."
|
|
3826 (funcall (or (and ange-ftp-dired-host-type
|
|
3827 (cdr (assq ange-ftp-dired-host-type
|
|
3828 ange-ftp-dired-move-to-filename-alist)))
|
|
3829 'ange-ftp-real-dired-move-to-filename)
|
|
3830 raise-error eol))
|
|
3831
|
|
3832 (defun ange-ftp-dired-move-to-end-of-filename (&optional no-error)
|
|
3833 "Documented as original."
|
|
3834 (funcall (or (and ange-ftp-dired-host-type
|
|
3835 (cdr (assq ange-ftp-dired-host-type
|
|
3836 ange-ftp-dired-move-to-end-of-filename-alist)))
|
|
3837 'ange-ftp-real-dired-move-to-end-of-filename)
|
|
3838 no-error))
|
|
3839
|
|
3840 (defun ange-ftp-dired-get-filename (&optional localp no-error-if-not-filep)
|
|
3841 "Documented as original."
|
|
3842 (funcall (or (and ange-ftp-dired-host-type
|
|
3843 (cdr (assq ange-ftp-dired-host-type
|
|
3844 ange-ftp-dired-get-filename-alist)))
|
|
3845 'ange-ftp-real-dired-get-filename)
|
|
3846 localp no-error-if-not-filep))
|
|
3847
|
|
3848 (defun ange-ftp-dired-between-files ()
|
|
3849 "Documented as original."
|
|
3850 (funcall (or (and ange-ftp-dired-host-type
|
|
3851 (cdr (assq ange-ftp-dired-host-type
|
|
3852 ange-ftp-dired-between-files-alist)))
|
|
3853 'ange-ftp-real-dired-between-files)))
|
|
3854
|
|
3855 (defvar ange-ftp-bob-version-alist nil
|
|
3856 "Association list of pairs \( TYPE \. FUNC \), where FUNC is
|
|
3857 a function to be used to bob the version number off of a filename
|
|
3858 in OS TYPE.")
|
|
3859
|
|
3860 (defun ange-ftp-dired-find-file ()
|
|
3861 "Documented as original."
|
|
3862 (interactive)
|
|
3863 (find-file (funcall (or (and ange-ftp-dired-host-type
|
|
3864 (cdr (assq ange-ftp-dired-host-type
|
|
3865 ange-ftp-bob-version-alist)))
|
|
3866 'identity)
|
|
3867 (dired-get-filename))))
|
|
3868
|
|
3869 ;; Need the following functions for making filenames of compressed
|
|
3870 ;; files, because some OS's (unlike UNIX) do not allow a filename to
|
|
3871 ;; have two extensions.
|
|
3872
|
|
3873 (defvar ange-ftp-dired-compress-make-compressed-filename-alist nil
|
|
3874 "Association list of \( TYPE \. FUNC \) pairs, where FUNC converts a
|
|
3875 filename to the filename of the associated compressed file.")
|
|
3876
|
|
3877 ;;; this overwrites dired's `dired-compress-make-compressed-filename'
|
|
3878 (defun ange-ftp-dired-compress-make-compressed-filename (name &optional reverse)
|
|
3879 "Converts a filename to the filename of the associated compressed
|
|
3880 file. With an optional reverse argument, the reverse conversion is done.
|
|
3881
|
|
3882 Modified to work with gzip (GNU zip) files."
|
|
3883 (let ((parsed (ange-ftp-ftp-path name))
|
|
3884 conversion-func)
|
|
3885 (if (and parsed
|
|
3886 (setq conversion-func
|
|
3887 (cdr (assq (ange-ftp-host-type (car parsed))
|
|
3888 ange-ftp-dired-compress-make-compressed-filename-alist))))
|
|
3889 (funcall conversion-func name reverse)
|
|
3890 (if reverse
|
|
3891
|
|
3892 ;; uncompress...
|
|
3893 ;; return `nil' if no match found -- better than nothing
|
|
3894 (let (case-fold-search ; case-sensitive search
|
|
3895 (string
|
|
3896 (concat "\\.\\(g?z\\|" (regexp-quote dired-gzip-file-extension)
|
|
3897 "$\\|Z\\)$")))
|
|
3898
|
|
3899 (and (string-match string name)
|
|
3900 (substring name 0 (match-beginning 0))))
|
|
3901
|
|
3902 ;; add appropriate extension
|
|
3903 ;; note: it could be that `gz' is not the proper extension for gzip
|
|
3904 (concat name
|
|
3905 (if dired-use-gzip-instead-of-compress
|
|
3906 dired-gzip-file-extension ".Z"))))))
|
|
3907
|
|
3908 (defun ange-ftp-dired-clean-directory (keep)
|
|
3909 "Documented as original."
|
|
3910 (interactive "P")
|
|
3911 (funcall (or (and ange-ftp-dired-host-type
|
|
3912 (cdr (assq ange-ftp-dired-host-type
|
|
3913 ange-ftp-dired-clean-directory-alist)))
|
|
3914 'ange-ftp-real-dired-clean-directory)
|
|
3915 keep))
|
|
3916
|
|
3917 (defun ange-ftp-dired-backup-diff (&optional switches)
|
|
3918 "Documented as original."
|
|
3919 (interactive (list (if (fboundp 'diff-read-switches)
|
|
3920 (diff-read-switches "Diff with switches: "))))
|
|
3921 (funcall (or (and ange-ftp-dired-host-type
|
|
3922 (cdr (assq ange-ftp-dired-host-type
|
|
3923 ange-ftp-dired-backup-diff-alist)))
|
|
3924 'ange-ftp-real-dired-backup-diff)
|
|
3925 switches))
|
|
3926
|
|
3927
|
|
3928 (defun ange-ftp-dired-fixup-subdirs (start file)
|
|
3929 "Turn each subdir name into a valid ange-ftp filename."
|
|
3930
|
|
3931 ;; We haven't indented the listing yet.
|
|
3932 ;; Must be careful about filelines ending in a colon: exclude spaces!
|
|
3933 (let ((subdir-regexp "^\\([^ \n\r]+\\)\\(:\\)[\n\r]"))
|
|
3934 (save-restriction
|
|
3935 (save-excursion
|
|
3936 (narrow-to-region start (point))
|
|
3937 (goto-char start)
|
|
3938 (while (re-search-forward subdir-regexp nil t)
|
|
3939 (goto-char (match-beginning 1))
|
|
3940 (let ((name (buffer-substring (point)
|
|
3941 (match-end 1))))
|
|
3942 (delete-region (point) (match-end 1))
|
|
3943 (insert (ange-ftp-replace-path-component
|
|
3944 file
|
|
3945 name))))))))
|
|
3946
|
|
3947 (defun ange-ftp-dired-ls (file switches &optional wildcard full-directory-p)
|
|
3948 "Documented as original."
|
|
3949 (let ((parsed (ange-ftp-ftp-path file)))
|
|
3950 (if parsed
|
|
3951 (let* ((pt (point))
|
|
3952 (path (nth 2 parsed))
|
|
3953 (host-type (ange-ftp-host-type (car parsed)))
|
|
3954 (dumb (memq host-type ange-ftp-dumb-host-types))
|
|
3955 trim-func case-fold-search)
|
|
3956 ;; Make sure that case-fold-search is nil
|
|
3957 ;; so that we can look at the switches.
|
|
3958 (if wildcard
|
|
3959 (if (not (memq host-type '(unix dumb-unix)))
|
|
3960 (insert (ange-ftp-ls file switches nil))
|
|
3961 ;; Prevent ls from inserting subdirs, as the subdir header
|
|
3962 ;; line format would be wrong (it would have no "/user@host:"
|
|
3963 ;; prefix)
|
|
3964 (insert (ange-ftp-ls file (concat switches "d") nil))
|
|
3965
|
|
3966 ;; Quoting the path part of the file name seems to be a good
|
|
3967 ;; idea (using dired.el's shell-quote function), but ftpd
|
|
3968 ;; always globs ls args before passing them to /bin/ls or even
|
|
3969 ;; doing the ls formatting itself. --> So wildcard characters
|
|
3970 ;; in FILE lose. Sigh...
|
|
3971
|
|
3972 ;; When using wildcards, some ftpd's put the whole directory
|
|
3973 ;; name in front of each filename. Walk down the listing
|
|
3974 ;; generated and remove this stuff.
|
|
3975 (let ((dir (ange-ftp-real-file-name-directory path)))
|
|
3976 (if dir
|
|
3977 (let ((dirq (regexp-quote dir)))
|
|
3978 (save-restriction
|
|
3979 (save-excursion
|
|
3980 (narrow-to-region pt (point))
|
|
3981 (goto-char pt)
|
|
3982 (while (not (eobp))
|
|
3983 (if (dired-move-to-filename)
|
|
3984 (if (re-search-forward dirq nil t)
|
|
3985 (replace-match "")))
|
|
3986 (forward-line 1))))))))
|
|
3987
|
|
3988 ;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
3989 ;; Big issue here Andy! ;;
|
|
3990 ;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
3991 ;; In tree dired V5.245 Sebastian has used the following
|
|
3992 ;; trick to resolve symbolic links to directories. This causes
|
|
3993 ;; havoc with ange-ftp, because ange-ftp expands dots, with
|
|
3994 ;; expand-file-name before it sends them. This means that this
|
|
3995 ;; trick currently fails for remote SysV machines. But worse,
|
|
3996 ;; /vms:/DEV:/FOO/. expands to /vms:/DEV:/FOO, which converts
|
|
3997 ;; to DEV:FOO and not DEV:[FOO]. i.e it is only in UNIX that
|
|
3998 ;; we can play fast and loose with the difference between
|
|
3999 ;; directory names and their associated filenames.
|
|
4000 ;; My temporary fix is to knock Sebastian's dot off.
|
|
4001 ;; Maybe things can be made real clever in
|
|
4002 ;; the future, so that Sebastian can have his way with remote
|
|
4003 ;; SysV machines.
|
|
4004 ;; Sebastian in dired-readin-insert says:
|
|
4005
|
|
4006 ;; On SysV derived system, symbolic links to
|
|
4007 ;; directories are not resolved, while on BSD
|
|
4008 ;; derived it suffices to let DIRNAME end in slash.
|
|
4009 ;; We always let it end in "/." since it does no
|
|
4010 ;; harm on BSD and makes Dired work on such links on
|
|
4011 ;; SysV.
|
|
4012
|
|
4013 (if (string-match "/\\.$" path)
|
|
4014 (setq
|
|
4015 file
|
|
4016 (ange-ftp-replace-path-component
|
|
4017 file (substring path 0 -1))))
|
|
4018 (if (string-match "R" switches)
|
|
4019 (progn
|
|
4020 (insert (ange-ftp-ls file switches nil))
|
|
4021 ;; fix up the subdirectory names in the recursive
|
|
4022 ;; listing.
|
|
4023 (ange-ftp-dired-fixup-subdirs pt file))
|
|
4024 (insert
|
|
4025 (ange-ftp-ls file
|
|
4026 switches
|
|
4027 (and (or dumb (string-match "[aA]" switches))
|
|
4028 full-directory-p))))
|
|
4029 (if (and (null full-directory-p)
|
|
4030 (setq trim-func
|
|
4031 (cdr (assq host-type
|
|
4032 ange-ftp-dired-ls-trim-alist))))
|
|
4033 ;; If full-directory-p and wild-card are null, then only one
|
|
4034 ;; line per file must be inserted.
|
|
4035 ;; Some OS's (like VMS) insert other crap. Clean it out.
|
|
4036 (save-restriction
|
|
4037 (narrow-to-region pt (point))
|
|
4038 (funcall trim-func)))))
|
|
4039 (ange-ftp-real-dired-ls file switches wildcard full-directory-p))))
|
|
4040
|
|
4041 (defvar ange-ftp-remote-shell-file-name
|
|
4042 (if (memq system-type '(hpux usg-unix-v)) ; hope that's right
|
|
4043 "remsh"
|
|
4044 "rsh")
|
|
4045 "Remote shell used by ange-ftp.")
|
|
4046
|
|
4047 (defun ange-ftp-dired-run-shell-command (command &optional in-background)
|
|
4048 "Documented as original."
|
|
4049 (let* ((parsed (ange-ftp-ftp-path default-directory))
|
|
4050 (host (nth 0 parsed))
|
|
4051 (user (nth 1 parsed))
|
|
4052 (path (nth 2 parsed)))
|
|
4053 (if (not parsed)
|
|
4054 (ange-ftp-real-dired-run-shell-command command in-background)
|
|
4055 (if (> (length path) 0) ; else it's $HOME
|
|
4056 (setq command (concat "cd " path "; " command)))
|
|
4057 (setq command
|
|
4058 (format "%s %s \"%s\"" ; remsh -l USER does not work well
|
|
4059 ; on a hp-ux machine I tried
|
|
4060 ange-ftp-remote-shell-file-name host command))
|
|
4061 (ange-ftp-message "Remote command '%s' ..." command)
|
|
4062 ;; Cannot call ange-ftp-real-dired-run-shell-command here as it
|
|
4063 ;; would prepend "cd default-directory" --- which bombs because
|
|
4064 ;; default-directory is in ange-ftp syntax for remote path names.
|
|
4065 (if in-background
|
|
4066 (comint::background command)
|
|
4067 (shell-command command)))))
|
|
4068
|
|
4069 (defun ange-ftp-make-directory (dir &optional parents)
|
|
4070 "Documented as original."
|
|
4071 (interactive (list (let ((current-prefix-arg current-prefix-arg))
|
|
4072 (read-directory-name "Create directory: "))
|
|
4073 current-prefix-arg))
|
|
4074 (if (file-exists-p dir)
|
|
4075 (error "Cannot make directory %s: file already exists" dir)
|
|
4076 (let ((parsed (ange-ftp-ftp-path dir)))
|
|
4077 (if parsed
|
|
4078 (let* ((host (nth 0 parsed))
|
|
4079 (user (nth 1 parsed))
|
|
4080 ;; Some ftp's on unix machines (at least on Suns)
|
|
4081 ;; insist that mkdir take a filename, and not a
|
|
4082 ;; directory-name name as an arg. Argh!! This is a bug.
|
|
4083 ;; Non-unix machines will probably always insist
|
|
4084 ;; that mkdir takes a directory-name as an arg
|
|
4085 ;; (as the ftp man page says it should).
|
|
4086 (path (ange-ftp-quote-string
|
|
4087 (if (eq (ange-ftp-host-type host) 'unix)
|
|
4088 (ange-ftp-real-directory-file-name (nth 2 parsed))
|
|
4089 (ange-ftp-real-file-name-as-directory
|
|
4090 (nth 2 parsed)))))
|
|
4091 (abbr (ange-ftp-abbreviate-filename dir))
|
|
4092 (result (ange-ftp-send-cmd host user
|
|
4093 (list 'mkdir path)
|
|
4094 (format "Making directory %s"
|
|
4095 abbr))))
|
|
4096 (or (car result)
|
|
4097 (ange-ftp-error host user
|
|
4098 (format "Could not make directory %s: %s"
|
|
4099 dir
|
|
4100 (cdr result))))
|
|
4101 (ange-ftp-add-file-entry dir t))
|
|
4102 (ange-ftp-real-make-directory dir parents)))))
|
|
4103
|
|
4104 (defun ange-ftp-remove-directory (dir)
|
|
4105 "Documented as original."
|
|
4106 (interactive
|
|
4107 (list (expand-file-name (read-file-name "Remove directory: "
|
|
4108 nil nil 'confirm))))
|
|
4109 (if (file-directory-p dir)
|
|
4110 (let ((parsed (ange-ftp-ftp-path dir)))
|
|
4111 (if parsed
|
|
4112 (let* ((host (nth 0 parsed))
|
|
4113 (user (nth 1 parsed))
|
|
4114 ;; Some ftp's on unix machines (at least on Suns)
|
|
4115 ;; insist that rmdir take a filename, and not a
|
|
4116 ;; directory-name name as an arg. Argh!! This is a bug.
|
|
4117 ;; Non-unix machines will probably always insist
|
|
4118 ;; that rmdir takes a directory-name as an arg
|
|
4119 ;; (as the ftp man page says it should).
|
|
4120 (path (ange-ftp-quote-string
|
|
4121 (if (eq (ange-ftp-host-type host) 'unix)
|
|
4122 (ange-ftp-real-directory-file-name
|
|
4123 (nth 2 parsed))
|
|
4124 (ange-ftp-real-file-name-as-directory
|
|
4125 (nth 2 parsed)))))
|
|
4126 (abbr (ange-ftp-abbreviate-filename dir))
|
|
4127 (result (ange-ftp-send-cmd host user
|
|
4128 (list 'rmdir path)
|
|
4129 (format "Removing directory %s"
|
|
4130 abbr))))
|
|
4131 (or (car result)
|
|
4132 (ange-ftp-error host user
|
|
4133 (format "Could not remove directory %s: %s"
|
|
4134 dir
|
|
4135 (cdr result))))
|
|
4136 (ange-ftp-delete-file-entry dir t))
|
|
4137 (ange-ftp-real-remove-directory dir)))
|
|
4138 (error "Not a directory: %s" dir)))
|
|
4139
|
|
4140 ;; XEmacs change: This function isn't in the FSF version. Maybe
|
|
4141 ;; because there is no such function as diff-read-args. I can't find
|
|
4142 ;; where there ever _has_ been such a function. If you want this
|
|
4143 ;; functionality, write diff-read-args and uncomment this.
|
|
4144
|
|
4145 ;;(defun ange-ftp-diff (fn1 fn2 &optional switches)
|
|
4146 ;; "Documented as original."
|
|
4147 ;; (interactive (diff-read-args "Diff: " "Diff %s with: "
|
|
4148 ;; "Diff with switches: "))
|
|
4149 ;; (or (and (stringp fn1)
|
|
4150 ;; (stringp fn2))
|
|
4151 ;; (error "diff: arguments must be strings: %s %s" fn1 fn2))
|
|
4152 ;; (or switches
|
|
4153 ;; (setq switches (if (stringp diff-switches)
|
|
4154 ;; diff-switches
|
|
4155 ;; (if (listp diff-switches)
|
|
4156 ;; (mapconcat 'identity diff-switches " ")
|
|
4157 ;; ""))))
|
|
4158 ;; (let* ((fn1 (expand-file-name fn1))
|
|
4159 ;; (fn2 (expand-file-name fn2))
|
|
4160 ;; (pa1 (ange-ftp-ftp-path fn1))
|
|
4161 ;; (pa2 (ange-ftp-ftp-path fn2)))
|
|
4162 ;; (if (or pa1 pa2)
|
|
4163 ;; (let* ((tmp1 (and pa1 (ange-ftp-make-tmp-name (car pa1))))
|
|
4164 ;; (tmp2 (and pa2 (ange-ftp-make-tmp-name (car pa2))))
|
|
4165 ;; (bin1 (and pa1 (ange-ftp-binary-file fn1)))
|
|
4166 ;; (bin2 (and pa2 (ange-ftp-binary-file fn2)))
|
|
4167 ;; (dir1 (file-directory-p fn1))
|
|
4168 ;; (dir2 (file-directory-p fn2))
|
|
4169 ;; (old-dir default-directory)
|
|
4170 ;; (default-directory "/tmp")) ;fool FTP-smart compile.el
|
|
4171 ;; (unwind-protect
|
|
4172 ;; (progn
|
|
4173 ;; (if (and dir1 dir2)
|
|
4174 ;; (error "can't compare remote directories"))
|
|
4175 ;; (if dir1
|
|
4176 ;; (setq fn1 (expand-file-name (file-name-nondirectory fn2)
|
|
4177 ;; fn1)
|
|
4178 ;; pa1 (ange-ftp-ftp-path fn1)
|
|
4179 ;; bin1 (ange-ftp-binary-file fn1)))
|
|
4180 ;; (if dir2
|
|
4181 ;; (setq fn2 (expand-file-name (file-name-nondirectory fn1)
|
|
4182 ;; fn2)
|
|
4183 ;; pa2 (ange-ftp-ftp-path fn2)
|
|
4184 ;; bin2 (ange-ftp-binary-file fn2)))
|
|
4185 ;; (and pa1 (ange-ftp-copy-file-internal fn1 tmp1 t nil
|
|
4186 ;; (format "Getting %s" fn1)))
|
|
4187 ;; (and pa2 (ange-ftp-copy-file-internal fn2 tmp2 t nil
|
|
4188 ;; (format "Getting %s" fn2)))
|
|
4189 ;; (and ange-ftp-process-verbose
|
|
4190 ;; (ange-ftp-message "doing diff..."))
|
|
4191 ;; (sit-for 0)
|
|
4192 ;; (ange-ftp-real-diff (or tmp1 fn1) (or tmp2 fn2) switches)
|
|
4193 ;; (cond ((boundp 'compilation-process)
|
|
4194 ;; (while (and compilation-process
|
|
4195 ;; (eq (process-status compilation-process)
|
|
4196 ;; 'run))
|
|
4197 ;; (accept-process-output compilation-process)))
|
|
4198 ;; ((boundp 'compilation-last-buffer)
|
|
4199 ;; (while (and compilation-last-buffer
|
|
4200 ;; (buffer-name compilation-last-buffer)
|
|
4201 ;; (get-buffer-process
|
|
4202 ;; compilation-last-buffer)
|
|
4203 ;; (eq (process-status
|
|
4204 ;; (get-buffer-process
|
|
4205 ;; compilation-last-buffer))
|
|
4206 ;; 'run))
|
|
4207 ;; (accept-process-output))))
|
|
4208 ;; (and ange-ftp-process-verbose
|
|
4209 ;; (ange-ftp-message "doing diff...done"))
|
|
4210 ;; (save-excursion
|
|
4211 ;; (set-buffer (get-buffer-create "*compilation*"))
|
|
4212 ;;
|
|
4213 ;; ;; replace the default directory that we munged earlier.
|
|
4214 ;; (goto-char (point-min))
|
|
4215 ;; (if (search-forward (concat "cd " default-directory) nil t)
|
|
4216 ;; (replace-match (concat "cd " old-dir)))
|
|
4217 ;; (setq default-directory old-dir)
|
|
4218 ;;
|
|
4219 ;; ;; massage the diff output, replacing the temporary file-
|
|
4220 ;; ;; names with their original names.
|
|
4221 ;; (if tmp1
|
|
4222 ;; (let ((q1 (shell-quote tmp1)))
|
|
4223 ;; (goto-char (point-min))
|
|
4224 ;; (while (search-forward q1 nil t)
|
|
4225 ;; (replace-match fn1))))
|
|
4226 ;; (if tmp2
|
|
4227 ;; (let ((q2 (shell-quote tmp2)))
|
|
4228 ;; (goto-char (point-min))
|
|
4229 ;; (while (search-forward q2 nil t)
|
|
4230 ;; (replace-match fn2))))))
|
|
4231 ;; (and tmp1 (ange-ftp-del-tmp-name tmp1))
|
|
4232 ;; (and tmp2 (ange-ftp-del-tmp-name tmp2))))
|
|
4233 ;; (ange-ftp-real-diff fn1 fn2 switches))))
|
|
4234
|
|
4235 (defun ange-ftp-dired-call-process (program discard &rest arguments)
|
|
4236 "Documented as original."
|
|
4237 ;; PROGRAM is always one of those below in the cond in dired.el.
|
|
4238 ;; The ARGUMENTS are (nearly) always files.
|
|
4239 (if (ange-ftp-ftp-path default-directory)
|
|
4240 ;; Can't use ange-ftp-dired-host-type here because the current
|
|
4241 ;; buffer is *dired-check-process output*
|
|
4242 (condition-case oops
|
|
4243 (cond ((equal "compress" program)
|
|
4244 (ange-ftp-call-compress arguments))
|
|
4245 ((equal "uncompress" program)
|
|
4246 (ange-ftp-call-uncompress arguments))
|
|
4247 ((equal "chmod" program)
|
|
4248 (ange-ftp-call-chmod arguments))
|
|
4249 ;; ((equal "chgrp" program))
|
|
4250 ;; ((equal dired-chown-program program))
|
|
4251 (t (error "Unknown remote command: %s" program)))
|
|
4252 (ftp-error (insert (format "%s: %s, %s\n"
|
|
4253 (nth 1 oops)
|
|
4254 (nth 2 oops)
|
|
4255 (nth 3 oops))))
|
|
4256 (error (insert (format "%s\n" (nth 1 oops)))))
|
|
4257 (apply 'call-process program nil (not discard) nil arguments)))
|
|
4258
|
|
4259
|
|
4260 (defun ange-ftp-call-compress (args)
|
|
4261 "Perform a compress command on a remote file.
|
|
4262 Works by taking a copy of the file, compressing it and copying the file
|
|
4263 back."
|
|
4264 (if (or (not (= (length args) 2))
|
|
4265 (not (string-equal "-f" (car args))))
|
|
4266 (error
|
|
4267 "ange-ftp-call-compress: missing -f flag and/or missing filename: %s"
|
|
4268 args))
|
|
4269 (let* ((file (nth 1 args))
|
|
4270 (parsed (ange-ftp-ftp-path file))
|
|
4271 (tmp1 (ange-ftp-make-tmp-name (car parsed)))
|
|
4272 (tmp2 (ange-ftp-make-tmp-name (car parsed)))
|
|
4273 (abbr (ange-ftp-abbreviate-filename file))
|
|
4274 (nfile (ange-ftp-dired-compress-make-compressed-filename file))
|
|
4275 (nabbr (ange-ftp-abbreviate-filename nfile))
|
|
4276 (msg1 (format "Getting %s" abbr))
|
|
4277 (msg2 (format "Putting %s" nabbr)))
|
|
4278 (unwind-protect
|
|
4279 (progn
|
|
4280 (ange-ftp-copy-file-internal file tmp1 t nil msg1)
|
|
4281 (and ange-ftp-process-verbose
|
|
4282 (ange-ftp-message "Compressing %s..." abbr))
|
|
4283 (call-process-region (point)
|
|
4284 (point)
|
|
4285 shell-file-name
|
|
4286 nil
|
|
4287 t
|
|
4288 nil
|
|
4289 "-c"
|
|
4290 (format "compress -f -c < %s > %s" tmp1 tmp2))
|
|
4291 (and ange-ftp-process-verbose
|
|
4292 (ange-ftp-message "Compressing %s...done" abbr))
|
|
4293 (if (zerop (buffer-size))
|
|
4294 (progn
|
|
4295 (let (ange-ftp-process-verbose)
|
|
4296 (delete-file file))
|
|
4297 (ange-ftp-copy-file-internal tmp2 nfile t nil msg2))))
|
|
4298 (ange-ftp-del-tmp-name tmp1)
|
|
4299 (ange-ftp-del-tmp-name tmp2))))
|
|
4300
|
|
4301 (defun ange-ftp-call-uncompress (args)
|
|
4302 "Perform an uncompress command on a remote file.
|
|
4303 Works by taking a copy of the file, uncompressing it and copying the file
|
|
4304 back."
|
|
4305 (if (not (= (length args) 1))
|
|
4306 (error "ange-ftp-call-uncompress: missing filename: %s" args))
|
|
4307 (let* ((file (car args))
|
|
4308 (parsed (ange-ftp-ftp-path file))
|
|
4309 (tmp1 (ange-ftp-make-tmp-name (car parsed)))
|
|
4310 (tmp2 (ange-ftp-make-tmp-name (car parsed)))
|
|
4311 (abbr (ange-ftp-abbreviate-filename file))
|
|
4312 (nfile (ange-ftp-dired-compress-make-compressed-filename file 'reverse))
|
|
4313 (nabbr (ange-ftp-abbreviate-filename nfile))
|
|
4314 (msg1 (format "Getting %s" abbr))
|
|
4315 (msg2 (format "Putting %s" nabbr))
|
|
4316 ;; ;; Cheap hack because of problems with binary file transfers from
|
|
4317 ;; ;; VMS hosts.
|
|
4318 ;; (gbinary (not (eq 'vms (ange-ftp-host-type (car parsed)))))
|
|
4319 )
|
|
4320 (unwind-protect
|
|
4321 (progn
|
|
4322 (ange-ftp-copy-file-internal file tmp1 t nil msg1)
|
|
4323 (and ange-ftp-process-verbose
|
|
4324 (ange-ftp-message "Uncompressing %s..." abbr))
|
|
4325 (call-process-region (point)
|
|
4326 (point)
|
|
4327 shell-file-name
|
|
4328 nil
|
|
4329 t
|
|
4330 nil
|
|
4331 "-c"
|
|
4332 (format "uncompress -c < %s > %s" tmp1 tmp2))
|
|
4333 (and ange-ftp-process-verbose
|
|
4334 (ange-ftp-message "Uncompressing %s...done" abbr))
|
|
4335 (if (zerop (buffer-size))
|
|
4336 (progn
|
|
4337 (let (ange-ftp-process-verbose)
|
|
4338 (delete-file file))
|
|
4339 (ange-ftp-copy-file-internal tmp2 nfile t nil msg2))))
|
|
4340 (ange-ftp-del-tmp-name tmp1)
|
|
4341 (ange-ftp-del-tmp-name tmp2))))
|
|
4342
|
|
4343 (defvar ange-ftp-remote-shell "rsh"
|
|
4344 "Remote shell to use for chmod, if FTP server rejects the `chmod' command.")
|
|
4345
|
|
4346 (defun ange-ftp-call-chmod (args)
|
|
4347 (if (< (length args) 2)
|
|
4348 (error "ange-ftp-call-chmod: missing mode and/or filename: %s" args))
|
|
4349 (let ((mode (car args)))
|
|
4350 (mapcar
|
|
4351 (function
|
|
4352 (lambda (file)
|
|
4353 (setq file (expand-file-name file))
|
|
4354 (let ((parsed (ange-ftp-ftp-path file)))
|
|
4355 (if parsed
|
|
4356 (let* ((host (nth 0 parsed))
|
|
4357 (user (nth 1 parsed))
|
|
4358 (path (ange-ftp-quote-string (nth 2 parsed)))
|
|
4359 (abbr (ange-ftp-abbreviate-filename file))
|
|
4360 (result (ange-ftp-send-cmd host user
|
|
4361 (list 'chmod mode path)
|
|
4362 (format "doing chmod %s"
|
|
4363 abbr))))
|
|
4364 (or (car result)
|
|
4365 ;; if FTP server rejects chmod, try rsh chmod instead
|
|
4366 (call-process
|
|
4367 ange-ftp-remote-shell
|
|
4368 nil t nil host "chmod" mode path)))))))
|
|
4369 (cdr args)))
|
|
4370 (setq ange-ftp-ls-cache-file nil)) ;stop confusing dired
|
|
4371
|
|
4372 ;; Need to abstract the way dired computes the names of compressed files.
|
|
4373 ;; I feel badly about these two overloads.
|
|
4374
|
|
4375 (defun ange-ftp-dired-compress ()
|
|
4376 ;; Compress current file. Return nil for success, offending filename else.
|
|
4377 (let* (buffer-read-only
|
|
4378 (from-file (dired-get-filename))
|
|
4379 (to-file (ange-ftp-dired-compress-make-compressed-filename from-file)))
|
|
4380 (cond ((save-excursion (beginning-of-line)
|
|
4381 (looking-at dired-re-sym))
|
|
4382 (dired-log (concat "Attempt to compress a symbolic link:\n"
|
|
4383 from-file))
|
|
4384 (dired-make-relative from-file))
|
|
4385 ((dired-check-process (concat "Compressing " from-file)
|
|
4386 "compress" "-f" from-file)
|
|
4387 ;; errors from the process are already logged by
|
|
4388 ;; dired-check-process
|
|
4389 (dired-make-relative from-file))
|
|
4390 (t
|
|
4391 (dired-update-file-line to-file)
|
|
4392 nil))))
|
|
4393
|
|
4394 (defun ange-ftp-dired-uncompress ()
|
|
4395 ;; Uncompress current file. Return nil for success,
|
|
4396 ;; offending filename else.
|
|
4397 (let* (buffer-read-only
|
|
4398 (from-file (dired-get-filename))
|
|
4399 (to-file (ange-ftp-dired-compress-make-compressed-filename from-file 'reverse)))
|
|
4400 (if (dired-check-process (concat "Uncompressing " from-file)
|
|
4401 "uncompress" from-file)
|
|
4402 (dired-make-relative from-file)
|
|
4403 (dired-update-file-line to-file)
|
|
4404 nil)))
|
|
4405
|
|
4406 (defun ange-ftp-dired-flag-backup-files (&optional unflag-p)
|
|
4407 "Documented as original."
|
|
4408 (interactive "P")
|
|
4409 (funcall (or (and ange-ftp-dired-host-type
|
|
4410 (cdr (assq ange-ftp-dired-host-type
|
|
4411 ange-ftp-dired-flag-backup-files-alist)))
|
|
4412 'ange-ftp-real-dired-flag-backup-files)
|
|
4413 unflag-p))
|
|
4414
|
|
4415 ;;; ------------------------------------------------------------
|
|
4416 ;;; Noddy support for async copy-file within dired.
|
|
4417 ;;; ------------------------------------------------------------
|
|
4418
|
|
4419 (defun ange-ftp-dired-copy-file (from to ok-flag &optional cont nowait)
|
|
4420 "Documented as original."
|
|
4421 (dired-handle-overwrite to)
|
|
4422 (ange-ftp-copy-file-internal from to ok-flag dired-copy-preserve-time nil
|
|
4423 cont nowait))
|
|
4424
|
|
4425 (defun ange-ftp-dired-do-create-files (op-symbol file-creator operation arg
|
|
4426 &optional marker-char op1
|
|
4427 how-to)
|
|
4428 "Documented as original."
|
|
4429 ;; we need to let ange-ftp-dired-create-files know that we indirectly
|
|
4430 ;; called it rather than somebody else.
|
|
4431 (let ((ange-ftp-dired-do-create-files t)) ; tell who caller is
|
|
4432 (ange-ftp-real-dired-do-create-files op-symbol file-creator operation
|
|
4433 arg marker-char op1 how-to)))
|
|
4434
|
|
4435 (defun ange-ftp-dired-create-files (file-creator operation fn-list name-constructor
|
|
4436 &optional marker-char)
|
|
4437 "Documented as original."
|
|
4438 (if (and (boundp 'ange-ftp-dired-do-create-files)
|
|
4439 ;; called from ange-ftp-dired-do-create-files?
|
|
4440 ange-ftp-dired-do-create-files
|
|
4441 ;; any files worth copying?
|
|
4442 fn-list
|
|
4443 ;; we only support async copy-file at the mo.
|
|
4444 (eq file-creator 'dired-copy-file)
|
|
4445 ;; it is only worth calling the alternative function for remote files
|
|
4446 ;; as we tie ourself in recursive knots otherwise.
|
|
4447 (or (ange-ftp-ftp-path (car fn-list))
|
|
4448 ;; we can only call the name constructor for dired-do-create-files
|
|
4449 ;; since the one for regexps starts prompting here, there and
|
|
4450 ;; everywhere.
|
|
4451 (ange-ftp-ftp-path (funcall name-constructor (car fn-list)))))
|
|
4452 ;; use the process-filter driven routine rather than the iterative one.
|
|
4453 (ange-ftp-dcf-1 file-creator
|
|
4454 operation
|
|
4455 fn-list
|
|
4456 name-constructor
|
|
4457 (and (boundp 'target) target) ;dynamically bound
|
|
4458 marker-char
|
|
4459 (current-buffer)
|
|
4460 nil ;overwrite-query
|
|
4461 nil ;overwrite-backup-query
|
|
4462 nil ;failures
|
|
4463 nil ;skipped
|
|
4464 0 ;success-count
|
|
4465 (length fn-list) ;total
|
|
4466 )
|
|
4467 ;; normal case... use the interative routine... much cheaper.
|
|
4468 (ange-ftp-real-dired-create-files file-creator operation fn-list
|
|
4469 name-constructor marker-char)))
|
|
4470
|
|
4471 (defun ange-ftp-dcf-1 (file-creator operation fn-list name-constructor
|
|
4472 target marker-char buffer overwrite-query
|
|
4473 overwrite-backup-query failures skipped
|
|
4474 success-count total)
|
|
4475 (let ((old-buf (current-buffer)))
|
|
4476 (unwind-protect
|
|
4477 (progn
|
|
4478 (set-buffer buffer)
|
|
4479 (if (null fn-list)
|
|
4480 (ange-ftp-dcf-3 failures operation total skipped
|
|
4481 success-count buffer)
|
|
4482
|
|
4483 (let* ((from (car fn-list))
|
|
4484 (to (funcall name-constructor from)))
|
|
4485 (if (equal to from)
|
|
4486 (progn
|
|
4487 (setq to nil)
|
|
4488 (dired-log "Cannot %s to same file: %s\n"
|
|
4489 (downcase operation) from)))
|
|
4490 (if (not to)
|
|
4491 (ange-ftp-dcf-1 file-creator
|
|
4492 operation
|
|
4493 (cdr fn-list)
|
|
4494 name-constructor
|
|
4495 target
|
|
4496 marker-char
|
|
4497 buffer
|
|
4498 overwrite-query
|
|
4499 overwrite-backup-query
|
|
4500 failures
|
|
4501 (cons (dired-make-relative from) skipped)
|
|
4502 success-count
|
|
4503 total)
|
|
4504 (let* ((overwrite (file-exists-p to))
|
|
4505 (overwrite-confirmed ; for dired-handle-overwrite
|
|
4506 (and overwrite
|
|
4507 (let ((help-form '(format "\
|
|
4508 Type SPC or `y' to overwrite file `%s',
|
|
4509 DEL or `n' to skip to next,
|
|
4510 ESC or `q' to not overwrite any of the remaining files,
|
|
4511 `!' to overwrite all remaining files with no more questions." to)))
|
|
4512 (dired-query 'overwrite-query
|
|
4513 "Overwrite `%s'?" to))))
|
|
4514 ;; must determine if FROM is marked before file-creator
|
|
4515 ;; gets a chance to delete it (in case of a move).
|
|
4516 (actual-marker-char
|
|
4517 (cond ((integerp marker-char) marker-char)
|
|
4518 (marker-char (dired-file-marker from)) ; slow
|
|
4519 (t nil))))
|
|
4520 (condition-case err
|
|
4521 (funcall file-creator from to overwrite-confirmed
|
|
4522 (list (function ange-ftp-dcf-2)
|
|
4523 nil ;err
|
|
4524 file-creator operation fn-list
|
|
4525 name-constructor
|
|
4526 target
|
|
4527 marker-char actual-marker-char
|
|
4528 buffer to from
|
|
4529 overwrite
|
|
4530 overwrite-confirmed
|
|
4531 overwrite-query
|
|
4532 overwrite-backup-query
|
|
4533 failures skipped success-count
|
|
4534 total)
|
|
4535 t)
|
|
4536 (file-error ; FILE-CREATOR aborted
|
|
4537 (ange-ftp-dcf-2 nil ;result
|
|
4538 nil ;line
|
|
4539 err
|
|
4540 file-creator operation fn-list
|
|
4541 name-constructor
|
|
4542 target
|
|
4543 marker-char actual-marker-char
|
|
4544 buffer to from
|
|
4545 overwrite
|
|
4546 overwrite-confirmed
|
|
4547 overwrite-query
|
|
4548 overwrite-backup-query
|
|
4549 failures skipped success-count
|
|
4550 total))))))))
|
|
4551 (set-buffer old-buf))))
|
|
4552
|
|
4553 (defun ange-ftp-dcf-2 (result line err
|
|
4554 file-creator operation fn-list
|
|
4555 name-constructor
|
|
4556 target
|
|
4557 marker-char actual-marker-char
|
|
4558 buffer to from
|
|
4559 overwrite
|
|
4560 overwrite-confirmed
|
|
4561 overwrite-query
|
|
4562 overwrite-backup-query
|
|
4563 failures skipped success-count
|
|
4564 total)
|
|
4565 (let ((old-buf (current-buffer)))
|
|
4566 (unwind-protect
|
|
4567 (progn
|
|
4568 (set-buffer buffer)
|
|
4569 (if (or err (not result))
|
|
4570 (progn
|
|
4571 (setq failures (cons (dired-make-relative from) failures))
|
|
4572 (dired-log "%s `%s' to `%s' failed:\n%s\n"
|
|
4573 operation from to (or err line)))
|
|
4574 (if overwrite
|
|
4575 ;; If we get here, file-creator hasn't been aborted
|
|
4576 ;; and the old entry (if any) has to be deleted
|
|
4577 ;; before adding the new entry.
|
|
4578 (dired-remove-file to))
|
|
4579 (setq success-count (1+ success-count))
|
|
4580 (message "%s: %d of %d" operation success-count total)
|
|
4581 (dired-add-file to actual-marker-char))
|
|
4582
|
|
4583 (ange-ftp-dcf-1 file-creator operation (cdr fn-list)
|
|
4584 name-constructor
|
|
4585 target
|
|
4586 marker-char
|
|
4587 buffer
|
|
4588 overwrite-query
|
|
4589 overwrite-backup-query
|
|
4590 failures skipped success-count
|
|
4591 total))
|
|
4592 (set-buffer old-buf))))
|
|
4593
|
|
4594 (defun ange-ftp-dcf-3 (failures operation total skipped success-count
|
|
4595 buffer)
|
|
4596 (let ((old-buf (current-buffer)))
|
|
4597 (unwind-protect
|
|
4598 (progn
|
|
4599 (set-buffer buffer)
|
|
4600 (cond
|
|
4601 (failures
|
|
4602 (dired-log-summary
|
|
4603 (message "%s failed for %d of %d file%s %s"
|
|
4604 operation (length failures) total
|
|
4605 (dired-plural-s total) failures)))
|
|
4606 (skipped
|
|
4607 (dired-log-summary
|
|
4608 (message "%s: %d of %d file%s skipped %s"
|
|
4609 operation (length skipped) total
|
|
4610 (dired-plural-s total) skipped)))
|
|
4611 (t
|
|
4612 (message "%s: %s file%s."
|
|
4613 operation success-count (dired-plural-s success-count))))
|
|
4614 (dired-move-to-filename))
|
|
4615 (set-buffer old-buf))))
|
|
4616
|
|
4617 ;;;; -----------------------------------------------
|
|
4618 ;;;; Unix Descriptive Listing (dl) Support
|
|
4619 ;;;; -----------------------------------------------
|
|
4620
|
|
4621 (defconst ange-ftp-dired-dl-re-dir
|
|
4622 "^. [^ /]+/[ \n]"
|
|
4623 "Regular expression to use to search for dl directories.")
|
|
4624
|
|
4625 (or (assq 'unix:dl ange-ftp-dired-re-dir-alist)
|
|
4626 (setq ange-ftp-dired-re-dir-alist
|
|
4627 (cons (cons 'unix:dl ange-ftp-dired-dl-re-dir)
|
|
4628 ange-ftp-dired-re-dir-alist)))
|
|
4629
|
|
4630 (defun ange-ftp-dired-dl-move-to-filename (&optional raise-error eol)
|
|
4631 "In dired, move to the first character of the filename on this line."
|
|
4632 ;; This is the Unix dl version.
|
|
4633 (or eol (setq eol (progn (end-of-line) (point))))
|
|
4634 (let (case-fold-search)
|
|
4635 (beginning-of-line)
|
|
4636 (if (looking-at ". [^ ]+ +\\([0-9]+\\|-\\|=\\) ")
|
|
4637 (goto-char (+ (point) 2))
|
|
4638 (if raise-error
|
|
4639 (error "No file on this line")
|
|
4640 nil))))
|
|
4641
|
|
4642 (or (assq 'unix:dl ange-ftp-dired-move-to-filename-alist)
|
|
4643 (setq ange-ftp-dired-move-to-filename-alist
|
|
4644 (cons '(unix:dl . ange-ftp-dired-dl-move-to-filename)
|
|
4645 ange-ftp-dired-move-to-filename-alist)))
|
|
4646
|
|
4647 (defun ange-ftp-dired-dl-move-to-end-of-filename (&optional no-error eol)
|
|
4648 ;; Assumes point is at beginning of filename.
|
|
4649 ;; So, it should be called only after (dired-move-to-filename t).
|
|
4650 ;; On failure, signals an error or returns nil.
|
|
4651 ;; This is the Unix dl version.
|
|
4652 (let ((opoint (point))
|
|
4653 case-fold-search hidden)
|
|
4654 (or eol (setq eol (save-excursion (end-of-line) (point))))
|
|
4655 (setq hidden (and selective-display
|
|
4656 (save-excursion
|
|
4657 (search-forward "\r" eol t))))
|
|
4658 (if hidden
|
|
4659 (if no-error
|
|
4660 nil
|
|
4661 (error
|
|
4662 (substitute-command-keys
|
|
4663 "File line is hidden, type \\[dired-hide-subdir] to unhide")))
|
|
4664 (skip-chars-forward "^ /" eol)
|
|
4665 (if (eq opoint (point))
|
|
4666 (if no-error
|
|
4667 nil
|
|
4668 (error "No file on this line"))
|
|
4669 (point)))))
|
|
4670
|
|
4671 (or (assq 'unix:dl ange-ftp-dired-move-to-end-of-filename-alist)
|
|
4672 (setq ange-ftp-dired-move-to-end-of-filename-alist
|
|
4673 (cons '(unix:dl . ange-ftp-dired-dl-move-to-end-of-filename)
|
|
4674 ange-ftp-dired-move-to-end-of-filename-alist)))
|
|
4675
|
|
4676 ;;;; ------------------------------------------------------------
|
|
4677 ;;;; File name completion support.
|
|
4678 ;;;; ------------------------------------------------------------
|
|
4679
|
|
4680 (defun ange-ftp-file-entry-active-p (sym)
|
|
4681 "If the file entry is a symlink, returns whether the file pointed to exists.
|
|
4682 Note that DIR is dynamically bound."
|
|
4683 (let ((val (get sym 'val)))
|
|
4684 (or (not (stringp val))
|
|
4685 (file-exists-p (ange-ftp-expand-symlink val dir)))))
|
|
4686
|
|
4687 (defun ange-ftp-file-entry-not-ignored-p (sym)
|
|
4688 "If the file entry is not a directory (nor a symlink pointing to a directory)
|
|
4689 returns whether the file (or file pointed to by the symlink) is ignored
|
|
4690 by completion-ignored-extensions.
|
|
4691 Note that DIR and COMPLETION-IGNORED-PATTERN are dynamically bound."
|
|
4692 (let ((val (get sym 'val))
|
|
4693 (symname (symbol-name sym)))
|
|
4694 (if (stringp val)
|
|
4695 (let ((file (ange-ftp-expand-symlink val dir)))
|
|
4696 (or (file-directory-p file)
|
|
4697 (and (file-exists-p file)
|
|
4698 (not (string-match completion-ignored-pattern
|
|
4699 symname)))))
|
|
4700 (or val ; is a directory name
|
|
4701 (not (string-match completion-ignored-pattern symname))))))
|
|
4702
|
|
4703 (defun ange-ftp-file-name-all-completions (file dir)
|
|
4704 "Documented as original."
|
|
4705 (setq dir (expand-file-name dir))
|
|
4706 (if (ange-ftp-ftp-path dir)
|
|
4707 (progn
|
|
4708 (ange-ftp-barf-if-not-directory dir)
|
|
4709 (setq dir (ange-ftp-real-file-name-as-directory dir))
|
|
4710 (let* ((tbl (ange-ftp-get-files dir))
|
|
4711 (completions
|
|
4712 (all-completions file tbl
|
|
4713 (function ange-ftp-file-entry-active-p))))
|
|
4714
|
|
4715 ;; see whether each matching file is a directory or not...
|
|
4716 (mapcar
|
|
4717 (function
|
|
4718 (lambda (file)
|
|
4719 (let ((ent (ange-ftp-get-hash-entry file tbl)))
|
|
4720 (if (and ent
|
|
4721 (or (not (stringp ent))
|
|
4722 (file-directory-p
|
|
4723 (ange-ftp-expand-symlink ent dir))))
|
|
4724 (concat file "/")
|
|
4725 file))))
|
|
4726 completions)))
|
|
4727
|
|
4728 (if (string-equal "/" dir)
|
|
4729 (nconc (all-completions file (ange-ftp-generate-root-prefixes))
|
|
4730 (ange-ftp-real-file-name-all-completions file dir))
|
|
4731 (ange-ftp-real-file-name-all-completions file dir))))
|
|
4732
|
|
4733 (defun ange-ftp-file-name-completion (file dir)
|
|
4734 "Documented as original."
|
|
4735 (setq dir (expand-file-name dir))
|
|
4736 (if (ange-ftp-ftp-path dir)
|
|
4737 (progn
|
|
4738 (ange-ftp-barf-if-not-directory dir)
|
|
4739 (if (equal file "")
|
|
4740 ""
|
|
4741 (setq dir (ange-ftp-real-file-name-as-directory dir)) ;real?
|
|
4742 (let* ((tbl (ange-ftp-get-files dir))
|
|
4743 (completion-ignored-pattern
|
|
4744 (mapconcat (function
|
|
4745 (lambda (s) (if (stringp s)
|
|
4746 (concat (regexp-quote s) "$")
|
|
4747 "/"))) ; / never in filename
|
|
4748 completion-ignored-extensions
|
|
4749 "\\|")))
|
|
4750 (ange-ftp-save-match-data
|
|
4751 (or (ange-ftp-file-name-completion-1
|
|
4752 file tbl dir (function ange-ftp-file-entry-not-ignored-p))
|
|
4753 (ange-ftp-file-name-completion-1
|
|
4754 file tbl dir (function ange-ftp-file-entry-active-p)))))))
|
|
4755 (if (string-equal "/" dir)
|
|
4756 (try-completion
|
|
4757 file
|
|
4758 (nconc (ange-ftp-generate-root-prefixes)
|
|
4759 (mapcar 'list
|
|
4760 (ange-ftp-real-file-name-all-completions file "/"))))
|
|
4761 (ange-ftp-real-file-name-completion file dir))))
|
|
4762
|
|
4763
|
|
4764 (defun ange-ftp-file-name-completion-1 (file tbl dir predicate)
|
|
4765 "Internal subroutine for ange-ftp-file-name-completion. Do not call this."
|
|
4766 (let ((bestmatch (try-completion file tbl predicate)))
|
|
4767 (if bestmatch
|
|
4768 (if (eq bestmatch t)
|
|
4769 (if (file-directory-p (expand-file-name file dir))
|
|
4770 (concat file "/")
|
|
4771 t)
|
|
4772 (if (and (eq (try-completion bestmatch tbl predicate) t)
|
|
4773 (file-directory-p
|
|
4774 (expand-file-name bestmatch dir)))
|
|
4775 (concat bestmatch "/")
|
|
4776 bestmatch)))))
|
|
4777
|
|
4778 (defun ange-ftp-quote-filename (file)
|
|
4779 "Quote `$' as `$$' in FILE to get it past function `substitute-in-file-name.'"
|
|
4780 (let ((pos 0))
|
|
4781 (while (setq pos (string-match "\\$" file pos))
|
|
4782 (setq file (concat (substring file 0 pos)
|
|
4783 "$";; precede by escape character (also a $)
|
|
4784 (substring file pos))
|
|
4785 ;; add 2 instead 1 since another $ was inserted
|
|
4786 pos (+ 2 pos)))
|
|
4787 file))
|
|
4788
|
|
4789 ;; (defun ange-ftp-read-file-name-internal (string dir action)
|
|
4790 ;; "Documented as original."
|
|
4791 ;; (let (name realdir)
|
|
4792 ;; (if (eq action 'lambda)
|
|
4793 ;; (if (> (length string) 0)
|
|
4794 ;; (file-exists-p (substitute-in-file-name string)))
|
|
4795 ;; (if (zerop (length string))
|
|
4796 ;; (setq name string realdir dir)
|
|
4797 ;; (setq string (substitute-in-file-name string)
|
|
4798 ;; name (file-name-nondirectory string)
|
|
4799 ;; realdir (file-name-directory string))
|
|
4800 ;; (setq realdir (if realdir (expand-file-name realdir dir) dir)))
|
|
4801 ;; (if action
|
|
4802 ;; (file-name-all-completions name realdir)
|
|
4803 ;; (let ((specdir (file-name-directory string))
|
|
4804 ;; (val (file-name-completion name realdir)))
|
|
4805 ;; (if (and specdir (stringp val))
|
|
4806 ;; (ange-ftp-quote-filename (concat specdir val))
|
|
4807 ;; val))))))
|
|
4808
|
|
4809 ;; Put these lines uncommmented in your .emacs if you want C-r to refresh
|
|
4810 ;; ange-ftp's cache whilst doing filename completion.
|
|
4811 ;;
|
|
4812 ;;(define-key minibuffer-local-completion-map "\C-r" 'ange-ftp-re-read-dir)
|
|
4813 ;;(define-key minibuffer-local-must-match-map "\C-r" 'ange-ftp-re-read-dir)
|
|
4814
|
|
4815 (defun ange-ftp-re-read-dir (&optional dir)
|
|
4816 "Forces a re-read of the directory DIR. If DIR is omitted then it defaults
|
|
4817 to the directory part of the contents of the current buffer."
|
|
4818 (interactive)
|
|
4819 (if dir
|
|
4820 (setq dir (expand-file-name dir))
|
|
4821 (setq dir (file-name-directory (expand-file-name (buffer-string)))))
|
|
4822 (if (ange-ftp-ftp-path dir)
|
|
4823 (progn
|
|
4824 (setq ange-ftp-ls-cache-file nil)
|
|
4825 (ange-ftp-del-hash-entry dir ange-ftp-files-hashtable)
|
|
4826 (ange-ftp-get-files dir t))))
|
|
4827
|
|
4828 ;;;; ------------------------------------------------------------
|
|
4829 ;;;; Bits and bobs to bolt ange-ftp into GNU Emacs.
|
|
4830 ;;;; ------------------------------------------------------------
|
|
4831
|
|
4832 (defvar ange-ftp-overwrite-msg
|
|
4833 "Note: This function has been modified to work with ange-ftp.")
|
|
4834
|
|
4835 (defun ange-ftp-safe-documentation (fun)
|
|
4836 "A documentation function that isn't quite as fragile."
|
|
4837 (condition-case ()
|
|
4838 (documentation fun)
|
|
4839 (error nil)))
|
|
4840
|
|
4841 (defun ange-ftp-overwrite-fn (fun)
|
|
4842 "Replace FUN's function definition with ange-ftp-FUN's, saving the
|
|
4843 original definition as ange-ftp-real-FUN. The original documentation is
|
|
4844 placed on the new definition suitably augmented."
|
|
4845 (let* ((name (symbol-name fun))
|
|
4846 (saved (intern (concat "ange-ftp-real-" name)))
|
|
4847 (new (intern (concat "ange-ftp-" name)))
|
|
4848 (nfun (symbol-function new))
|
|
4849 (exec-directory (if (or (equal (nth 3 command-line-args) "dump")
|
|
4850 (equal (nth 4 command-line-args) "dump"))
|
|
4851 "../etc/"
|
|
4852 exec-directory)))
|
|
4853
|
|
4854 ;; *** This is unnecessary for any ange-ftp function (I think):
|
|
4855 (while (symbolp nfun)
|
|
4856 (setq nfun (symbol-function nfun)))
|
|
4857
|
|
4858 ;; Interpose the ange-ftp function between the function symbol and the
|
|
4859 ;; original definition of the function symbol AT TIME OF FIRST LOAD.
|
|
4860 ;; We must only redefine the symbol-function of FUN the very first
|
|
4861 ;; time, to avoid blowing away stuff that overloads FUN after this.
|
|
4862
|
|
4863 ;; We direct the function symbol to the ange-ftp's function symbol
|
|
4864 ;; rather than function definition to allow reloading of this file or
|
|
4865 ;; redefining of the individual function (e.g., during debugging)
|
|
4866 ;; later after some other code has been loaded on top of our stuff.
|
|
4867
|
|
4868 (or (fboundp saved)
|
|
4869 (progn
|
|
4870 (fset saved (symbol-function fun))
|
|
4871 (fset fun new)))
|
|
4872
|
|
4873 ;; Rewrite the doc string on the new ange-ftp function. This should
|
|
4874 ;; be done every time the file is loaded (or a function is redefined),
|
|
4875 ;; because the underlying overloaded function may have changed its doc
|
|
4876 ;; string.
|
|
4877
|
|
4878 (let* ((doc-str (ange-ftp-safe-documentation saved))
|
|
4879 (ndoc-str (concat doc-str (and doc-str "\n")
|
|
4880 ange-ftp-overwrite-msg)))
|
|
4881
|
|
4882 (cond ((listp nfun)
|
|
4883 ;; Probe to test whether function is in preloaded read-only
|
|
4884 ;; memory, and if so make writable copy:
|
|
4885 (condition-case nil
|
|
4886 (setcar nfun (car nfun))
|
|
4887 (error
|
|
4888 (setq nfun (copy-sequence nfun)) ; shallow copy only
|
|
4889 (fset new nfun)))
|
|
4890 (let ((ndoc-cdr (nthcdr 2 nfun)))
|
|
4891 (if (stringp (car ndoc-cdr))
|
|
4892 ;; Replace the existing docstring.
|
|
4893 (setcar ndoc-cdr ndoc-str)
|
|
4894 ;; There is no docstring. Insert the overwrite msg.
|
|
4895 (setcdr ndoc-cdr (cons (car ndoc-cdr) (cdr ndoc-cdr)))
|
|
4896 (setcar ndoc-cdr ange-ftp-overwrite-msg))))
|
|
4897 (t
|
|
4898 ;; it's an emacs19 compiled-code object
|
|
4899 (if (not (fboundp 'compiled-function-arglist))
|
|
4900 ;; the old way (typical emacs lack of abstraction)
|
|
4901 (let ((new-code (append nfun nil))) ; turn it into a list
|
|
4902 (if (nthcdr 4 new-code)
|
|
4903 (setcar (nthcdr 4 new-code) ndoc-str)
|
|
4904 (setcdr (nthcdr 3 new-code) (cons ndoc-str nil)))
|
|
4905 (fset new (apply 'make-byte-code new-code)))
|
|
4906 ;; the new way (marginally less random) for XEmacs 19.8+
|
|
4907 (fset new
|
|
4908 (apply 'make-byte-code
|
|
4909 (compiled-function-arglist nfun)
|
|
4910 (compiled-function-instructions nfun)
|
|
4911 (compiled-function-constants nfun)
|
|
4912 (compiled-function-stack-depth nfun)
|
|
4913 ndoc-str
|
|
4914 (if (commandp nfun)
|
|
4915 (list (nth 1 (compiled-function-interactive
|
|
4916 nfun)))
|
|
4917 nil)))
|
|
4918 ))))))
|
|
4919
|
|
4920 (defun ange-ftp-overwrite-dired ()
|
|
4921 (if (not (fboundp 'dired-ls)) ;dired should have been loaded by now
|
|
4922 (ange-ftp-overwrite-fn 'dired-readin) ; classic dired
|
|
4923 (ange-ftp-overwrite-fn 'make-directory) ; tree dired and v19 stuff
|
|
4924 (ange-ftp-overwrite-fn 'remove-directory)
|
|
4925 ;; XEmacs - not anymore because ange-ftp-diff is hosed
|
|
4926 ;; (ange-ftp-overwrite-fn 'diff)
|
|
4927 (ange-ftp-overwrite-fn 'dired-run-shell-command)
|
|
4928 (ange-ftp-overwrite-fn 'dired-ls)
|
|
4929 (ange-ftp-overwrite-fn 'dired-call-process)
|
|
4930 ;; Can't use (fset 'ange-ftp-dired-readin 'ange-ftp-tree-dired-readin)
|
|
4931 ;; here because it confuses ange-ftp-overwrite-fn.
|
|
4932 (fset 'ange-ftp-dired-readin (symbol-function 'ange-ftp-tree-dired-readin))
|
|
4933 (ange-ftp-overwrite-fn 'dired-readin)
|
|
4934 (ange-ftp-overwrite-fn 'dired-insert-headerline)
|
|
4935 (ange-ftp-overwrite-fn 'dired-move-to-filename)
|
|
4936 (ange-ftp-overwrite-fn 'dired-move-to-end-of-filename)
|
|
4937 (ange-ftp-overwrite-fn 'dired-get-filename)
|
|
4938 (ange-ftp-overwrite-fn 'dired-between-files)
|
|
4939 (ange-ftp-overwrite-fn 'dired-clean-directory)
|
|
4940 (ange-ftp-overwrite-fn 'dired-flag-backup-files)
|
|
4941 (ange-ftp-overwrite-fn 'dired-backup-diff)
|
|
4942 (if (fboundp 'dired-do-create-files)
|
|
4943 ;; dired 6.0 or later.
|
|
4944 (progn
|
|
4945 (ange-ftp-overwrite-fn 'dired-copy-file)
|
|
4946 (ange-ftp-overwrite-fn 'dired-create-files)
|
|
4947 (ange-ftp-overwrite-fn 'dired-do-create-files)))
|
|
4948 (if (fboundp 'dired-compress-make-compressed-filename)
|
|
4949 ;; it's V5.255 or later
|
|
4950 (ange-ftp-overwrite-fn 'dired-compress-make-compressed-filename)
|
|
4951 ;; ange-ftp-overwrite-fn confuses dired-mark-map here.
|
|
4952 (fset 'ange-ftp-real-dired-compress (symbol-function 'dired-compress))
|
|
4953 (fset 'dired-compress 'ange-ftp-dired-compress)
|
|
4954 (fset 'ange-ftp-real-dired-uncompress (symbol-function 'dired-uncompress))
|
|
4955 (fset 'dired-uncompress 'ange-ftp-dired-uncompress)))
|
|
4956
|
|
4957 (ange-ftp-overwrite-fn 'dired-find-file)
|
|
4958 (ange-ftp-overwrite-fn 'dired-revert))
|
|
4959
|
|
4960 ;; Attention!
|
|
4961 ;; It would be nice if ange-ftp-add-hook was generalized to
|
|
4962 ;; (defun ange-ftp-add-hook (hook-var hook-function &optional postpend),
|
|
4963 ;; where the optional postpend variable stipulates that hook-function
|
|
4964 ;; should be post-pended to the hook-var, rather than prepended.
|
|
4965 ;; Then, maybe we should overwrite dired with
|
|
4966 ;; (ange-ftp-add-hook 'dired-load-hook 'ange-ftp-overwrite-dired t).
|
|
4967 ;; This is because dired-load-hook is commonly used to add the dired extras
|
|
4968 ;; features (dired-x.el, dired-trns.el, dired-nstd.el, ...). Some of these
|
|
4969 ;; extras features overwrite functions in dired.el with fancier versions.
|
|
4970 ;; The "extras" overwrites would then clobber the ange-ftp overwrites.
|
|
4971 ;; As long as the ange-ftp overwrites are carefully written to use
|
|
4972 ;; ange-ftp-real-... when the directory is local, then doing the ange-ftp
|
|
4973 ;; overwrites after the extras overwites should be OK.
|
|
4974 ;; At the moment, I think that there aren't any conflicts between the extras
|
|
4975 ;; overwrites, and the ange-ftp overwrites. This may not last though.
|
|
4976
|
|
4977 (defun ange-ftp-add-hook (hook-var hook-function)
|
|
4978 "Prepend hook-function to hook-var's value, if it is not already an element.
|
|
4979 hook-var's value may be a single function or a list of functions."
|
|
4980 (if (boundp hook-var)
|
|
4981 (let ((value (symbol-value hook-var)))
|
|
4982 (if (and (listp value) (not (eq (car value) 'lambda)))
|
|
4983 (and (not (memq hook-function value))
|
|
4984 (set hook-var
|
|
4985 (if value (cons hook-function value) hook-function)))
|
|
4986 (and (not (eq hook-function value))
|
|
4987 (set hook-var
|
|
4988 (list hook-function value)))))
|
|
4989 (set hook-var hook-function)))
|
|
4990
|
|
4991 ;; To load ange-ftp and not dired (leaving it to autoload), define
|
|
4992 ;; dired-load-hook and make sure dired.el ends with:
|
|
4993 ;; (run-hooks 'dired-load-hook)
|
|
4994 ;;
|
|
4995 (if (and (boundp 'dired-load-hook)
|
|
4996 (not (featurep 'dired)))
|
|
4997 (ange-ftp-add-hook 'dired-load-hook 'ange-ftp-overwrite-dired)
|
|
4998 (require 'dired)
|
|
4999 (ange-ftp-overwrite-dired))
|
|
5000
|
|
5001 ;; In case v19 or emacs-19.el already loaded:
|
|
5002 ;; (Can't use fboundp to check if emacs-19.el is
|
|
5003 ;; loaded, because these functions are probably
|
|
5004 ;; bound to autoloads.)
|
|
5005
|
|
5006 (if (and (fboundp 'make-directory)
|
|
5007 (not (and (listp (symbol-function 'make-directory))
|
|
5008 (eq (car (symbol-function 'make-directory)) 'autoload))))
|
|
5009 (ange-ftp-overwrite-fn 'make-directory))
|
|
5010 (if (and (fboundp 'remove-directory)
|
|
5011 (not (and (listp (symbol-function 'remove-directory))
|
|
5012 (eq (car (symbol-function 'remove-directory)) 'autoload))))
|
|
5013 (ange-ftp-overwrite-fn 'remove-directory))
|
|
5014 ;; XEmacs change -- ange-ftp-diff is hosed
|
|
5015 ;;(if (and (fboundp 'diff)
|
|
5016 ;; (not (and (listp (symbol-function 'diff))
|
|
5017 ;; (eq (car (symbol-function 'diff)) 'autoload))))
|
|
5018 ;; (ange-ftp-overwrite-fn 'diff))
|
|
5019
|
|
5020 (ange-ftp-overwrite-fn 'insert-file-contents)
|
|
5021 (ange-ftp-overwrite-fn 'directory-files)
|
|
5022 (ange-ftp-overwrite-fn 'file-directory-p)
|
|
5023 (ange-ftp-overwrite-fn 'file-writable-p)
|
|
5024 (ange-ftp-overwrite-fn 'file-readable-p)
|
|
5025 (ange-ftp-overwrite-fn 'file-symlink-p)
|
|
5026 (ange-ftp-overwrite-fn 'delete-file)
|
|
5027 ;; (ange-ftp-overwrite-fn 'read-file-name-internal)
|
|
5028 (ange-ftp-overwrite-fn 'verify-visited-file-modtime)
|
|
5029 (ange-ftp-overwrite-fn 'file-exists-p)
|
|
5030 (ange-ftp-overwrite-fn 'write-region)
|
|
5031 (ange-ftp-overwrite-fn 'backup-buffer)
|
|
5032 (ange-ftp-overwrite-fn 'copy-file)
|
|
5033 (ange-ftp-overwrite-fn 'rename-file)
|
|
5034 (ange-ftp-overwrite-fn 'file-attributes)
|
|
5035 (ange-ftp-overwrite-fn 'file-name-directory)
|
|
5036 (ange-ftp-overwrite-fn 'file-name-nondirectory)
|
|
5037 (ange-ftp-overwrite-fn 'file-name-as-directory)
|
|
5038 (ange-ftp-overwrite-fn 'directory-file-name)
|
|
5039 (ange-ftp-overwrite-fn 'expand-file-name)
|
|
5040 (ange-ftp-overwrite-fn 'file-name-all-completions)
|
|
5041 (ange-ftp-overwrite-fn 'file-name-completion)
|
4
|
5042 (ange-ftp-overwrite-fn 'load)
|
0
|
5043
|
|
5044 (or (memq 'ange-ftp-set-buffer-mode find-file-hooks)
|
|
5045 (setq find-file-hooks
|
|
5046 (cons 'ange-ftp-set-buffer-mode find-file-hooks)))
|
|
5047
|
|
5048
|
|
5049 ;;;; ------------------------------------------------------------
|
|
5050 ;;;; VOS support (VOS support is probably broken,
|
|
5051 ;;;; but I don't know anything about VOS.)
|
|
5052 ;;;; ------------------------------------------------------------
|
|
5053 ;
|
|
5054 ;(defun ange-ftp-fix-path-for-vos (path &optional reverse)
|
|
5055 ; (setq path (copy-sequence path))
|
|
5056 ; (let ((from (if reverse ?\> ?\/))
|
|
5057 ; (to (if reverse ?\/ ?\>))
|
|
5058 ; (i (1- (length path))))
|
|
5059 ; (while (>= i 0)
|
|
5060 ; (if (= (aref path i) from)
|
|
5061 ; (aset path i to))
|
|
5062 ; (setq i (1- i)))
|
|
5063 ; path))
|
|
5064 ;
|
|
5065 ;(or (assq 'vos ange-ftp-fix-path-func-alist)
|
|
5066 ; (setq ange-ftp-fix-path-func-alist
|
|
5067 ; (cons '(vos . ange-ftp-fix-path-for-vos)
|
|
5068 ; ange-ftp-fix-path-func-alist)))
|
|
5069 ;
|
|
5070 ;(or (memq 'vos ange-ftp-dumb-host-types)
|
|
5071 ; (setq ange-ftp-dumb-host-types
|
|
5072 ; (cons 'vos ange-ftp-dumb-host-types)))
|
|
5073 ;
|
|
5074 ;(defun ange-ftp-fix-dir-path-for-vos (dir-path)
|
|
5075 ; (ange-ftp-fix-path-for-vos
|
|
5076 ; (concat dir-path
|
|
5077 ; (if (eq ?/ (aref dir-path (1- (length dir-path))))
|
|
5078 ; "" "/")
|
|
5079 ; "*")))
|
|
5080 ;
|
|
5081 ;(or (assq 'vos ange-ftp-fix-dir-path-func-alist)
|
|
5082 ; (setq ange-ftp-fix-dir-path-func-alist
|
|
5083 ; (cons '(vos . ange-ftp-fix-dir-path-for-vos)
|
|
5084 ; ange-ftp-fix-dir-path-func-alist)))
|
|
5085 ;
|
|
5086 ;(defvar ange-ftp-vos-host-regexp nil
|
|
5087 ; "If a host matches this regexp then it is assumed to be running VOS.")
|
|
5088 ;
|
|
5089 ;(defun ange-ftp-vos-host (host)
|
|
5090 ; (and ange-ftp-vos-host-regexp
|
|
5091 ; (ange-ftp-save-match-data
|
|
5092 ; (string-match ange-ftp-vos-host-regexp host))))
|
|
5093 ;
|
|
5094 ;(defun ange-ftp-parse-vos-listing ()
|
|
5095 ; "Parse the current buffer which is assumed to be in VOS list -all
|
|
5096 ;format, and return a hashtable as the result."
|
|
5097 ; (let ((tbl (ange-ftp-make-hashtable))
|
|
5098 ; (type-list
|
|
5099 ; '(("^Files: [0-9]+ +Blocks: [0-9]+\n+" nil 40)
|
|
5100 ; ("^Dirs: [0-9]+\n+" t 30)))
|
|
5101 ; type-regexp type-is-dir type-col file)
|
|
5102 ; (goto-char (point-min))
|
|
5103 ; (ange-ftp-save-match-data
|
|
5104 ; (while type-list
|
|
5105 ; (setq type-regexp (car (car type-list))
|
|
5106 ; type-is-dir (nth 1 (car type-list))
|
|
5107 ; type-col (nth 2 (car type-list))
|
|
5108 ; type-list (cdr type-list))
|
|
5109 ; (if (re-search-forward type-regexp nil t)
|
|
5110 ; (while (eq (char-after (point)) ? )
|
|
5111 ; (move-to-column type-col)
|
|
5112 ; (setq file (buffer-substring (point)
|
|
5113 ; (progn
|
|
5114 ; (end-of-line 1)
|
|
5115 ; (point))))
|
|
5116 ; (ange-ftp-put-hash-entry file type-is-dir tbl)
|
|
5117 ; (forward-line 1))))
|
|
5118 ; (ange-ftp-put-hash-entry "." 'vosdir tbl)
|
|
5119 ; (ange-ftp-put-hash-entry ".." 'vosdir tbl))
|
|
5120 ; tbl))
|
|
5121 ;
|
|
5122 ;(or (assq 'vos ange-ftp-parse-list-func-alist)
|
|
5123 ; (setq ange-ftp-parse-list-func-alist
|
|
5124 ; (cons '(vos . ange-ftp-parse-vos-listing)
|
|
5125 ; ange-ftp-parse-list-func-alist)))
|
|
5126
|
|
5127 ;;;; ------------------------------------------------------------
|
|
5128 ;;;; VMS support.
|
|
5129 ;;;; ------------------------------------------------------------
|
|
5130
|
|
5131 (defun ange-ftp-fix-path-for-vms (path &optional reverse)
|
|
5132 "Convert PATH from UNIX-ish to VMS. If REVERSE given then convert from VMS
|
|
5133 to UNIX-ish."
|
|
5134 (ange-ftp-save-match-data
|
|
5135 (if reverse
|
|
5136 (if (string-match "^\\([^:]+:\\)?\\(\\[.*\\]\\)?\\([^][]*\\)$" path)
|
|
5137 (let (drive dir file)
|
|
5138 (if (match-beginning 1)
|
|
5139 (setq drive (substring path
|
|
5140 (match-beginning 1)
|
|
5141 (match-end 1))))
|
|
5142 (if (match-beginning 2)
|
|
5143 (setq dir
|
|
5144 (substring path (match-beginning 2) (match-end 2))))
|
|
5145 (if (match-beginning 3)
|
|
5146 (setq file
|
|
5147 (substring path (match-beginning 3) (match-end 3))))
|
|
5148 (and dir
|
|
5149 (setq dir (apply (function concat)
|
|
5150 (mapcar (function
|
|
5151 (lambda (char)
|
|
5152 (if (= char ?.)
|
|
5153 (vector ?/)
|
|
5154 (vector char))))
|
|
5155 (substring dir 1 -1)))))
|
|
5156 (concat (and drive
|
|
5157 (concat "/" drive "/"))
|
|
5158 dir (and dir "/")
|
|
5159 file))
|
|
5160 (error "path %s didn't match" path))
|
|
5161 (let (drive dir file tmp)
|
|
5162 (if (string-match "^/[^:]+:/" path)
|
|
5163 (setq drive (substring path 1
|
|
5164 (1- (match-end 0)))
|
|
5165 path (substring path (match-end 0))))
|
|
5166 (setq tmp (file-name-directory path))
|
|
5167 (if tmp
|
|
5168 (setq dir (apply (function concat)
|
|
5169 (mapcar (function
|
|
5170 (lambda (char)
|
|
5171 (if (= char ?/)
|
|
5172 (vector ?.)
|
|
5173 (vector char))))
|
|
5174 (substring tmp 0 -1)))))
|
|
5175 (setq file (file-name-nondirectory path))
|
|
5176 (concat drive
|
|
5177 (and dir (concat "[" (if drive nil ".") dir "]"))
|
|
5178 file)))))
|
|
5179
|
|
5180 ;; (ange-ftp-fix-path-for-vms "/PUB$:/ANONYMOUS/SDSCPUB/NEXT/Readme.txt;1")
|
|
5181 ;; (ange-ftp-fix-path-for-vms "/PUB$:[ANONYMOUS.SDSCPUB.NEXT]Readme.txt;1" t)
|
|
5182
|
|
5183 (or (assq 'vms ange-ftp-fix-path-func-alist)
|
|
5184 (setq ange-ftp-fix-path-func-alist
|
|
5185 (cons '(vms . ange-ftp-fix-path-for-vms)
|
|
5186 ange-ftp-fix-path-func-alist)))
|
|
5187
|
|
5188 (or (memq 'vms ange-ftp-dumb-host-types)
|
|
5189 (setq ange-ftp-dumb-host-types
|
|
5190 (cons 'vms ange-ftp-dumb-host-types)))
|
|
5191
|
|
5192 ;; It is important that this function barf for directories for which we know
|
|
5193 ;; that we cannot possibly get a directory listing, such as "/" and "/DEV:/".
|
|
5194 ;; This is because it saves an unnecessary FTP error, or possibly the listing
|
|
5195 ;; might succeed, but give erroneous info. This last case is particularly
|
|
5196 ;; likely for OS's (like MTS) for which we need to use a wildcard in order
|
|
5197 ;; to list a directory.
|
|
5198
|
|
5199 (defun ange-ftp-fix-dir-path-for-vms (dir-path)
|
|
5200 "Convert path from UNIX-ish to VMS ready for a DIRectory listing."
|
|
5201 ;; Should there be entries for .. -> [-] and . -> [] below. Don't
|
|
5202 ;; think so, because expand-filename should have already short-circuited
|
|
5203 ;; them.
|
|
5204 (cond ((string-equal dir-path "/")
|
|
5205 (error "Cannot get listing for fictitious \"/\" directory."))
|
|
5206 ((string-match "^/[-A-Z0-9_$]+:/$" dir-path)
|
|
5207 (error "Cannot get listing for device."))
|
|
5208 ((ange-ftp-fix-path-for-vms dir-path))))
|
|
5209
|
|
5210 (or (assq 'vms ange-ftp-fix-dir-path-func-alist)
|
|
5211 (setq ange-ftp-fix-dir-path-func-alist
|
|
5212 (cons '(vms . ange-ftp-fix-dir-path-for-vms)
|
|
5213 ange-ftp-fix-dir-path-func-alist)))
|
|
5214
|
|
5215 (defvar ange-ftp-vms-host-regexp nil)
|
|
5216
|
|
5217 (defun ange-ftp-vms-host (host)
|
|
5218 "Return whether HOST is running VMS."
|
|
5219 (and ange-ftp-vms-host-regexp
|
|
5220 (ange-ftp-save-match-data
|
|
5221 (string-match ange-ftp-vms-host-regexp host))))
|
|
5222
|
|
5223 ;; Because some VMS ftp servers convert filenames to lower case
|
|
5224 ;; we allow a-z in the filename regexp. I'm not too happy about this.
|
|
5225
|
|
5226 (defconst ange-ftp-vms-filename-regexp
|
|
5227 (concat
|
|
5228 "\\(\\([_A-Za-z0-9$]?\\|[_A-Za-z0-9$][_A-Za-z0-9$---]*\\)\\."
|
|
5229 "[_A-Za-z0-9$---]*;+[0-9]*\\)")
|
|
5230 "Regular expression to match for a valid VMS file name in Dired buffer.
|
|
5231 Stupid freaking bug! Position of _ and $ shouldn't matter but they do.
|
|
5232 Having [A-Z0-9$_] bombs on filename _$$CHANGE_LOG$.TXT$ and $CHANGE_LOG$.TX
|
|
5233 Other orders of $ and _ seem to all work just fine.")
|
|
5234
|
|
5235 ;; These parsing functions are as general as possible because the syntax
|
|
5236 ;; of ftp listings from VMS hosts is a bit erratic. What saves us is that
|
|
5237 ;; the VMS filename syntax is so rigid. If they bomb on a listing in the
|
|
5238 ;; standard VMS Multinet format, then this is a bug. If they bomb on a listing
|
|
5239 ;; from vms.weird.net, then too bad.
|
|
5240
|
|
5241 (defun ange-ftp-parse-vms-filename ()
|
|
5242 "Extract the next filename from a VMS dired-like listing."
|
|
5243 (if (re-search-forward
|
|
5244 ange-ftp-vms-filename-regexp
|
|
5245 nil t)
|
|
5246 (buffer-substring (match-beginning 0) (match-end 0))))
|
|
5247
|
|
5248 (defun ange-ftp-parse-vms-listing ()
|
|
5249 "Parse the current buffer which is assumed to be in MultiNet FTP dir
|
|
5250 format, and return a hashtable as the result."
|
|
5251 (let ((tbl (ange-ftp-make-hashtable))
|
|
5252 file)
|
|
5253 (goto-char (point-min))
|
|
5254 (ange-ftp-save-match-data
|
|
5255 (while (setq file (ange-ftp-parse-vms-filename))
|
|
5256 (if (string-match "\\.\\(DIR\\|dir\\);[0-9]+" file)
|
|
5257 ;; deal with directories
|
|
5258 (ange-ftp-put-hash-entry
|
|
5259 (substring file 0 (match-beginning 0)) t tbl)
|
|
5260 (ange-ftp-put-hash-entry file nil tbl)
|
|
5261 (if (string-match ";[0-9]+$" file) ; deal with extension
|
|
5262 ;; sans extension
|
|
5263 (ange-ftp-put-hash-entry
|
|
5264 (substring file 0 (match-beginning 0)) nil tbl)))
|
|
5265 (forward-line 1))
|
|
5266 ;; Would like to look for a "Total" line, or a "Directory" line to
|
|
5267 ;; make sure that the listing isn't complete garbage before putting
|
|
5268 ;; in "." and "..", but we can't even count on all VAX's giving us
|
|
5269 ;; either of these.
|
|
5270 (ange-ftp-put-hash-entry "." t tbl)
|
|
5271 (ange-ftp-put-hash-entry ".." t tbl))
|
|
5272 tbl))
|
|
5273
|
|
5274 (or (assq 'vms ange-ftp-parse-list-func-alist)
|
|
5275 (setq ange-ftp-parse-list-func-alist
|
|
5276 (cons '(vms . ange-ftp-parse-vms-listing)
|
|
5277 ange-ftp-parse-list-func-alist)))
|
|
5278
|
|
5279 ;; This version only deletes file entries which have
|
|
5280 ;; explicit version numbers, because that is all VMS allows.
|
|
5281
|
|
5282 ;; Can the following two functions be speeded up using file
|
|
5283 ;; completion functions?
|
|
5284
|
|
5285 (defun ange-ftp-vms-delete-file-entry (path &optional dir-p)
|
|
5286 (if dir-p
|
|
5287 (ange-ftp-internal-delete-file-entry path t)
|
|
5288 (ange-ftp-save-match-data
|
|
5289 (let ((file (ange-ftp-get-file-part path)))
|
|
5290 (if (string-match ";[0-9]+$" file)
|
|
5291 ;; In VMS you can't delete a file without an explicit
|
|
5292 ;; version number, or wild-card (e.g. FOO;*)
|
|
5293 ;; For now, we give up on wildcards.
|
|
5294 (let ((files (ange-ftp-get-hash-entry
|
|
5295 (file-name-directory path)
|
|
5296 ange-ftp-files-hashtable)))
|
|
5297 (if files
|
|
5298 (let* ((root (substring file 0
|
|
5299 (match-beginning 0)))
|
|
5300 (regexp (concat "^"
|
|
5301 (regexp-quote root)
|
|
5302 ";[0-9]+$"))
|
|
5303 versions)
|
|
5304 (ange-ftp-del-hash-entry file files)
|
|
5305 ;; Now we need to check if there are any
|
|
5306 ;; versions left. If not, then delete the
|
|
5307 ;; root entry.
|
|
5308 (mapatoms
|
|
5309 '(lambda (sym)
|
|
5310 (and (string-match regexp (get sym 'key))
|
|
5311 (setq versions t)))
|
|
5312 files)
|
|
5313 (or versions
|
|
5314 (ange-ftp-del-hash-entry root files))))))))))
|
|
5315
|
|
5316 (or (assq 'vms ange-ftp-delete-file-entry-alist)
|
|
5317 (setq ange-ftp-delete-file-entry-alist
|
|
5318 (cons '(vms . ange-ftp-vms-delete-file-entry)
|
|
5319 ange-ftp-delete-file-entry-alist)))
|
|
5320
|
|
5321 (defun ange-ftp-vms-add-file-entry (path &optional dir-p)
|
|
5322 (if dir-p
|
|
5323 (ange-ftp-internal-add-file-entry path t)
|
|
5324 (let ((files (ange-ftp-get-hash-entry
|
|
5325 (file-name-directory path)
|
|
5326 ange-ftp-files-hashtable)))
|
|
5327 (if files
|
|
5328 (let ((file (ange-ftp-get-file-part path)))
|
|
5329 (ange-ftp-save-match-data
|
|
5330 (if (string-match ";[0-9]+$" file)
|
|
5331 (ange-ftp-put-hash-entry
|
|
5332 (substring file 0 (match-beginning 0))
|
|
5333 nil files)
|
|
5334 ;; Need to figure out what version of the file
|
|
5335 ;; is being added.
|
|
5336 (let ((regexp (concat "^"
|
|
5337 (regexp-quote file)
|
|
5338 ";\\([0-9]+\\)$"))
|
|
5339 (version 0))
|
|
5340 (mapatoms
|
|
5341 '(lambda (sym)
|
|
5342 (let ((name (get sym 'key)))
|
|
5343 (and (string-match regexp name)
|
|
5344 (setq version
|
|
5345 (max version
|
|
5346 (string-to-int
|
|
5347 (substring name
|
|
5348 (match-beginning 1)
|
|
5349 (match-end 1))))))))
|
|
5350 files)
|
|
5351 (setq version (1+ version))
|
|
5352 (ange-ftp-put-hash-entry
|
|
5353 (concat file ";" (int-to-string version))
|
|
5354 nil files))))
|
|
5355 (ange-ftp-put-hash-entry file nil files))))))
|
|
5356
|
|
5357 (or (assq 'vms ange-ftp-add-file-entry-alist)
|
|
5358 (setq ange-ftp-add-file-entry-alist
|
|
5359 (cons '(vms . ange-ftp-vms-add-file-entry)
|
|
5360 ange-ftp-add-file-entry-alist)))
|
|
5361
|
|
5362
|
|
5363 (defun ange-ftp-add-vms-host (host)
|
|
5364 "Interactively adds a given HOST to ange-ftp-vms-host-regexp."
|
|
5365 (interactive
|
|
5366 (list (read-string "Host: "
|
|
5367 (let ((name (or (buffer-file-name)
|
|
5368 (and (eq major-mode 'dired-mode)
|
|
5369 dired-directory))))
|
|
5370 (and name (car (ange-ftp-ftp-path name)))))))
|
|
5371 (if (not (ange-ftp-vms-host host))
|
|
5372 (setq ange-ftp-vms-host-regexp
|
|
5373 (concat "^" (regexp-quote host) "$"
|
|
5374 (and ange-ftp-vms-host-regexp "\\|")
|
|
5375 ange-ftp-vms-host-regexp)
|
|
5376 ange-ftp-host-cache nil)))
|
|
5377
|
|
5378
|
|
5379 (defun ange-ftp-vms-file-name-as-directory (name)
|
|
5380 (ange-ftp-save-match-data
|
|
5381 (if (string-match "\\.\\(DIR\\|dir\\)\\(;[0-9]+\\)?$" name)
|
|
5382 (setq name (substring name 0 (match-beginning 0))))
|
|
5383 (ange-ftp-real-file-name-as-directory name)))
|
|
5384
|
|
5385 (or (assq 'vms ange-ftp-file-name-as-directory-alist)
|
|
5386 (setq ange-ftp-file-name-as-directory-alist
|
|
5387 (cons '(vms . ange-ftp-vms-file-name-as-directory)
|
|
5388 ange-ftp-file-name-as-directory-alist)))
|
|
5389
|
|
5390 ;;; Tree dired support:
|
|
5391
|
|
5392 ;; For this code I have borrowed liberally from Sebastian Kremer's
|
|
5393 ;; dired-vms.el
|
|
5394
|
|
5395
|
|
5396 ;; These regexps must be anchored to beginning of line.
|
|
5397 ;; Beware that the ftpd may put the device in front of the filename.
|
|
5398
|
|
5399 (defconst ange-ftp-dired-vms-re-exe "^. [^ \t.]+\\.\\(EXE\\|exe\\)[; ]"
|
|
5400 "Regular expression to use to search for VMS executable files.")
|
|
5401
|
|
5402 (defconst ange-ftp-dired-vms-re-dir "^. [^ \t.]+\\.\\(DIR\\|dir\\)[; ]"
|
|
5403 "Regular expression to use to search for VMS directories.")
|
|
5404
|
|
5405 (or (assq 'vms ange-ftp-dired-re-exe-alist)
|
|
5406 (setq ange-ftp-dired-re-exe-alist
|
|
5407 (cons (cons 'vms ange-ftp-dired-vms-re-exe)
|
|
5408 ange-ftp-dired-re-exe-alist)))
|
|
5409
|
|
5410 (or (assq 'vms ange-ftp-dired-re-dir-alist)
|
|
5411 (setq ange-ftp-dired-re-dir-alist
|
|
5412 (cons (cons 'vms ange-ftp-dired-vms-re-dir)
|
|
5413 ange-ftp-dired-re-dir-alist)))
|
|
5414
|
|
5415 (defun ange-ftp-dired-vms-insert-headerline (dir)
|
|
5416 ;; VMS inserts a headerline. I would prefer the headerline
|
|
5417 ;; to be in ange-ftp format. This version tries to
|
|
5418 ;; be careful, because we can't count on a headerline
|
|
5419 ;; over ftp, and we wouldn't want to delete anything
|
|
5420 ;; important.
|
|
5421 (save-excursion
|
|
5422 (if (looking-at "^ wildcard ")
|
|
5423 (forward-line 1))
|
|
5424 (if (looking-at "^[ \n\t]*[^\n]+\\][ \t]*\n")
|
|
5425 (delete-region (point) (match-end 0))))
|
|
5426 (ange-ftp-real-dired-insert-headerline dir))
|
|
5427
|
|
5428 (or (assq 'vms ange-ftp-dired-insert-headerline-alist)
|
|
5429 (setq ange-ftp-dired-insert-headerline-alist
|
|
5430 (cons '(vms . ange-ftp-dired-vms-insert-headerline)
|
|
5431 ange-ftp-dired-insert-headerline-alist)))
|
|
5432
|
|
5433 (defun ange-ftp-dired-vms-move-to-filename (&optional raise-error eol)
|
|
5434 "In dired, move to first char of filename on this line.
|
|
5435 Returns position (point) or nil if no filename on this line."
|
|
5436 ;; This is the VMS version.
|
|
5437 (let (case-fold-search)
|
|
5438 (or eol (setq eol (progn (end-of-line) (point))))
|
|
5439 (beginning-of-line)
|
|
5440 (if (re-search-forward ange-ftp-vms-filename-regexp eol t)
|
|
5441 (goto-char (match-beginning 1))
|
|
5442 (if raise-error
|
|
5443 (error "No file on this line")
|
|
5444 nil))))
|
|
5445
|
|
5446 (or (assq 'vms ange-ftp-dired-move-to-filename-alist)
|
|
5447 (setq ange-ftp-dired-move-to-filename-alist
|
|
5448 (cons '(vms . ange-ftp-dired-vms-move-to-filename)
|
|
5449 ange-ftp-dired-move-to-filename-alist)))
|
|
5450
|
|
5451 (defun ange-ftp-dired-vms-move-to-end-of-filename (&optional no-error eol)
|
|
5452 ;; Assumes point is at beginning of filename.
|
|
5453 ;; So, it should be called only after (dired-move-to-filename t).
|
|
5454 ;; case-fold-search must be nil, at least for VMS.
|
|
5455 ;; On failure, signals an error or returns nil.
|
|
5456 ;; This is the VMS version.
|
|
5457 (let (opoint hidden case-fold-search)
|
|
5458 (setq opoint (point))
|
|
5459 (or eol (setq eol (save-excursion (end-of-line) (point))))
|
|
5460 (setq hidden (and selective-display
|
|
5461 (save-excursion (search-forward "\r" eol t))))
|
|
5462 (if hidden
|
|
5463 nil
|
|
5464 (re-search-forward ange-ftp-vms-filename-regexp eol t))
|
|
5465 (or no-error
|
|
5466 (not (eq opoint (point)))
|
|
5467 (error
|
|
5468 (if hidden
|
|
5469 (substitute-command-keys
|
|
5470 "File line is hidden, type \\[dired-hide-subdir] to unhide")
|
|
5471 "No file on this line")))
|
|
5472 (if (eq opoint (point))
|
|
5473 nil
|
|
5474 (point))))
|
|
5475
|
|
5476 (or (assq 'vms ange-ftp-dired-move-to-end-of-filename-alist)
|
|
5477 (setq ange-ftp-dired-move-to-end-of-filename-alist
|
|
5478 (cons '(vms . ange-ftp-dired-vms-move-to-end-of-filename)
|
|
5479 ange-ftp-dired-move-to-end-of-filename-alist)))
|
|
5480
|
|
5481 (defun ange-ftp-dired-vms-between-files ()
|
|
5482 (save-excursion
|
|
5483 (beginning-of-line)
|
|
5484 (or (equal (following-char) 10) ; newline
|
|
5485 (equal (following-char) 9) ; tab
|
|
5486 (progn (forward-char 2)
|
|
5487 (or (looking-at "Total of")
|
|
5488 (equal (following-char) 32))))))
|
|
5489
|
|
5490 (or (assq 'vms ange-ftp-dired-between-files-alist)
|
|
5491 (setq ange-ftp-dired-between-files-alist
|
|
5492 (cons '(vms . ange-ftp-dired-vms-between-files)
|
|
5493 ange-ftp-dired-between-files-alist)))
|
|
5494
|
|
5495 ;; Beware! In VMS filenames must be of the form "FILE.TYPE".
|
|
5496 ;; Therefore, we cannot just append a ".Z" to filenames for
|
|
5497 ;; compressed files. Instead, we turn "FILE.TYPE" into
|
|
5498 ;; "FILE.TYPE-Z". Hope that this is a reasonable thing to do.
|
|
5499
|
|
5500 (defun ange-ftp-vms-make-compressed-filename (name &optional reverse)
|
|
5501 (if reverse
|
|
5502 (cond
|
|
5503 ((string-match "-Z;[0-9]+$" name)
|
|
5504 (substring name 0 (match-beginning 0)))
|
|
5505 ((string-match ";[0-9]+$" name)
|
|
5506 (substring name 0 (match-beginning 0)))
|
|
5507 ((string-match "-Z$" name)
|
|
5508 (substring name 0 -2))
|
|
5509 (t name))
|
|
5510 (if (string-match ";[0-9]+$" name)
|
|
5511 (concat (substring name 0 (match-beginning 0))
|
|
5512 "-Z")
|
|
5513 (concat name "-Z"))))
|
|
5514
|
|
5515 (or (assq 'vms ange-ftp-dired-compress-make-compressed-filename-alist)
|
|
5516 (setq ange-ftp-dired-compress-make-compressed-filename-alist
|
|
5517 (cons '(vms . ange-ftp-vms-make-compressed-filename)
|
|
5518 ange-ftp-dired-compress-make-compressed-filename-alist)))
|
|
5519
|
|
5520 ;; When the filename is too long, VMS will use two lines to list a file
|
|
5521 ;; (damn them!) This will confuse dired. To solve this, need to convince
|
|
5522 ;; Sebastian to use a function dired-go-to-end-of-file-line, instead of
|
|
5523 ;; (forward-line 1). This would require a number of changes to dired.el.
|
|
5524 ;; If dired gets confused, revert-buffer will fix it.
|
|
5525
|
|
5526 (defun ange-ftp-dired-vms-ls-trim ()
|
|
5527 (goto-char (point-min))
|
|
5528 (let ((case-fold-search nil))
|
|
5529 (re-search-forward ange-ftp-vms-filename-regexp))
|
|
5530 (beginning-of-line)
|
|
5531 (delete-region (point-min) (point))
|
|
5532 (forward-line 1)
|
|
5533 (delete-region (point) (point-max)))
|
|
5534
|
|
5535
|
|
5536 (or (assq 'vms ange-ftp-dired-ls-trim-alist)
|
|
5537 (setq ange-ftp-dired-ls-trim-alist
|
|
5538 (cons '(vms . ange-ftp-dired-vms-ls-trim)
|
|
5539 ange-ftp-dired-ls-trim-alist)))
|
|
5540
|
|
5541 (defun ange-ftp-vms-bob-version (name)
|
|
5542 (ange-ftp-save-match-data
|
|
5543 (if (string-match ";[0-9]+$" name)
|
|
5544 (substring name 0 (match-beginning 0))
|
|
5545 name)))
|
|
5546
|
|
5547 (or (assq 'vms ange-ftp-bob-version-alist)
|
|
5548 (setq ange-ftp-bob-version-alist
|
|
5549 (cons '(vms . ange-ftp-vms-bob-version)
|
|
5550 ange-ftp-bob-version-alist)))
|
|
5551
|
|
5552 ;;; The vms version of clean-directory has 2 more optional args
|
|
5553 ;;; than the usual dired version. This is so that it can be used by
|
|
5554 ;;; ange-ftp-dired-vms-flag-backup-files.
|
|
5555
|
|
5556 (defun ange-ftp-dired-vms-clean-directory (keep &optional marker msg)
|
|
5557 "Flag numerical backups for deletion.
|
|
5558 Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest.
|
|
5559 Positive prefix arg KEEP overrides `dired-kept-versions';
|
|
5560 Negative prefix arg KEEP overrides `kept-old-versions' with KEEP made positive.
|
|
5561
|
|
5562 To clear the flags on these files, you can use \\[dired-flag-backup-files]
|
|
5563 with a prefix argument."
|
|
5564 ; (interactive "P") ; Never actually called interactively.
|
|
5565 (setq keep (max 1 (if keep (prefix-numeric-value keep) dired-kept-versions)))
|
|
5566 (let ((early-retention (if (< keep 0) (- keep) kept-old-versions))
|
|
5567 ;; late-retention must NEVER be allowed to be less than 1 in VMS!
|
|
5568 ;; This could wipe ALL copies of the file.
|
|
5569 (late-retention (max 1 (if (<= keep 0) dired-kept-versions keep)))
|
|
5570 (action (or msg "Cleaning"))
|
|
5571 (trample-marker (or marker dired-del-marker))
|
|
5572 (file-version-assoc-list ()))
|
|
5573 (message (concat action
|
|
5574 " numerical backups (keeping %d late, %d old)...")
|
|
5575 late-retention early-retention)
|
|
5576 ;; Look at each file.
|
|
5577 ;; If the file has numeric backup versions,
|
|
5578 ;; put on file-version-assoc-list an element of the form
|
|
5579 ;; (FILENAME . VERSION-NUMBER-LIST)
|
|
5580 (dired-map-dired-file-lines (function
|
|
5581 ange-ftp-dired-vms-collect-file-versions))
|
|
5582 ;; Sort each VERSION-NUMBER-LIST,
|
|
5583 ;; and remove the versions not to be deleted.
|
|
5584 (let ((fval file-version-assoc-list))
|
|
5585 (while fval
|
|
5586 (let* ((sorted-v-list (cons 'q (sort (cdr (car fval)) '<)))
|
|
5587 (v-count (length sorted-v-list)))
|
|
5588 (if (> v-count (+ early-retention late-retention))
|
|
5589 (rplacd (nthcdr early-retention sorted-v-list)
|
|
5590 (nthcdr (- v-count late-retention)
|
|
5591 sorted-v-list)))
|
|
5592 (rplacd (car fval)
|
|
5593 (cdr sorted-v-list)))
|
|
5594 (setq fval (cdr fval))))
|
|
5595 ;; Look at each file. If it is a numeric backup file,
|
|
5596 ;; find it in a VERSION-NUMBER-LIST and maybe flag it for deletion.
|
|
5597 (dired-map-dired-file-lines
|
|
5598 (function
|
|
5599 ange-ftp-dired-vms-trample-file-versions mark))
|
|
5600 (message (concat action " numerical backups...done"))))
|
|
5601
|
|
5602 (or (assq 'vms ange-ftp-dired-clean-directory-alist)
|
|
5603 (setq ange-ftp-dired-clean-directory-alist
|
|
5604 (cons '(vms . ange-ftp-dired-vms-clean-directory)
|
|
5605 ange-ftp-dired-clean-directory-alist)))
|
|
5606
|
|
5607 (defun ange-ftp-dired-vms-collect-file-versions (fn)
|
|
5608 ;; "If it looks like file FN has versions, return a list of the versions.
|
|
5609 ;;That is a list of strings which are file names.
|
|
5610 ;;The caller may want to flag some of these files for deletion."
|
|
5611 (let ((path (nth 2 (ange-ftp-ftp-path fn))))
|
|
5612 (if (string-match ";[0-9]+$" path)
|
|
5613 (let* ((path (substring path 0 (match-beginning 0)))
|
|
5614 (fn (ange-ftp-replace-path-component fn path)))
|
|
5615 (if (not (assq fn file-version-assoc-list))
|
|
5616 (let* ((base-versions
|
|
5617 (concat (file-name-nondirectory path) ";"))
|
|
5618 (bv-length (length base-versions))
|
|
5619 (possibilities (file-name-all-completions
|
|
5620 base-versions
|
|
5621 (file-name-directory fn)))
|
|
5622 (versions (mapcar
|
|
5623 '(lambda (arg)
|
|
5624 (if (and (string-match
|
|
5625 "[0-9]+$" arg bv-length)
|
|
5626 (= (match-beginning 0) bv-length))
|
|
5627 (string-to-int (substring arg bv-length))
|
|
5628 0))
|
|
5629 possibilities)))
|
|
5630 (if versions
|
|
5631 (setq
|
|
5632 file-version-assoc-list
|
|
5633 (cons (cons fn versions)
|
|
5634 file-version-assoc-list)))))))))
|
|
5635
|
|
5636 (defun ange-ftp-dired-vms-trample-file-versions (fn)
|
|
5637 (let* ((start-vn (string-match ";[0-9]+$" fn))
|
|
5638 base-version-list)
|
|
5639 (and start-vn
|
|
5640 (setq base-version-list ; there was a base version to which
|
|
5641 (assoc (substring fn 0 start-vn) ; this looks like a
|
|
5642 file-version-assoc-list)) ; subversion
|
|
5643 (not (memq (string-to-int (substring fn (1+ start-vn)))
|
|
5644 base-version-list)) ; this one doesn't make the cut
|
|
5645 (progn (beginning-of-line)
|
|
5646 (delete-char 1)
|
|
5647 (insert trample-marker)))))
|
|
5648
|
|
5649 (defun ange-ftp-dired-vms-flag-backup-files (&optional unflag-p)
|
|
5650 (let ((dired-kept-versions 1)
|
|
5651 (kept-old-versions 0)
|
|
5652 marker msg)
|
|
5653 (if unflag-p
|
|
5654 (setq marker ?\040 msg "Unflagging")
|
|
5655 (setq marker dired-del-marker msg "Cleaning"))
|
|
5656 (ange-ftp-dired-vms-clean-directory nil marker msg)))
|
|
5657
|
|
5658 (or (assq 'vms ange-ftp-dired-flag-backup-files-alist)
|
|
5659 (setq ange-ftp-dired-flag-backup-files-alist
|
|
5660 (cons '(vms . ange-ftp-dired-vms-flag-backup-files)
|
|
5661 ange-ftp-dired-flag-backup-files-alist)))
|
|
5662
|
|
5663 (defun ange-ftp-dired-vms-backup-diff (&optional switches)
|
|
5664 (let ((file (dired-get-filename 'no-dir))
|
|
5665 bak)
|
|
5666 (if (and (string-match ";[0-9]+$" file)
|
|
5667 ;; Find most recent previous version.
|
|
5668 (let ((root (substring file 0 (match-beginning 0)))
|
|
5669 (ver
|
|
5670 (string-to-int (substring file (1+ (match-beginning 0)))))
|
|
5671 found)
|
|
5672 (setq ver (1- ver))
|
|
5673 (while (and (> ver 0) (not found))
|
|
5674 (setq bak (concat root ";" (int-to-string ver)))
|
|
5675 (and (file-exists-p bak) (setq found t))
|
|
5676 (setq ver (1- ver)))
|
|
5677 found))
|
|
5678 (if switches
|
|
5679 (diff (expand-file-name bak) (expand-file-name file) switches)
|
|
5680 (diff (expand-file-name bak) (expand-file-name file)))
|
|
5681 (error "No previous version found for %s" file))))
|
|
5682
|
|
5683 (or (assq 'vms ange-ftp-dired-backup-diff-alist)
|
|
5684 (setq ange-ftp-dired-backup-diff-alist
|
|
5685 (cons '(vms . ange-ftp-dired-vms-backup-diff)
|
|
5686 ange-ftp-dired-backup-diff-alist)))
|
|
5687
|
|
5688
|
|
5689 ;;;; ------------------------------------------------------------
|
|
5690 ;;;; MTS support
|
|
5691 ;;;; ------------------------------------------------------------
|
|
5692
|
|
5693
|
|
5694 (defun ange-ftp-fix-path-for-mts (path &optional reverse)
|
|
5695 "Convert PATH from UNIX-ish to MTS. If REVERSE given then convert from
|
|
5696 MTS to UNIX-ish."
|
|
5697 (ange-ftp-save-match-data
|
|
5698 (if reverse
|
|
5699 (if (string-match "^\\([^:]+:\\)?\\(.*\\)$" path)
|
|
5700 (let (acct file)
|
|
5701 (if (match-beginning 1)
|
|
5702 (setq acct (substring path 0 (match-end 1))))
|
|
5703 (if (match-beginning 2)
|
|
5704 (setq file (substring path
|
|
5705 (match-beginning 2) (match-end 2))))
|
|
5706 (concat (and acct (concat "/" acct "/"))
|
|
5707 file))
|
|
5708 (error "path %s didn't match" path))
|
|
5709 (if (string-match "^/\\([^:]+:\\)/\\(.*\\)$" path)
|
|
5710 (concat (substring path 1 (match-end 1))
|
|
5711 (substring path (match-beginning 2) (match-end 2)))
|
|
5712 ;; Let's hope that mts will recognize it anyway.
|
|
5713 path))))
|
|
5714
|
|
5715 (or (assq 'mts ange-ftp-fix-path-func-alist)
|
|
5716 (setq ange-ftp-fix-path-func-alist
|
|
5717 (cons '(mts . ange-ftp-fix-path-for-mts)
|
|
5718 ange-ftp-fix-path-func-alist)))
|
|
5719
|
|
5720 (defun ange-ftp-fix-dir-path-for-mts (dir-path)
|
|
5721 "Convert path from UNIX-ish to MTS ready for a DIRectory listing.
|
|
5722 Remember that there are no directories in MTS."
|
|
5723 (if (string-equal dir-path "/")
|
|
5724 (error "Cannot get listing for fictitious \"/\" directory.")
|
|
5725 (let ((dir-path (ange-ftp-fix-path-for-mts dir-path)))
|
|
5726 (cond
|
|
5727 ((string-equal dir-path "")
|
|
5728 "?")
|
|
5729 ((string-match ":$" dir-path)
|
|
5730 (concat dir-path "?"))
|
|
5731 (dir-path))))) ; It's just a single file.
|
|
5732
|
|
5733 (or (assq 'mts ange-ftp-fix-dir-path-func-alist)
|
|
5734 (setq ange-ftp-fix-dir-path-func-alist
|
|
5735 (cons '(mts . ange-ftp-fix-dir-path-for-mts)
|
|
5736 ange-ftp-fix-dir-path-func-alist)))
|
|
5737
|
|
5738 (or (memq 'mts ange-ftp-dumb-host-types)
|
|
5739 (setq ange-ftp-dumb-host-types
|
|
5740 (cons 'mts ange-ftp-dumb-host-types)))
|
|
5741
|
|
5742 (defvar ange-ftp-mts-host-regexp nil)
|
|
5743
|
|
5744 (defun ange-ftp-mts-host (host)
|
|
5745 "Return whether HOST is running MTS."
|
|
5746 (and ange-ftp-mts-host-regexp
|
|
5747 (ange-ftp-save-match-data
|
|
5748 (string-match ange-ftp-mts-host-regexp host))))
|
|
5749
|
|
5750 (defun ange-ftp-parse-mts-listing ()
|
|
5751 "Parse the current buffer which is assumed to be in
|
|
5752 mts ftp dir format."
|
|
5753 (let ((tbl (ange-ftp-make-hashtable)))
|
|
5754 (goto-char (point-min))
|
|
5755 (ange-ftp-save-match-data
|
|
5756 (while (re-search-forward ange-ftp-date-regexp nil t)
|
|
5757 (end-of-line)
|
|
5758 (skip-chars-backward " ")
|
|
5759 (let ((end (point)))
|
|
5760 (skip-chars-backward "-A-Z0-9_.!")
|
|
5761 (ange-ftp-put-hash-entry (buffer-substring (point) end) nil tbl))
|
|
5762 (forward-line 1)))
|
|
5763 ;; Don't need to bother with ..
|
|
5764 (ange-ftp-put-hash-entry "." t tbl)
|
|
5765 tbl))
|
|
5766
|
|
5767 (or (assq 'mts ange-ftp-parse-list-func-alist)
|
|
5768 (setq ange-ftp-parse-list-func-alist
|
|
5769 (cons '(mts . ange-ftp-parse-mts-listing)
|
|
5770 ange-ftp-parse-list-func-alist)))
|
|
5771
|
|
5772 (defun ange-ftp-add-mts-host (host)
|
|
5773 "Interactively adds a given HOST to ange-ftp-mts-host-regexp."
|
|
5774 (interactive
|
|
5775 (list (read-string "Host: "
|
|
5776 (let ((name (or (buffer-file-name)
|
|
5777 (and (eq major-mode 'dired-mode)
|
|
5778 dired-directory))))
|
|
5779 (and name (car (ange-ftp-ftp-path name)))))))
|
|
5780 (if (not (ange-ftp-mts-host host))
|
|
5781 (setq ange-ftp-mts-host-regexp
|
|
5782 (concat "^" (regexp-quote host) "$"
|
|
5783 (and ange-ftp-mts-host-regexp "\\|")
|
|
5784 ange-ftp-mts-host-regexp)
|
|
5785 ange-ftp-host-cache nil)))
|
|
5786
|
|
5787 ;;; Tree dired support:
|
|
5788
|
|
5789 ;; There aren't too many systems left that use MTS. This dired support will
|
|
5790 ;; work for the implementation of ftp on mtsg.ubc.ca. I hope other mts systems
|
|
5791 ;; implement ftp in the same way. If not, it might be necessary to make the
|
|
5792 ;; following more flexible.
|
|
5793
|
|
5794 (defun ange-ftp-dired-mts-move-to-filename (&optional raise-error eol)
|
|
5795 "In dired, move to first char of filename on this line.
|
|
5796 Returns position (point) or nil if no filename on this line."
|
|
5797 ;; This is the MTS version.
|
|
5798 (or eol (setq eol (progn (end-of-line) (point))))
|
|
5799 (beginning-of-line)
|
|
5800 (if (re-search-forward
|
|
5801 ange-ftp-date-regexp eol t)
|
|
5802 (progn
|
|
5803 (skip-chars-forward " ") ; Eat blanks after date
|
|
5804 (skip-chars-forward "0-9:" eol) ; Eat time or year
|
|
5805 (skip-chars-forward " " eol) ; one space before filename
|
|
5806 ;; When listing an account other than the users own account it appends
|
|
5807 ;; ACCT: to the beginning of the filename. Skip over this.
|
|
5808 (and (looking-at "[A-Z0-9_.]+:")
|
|
5809 (goto-char (match-end 0)))
|
|
5810 (point))
|
|
5811 (if raise-error
|
|
5812 (error "No file on this line")
|
|
5813 nil)))
|
|
5814
|
|
5815 (or (assq 'mts ange-ftp-dired-move-to-filename-alist)
|
|
5816 (setq ange-ftp-dired-move-to-filename-alist
|
|
5817 (cons '(mts . ange-ftp-dired-mts-move-to-filename)
|
|
5818 ange-ftp-dired-move-to-filename-alist)))
|
|
5819
|
|
5820 (defun ange-ftp-dired-mts-move-to-end-of-filename (&optional no-error eol)
|
|
5821 ;; Assumes point is at beginning of filename.
|
|
5822 ;; So, it should be called only after (dired-move-to-filename t).
|
|
5823 ;; On failure, signals an error or returns nil.
|
|
5824 ;; This is the MTS version.
|
|
5825 (let (opoint hidden case-fold-search)
|
|
5826 (setq opoint (point)
|
|
5827 eol (save-excursion (end-of-line) (point))
|
|
5828 hidden (and selective-display
|
|
5829 (save-excursion (search-forward "\r" eol t))))
|
|
5830 (if hidden
|
|
5831 nil
|
|
5832 (skip-chars-forward "-A-Z0-9._!" eol))
|
|
5833 (or no-error
|
|
5834 (not (eq opoint (point)))
|
|
5835 (error
|
|
5836 (if hidden
|
|
5837 (substitute-command-keys
|
|
5838 "File line is hidden, type \\[dired-hide-subdir] to unhide")
|
|
5839 "No file on this line")))
|
|
5840 (if (eq opoint (point))
|
|
5841 nil
|
|
5842 (point))))
|
|
5843
|
|
5844 (or (assq 'mts ange-ftp-dired-move-to-end-of-filename-alist)
|
|
5845 (setq ange-ftp-dired-move-to-end-of-filename-alist
|
|
5846 (cons '(mts . ange-ftp-dired-mts-move-to-end-of-filename)
|
|
5847 ange-ftp-dired-move-to-end-of-filename-alist)))
|
|
5848
|
|
5849 ;;;; ------------------------------------------------------------
|
|
5850 ;;;; CMS support
|
|
5851 ;;;; ------------------------------------------------------------
|
|
5852
|
|
5853 ;; Since CMS doesn't have any full pathname syntax, we have to fudge
|
|
5854 ;; things with cd's. We actually send too many cd's, but is dangerous
|
|
5855 ;; to try to remember the current minidisk, because if the connection
|
|
5856 ;; is closed and needs to be reopened, we will find ourselves back in
|
|
5857 ;; the default minidisk. This is fairly likely since CMS ftp servers
|
|
5858 ;; usually close the connection after 5 minutes of inactivity.
|
|
5859
|
|
5860 ;; Have I got the filename character set right?
|
|
5861
|
|
5862 (defun ange-ftp-fix-path-for-cms (path &optional reverse)
|
|
5863 "Convert PATH from UNIX-ish to CMS. If REVERSE is given, convert
|
|
5864 from CMS to UNIX. Actually, CMS doesn't have a full pathname syntax,
|
|
5865 so we fudge things by sending cd's."
|
|
5866 (ange-ftp-save-match-data
|
|
5867 (if reverse
|
|
5868 ;; Since we only convert output from a pwd in this direction,
|
|
5869 ;; we'll assume that it's a minidisk, and make it into a
|
|
5870 ;; directory file name. Note that the expand-dir-hashtable
|
|
5871 ;; stores directories without the trailing /. Is this
|
|
5872 ;; consistent?
|
|
5873 (concat "/" path)
|
|
5874 (if (string-match "^/\\([-A-Z0-9$*._]+\\)/\\([-A-Z0-9$._]+\\)?$"
|
|
5875 path)
|
|
5876 (let ((minidisk (substring path 1 (match-end 1))))
|
|
5877 (if (match-beginning 2)
|
|
5878 (let ((file (substring path (match-beginning 2)
|
|
5879 (match-end 2)))
|
|
5880 (cmd (concat "cd " minidisk))
|
|
5881
|
|
5882 ;; Note that host and user are bound in the call
|
|
5883 ;; to ange-ftp-send-cmd
|
|
5884 (proc (ange-ftp-get-process host user)))
|
|
5885
|
|
5886 ;; Must use ange-ftp-raw-send-cmd here to avoid
|
|
5887 ;; an infinite loop.
|
|
5888 (if (car (ange-ftp-raw-send-cmd proc cmd msg))
|
|
5889 file
|
|
5890 ;; failed... try ONCE more.
|
|
5891 (setq proc (ange-ftp-get-process host user))
|
|
5892 (let ((result (ange-ftp-raw-send-cmd proc cmd msg)))
|
|
5893 (if (car result)
|
|
5894 file
|
|
5895 ;; failed. give up.
|
|
5896 (ange-ftp-error host user
|
|
5897 (format "cd to minidisk %s failed: %s"
|
|
5898 minidisk (cdr result)))))))
|
|
5899 ;; return the minidisk
|
|
5900 minidisk))
|
|
5901 (error "Invalid CMS filename")))))
|
|
5902
|
|
5903 (or (assq 'cms ange-ftp-fix-path-func-alist)
|
|
5904 (setq ange-ftp-fix-path-func-alist
|
|
5905 (cons '(cms . ange-ftp-fix-path-for-cms)
|
|
5906 ange-ftp-fix-path-func-alist)))
|
|
5907
|
|
5908 (or (memq 'cms ange-ftp-dumb-host-types)
|
|
5909 (setq ange-ftp-dumb-host-types
|
|
5910 (cons 'cms ange-ftp-dumb-host-types)))
|
|
5911
|
|
5912 (defun ange-ftp-fix-dir-path-for-cms (dir-path)
|
|
5913 "Convert path from UNIX-ish to VMS ready for a DIRectory listing."
|
|
5914 (cond
|
|
5915 ((string-equal "/" dir-path)
|
|
5916 (error "Cannot get listing for fictitious \"/\" directory."))
|
|
5917 ((string-match "^/\\([-A-Z0-9$*._]+\\)/\\([-A-Z0-9$._]+\\)?$" dir-path)
|
|
5918 (let* ((minidisk (substring dir-path (match-beginning 1) (match-end 1)))
|
|
5919 ;; host and user are bound in the call to ange-ftp-send-cmd
|
|
5920 (proc (ange-ftp-get-process host user))
|
|
5921 (cmd (concat "cd " minidisk))
|
|
5922 (file (if (match-beginning 2)
|
|
5923 ;; it's a single file
|
|
5924 (substring path (match-beginning 2)
|
|
5925 (match-end 2))
|
|
5926 ;; use the wild-card
|
|
5927 "*")))
|
|
5928 (if (car (ange-ftp-raw-send-cmd proc cmd))
|
|
5929 file
|
|
5930 ;; try again...
|
|
5931 (setq proc (ange-ftp-get-process host user))
|
|
5932 (let ((result (ange-ftp-raw-send-cmd proc cmd)))
|
|
5933 (if (car result)
|
|
5934 file
|
|
5935 ;; give up
|
|
5936 (ange-ftp-error host user
|
|
5937 (format "cd to minidisk %s failed: "
|
|
5938 minidisk (cdr result))))))))
|
|
5939 (t (error "Invalid CMS pathname"))))
|
|
5940
|
|
5941 (or (assq 'cms ange-ftp-fix-dir-path-func-alist)
|
|
5942 (setq ange-ftp-fix-dir-path-func-alist
|
|
5943 (cons '(cms . ange-ftp-fix-dir-path-for-cms)
|
|
5944 ange-ftp-fix-dir-path-func-alist)))
|
|
5945
|
|
5946 (defvar ange-ftp-cms-host-regexp nil
|
|
5947 "Regular expression to match hosts running the CMS operating system.")
|
|
5948
|
|
5949 (defun ange-ftp-cms-host (host)
|
|
5950 "Return whether the host is running CMS."
|
|
5951 (and ange-ftp-cms-host-regexp
|
|
5952 (ange-ftp-save-match-data
|
|
5953 (string-match ange-ftp-cms-host-regexp host))))
|
|
5954
|
|
5955 (defun ange-ftp-add-cms-host (host)
|
|
5956 "Interactively adds a given HOST to ange-ftp-cms-host-regexp."
|
|
5957 (interactive
|
|
5958 (list (read-string "Host: "
|
|
5959 (let ((name (or (buffer-file-name)
|
|
5960 (and (eq major-mode 'dired-mode)
|
|
5961 dired-directory))))
|
|
5962 (and name (car (ange-ftp-ftp-path name)))))))
|
|
5963 (if (not (ange-ftp-cms-host host))
|
|
5964 (setq ange-ftp-cms-host-regexp
|
|
5965 (concat "^" (regexp-quote host) "$"
|
|
5966 (and ange-ftp-cms-host-regexp "\\|")
|
|
5967 ange-ftp-cms-host-regexp)
|
|
5968 ange-ftp-host-cache nil)))
|
|
5969
|
|
5970 (defun ange-ftp-parse-cms-listing ()
|
|
5971 "Parse the current buffer which is assumed to be a CMS directory listing."
|
|
5972 ;; If we succeed in getting a listing, then we will assume that the minidisk
|
|
5973 ;; exists. file is bound by the call to ange-ftp-ls. This doesn't work
|
|
5974 ;; because ange-ftp doesn't know that the root hashtable has only part of
|
|
5975 ;; the info. It will assume that if a minidisk isn't in it, then it doesn't
|
|
5976 ;; exist. It would be nice if completion worked for minidisks, as we
|
|
5977 ;; discover them.
|
|
5978 ; (let* ((dir-file (directory-file-name file))
|
|
5979 ; (root (file-name-directory dir-file))
|
|
5980 ; (minidisk (ange-ftp-get-file-part dir-file))
|
|
5981 ; (root-tbl (ange-ftp-get-hash-entry root ange-ftp-files-hashtable)))
|
|
5982 ; (if root-tbl
|
|
5983 ; (ange-ftp-put-hash-entry minidisk t root-tbl)
|
|
5984 ; (setq root-tbl (ange-ftp-make-hashtable))
|
|
5985 ; (ange-ftp-put-hash-entry minidisk t root-tbl)
|
|
5986 ; (ange-ftp-put-hash-entry "." t root-tbl)
|
|
5987 ; (ange-ftp-set-files root root-tbl)))
|
|
5988 ;; Now do the usual parsing
|
|
5989 (let ((tbl (ange-ftp-make-hashtable)))
|
|
5990 (goto-char (point-min))
|
|
5991 (ange-ftp-save-match-data
|
|
5992 (while
|
|
5993 (re-search-forward
|
|
5994 "^\\([-A-Z0-9$_]+\\) +\\([-A-Z0-9$_]+\\) +[VF] +[0-9]+ " nil t)
|
|
5995 (ange-ftp-put-hash-entry
|
|
5996 (concat (buffer-substring (match-beginning 1)
|
|
5997 (match-end 1))
|
|
5998 "."
|
|
5999 (buffer-substring (match-beginning 2)
|
|
6000 (match-end 2)))
|
|
6001 nil tbl)
|
|
6002 (forward-line 1))
|
|
6003 (ange-ftp-put-hash-entry "." t tbl))
|
|
6004 tbl))
|
|
6005
|
|
6006 (or (assq 'cms ange-ftp-parse-list-func-alist)
|
|
6007 (setq ange-ftp-parse-list-func-alist
|
|
6008 (cons '(cms . ange-ftp-parse-cms-listing)
|
|
6009 ange-ftp-parse-list-func-alist)))
|
|
6010
|
|
6011 ;;; Tree dired support:
|
|
6012
|
|
6013 (defconst ange-ftp-dired-cms-re-exe
|
|
6014 "^. [-A-Z0-9$_]+ +EXEC "
|
|
6015 "Regular expression to use to search for CMS executables.")
|
|
6016
|
|
6017 (or (assq 'cms ange-ftp-dired-re-exe-alist)
|
|
6018 (setq ange-ftp-dired-re-exe-alist
|
|
6019 (cons (cons 'cms ange-ftp-dired-cms-re-exe)
|
|
6020 ange-ftp-dired-re-exe-alist)))
|
|
6021
|
|
6022
|
|
6023 (defun ange-ftp-dired-cms-insert-headerline (dir)
|
|
6024 ;; CMS has no total line, so we insert a blank line for
|
|
6025 ;; aesthetics.
|
|
6026 (insert "\n")
|
|
6027 (forward-char -1)
|
|
6028 (ange-ftp-real-dired-insert-headerline dir))
|
|
6029
|
|
6030 (or (assq 'cms ange-ftp-dired-insert-headerline-alist)
|
|
6031 (setq ange-ftp-dired-insert-headerline-alist
|
|
6032 (cons '(cms . ange-ftp-dired-cms-insert-headerline)
|
|
6033 ange-ftp-dired-insert-headerline-alist)))
|
|
6034
|
|
6035 (defun ange-ftp-dired-cms-move-to-filename (&optional raise-error eol)
|
|
6036 "In dired, move to the first char of filename on this line."
|
|
6037 ;; This is the CMS version.
|
|
6038 (or eol (setq eol (progn (end-of-line) (point))))
|
|
6039 (let (case-fold-search)
|
|
6040 (beginning-of-line)
|
|
6041 (if (re-search-forward " [-A-Z0-9$_]+ +[-A-Z0-9$_]+ +[VF] +[0-9]+ " eol t)
|
|
6042 (goto-char (1+ (match-beginning 0)))
|
|
6043 (if raise-error
|
|
6044 (error "No file on this line")
|
|
6045 nil))))
|
|
6046
|
|
6047 (or (assq 'cms ange-ftp-dired-move-to-filename-alist)
|
|
6048 (setq ange-ftp-dired-move-to-filename-alist
|
|
6049 (cons '(cms . ange-ftp-dired-cms-move-to-filename)
|
|
6050 ange-ftp-dired-move-to-filename-alist)))
|
|
6051
|
|
6052 (defun ange-ftp-dired-cms-move-to-end-of-filename (&optional no-error eol)
|
|
6053 ;; Assumes point is at beginning of filename.
|
|
6054 ;; So, it should be called only after (dired-move-to-filename t).
|
|
6055 ;; case-fold-search must be nil, at least for VMS.
|
|
6056 ;; On failure, signals an error or returns nil.
|
|
6057 ;; This is the CMS version.
|
|
6058 (let ((opoint (point))
|
|
6059 case-fold-search hidden)
|
|
6060 (or eol (setq eol (save-excursion (end-of-line) (point))))
|
|
6061 (setq hidden (and selective-display
|
|
6062 (save-excursion
|
|
6063 (search-forward "\r" eol t))))
|
|
6064 (if hidden
|
|
6065 (if no-error
|
|
6066 nil
|
|
6067 (error
|
|
6068 (substitute-command-keys
|
|
6069 "File line is hidden, type \\[dired-hide-subdir] to unhide")))
|
|
6070 (skip-chars-forward "-A-Z0-9$_" eol)
|
|
6071 (skip-chars-forward " " eol)
|
|
6072 (skip-chars-forward "-A-Z0-9$_" eol)
|
|
6073 (if (eq opoint (point))
|
|
6074 (if no-error
|
|
6075 nil
|
|
6076 (error "No file on this line"))
|
|
6077 (point)))))
|
|
6078
|
|
6079 (or (assq 'cms ange-ftp-dired-move-to-end-of-filename-alist)
|
|
6080 (setq ange-ftp-dired-move-to-end-of-filename-alist
|
|
6081 (cons '(cms . ange-ftp-dired-cms-move-to-end-of-filename)
|
|
6082 ange-ftp-dired-move-to-end-of-filename-alist)))
|
|
6083
|
|
6084 (defun ange-ftp-cms-make-compressed-filename (name &optional reverse)
|
|
6085 (if reverse
|
|
6086 (if (string-match "-Z$" name)
|
|
6087 (substring name 0 -2)
|
|
6088 name)
|
|
6089 (concat name "-Z")))
|
|
6090
|
|
6091 (or (assq 'cms ange-ftp-dired-compress-make-compressed-filename-alist)
|
|
6092 (setq ange-ftp-dired-compress-make-compressed-filename-alist
|
|
6093 (cons '(cms . ange-ftp-cms-make-compressed-filename)
|
|
6094 ange-ftp-dired-compress-make-compressed-filename-alist)))
|
|
6095
|
|
6096 (defun ange-ftp-dired-cms-get-filename (&optional localp no-error-if-not-filep)
|
|
6097 (let ((name (ange-ftp-real-dired-get-filename localp no-error-if-not-filep)))
|
|
6098 (and name
|
|
6099 (if (string-match "^\\([^ ]+\\) +\\([^ ]+\\)$" name)
|
|
6100 (concat (substring name 0 (match-end 1))
|
|
6101 "."
|
|
6102 (substring name (match-beginning 2) (match-end 2)))
|
|
6103 name))))
|
|
6104
|
|
6105 (or (assq 'cms ange-ftp-dired-get-filename-alist)
|
|
6106 (setq ange-ftp-dired-get-filename-alist
|
|
6107 (cons '(cms . ange-ftp-dired-cms-get-filename)
|
|
6108 ange-ftp-dired-get-filename-alist)))
|
|
6109
|
|
6110 ;;;; ------------------------------------------------------------
|
|
6111 ;;;; Finally provide package.
|
|
6112 ;;;; ------------------------------------------------------------
|
|
6113
|
|
6114 ;; This is so that VC doesn't need to be hacked up. I think the fsf way is
|
|
6115 ;; a bit cleaner. (Forgive me, as I have sinned...) The great side-effect
|
|
6116 ;; of this change is that ange-ftp will now autoload...even w/o being fully
|
|
6117 ;; converted to use the filename-handler-alist. --Stig
|
|
6118
|
|
6119 ;; Turn off RCS/SCCS processing to save time.
|
|
6120 ;; This returns nil for any file name as argument.
|
|
6121 (put 'vc-registered 'ange-ftp 'null)
|
|
6122 ^L
|
|
6123 ;;; Define ways of getting at unmodified Emacs primitives,
|
|
6124 ;;; turning off our handler.
|
|
6125
|
|
6126 (defun ange-ftp-run-real-handler (operation args)
|
|
6127 (let ((inhibit-file-name-handlers
|
|
6128 (cons 'ange-ftp-hook-function
|
|
6129 (cons 'ange-ftp-completion-hook-function
|
|
6130 (and (eq inhibit-file-name-operation operation)
|
|
6131 inhibit-file-name-handlers))))
|
|
6132 (inhibit-file-name-operation operation))
|
|
6133 (apply operation args)))
|
|
6134
|
|
6135 ;;;###autoload
|
|
6136 (defun ange-ftp-hook-function (operation &rest args)
|
|
6137 (let ((fn (get operation 'ange-ftp)))
|
|
6138 (if fn (apply fn args)
|
|
6139 (ange-ftp-run-real-handler operation args))))
|
|
6140
|
|
6141 ;;;###autoload
|
|
6142 (or (assoc (car ange-ftp-path-format) file-name-handler-alist)
|
|
6143 (setq file-name-handler-alist
|
|
6144 (cons (cons (car ange-ftp-path-format) 'ange-ftp-hook-function)
|
|
6145 file-name-handler-alist)))
|
|
6146
|
|
6147 ;; ;;; This regexp recognizes and absolute filenames with only one component,
|
|
6148 ;; ;;; for the sake of hostname completion.
|
|
6149 ;; ;;;###autoload
|
|
6150 ;; (or (assoc "^/[^/:]*\\'" file-name-handler-alist)
|
|
6151 ;; (setq file-name-handler-alist
|
|
6152 ;; (cons '("^/[^/:]*\\'" . ange-ftp-completion-hook-function)
|
|
6153 ;; file-name-handler-alist)))
|
|
6154
|
|
6155 (provide 'ange-ftp)
|