54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1 ;;; url-cache.el --- Uniform Resource Locator retrieval tool
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2 ;; Keywords: comm, data, processes, hypermedia
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
3
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
5 ;;; Copyright (c) 1993 - 1996 by William M. Perry <wmperry@cs.indiana.edu>
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
6 ;;; Copyright (c) 1996 - 1999 Free Software Foundation, Inc.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
7 ;;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
8 ;;; This file is part of GNU Emacs.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
9 ;;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
10 ;;; GNU Emacs is free software; you can redistribute it and/or modify
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
11 ;;; it under the terms of the GNU General Public License as published by
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
12 ;;; the Free Software Foundation; either version 2, or (at your option)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
13 ;;; any later version.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
14 ;;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
15 ;;; GNU Emacs is distributed in the hope that it will be useful,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
18 ;;; GNU General Public License for more details.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
19 ;;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
20 ;;; You should have received a copy of the GNU General Public License
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
21 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
22 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
23 ;;; Boston, MA 02111-1307, USA.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
25 (require 'url-parse)
|
54793
|
26 (require 'url-util)
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
27
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
28 (defcustom url-cache-directory
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
29 (expand-file-name "cache" url-configuration-directory)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
30 "*The directory where cache files should be stored."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
31 :type 'directory
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
32 :group 'url-file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
33
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
34 ;; Cache manager
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
35 (defun url-cache-file-writable-p (file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
36 "Follows the documentation of `file-writable-p', unlike `file-writable-p'."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
37 (and (file-writable-p file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
38 (if (file-exists-p file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
39 (not (file-directory-p file))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
40 (file-directory-p (file-name-directory file)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
41
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
42 (defun url-cache-prepare (file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
43 "Makes it possible to cache data in FILE.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
44 Creates any necessary parent directories, deleting any non-directory files
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
45 that would stop this. Returns nil if parent directories can not be
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
46 created. If FILE already exists as a non-directory, it changes
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
47 permissions of FILE or deletes FILE to make it possible to write a new
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
48 version of FILE. Returns nil if this can not be done. Returns nil if
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
49 FILE already exists as a directory. Otherwise, returns t, indicating that
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
50 FILE can be created or overwritten."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
51 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
52 ((url-cache-file-writable-p file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
53 t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
54 ((file-directory-p file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
55 nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
56 (t
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
57 (condition-case ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
58 (or (make-directory (file-name-directory file) t) t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
59 (error nil)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
60
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
61 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
62 (defun url-store-in-cache (&optional buff)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
63 "Store buffer BUFF in the cache."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
64 (if (not (and buff (get-buffer buff)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
65 nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
66 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
67 (and buff (set-buffer buff))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
68 (let* ((fname (url-cache-create-filename (url-view-url t))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
69 (if (url-cache-prepare fname)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
70 (let ((coding-system-for-write 'binary))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
71 (write-region (point-min) (point-max) fname nil 5)))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
72
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
73 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
74 (defun url-is-cached (url)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
75 "Return non-nil if the URL is cached."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
76 (let* ((fname (url-cache-create-filename url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
77 (attribs (file-attributes fname)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
78 (and fname ; got a filename
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
79 (file-exists-p fname) ; file exists
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
80 (not (eq (nth 0 attribs) t)) ; Its not a directory
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
81 (nth 5 attribs)))) ; Can get last mod-time
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
82
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
83 (defun url-cache-create-filename-human-readable (url)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
84 "Return a filename in the local cache for URL"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
85 (if url
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
86 (let* ((url (if (vectorp url) (url-recreate-url url) url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
87 (urlobj (url-generic-parse-url url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
88 (protocol (url-type urlobj))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
89 (hostname (url-host urlobj))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
90 (host-components
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
91 (cons
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
92 (user-real-login-name)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
93 (cons (or protocol "file")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
94 (reverse (split-string (or hostname "localhost")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
95 (eval-when-compile
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
96 (regexp-quote ".")))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
97 (fname (url-filename urlobj)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
98 (if (and fname (/= (length fname) 0) (= (aref fname 0) ?/))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
99 (setq fname (substring fname 1 nil)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
100 (if fname
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
101 (let ((slash nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
102 (setq fname
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
103 (mapconcat
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
104 (function
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
105 (lambda (x)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
106 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
107 ((and (= ?/ x) slash)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
108 (setq slash nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
109 "%2F")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
110 ((= ?/ x)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
111 (setq slash t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
112 "/")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
113 (t
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
114 (setq slash nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
115 (char-to-string x))))) fname ""))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
116
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
117 (setq fname (and fname
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
118 (mapconcat
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
119 (function (lambda (x)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
120 (if (= x ?~) "" (char-to-string x))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
121 fname ""))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
122 fname (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
123 ((null fname) nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
124 ((or (string= "" fname) (string= "/" fname))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
125 url-directory-index-file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
126 ((= (string-to-char fname) ?/)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
127 (if (string= (substring fname -1 nil) "/")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
128 (concat fname url-directory-index-file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
129 (substring fname 1 nil)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
130 (t
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
131 (if (string= (substring fname -1 nil) "/")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
132 (concat fname url-directory-index-file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
133 fname))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
134 (and fname
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
135 (expand-file-name fname
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
136 (expand-file-name
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
137 (mapconcat 'identity host-components "/")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
138 url-cache-directory))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
139
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
140 (defun url-cache-create-filename-using-md5 (url)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
141 "Create a cached filename using MD5.
|
54793
|
142 Very fast if you have an `md5' primitive function, suitably fast otherwise."
|
54695
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
143 (require 'md5)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
144 (if url
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
145 (let* ((url (if (vectorp url) (url-recreate-url url) url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
146 (checksum (md5 url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
147 (urlobj (url-generic-parse-url url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
148 (protocol (url-type urlobj))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
149 (hostname (url-host urlobj))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
150 (host-components
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
151 (cons
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
152 (user-real-login-name)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
153 (cons (or protocol "file")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
154 (nreverse
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
155 (delq nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
156 (split-string (or hostname "localhost")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
157 (eval-when-compile
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
158 (regexp-quote "."))))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
159 (fname (url-filename urlobj)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
160 (and fname
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
161 (expand-file-name checksum
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
162 (expand-file-name
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
163 (mapconcat 'identity host-components "/")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
164 url-cache-directory))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
165
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
166 (defcustom url-cache-creation-function 'url-cache-create-filename-using-md5
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
167 "*What function to use to create a cached filename."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
168 :type '(choice (const :tag "MD5 of filename (low collision rate)"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
169 :value url-cache-create-filename-using-md5)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
170 (const :tag "Human readable filenames (higher collision rate)"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
171 :value url-cache-create-filename-human-readable)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
172 (function :tag "Other"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
173 :group 'url-cache)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
174
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
175 (defun url-cache-create-filename (url)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
176 (funcall url-cache-creation-function url))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
177
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
178 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
179 (defun url-cache-extract (fnam)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
180 "Extract FNAM from the local disk cache"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
181 (erase-buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
182 (insert-file-contents-literally fnam))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
183
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
184 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
185 (defun url-cache-expired (url mod)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
186 "Return t iff a cached file has expired."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
187 (let* ((urlobj (if (vectorp url) url (url-generic-parse-url url)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
188 (type (url-type urlobj)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
189 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
190 (url-standalone-mode
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
191 (not (file-exists-p (url-cache-create-filename url))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
192 ((string= type "http")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
193 t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
194 ((member type '("file" "ftp"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
195 (if (or (equal mod '(0 0)) (not mod))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
196 t
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
197 (or (> (nth 0 mod) (nth 0 (current-time)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
198 (> (nth 1 mod) (nth 1 (current-time))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
199 (t nil))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
200
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
201 (provide 'url-cache)
|
54699
|
202
|
|
203 ;;; arch-tag: 95b050a6-8e81-4f23-8e63-191b9d1d657c
|