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