]> git.eshelyaron.com Git - emacs.git/commitdiff
(url-cookie-write-file): Use url-make-private-file and with-temp-buffer.
authorGlenn Morris <rgm@gnu.org>
Tue, 11 Dec 2007 05:49:53 +0000 (05:49 +0000)
committerGlenn Morris <rgm@gnu.org>
Tue, 11 Dec 2007 05:49:53 +0000 (05:49 +0000)
lisp/url/url-cookie.el

index cdca65104adc37d1acf667cb3f76acd6d8bf4c9b..eea34042970efd200a6c40e22a4721b03b15b242 100644 (file)
@@ -148,34 +148,31 @@ telling Microsoft that."
     (set var new)))
 
 (defun url-cookie-write-file (&optional fname)
-  (setq fname (or fname url-cookie-file))
-  (unless (file-directory-p (file-name-directory fname))
-    (ignore-errors (make-directory (file-name-directory fname))))
-  (cond
-   ((not url-cookies-changed-since-last-save) nil)
-   ((not (file-writable-p fname))
-    (message "Cookies file %s (see variable `url-cookie-file') is unwritable." fname))
-   (t
-    (url-cookie-clean-up)
-    (url-cookie-clean-up t)
-    (with-current-buffer (get-buffer-create " *cookies*")
-      (erase-buffer)
-      (fundamental-mode)
-      (insert ";; Emacs-W3 HTTP cookies file\n"
-             ";; Automatically generated file!!! DO NOT EDIT!!!\n\n"
-             "(setq url-cookie-storage\n '")
-      (pp url-cookie-storage (current-buffer))
-      (insert ")\n(setq url-cookie-secure-storage\n '")
-      (pp url-cookie-secure-storage (current-buffer))
-      (insert ")\n")
-      (insert "\f\n;; Local Variables:\n"
-              ";; version-control: never\n"
-              ";; no-byte-compile: t\n"
-              ";; End:\n")
-      (set (make-local-variable 'version-control) 'never)
-      (write-file fname)
-      (setq url-cookies-changed-since-last-save nil)
-      (kill-buffer (current-buffer))))))
+  (when url-cookies-changed-since-last-save
+    (or fname (setq fname (expand-file-name url-cookie-file)))
+    (if (condition-case nil
+            (progn
+              (url-make-private-file fname)
+              nil)
+          (error t))
+        (message "Error accessing cookie file `%s'" fname)
+      (url-cookie-clean-up)
+      (url-cookie-clean-up t)
+      (with-temp-buffer
+        (insert ";; Emacs-W3 HTTP cookies file\n"
+                ";; Automatically generated file!!! DO NOT EDIT!!!\n\n"
+                "(setq url-cookie-storage\n '")
+        (pp url-cookie-storage (current-buffer))
+        (insert ")\n(setq url-cookie-secure-storage\n '")
+        (pp url-cookie-secure-storage (current-buffer))
+        (insert ")\n")
+        (insert "\f\n;; Local Variables:\n"
+                ";; version-control: never\n"
+                ";; no-byte-compile: t\n"
+                ";; End:\n")
+        (set (make-local-variable 'version-control) 'never)
+        (write-file fname))
+      (setq url-cookies-changed-since-last-save nil))))
 
 (defun url-cookie-store (name value &optional expires domain localpart secure)
   "Store a netscape-style cookie."