comparison lisp/net/ange-ftp.el @ 65762:77dd61f8bf51

(ange-ftp-gwp-start): Use with-current-buffer. (ange-ftp-file-directory-p): Fix the symlink case. (ange-ftp-insert-directory): When listing a single file, get a list of the parent buffer and extract the relevant line. Inspired from a patch by Katsumi Yamaoka <yamaoka@jpl.org>. (ange-ftp-file-name-sans-versions): Simplify.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 30 Sep 2005 21:04:56 +0000
parents 5fd07f61ee51
children 2eea5cbe306f
comparison
equal deleted inserted replaced
65761:eef36feee76a 65762:77dd61f8bf51
1296 (let (temp) 1296 (let (temp)
1297 (while (setq temp (ange-ftp-real-file-symlink-p file)) 1297 (while (setq temp (ange-ftp-real-file-symlink-p file))
1298 (setq file 1298 (setq file
1299 (if (file-name-absolute-p temp) 1299 (if (file-name-absolute-p temp)
1300 temp 1300 temp
1301 ;; Wouldn't `expand-file-name' be better than `concat' ?
1302 ;; It would fail when `a/b/..' != `a', tho. --Stef
1301 (concat (file-name-directory file) temp))))) 1303 (concat (file-name-directory file) temp)))))
1302 file) 1304 file)
1303 1305
1304 ;; Move along current line looking for the value of the TOKEN. 1306 ;; Move along current line looking for the value of the TOKEN.
1305 ;; Valid separators between TOKEN and its value are commas and 1307 ;; Valid separators between TOKEN and its value are commas and
1798 ange-ftp-gateway-host))) 1800 ange-ftp-gateway-host)))
1799 (ftp (mapconcat 'identity args " "))) 1801 (ftp (mapconcat 'identity args " ")))
1800 (set-process-query-on-exit-flag proc nil) 1802 (set-process-query-on-exit-flag proc nil)
1801 (set-process-sentinel proc 'ange-ftp-gwp-sentinel) 1803 (set-process-sentinel proc 'ange-ftp-gwp-sentinel)
1802 (set-process-filter proc 'ange-ftp-gwp-filter) 1804 (set-process-filter proc 'ange-ftp-gwp-filter)
1803 (save-excursion 1805 (with-current-buffer (process-buffer proc)
1804 (set-buffer (process-buffer proc))
1805 (goto-char (point-max)) 1806 (goto-char (point-max))
1806 (set-marker (process-mark proc) (point))) 1807 (set-marker (process-mark proc) (point)))
1807 (setq ange-ftp-gwp-running t 1808 (setq ange-ftp-gwp-running t
1808 ange-ftp-gwp-status nil) 1809 ange-ftp-gwp-status nil)
1809 (ange-ftp-message "Connecting to gateway %s..." ange-ftp-gateway-host) 1810 (ange-ftp-message "Connecting to gateway %s..." ange-ftp-gateway-host)
2322 (setq cmd0 'ls) 2323 (setq cmd0 'ls)
2323 ;; We cd and then use `ls' with no directory argument. 2324 ;; We cd and then use `ls' with no directory argument.
2324 ;; This works around a misfeature of some versions of netbsd ftpd 2325 ;; This works around a misfeature of some versions of netbsd ftpd
2325 ;; where `ls' can only take one argument: either one set of flags 2326 ;; where `ls' can only take one argument: either one set of flags
2326 ;; or a file/directory name. 2327 ;; or a file/directory name.
2327 ;; FIXME: if we're trying to `ls' a single file, this fails since we 2328 ;; If we're trying to `ls' a single file, this fails since we
2328 ;; can't cd to a file. We can't fix this problem here, tho, because 2329 ;; can't cd to a file. We can't fix this problem here, tho, because
2329 ;; at this point we don't know whether the argument is a file or 2330 ;; at this point we don't know whether the argument is a file or
2330 ;; a directory. Such an `ls' is only every used (apparently) from 2331 ;; a directory. Such an `ls' is only ever used (apparently) from
2331 ;; `insert-directory' when the `full-directory-p' argument is nil 2332 ;; `insert-directory' when the `full-directory-p' argument is nil
2332 ;; (which seems to only be used by dired when updating its display 2333 ;; (which seems to only be used by dired when updating its display
2333 ;; after operating on a set of files). We should change 2334 ;; after operating on a set of files). So we've changed
2334 ;; ange-ftp-insert-directory so that this case is handled by getting 2335 ;; `ange-ftp-insert-directory' such that in this case it gets
2335 ;; a full listing of the directory and extracting the line 2336 ;; a full listing of the directory and extracting the line
2336 ;; corresponding to the requested file. 2337 ;; corresponding to the requested file.
2337 (unless (equal cmd1 ".") 2338 (unless (equal cmd1 ".")
2338 (setq result (ange-ftp-cd host user (nth 1 cmd) 'noerror))) 2339 (setq result (ange-ftp-cd host user (nth 1 cmd) 'noerror)))
2339 (setq cmd1 cmd3))) 2340 (setq cmd1 cmd3)))
3172 (ange-ftp-real-expand-file-name 3173 (ange-ftp-real-expand-file-name
3173 (ange-ftp-real-file-name-nondirectory n) 3174 (ange-ftp-real-file-name-nondirectory n)
3174 (ange-ftp-real-file-name-directory n)))))) 3175 (ange-ftp-real-file-name-directory n))))))
3175 3176
3176 (defun ange-ftp-expand-file-name (name &optional default) 3177 (defun ange-ftp-expand-file-name (name &optional default)
3177 "Documented as original." 3178 "Documented as `expand-file-name'."
3178 (save-match-data 3179 (save-match-data
3179 (setq default (or default default-directory)) 3180 (setq default (or default default-directory))
3180 (cond ((eq (string-to-char name) ?~) 3181 (cond ((eq (string-to-char name) ?~)
3181 (ange-ftp-real-expand-file-name name)) 3182 (ange-ftp-real-expand-file-name name))
3182 ((eq (string-to-char name) ?/) 3183 ((eq (string-to-char name) ?/)
3446 ;; machines (VMS) use a .DIR to indicate the filename associated 3447 ;; machines (VMS) use a .DIR to indicate the filename associated
3447 ;; with a directory. This needs to be canonicalized. 3448 ;; with a directory. This needs to be canonicalized.
3448 (let ((file-ent (ange-ftp-get-file-entry 3449 (let ((file-ent (ange-ftp-get-file-entry
3449 (ange-ftp-file-name-as-directory name)))) 3450 (ange-ftp-file-name-as-directory name))))
3450 (if (stringp file-ent) 3451 (if (stringp file-ent)
3451 (file-directory-p 3452 ;; Calling file-directory-p doesn't work because ange-ftp
3453 ;; is temporarily disabled for this operation.
3454 (ange-ftp-file-directory-p
3452 (ange-ftp-expand-symlink file-ent 3455 (ange-ftp-expand-symlink file-ent
3453 (file-name-directory 3456 (file-name-directory
3454 (directory-file-name name)))) 3457 (directory-file-name name))))
3455 file-ent)) 3458 file-ent))
3456 (ange-ftp-real-file-directory-p name))) 3459 (ange-ftp-real-file-directory-p name)))
4474 4477
4475 ;; When called from dired, SWITCHES may start with "--dired". 4478 ;; When called from dired, SWITCHES may start with "--dired".
4476 ;; `ange-ftp-ls' handles this. 4479 ;; `ange-ftp-ls' handles this.
4477 4480
4478 (defun ange-ftp-insert-directory (file switches &optional wildcard full) 4481 (defun ange-ftp-insert-directory (file switches &optional wildcard full)
4479 (let ((parsed (ange-ftp-ftp-name (expand-file-name file))) 4482 (if (not (ange-ftp-ftp-name (expand-file-name file)))
4480 tem) 4483 (ange-ftp-real-insert-directory file switches wildcard full)
4481 (if parsed 4484 ;; Follow symlinks.
4482 (if (and (not wildcard) 4485 (let (tem)
4483 (setq tem (file-symlink-p (directory-file-name file)))) 4486 (while (and (not wildcard)
4484 (ange-ftp-insert-directory 4487 (stringp (setq tem (ange-ftp-get-file-entry
4485 (ange-ftp-expand-symlink 4488 (directory-file-name file)))))
4486 tem (file-name-directory (directory-file-name file))) 4489 (setq file
4487 switches wildcard full) 4490 (ange-ftp-expand-symlink
4488 (insert 4491 tem (file-name-directory (directory-file-name file))))))
4489 (if wildcard 4492 (insert
4490 (let ((default-directory (file-name-directory file))) 4493 (cond
4491 (ange-ftp-ls (file-name-nondirectory file) switches nil nil t)) 4494 (wildcard
4492 (ange-ftp-ls file switches full)))) 4495 (let ((default-directory (file-name-directory file)))
4493 (ange-ftp-real-insert-directory file switches wildcard full)))) 4496 (ange-ftp-ls (file-name-nondirectory file) switches nil nil t)))
4497 (full
4498 (ange-ftp-ls file switches 'parse))
4499 (t
4500 ;; If `full' is nil we're going to do `ls' for a single file.
4501 ;; Problem is that for various reasons, ange-ftp-ls needs to cd and
4502 ;; then do an ls of current dir, which obviously won't work if we
4503 ;; want to ls a file. So instead, we get a full listing of the
4504 ;; parent directory and extract the line corresponding to `file'.
4505 (when (string-match "d\\'" switches)
4506 ;; Remove "d" which dired added to `switches'.
4507 (setq switches (substring switches 0 (match-beginning 0))))
4508 (let* ((dirlist (ange-ftp-ls (or (file-name-directory file) ".")
4509 switches nil))
4510 (case-fold-search nil))
4511 ;; FIXME: This presumes a particular output format, which is
4512 ;; basically Unix.
4513 (if (string-match (concat "^.+[^ ] " (regexp-quote file)
4514 "\\( -> .*\\)?[@/*=]?\n") dirlist)
4515 (match-string 0 dirlist)
4516 "")))))))
4494 4517
4495 (defun ange-ftp-dired-uncache (dir) 4518 (defun ange-ftp-dired-uncache (dir)
4496 (if (ange-ftp-ftp-name (expand-file-name dir)) 4519 (if (ange-ftp-ftp-name (expand-file-name dir))
4497 (setq ange-ftp-ls-cache-file nil))) 4520 (setq ange-ftp-ls-cache-file nil)))
4498 4521
4500 "Alist of mapping host type into function to remove file version numbers.") 4523 "Alist of mapping host type into function to remove file version numbers.")
4501 4524
4502 (defun ange-ftp-file-name-sans-versions (file keep-backup-version) 4525 (defun ange-ftp-file-name-sans-versions (file keep-backup-version)
4503 (let* ((short (ange-ftp-abbreviate-filename file)) 4526 (let* ((short (ange-ftp-abbreviate-filename file))
4504 (parsed (ange-ftp-ftp-name short)) 4527 (parsed (ange-ftp-ftp-name short))
4505 func) 4528 (func (if parsed (cdr (assq (ange-ftp-host-type (car parsed))
4506 (if parsed 4529 ange-ftp-sans-version-alist)))))
4507 (setq func (cdr (assq (ange-ftp-host-type (car parsed))
4508 ange-ftp-sans-version-alist))))
4509 (if func (funcall func file keep-backup-version) 4530 (if func (funcall func file keep-backup-version)
4510 (ange-ftp-real-file-name-sans-versions file keep-backup-version)))) 4531 (ange-ftp-real-file-name-sans-versions file keep-backup-version))))
4511 4532
4512 ;; This is the handler for shell-command. 4533 ;; This is the handler for shell-command.
4513 (defun ange-ftp-shell-command (command &optional output-buffer error-buffer) 4534 (defun ange-ftp-shell-command (command &optional output-buffer error-buffer)