]> git.eshelyaron.com Git - emacs.git/commitdiff
Add extra checks before expiring the URL cache
authorLars Ingebrigtsen <larsi@gnus.org>
Mon, 6 Feb 2012 21:37:56 +0000 (22:37 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Mon, 6 Feb 2012 21:37:56 +0000 (22:37 +0100)
(url-cache-prune-cache): Check that the directory exists before
trying to delete it.

lisp/url/ChangeLog
lisp/url/url-cache.el

index 4e748fbd99e89ec1d96079211c6776f4db529bda..f4cca618b4987497ad0d8bba1c05cb6cfa4b67eb 100644 (file)
@@ -1,6 +1,8 @@
 2012-02-06  Lars Ingebrigtsen  <larsi@gnus.org>
 
        * url-cache.el (url-cache-prune-cache): New function.
+       (url-cache-prune-cache): Check that the directory exists before
+       trying to delete it.
 
        * url.el (url-retrieve-number-of-calls): New variable.
        (url-retrieve-internal): Use it to expire the cache once in a
index 8fec2495675af978a397ecec25f9cdf51ae8a8c0..6559de4deb721bb9f0a42b487dff3ff3c84f37a8 100644 (file)
@@ -216,24 +216,26 @@ considered \"expired\"."
   (let ((current-time (current-time))
        (total-files 0)
        (deleted-files 0))
-    (dolist (file (directory-files (or directory url-cache-directory) t))
-      (unless (member (file-name-nondirectory file) '("." ".."))
-       (setq total-files (1+ total-files))
-       (cond
-        ((file-directory-p file)
-         (when (url-cache-prune-cache file)
-           (setq deleted-files (1+ deleted-files))))
-        ((time-less-p
-          (time-add
-           (nth 5 (file-attributes file))
-           (seconds-to-time url-cache-expire-time))
-          current-time)
-         (delete-file file)
-         (setq deleted-files (1+ deleted-files))))))
-    (if (< deleted-files total-files)
-       nil
-      (delete-directory directory)
-      t)))
+    (setq directory (or directory url-cache-directory))
+    (when (file-exists-p directory)
+      (dolist (file (directory-files directory t))
+       (unless (member (file-name-nondirectory file) '("." ".."))
+         (setq total-files (1+ total-files))
+         (cond
+          ((file-directory-p file)
+           (when (url-cache-prune-cache file)
+             (setq deleted-files (1+ deleted-files))))
+          ((time-less-p
+            (time-add
+             (nth 5 (file-attributes file))
+             (seconds-to-time url-cache-expire-time))
+            current-time)
+           (delete-file file)
+           (setq deleted-files (1+ deleted-files))))))
+      (if (< deleted-files total-files)
+         nil
+       (delete-directory directory)
+       t))))
 
 (provide 'url-cache)