Mercurial > emacs
changeset 79558:ba4da6f08090
(url-make-private-file): New function.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Tue, 11 Dec 2007 05:50:26 +0000 |
parents | 3d0d9d7bb356 |
children | 415850ba0b0f |
files | lisp/url/url-util.el |
diffstat | 1 files changed, 22 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/url/url-util.el Tue Dec 11 05:50:11 2007 +0000 +++ b/lisp/url/url-util.el Tue Dec 11 05:50:26 2007 +0000 @@ -523,6 +523,28 @@ (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