summaryrefslogtreecommitdiff
path: root/lisp/url/url-util.el
diff options
context:
space:
mode:
authorGlenn Morris <rgm@gnu.org>2007-12-11 05:50:37 +0000
committerGlenn Morris <rgm@gnu.org>2007-12-11 05:50:37 +0000
commit812498713a4bc715d7aaffb4f68382b73fb83ede (patch)
tree5c9d3699eee66094c120b55516daa220f1a187c1 /lisp/url/url-util.el
parent57f44ca44a21b5030a29860918b26fad5297e55b (diff)
downloademacs-812498713a4bc715d7aaffb4f68382b73fb83ede.tar.gz
(url-make-private-file): New function.
Diffstat (limited to 'lisp/url/url-util.el')
-rw-r--r--lisp/url/url-util.el22
1 files changed, 22 insertions, 0 deletions
diff --git a/lisp/url/url-util.el b/lisp/url/url-util.el
index d7d8e2b4a4b..4f5b4b8cd17 100644
--- a/lisp/url/url-util.el
+++ b/lisp/url/url-util.el
@@ -523,6 +523,28 @@ Has a preference for looking backward when not directly on a symbol."
(set (make-local-variable 'url-current-mime-headers)
(mail-header-extract)))))
+(defun url-make-private-file (file)
+ "Make FILE only readable and writable by the current user.
+Creates FILE and its parent directories if they do not exist."
+ (let ((dir (file-name-directory file)))
+ (when dir
+ ;; For historical reasons.
+ (make-directory dir t)))
+ ;; Based on doc-view-make-safe-dir.
+ (condition-case nil
+ (let ((umask (default-file-modes)))
+ (unwind-protect
+ (progn
+ (set-default-file-modes #o0600)
+ (with-temp-buffer
+ (write-region (point-min) (point-max)
+ file nil 'silent nil 'excl)))
+ (set-default-file-modes umask)))
+ (file-already-exists
+ (if (file-symlink-p file)
+ (error "Danger: `%s' is a symbolic link" file))
+ (set-file-modes file #o0600))))
+
(provide 'url-util)
;; arch-tag: 24352abc-5a5a-412e-90cd-313b26bed5c9