From 812498713a4bc715d7aaffb4f68382b73fb83ede Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Tue, 11 Dec 2007 05:50:37 +0000 Subject: [PATCH] (url-make-private-file): New function. --- lisp/url/ChangeLog | 7 +++++++ lisp/url/url-util.el | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lisp/url/ChangeLog b/lisp/url/ChangeLog index 7016382f71e..aadd79ccc02 100644 --- a/lisp/url/ChangeLog +++ b/lisp/url/ChangeLog @@ -1,3 +1,10 @@ +2007-12-11 Glenn Morris + + * url-util.el (url-make-private-file): New function. + * url-cookie.el (url-cookie-write-file): + * url-history.el (url-history-save-history): + Use url-make-private-file and with-temp-buffer. + 2007-12-02 Glenn Morris * url-news.el (nntp-open-tls-stream, nntp-open-ssl-stream): 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 -- 2.39.2