54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1 ;;; url-file.el --- File retrieval code
|
54796
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
3 ;; Copyright (c) 1996 - 1999,2004 Free Software Foundation, Inc.
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
4
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
5 ;; Keywords: comm, data, processes
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
6
|
54796
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
7 ;; This file is part of GNU Emacs.
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
8 ;;
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
10 ;; it under the terms of the GNU General Public License as published by
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
12 ;; any later version.
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
13 ;;
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
14 ;; GNU Emacs is distributed in the hope that it will be useful,
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
17 ;; GNU General Public License for more details.
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
18 ;;
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
19 ;; You should have received a copy of the GNU General Public License
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
22 ;; Boston, MA 02111-1307, USA.
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
23
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
24 ;;; Commentary:
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
25
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
26 ;;; Code:
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
27
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
28 (eval-when-compile (require 'cl))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
29 (require 'mailcap)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
30 (require 'url-vars)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
31 (require 'url-parse)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
32 (require 'url-dired)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
33
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
34 (defconst url-file-default-port 21 "Default FTP port.")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
35 (defconst url-file-asynchronous-p t "FTP transfers are asynchronous.")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
36 (defalias 'url-file-expand-file-name 'url-default-expander)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
37
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
38 (defun url-file-find-possibly-compressed-file (fname &rest args)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
39 "Find the exact file referenced by `fname'.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
40 This tries the common compression extensions, because things like
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
41 ange-ftp and efs are not quite smart enough to realize when a server
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
42 can do automatic decompression for them, and won't find 'foo' if
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
43 'foo.gz' exists, even though the ftp server would happily serve it up
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
44 to them."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
45 (let ((scratch nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
46 (compressed-extensions '("" ".gz" ".z" ".Z" ".bz2"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
47 (found nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
48 (while (and compressed-extensions (not found))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
49 (if (file-exists-p (setq scratch (concat fname (pop compressed-extensions))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
50 (setq found scratch)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
51 found))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
52
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
53 (defun url-file-host-is-local-p (host)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
54 "Return t iff HOST references our local machine."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
55 (let ((case-fold-search t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
56 (or
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
57 (null host)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
58 (string= "" host)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
59 (equal (downcase host) (downcase (system-name)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
60 (and (string-match "^localhost$" host) t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
61 (and (not (string-match (regexp-quote ".") host))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
62 (equal (downcase host) (if (string-match (regexp-quote ".")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
63 (system-name))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
64 (substring (system-name) 0
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
65 (match-beginning 0))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
66 (system-name)))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
67
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
68 (defun url-file-asynch-callback (x y name buff func args &optional efs)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
69 (if (not (featurep 'ange-ftp))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
70 ;; EFS passes us an extra argument
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
71 (setq name buff
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
72 buff func
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
73 func args
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
74 args efs))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
75 (let ((size (nth 7 (file-attributes name))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
76 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
77 (set-buffer buff)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
78 (goto-char (point-max))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
79 (if (/= -1 size)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
80 (insert (format "Content-length: %d\n" size)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
81 (insert "\n")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
82 (insert-file-contents-literally name)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
83 (if (not (url-file-host-is-local-p (url-host url-current-object)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
84 (condition-case ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
85 (delete-file name)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
86 (error nil)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
87 (apply func args))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
88
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
89 (defun url-file-build-filename (url)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
90 (if (not (vectorp url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
91 (setq url (url-generic-parse-url url)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
92 (let* ((user (url-user url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
93 (pass (url-password url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
94 (port (url-port url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
95 (host (url-host url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
96 (site (if (and port (/= port 21))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
97 (if (featurep 'ange-ftp)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
98 (format "%s %d" host port)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
99 ;; This works in Emacs 21's ange-ftp too.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
100 (format "%s#%d" host port))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
101 host))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
102 (file (url-unhex-string (url-filename url)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
103 (filename (if (or user (not (url-file-host-is-local-p host)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
104 (concat "/" (or user "anonymous") "@" site ":" file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
105 (if (and (memq system-type
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
106 '(emx ms-dos windows-nt ms-windows))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
107 (string-match "^/[a-zA-Z]:/" file))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
108 (substring file 1)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
109 file)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
110 pos-index)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
111
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
112 (and user pass
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
113 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
114 ((featurep 'ange-ftp)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
115 (ange-ftp-set-passwd host user pass))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
116 ((or (featurep 'efs) (featurep 'efs-auto))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
117 (efs-set-passwd host user pass))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
118 (t
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
119 nil)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
120
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
121 ;; This makes sure that directories have a trailing directory
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
122 ;; separator on them so URL expansion works right.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
123 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
124 ;; FIXME? What happens if the remote system doesn't use our local
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
125 ;; directory-sep-char as its separator? Would it be safer to just
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
126 ;; use '/' unconditionally and rely on the FTP server to
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
127 ;; straighten it out for us?
|
54796
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
128 ;; (if (and (file-directory-p filename)
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
129 ;; (not (string-match (format "%c$" directory-sep-char) filename)))
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
130 ;; (url-set-filename url (format "%s%c" filename directory-sep-char)))
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
131 (if (and (file-directory-p filename)
|
54796
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
132 (not (string-match "/\\'" filename)))
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
133 (url-set-filename url (format "%s/" filename)))
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
134
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
135
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
136 ;; If it is a directory, look for an index file first.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
137 (if (and (file-directory-p filename)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
138 url-directory-index-file
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
139 (setq pos-index (expand-file-name url-directory-index-file filename))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
140 (file-exists-p pos-index)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
141 (file-readable-p pos-index))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
142 (setq filename pos-index))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
143
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
144 ;; Find the (possibly compressed) file
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
145 (setq filename (url-file-find-possibly-compressed-file filename))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
146 filename))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
147
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
148 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
149 (defun url-file (url callback cbargs)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
150 "Handle file: and ftp: URLs."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
151 (let* ((buffer nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
152 (uncompressed-filename nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
153 (content-type nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
154 (content-encoding nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
155 (coding-system-for-read 'binary))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
156
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
157 (setq filename (url-file-build-filename url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
158
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
159 (if (not filename)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
160 (error "File does not exist: %s" (url-recreate-url url)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
161
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
162 ;; Need to figure out the content-type from the real extension,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
163 ;; not the compressed one.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
164 (setq uncompressed-filename (if (string-match "\\.\\(gz\\|Z\\|z\\)$" filename)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
165 (substring filename 0 (match-beginning 0))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
166 filename))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
167 (setq content-type (mailcap-extension-to-mime
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
168 (url-file-extension uncompressed-filename))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
169 content-encoding (case (intern (url-file-extension filename))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
170 ((\.z \.gz) "gzip")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
171 (\.Z "compress")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
172 (\.uue "x-uuencoded")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
173 (\.hqx "x-hqx")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
174 (\.bz2 "x-bzip2")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
175 (otherwise nil)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
176
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
177 (if (file-directory-p filename)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
178 ;; A directory is done the same whether we are local or remote
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
179 (url-find-file-dired filename)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
180 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
181 (setq buffer (generate-new-buffer " *url-file*"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
182 (set-buffer buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
183 (mm-disable-multibyte)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
184 (setq url-current-object url)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
185 (insert "Content-type: " (or content-type "application/octet-stream") "\n")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
186 (if content-encoding
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
187 (insert "Content-transfer-encoding: " content-encoding "\n"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
188 (if (url-file-host-is-local-p (url-host url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
189 ;; Local files are handled slightly oddly
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
190 (if (featurep 'ange-ftp)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
191 (url-file-asynch-callback nil nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
192 filename
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
193 (current-buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
194 callback cbargs)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
195 (url-file-asynch-callback nil nil nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
196 filename
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
197 (current-buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
198 callback cbargs))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
199 ;; FTP handling
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
200 (let* ((extension (url-file-extension filename))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
201 (new (url-generate-unique-filename
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
202 (and (> (length extension) 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
203 (concat "%s." extension)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
204 (if (featurep 'ange-ftp)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
205 (ange-ftp-copy-file-internal filename (expand-file-name new) t
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
206 nil t
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
207 (list 'url-file-asynch-callback
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
208 new (current-buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
209 callback cbargs)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
210 t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
211 (autoload 'efs-copy-file-internal "efs")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
212 (efs-copy-file-internal filename (efs-ftp-path filename)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
213 new (efs-ftp-path new)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
214 t nil 0
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
215 (list 'url-file-asynch-callback
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
216 new (current-buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
217 callback cbargs)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
218 0 nil))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
219 buffer))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
220
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
221 (defmacro url-file-create-wrapper (method args)
|
54930
|
222 `(defalias ',(intern (format "url-ftp-%s" method))
|
|
223 (defun ,(intern (format "url-file-%s" method)) ,args
|
|
224 ,(format "FTP/FILE URL wrapper around `%s' call." method)
|
|
225 (setq url (url-file-build-filename url))
|
|
226 (and url (,method ,@(remove '&rest (remove '&optional args)))))))
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
227
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
228 (url-file-create-wrapper file-exists-p (url))
|
54930
|
229 (url-file-create-wrapper file-attributes (url &optional id-format))
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
230 (url-file-create-wrapper file-symlink-p (url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
231 (url-file-create-wrapper file-readable-p (url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
232 (url-file-create-wrapper file-writable-p (url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
233 (url-file-create-wrapper file-executable-p (url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
234 (if (featurep 'xemacs)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
235 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
236 (url-file-create-wrapper directory-files (url &optional full match nosort files-only))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
237 (url-file-create-wrapper file-truename (url &optional default)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
238 (url-file-create-wrapper directory-files (url &optional full match nosort))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
239 (url-file-create-wrapper file-truename (url &optional counter prev-dirs)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
240
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
241 (provide 'url-file)
|
54699
|
242
|
54796
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
243 ;; arch-tag: 010e914a-7313-494b-8a8c-6495a862157d
|
351fde140ac4
(url-file-build-filename): Don't use directory-sep-char.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
244 ;;; url-file.el ends here
|