aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2014-05-14 10:15:15 -0700
committerGlenn Morris2014-05-14 10:15:15 -0700
commitd63d883a97e385392a12a5155201417dea7437ec (patch)
tree7141dda616156ada1c5935d49dfc9e6915a5857b
parentabad7b05fa544e5dfccf240180c37157dd92ac54 (diff)
downloademacs-d63d883a97e385392a12a5155201417dea7437ec.tar.gz
emacs-d63d883a97e385392a12a5155201417dea7437ec.zip
Add with-file-modes macro, and use it
* lisp/subr.el (with-file-modes): New macro. * lisp/printing.el (pr-save-file-modes): * lisp/eshell/esh-util.el (eshell-with-file-modes): Make obsolete. * lisp/emacs-lisp/lisp-mode.el (lisp-el-font-lock-keywords-2): Add with-file-modes. * lisp/doc-view.el (doc-view-make-safe-dir): * lisp/epg.el (epg--start): * lisp/files.el (locate-user-emacs-file, make-temp-file) (backup-buffer-copy, move-file-to-trash): * printing.el (pr-despool-print, pr-call-process, pr-text2ps): * eshell/esh-util.el (eshell-with-private-file-modes) (eshell-make-private-directory): * lisp/net/browse-url.el (browse-url-mosaic): * lisp/obsolete/mailpost.el (post-mail-send-it): * lisp/obsolete/pgg-pgp.el (pgg-pgp-verify-region): * lisp/obsolete/pgg-pgp5.el (pgg-pgp5-verify-region): * lisp/url/url-util.el (url-make-private-file): Use with-file-modes. * doc/lispref/files.texi (Changing Files): Mention with-file-modes. * etc/NEWS: Mention this.
-rw-r--r--doc/lispref/ChangeLog4
-rw-r--r--doc/lispref/files.texi10
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/ChangeLog18
-rw-r--r--lisp/doc-view.el14
-rw-r--r--lisp/emacs-lisp/lisp-mode.el1
-rw-r--r--lisp/epg.el12
-rw-r--r--lisp/eshell/esh-util.el13
-rw-r--r--lisp/files.el126
-rw-r--r--lisp/net/browse-url.el16
-rw-r--r--lisp/obsolete/mailpost.el7
-rw-r--r--lisp/obsolete/pgg-pgp.el14
-rw-r--r--lisp/obsolete/pgg-pgp5.el14
-rw-r--r--lisp/printing.el105
-rw-r--r--lisp/subr.el13
-rw-r--r--lisp/url/ChangeLog4
-rw-r--r--lisp/url/url-util.el11
17 files changed, 191 insertions, 195 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 2400c6a8e0a..b62a4daa051 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,7 @@
12014-05-14 Glenn Morris <rgm@gnu.org>
2
3 * files.texi (Changing Files): Mention with-file-modes.
4
12014-05-08 Paul Eggert <eggert@cs.ucla.edu> 52014-05-08 Paul Eggert <eggert@cs.ucla.edu>
2 6
3 * internals.texi (C Dialect): New section. 7 * internals.texi (C Dialect): New section.
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi
index 64ed3a05ee6..fcfd37e987d 100644
--- a/doc/lispref/files.texi
+++ b/doc/lispref/files.texi
@@ -1688,6 +1688,16 @@ version of an existing file; saving a file preserves its existing
1688permissions. 1688permissions.
1689@end defun 1689@end defun
1690 1690
1691@defmac with-file-modes mode body@dots{}
1692This macro evaluates the @var{body} forms with the default
1693permissions for new files temporarily set to @var{modes} (whose value
1694is as for @code{set-file-modes} above). When finished, it restores
1695the original default file permissions, and returns the value of the
1696last form in @var{body}.
1697
1698This is useful for creating private files, for example.
1699@end defmac
1700
1691@defun default-file-modes 1701@defun default-file-modes
1692This function returns the default file permissions, as an integer. 1702This function returns the default file permissions, as an integer.
1693@end defun 1703@end defun
diff --git a/etc/NEWS b/etc/NEWS
index 4c79d49d25b..42f2a870f21 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -122,6 +122,10 @@ active region handling.
122*** (side-effect-free VAL), if VAL is non-nil, indicates the function does not 122*** (side-effect-free VAL), if VAL is non-nil, indicates the function does not
123have side effects. 123have side effects.
124 124
125+++
126** New macro `with-file-modes', for evaluating expressions with default file
127permissions set to temporary values (e.g., for creating private files).
128
125** You can access the slots of structures using `cl-struct-slot-value'. 129** You can access the slots of structures using `cl-struct-slot-value'.
126 130
127 131
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 9fa46937f77..015650510f7 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,23 @@
12014-05-14 Glenn Morris <rgm@gnu.org> 12014-05-14 Glenn Morris <rgm@gnu.org>
2 2
3 * subr.el (with-file-modes): New macro.
4 * printing.el (pr-save-file-modes): Make obsolete.
5 * eshell/esh-util.el (eshell-with-file-modes): Make obsolete.
6 * emacs-lisp/lisp-mode.el (lisp-el-font-lock-keywords-2):
7 Add with-file-modes.
8 * doc-view.el (doc-view-make-safe-dir):
9 * epg.el (epg--start):
10 * files.el (locate-user-emacs-file, make-temp-file)
11 (backup-buffer-copy, move-file-to-trash):
12 * printing.el (pr-despool-print, pr-call-process, pr-text2ps):
13 * eshell/esh-util.el (eshell-with-private-file-modes)
14 (eshell-make-private-directory):
15 * net/browse-url.el (browse-url-mosaic):
16 * obsolete/mailpost.el (post-mail-send-it):
17 * obsolete/pgg-pgp.el (pgg-pgp-verify-region):
18 * obsolete/pgg-pgp5.el (pgg-pgp5-verify-region):
19 Use with-file-modes.
20
3 * vc/emerge.el (emerge-make-temp-file): Simplify. 21 * vc/emerge.el (emerge-make-temp-file): Simplify.
4 22
52014-05-14 Stephen Berman <stephen.berman@gmx.net> 232014-05-14 Stephen Berman <stephen.berman@gmx.net>
diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index 4ff78b55d4b..5d2c897e4f9 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -654,16 +654,10 @@ at the top edge of the page moves to the previous page."
654 654
655(defun doc-view-make-safe-dir (dir) 655(defun doc-view-make-safe-dir (dir)
656 (condition-case nil 656 (condition-case nil
657 (let ((umask (default-file-modes))) 657 ;; Create temp files with strict access rights. It's easy to
658 (unwind-protect 658 ;; loosen them later, whereas it's impossible to close the
659 (progn 659 ;; time-window of loose permissions otherwise.
660 ;; Create temp files with strict access rights. It's easy to 660 (with-file-modes #o0700 (make-directory dir))
661 ;; loosen them later, whereas it's impossible to close the
662 ;; time-window of loose permissions otherwise.
663 (set-default-file-modes #o0700)
664 (make-directory dir))
665 ;; Reset the umask.
666 (set-default-file-modes umask)))
667 (file-already-exists 661 (file-already-exists
668 (when (file-symlink-p dir) 662 (when (file-symlink-p dir)
669 (error "Danger: %s points to a symbolic link" dir)) 663 (error "Danger: %s points to a symbolic link" dir))
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index 21529894fed..18ad859e0b5 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -208,6 +208,7 @@ It has `lisp-mode-abbrev-table' as its parent."
208 "with-category-table" "with-coding-priority" 208 "with-category-table" "with-coding-priority"
209 "with-current-buffer" "with-demoted-errors" 209 "with-current-buffer" "with-demoted-errors"
210 "with-electric-help" "with-eval-after-load" 210 "with-electric-help" "with-eval-after-load"
211 "with-file-modes"
211 "with-local-quit" "with-no-warnings" 212 "with-local-quit" "with-no-warnings"
212 "with-output-to-temp-buffer" "with-selected-window" 213 "with-output-to-temp-buffer" "with-selected-window"
213 "with-selected-frame" "with-silent-modifications" 214 "with-selected-frame" "with-silent-modifications"
diff --git a/lisp/epg.el b/lisp/epg.el
index 77181a1a342..26e3b3d2501 100644
--- a/lisp/epg.el
+++ b/lisp/epg.el
@@ -1206,7 +1206,6 @@ This function is for internal use only."
1206 (coding-system-for-read 'binary) 1206 (coding-system-for-read 'binary)
1207 process-connection-type 1207 process-connection-type
1208 (process-environment process-environment) 1208 (process-environment process-environment)
1209 (orig-mode (default-file-modes))
1210 (buffer (generate-new-buffer " *epg*")) 1209 (buffer (generate-new-buffer " *epg*"))
1211 process 1210 process
1212 terminal-name 1211 terminal-name
@@ -1265,14 +1264,9 @@ This function is for internal use only."
1265 (setq epg-agent-file agent-file) 1264 (setq epg-agent-file agent-file)
1266 (make-local-variable 'epg-agent-mtime) 1265 (make-local-variable 'epg-agent-mtime)
1267 (setq epg-agent-mtime agent-mtime)) 1266 (setq epg-agent-mtime agent-mtime))
1268 (unwind-protect 1267 (with-file-modes 448
1269 (progn 1268 (setq process (apply #'start-process "epg" buffer
1270 (set-default-file-modes 448) 1269 (epg-context-program context) args)))
1271 (setq process
1272 (apply #'start-process "epg" buffer
1273 (epg-context-program context)
1274 args)))
1275 (set-default-file-modes orig-mode))
1276 (set-process-filter process #'epg--process-filter) 1270 (set-process-filter process #'epg--process-filter)
1277 (epg-context-set-process context process))) 1271 (epg-context-set-process context process)))
1278 1272
diff --git a/lisp/eshell/esh-util.el b/lisp/eshell/esh-util.el
index 5286f280b39..3bb6e8f31c7 100644
--- a/lisp/eshell/esh-util.el
+++ b/lisp/eshell/esh-util.el
@@ -539,20 +539,17 @@ Unless optional argument INPLACE is non-nil, return a new string."
539 539
540(defmacro eshell-with-file-modes (modes &rest forms) 540(defmacro eshell-with-file-modes (modes &rest forms)
541 "Evaluate, with file-modes set to MODES, the given FORMS." 541 "Evaluate, with file-modes set to MODES, the given FORMS."
542 `(let ((modes (default-file-modes))) 542 (declare (obsolete with-file-modes "24.5"))
543 (set-default-file-modes ,modes) 543 `(with-file-modes ,modes ,@forms))
544 (unwind-protect
545 (progn ,@forms)
546 (set-default-file-modes modes))))
547 544
548(defmacro eshell-with-private-file-modes (&rest forms) 545(defmacro eshell-with-private-file-modes (&rest forms)
549 "Evaluate FORMS with private file modes set." 546 "Evaluate FORMS with private file modes set."
550 `(eshell-with-file-modes ,eshell-private-file-modes ,@forms)) 547 `(with-file-modes ,eshell-private-file-modes ,@forms))
551 548
552(defsubst eshell-make-private-directory (dir &optional parents) 549(defsubst eshell-make-private-directory (dir &optional parents)
553 "Make DIR with file-modes set to `eshell-private-directory-modes'." 550 "Make DIR with file-modes set to `eshell-private-directory-modes'."
554 (eshell-with-file-modes eshell-private-directory-modes 551 (with-file-modes eshell-private-directory-modes
555 (make-directory dir parents))) 552 (make-directory dir parents)))
556 553
557(defsubst eshell-substring (string sublen) 554(defsubst eshell-substring (string sublen)
558 "Return the beginning of STRING, up to SUBLEN bytes." 555 "Return the beginning of STRING, up to SUBLEN bytes."
diff --git a/lisp/files.el b/lisp/files.el
index cd2feb69610..666316a2353 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -941,14 +941,10 @@ directory if it does not exist."
941 (if (file-directory-p user-emacs-directory) 941 (if (file-directory-p user-emacs-directory)
942 (or (file-accessible-directory-p user-emacs-directory) 942 (or (file-accessible-directory-p user-emacs-directory)
943 (setq errtype "access")) 943 (setq errtype "access"))
944 (let ((umask (default-file-modes))) 944 (with-file-modes ?\700
945 (unwind-protect 945 (condition-case nil
946 (progn 946 (make-directory user-emacs-directory)
947 (set-default-file-modes ?\700) 947 (error (setq errtype "create")))))
948 (condition-case nil
949 (make-directory user-emacs-directory)
950 (error (setq errtype "create"))))
951 (set-default-file-modes umask))))
952 (when (and errtype 948 (when (and errtype
953 user-emacs-directory-warning 949 user-emacs-directory-warning
954 (not (get 'user-emacs-directory-warning 'this-session))) 950 (not (get 'user-emacs-directory-warning 'this-session)))
@@ -1273,36 +1269,31 @@ You can then use `write-region' to write new data into the file.
1273If DIR-FLAG is non-nil, create a new empty directory instead of a file. 1269If DIR-FLAG is non-nil, create a new empty directory instead of a file.
1274 1270
1275If SUFFIX is non-nil, add that at the end of the file name." 1271If SUFFIX is non-nil, add that at the end of the file name."
1276 (let ((umask (default-file-modes)) 1272 ;; Create temp files with strict access rights. It's easy to
1277 file) 1273 ;; loosen them later, whereas it's impossible to close the
1278 (unwind-protect 1274 ;; time-window of loose permissions otherwise.
1279 (progn 1275 (with-file-modes ?\700
1280 ;; Create temp files with strict access rights. It's easy to 1276 (let (file)
1281 ;; loosen them later, whereas it's impossible to close the 1277 (while (condition-case ()
1282 ;; time-window of loose permissions otherwise. 1278 (progn
1283 (set-default-file-modes ?\700) 1279 (setq file
1284 (while (condition-case () 1280 (make-temp-name
1285 (progn 1281 (if (zerop (length prefix))
1286 (setq file 1282 (file-name-as-directory
1287 (make-temp-name 1283 temporary-file-directory)
1288 (if (zerop (length prefix)) 1284 (expand-file-name prefix
1289 (file-name-as-directory 1285 temporary-file-directory))))
1290 temporary-file-directory) 1286 (if suffix
1291 (expand-file-name prefix 1287 (setq file (concat file suffix)))
1292 temporary-file-directory)))) 1288 (if dir-flag
1293 (if suffix 1289 (make-directory file)
1294 (setq file (concat file suffix))) 1290 (write-region "" nil file nil 'silent nil 'excl))
1295 (if dir-flag 1291 nil)
1296 (make-directory file) 1292 (file-already-exists t))
1297 (write-region "" nil file nil 'silent nil 'excl)) 1293 ;; the file was somehow created by someone else between
1298 nil) 1294 ;; `make-temp-name' and `write-region', let's try again.
1299 (file-already-exists t)) 1295 nil)
1300 ;; the file was somehow created by someone else between 1296 file)))
1301 ;; `make-temp-name' and `write-region', let's try again.
1302 nil)
1303 file)
1304 ;; Reset the umask.
1305 (set-default-file-modes umask))))
1306 1297
1307(defun recode-file-name (file coding new-coding &optional ok-if-already-exists) 1298(defun recode-file-name (file coding new-coding &optional ok-if-already-exists)
1308 "Change the encoding of FILE's name from CODING to NEW-CODING. 1299 "Change the encoding of FILE's name from CODING to NEW-CODING.
@@ -4071,31 +4062,26 @@ BACKUPNAME is the backup file name, which is the old file renamed."
4071 (file-error nil)))))) 4062 (file-error nil))))))
4072 4063
4073(defun backup-buffer-copy (from-name to-name modes extended-attributes) 4064(defun backup-buffer-copy (from-name to-name modes extended-attributes)
4074 (let ((umask (default-file-modes))) 4065 ;; Create temp files with strict access rights. It's easy to
4075 (unwind-protect 4066 ;; loosen them later, whereas it's impossible to close the
4076 (progn 4067 ;; time-window of loose permissions otherwise.
4077 ;; Create temp files with strict access rights. It's easy to 4068 (with-file-modes ?\700
4078 ;; loosen them later, whereas it's impossible to close the 4069 (when (condition-case nil
4079 ;; time-window of loose permissions otherwise. 4070 ;; Try to overwrite old backup first.
4080 (set-default-file-modes ?\700) 4071 (copy-file from-name to-name t t t)
4081 (when (condition-case nil 4072 (error t))
4082 ;; Try to overwrite old backup first. 4073 (while (condition-case nil
4083 (copy-file from-name to-name t t t) 4074 (progn
4084 (error t)) 4075 (when (file-exists-p to-name)
4085 (while (condition-case nil 4076 (delete-file to-name))
4086 (progn 4077 (copy-file from-name to-name nil t t)
4087 (when (file-exists-p to-name) 4078 nil)
4088 (delete-file to-name)) 4079 (file-already-exists t))
4089 (copy-file from-name to-name nil t t) 4080 ;; The file was somehow created by someone else between
4090 nil) 4081 ;; `delete-file' and `copy-file', so let's try again.
4091 (file-already-exists t)) 4082 ;; rms says "I think there is also a possible race
4092 ;; The file was somehow created by someone else between 4083 ;; condition for making backup files" (emacs-devel 20070821).
4093 ;; `delete-file' and `copy-file', so let's try again. 4084 nil)))
4094 ;; rms says "I think there is also a possible race
4095 ;; condition for making backup files" (emacs-devel 20070821).
4096 nil)))
4097 ;; Reset the umask.
4098 (set-default-file-modes umask)))
4099 ;; If set-file-extended-attributes fails, fall back on set-file-modes. 4085 ;; If set-file-extended-attributes fails, fall back on set-file-modes.
4100 (unless (and extended-attributes 4086 (unless (and extended-attributes
4101 (with-demoted-errors 4087 (with-demoted-errors
@@ -6863,15 +6849,11 @@ Otherwise, trash FILENAME using the freedesktop.org conventions,
6863 trash-info-dir filename)) 6849 trash-info-dir filename))
6864 6850
6865 ;; Ensure that the trash directory exists; otherwise, create it. 6851 ;; Ensure that the trash directory exists; otherwise, create it.
6866 (let ((saved-default-file-modes (default-file-modes))) 6852 (with-file-modes #o700
6867 (unwind-protect 6853 (unless (file-exists-p trash-files-dir)
6868 (progn 6854 (make-directory trash-files-dir t))
6869 (set-default-file-modes #o700) 6855 (unless (file-exists-p trash-info-dir)
6870 (unless (file-exists-p trash-files-dir) 6856 (make-directory trash-info-dir t)))
6871 (make-directory trash-files-dir t))
6872 (unless (file-exists-p trash-info-dir)
6873 (make-directory trash-info-dir t)))
6874 (set-default-file-modes saved-default-file-modes)))
6875 6857
6876 ;; Try to move to trash with .trashinfo undo information 6858 ;; Try to move to trash with .trashinfo undo information
6877 (save-excursion 6859 (save-excursion
diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el
index 9644a509b22..09d84795f4f 100644
--- a/lisp/net/browse-url.el
+++ b/lisp/net/browse-url.el
@@ -1343,16 +1343,12 @@ used instead of `browse-url-new-window-flag'."
1343 "newwin\n" 1343 "newwin\n"
1344 "goto\n") 1344 "goto\n")
1345 url "\n") 1345 url "\n")
1346 (let ((umask (default-file-modes))) 1346 (with-file-modes ?\700
1347 (unwind-protect 1347 (if (file-exists-p
1348 (progn 1348 (setq pidfile (format "/tmp/Mosaic.%d" pid)))
1349 (set-default-file-modes ?\700) 1349 (delete-file pidfile))
1350 (if (file-exists-p 1350 ;; http://debbugs.gnu.org/17428. Use O_EXCL.
1351 (setq pidfile (format "/tmp/Mosaic.%d" pid))) 1351 (write-region nil nil pidfile nil 'silent nil 'excl)))
1352 (delete-file pidfile))
1353 ;; http://debbugs.gnu.org/17428. Use O_EXCL.
1354 (write-region nil nil pidfile nil 'silent nil 'excl))
1355 (set-default-file-modes umask))))
1356 ;; Send signal SIGUSR to Mosaic 1352 ;; Send signal SIGUSR to Mosaic
1357 (message "Signaling Mosaic...") 1353 (message "Signaling Mosaic...")
1358 (signal-process pid 'SIGUSR1) 1354 (signal-process pid 'SIGUSR1)
diff --git a/lisp/obsolete/mailpost.el b/lisp/obsolete/mailpost.el
index 880780c577c..bcd468c2b06 100644
--- a/lisp/obsolete/mailpost.el
+++ b/lisp/obsolete/mailpost.el
@@ -75,12 +75,7 @@ site-init."
75 (if mail-interactive 75 (if mail-interactive
76 (with-current-buffer errbuf 76 (with-current-buffer errbuf
77 (erase-buffer)))) 77 (erase-buffer))))
78 (let ((m (default-file-modes))) 78 (with-file-modes 384 (setq temfile (make-temp-file ",rpost")))
79 (unwind-protect
80 (progn
81 (set-default-file-modes 384)
82 (setq temfile (make-temp-file ",rpost")))
83 (set-default-file-modes m)))
84 (apply 'call-process 79 (apply 'call-process
85 (append (list (if (boundp 'post-mail-program) 80 (append (list (if (boundp 'post-mail-program)
86 post-mail-program 81 post-mail-program
diff --git a/lisp/obsolete/pgg-pgp.el b/lisp/obsolete/pgg-pgp.el
index 5a54cb0caff..5d6ae9cc2e9 100644
--- a/lisp/obsolete/pgg-pgp.el
+++ b/lisp/obsolete/pgg-pgp.el
@@ -202,15 +202,11 @@ passphrase cache or user."
202(defun pgg-pgp-verify-region (start end &optional signature) 202(defun pgg-pgp-verify-region (start end &optional signature)
203 "Verify region between START and END as the detached signature SIGNATURE." 203 "Verify region between START and END as the detached signature SIGNATURE."
204 (let* ((orig-file (pgg-make-temp-file "pgg")) 204 (let* ((orig-file (pgg-make-temp-file "pgg"))
205 (args "+verbose=1 +batchmode +language=us") 205 (args "+verbose=1 +batchmode +language=us"))
206 (orig-mode (default-file-modes))) 206 (with-file-modes 448
207 (unwind-protect 207 (let ((coding-system-for-write 'binary)
208 (progn 208 jka-compr-compression-info-list jam-zcat-filename-list)
209 (set-default-file-modes 448) 209 (write-region start end orig-file)))
210 (let ((coding-system-for-write 'binary)
211 jka-compr-compression-info-list jam-zcat-filename-list)
212 (write-region start end orig-file)))
213 (set-default-file-modes orig-mode))
214 (if (stringp signature) 210 (if (stringp signature)
215 (progn 211 (progn
216 (copy-file signature (setq signature (concat orig-file ".asc"))) 212 (copy-file signature (setq signature (concat orig-file ".asc")))
diff --git a/lisp/obsolete/pgg-pgp5.el b/lisp/obsolete/pgg-pgp5.el
index beece7ea2ea..944800cf0f6 100644
--- a/lisp/obsolete/pgg-pgp5.el
+++ b/lisp/obsolete/pgg-pgp5.el
@@ -208,15 +208,11 @@ Bourne shell or its equivalent \(not tcsh) is needed for \"2>\"."
208(defun pgg-pgp5-verify-region (start end &optional signature) 208(defun pgg-pgp5-verify-region (start end &optional signature)
209 "Verify region between START and END as the detached signature SIGNATURE." 209 "Verify region between START and END as the detached signature SIGNATURE."
210 (let ((orig-file (pgg-make-temp-file "pgg")) 210 (let ((orig-file (pgg-make-temp-file "pgg"))
211 (args '("+verbose=1" "+batchmode=1" "+language=us")) 211 (args '("+verbose=1" "+batchmode=1" "+language=us")))
212 (orig-mode (default-file-modes))) 212 (with-file-modes 448
213 (unwind-protect 213 (let ((coding-system-for-write 'binary)
214 (progn 214 jka-compr-compression-info-list jam-zcat-filename-list)
215 (set-default-file-modes 448) 215 (write-region start end orig-file)))
216 (let ((coding-system-for-write 'binary)
217 jka-compr-compression-info-list jam-zcat-filename-list)
218 (write-region start end orig-file)))
219 (set-default-file-modes orig-mode))
220 (when (stringp signature) 216 (when (stringp signature)
221 (copy-file signature (setq signature (concat orig-file ".asc"))) 217 (copy-file signature (setq signature (concat orig-file ".asc")))
222 (setq args (append args (list signature)))) 218 (setq args (append args (list signature))))
diff --git a/lisp/printing.el b/lisp/printing.el
index de7958ea0e6..39da132d64e 100644
--- a/lisp/printing.el
+++ b/lisp/printing.el
@@ -3171,12 +3171,9 @@ See `pr-ps-printer-alist'.")
3171 3171
3172 3172
3173(defmacro pr-save-file-modes (&rest body) 3173(defmacro pr-save-file-modes (&rest body)
3174 "Set temporally file modes to `pr-file-modes'." 3174 "Execute BODY with file permissions temporarily set to `pr-file-modes'."
3175 `(let ((pr--default-file-modes (default-file-modes))) ; save default 3175 (declare (obsolete with-file-modes "24.5"))
3176 (set-default-file-modes pr-file-modes) 3176 `(with-file-modes pr-file-modes ,@body))
3177 ,@body
3178 (set-default-file-modes pr--default-file-modes))) ; restore default
3179
3180 3177
3181;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 3178;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3182;; Keys & Menus 3179;; Keys & Menus
@@ -4372,12 +4369,12 @@ Noninteractively, the argument FILENAME is treated as follows: if it is nil,
4372send the image to the printer. If FILENAME is a string, save the PostScript 4369send the image to the printer. If FILENAME is a string, save the PostScript
4373image in a file with that name." 4370image in a file with that name."
4374 (interactive (list (ps-print-preprint current-prefix-arg))) 4371 (interactive (list (ps-print-preprint current-prefix-arg)))
4375 (pr-save-file-modes 4372 (with-file-modes pr-file-modes
4376 (let ((ps-lpr-command (pr-command pr-ps-command)) 4373 (let ((ps-lpr-command (pr-command pr-ps-command))
4377 (ps-lpr-switches pr-ps-switches) 4374 (ps-lpr-switches pr-ps-switches)
4378 (ps-printer-name-option pr-ps-printer-switch) 4375 (ps-printer-name-option pr-ps-printer-switch)
4379 (ps-printer-name pr-ps-printer)) 4376 (ps-printer-name pr-ps-printer))
4380 (ps-despool filename)))) 4377 (ps-despool filename))))
4381 4378
4382 4379
4383;;;###autoload 4380;;;###autoload
@@ -5640,12 +5637,12 @@ If menu binding was not done, calls `pr-menu-bind'."
5640 (goto-char (point-max)) 5637 (goto-char (point-max))
5641 (insert (format "%s %S\n" cmd args))) 5638 (insert (format "%s %S\n" cmd args)))
5642 ;; *Printing Command Output* == show any return message from command 5639 ;; *Printing Command Output* == show any return message from command
5643 (pr-save-file-modes 5640 (with-file-modes pr-file-modes
5644 (setq status 5641 (setq status
5645 (condition-case data 5642 (condition-case data
5646 (apply 'call-process cmd nil buffer nil args) 5643 (apply 'call-process cmd nil buffer nil args)
5647 ((quit error) 5644 ((quit error)
5648 (error-message-string data))))) 5645 (error-message-string data)))))
5649 ;; *Printing Command Output* == show exit status 5646 ;; *Printing Command Output* == show exit status
5650 (with-current-buffer buffer 5647 (with-current-buffer buffer
5651 (goto-char (point-max)) 5648 (goto-char (point-max))
@@ -5890,42 +5887,42 @@ If menu binding was not done, calls `pr-menu-bind'."
5890 5887
5891 5888
5892(defun pr-text2ps (kind n-up filename &optional from to) 5889(defun pr-text2ps (kind n-up filename &optional from to)
5893 (pr-save-file-modes 5890 (with-file-modes pr-file-modes
5894 (let ((ps-n-up-printing n-up) 5891 (let ((ps-n-up-printing n-up)
5895 (ps-spool-config (and (eq ps-spool-config 'setpagedevice) 5892 (ps-spool-config (and (eq ps-spool-config 'setpagedevice)
5896 'setpagedevice))) 5893 'setpagedevice)))
5897 (pr-delete-file-if-exists filename) 5894 (pr-delete-file-if-exists filename)
5898 (cond (pr-faces-p 5895 (cond (pr-faces-p
5899 (cond (pr-spool-p 5896 (cond (pr-spool-p
5900 ;; pr-faces-p and pr-spool-p 5897 ;; pr-faces-p and pr-spool-p
5901 ;; here FILENAME arg is ignored 5898 ;; here FILENAME arg is ignored
5902 (cond ((eq kind 'buffer) 5899 (cond ((eq kind 'buffer)
5903 (ps-spool-buffer-with-faces)) 5900 (ps-spool-buffer-with-faces))
5904 ((eq kind 'region) 5901 ((eq kind 'region)
5905 (ps-spool-region-with-faces (or from (point)) 5902 (ps-spool-region-with-faces (or from (point))
5906 (or to (mark)))) 5903 (or to (mark))))
5907 )) 5904 ))
5908 ;; pr-faces-p and not pr-spool-p 5905 ;; pr-faces-p and not pr-spool-p
5909 ((eq kind 'buffer) 5906 ((eq kind 'buffer)
5910 (ps-print-buffer-with-faces filename)) 5907 (ps-print-buffer-with-faces filename))
5911 ((eq kind 'region) 5908 ((eq kind 'region)
5912 (ps-print-region-with-faces (or from (point)) 5909 (ps-print-region-with-faces (or from (point))
5913 (or to (mark)) filename)) 5910 (or to (mark)) filename))
5914 )) 5911 ))
5915 (pr-spool-p 5912 (pr-spool-p
5916 ;; not pr-faces-p and pr-spool-p 5913 ;; not pr-faces-p and pr-spool-p
5917 ;; here FILENAME arg is ignored 5914 ;; here FILENAME arg is ignored
5918 (cond ((eq kind 'buffer) 5915 (cond ((eq kind 'buffer)
5919 (ps-spool-buffer)) 5916 (ps-spool-buffer))
5920 ((eq kind 'region) 5917 ((eq kind 'region)
5921 (ps-spool-region (or from (point)) (or to (mark)))) 5918 (ps-spool-region (or from (point)) (or to (mark))))
5922 )) 5919 ))
5923 ;; not pr-faces-p and not pr-spool-p 5920 ;; not pr-faces-p and not pr-spool-p
5924 ((eq kind 'buffer) 5921 ((eq kind 'buffer)
5925 (ps-print-buffer filename)) 5922 (ps-print-buffer filename))
5926 ((eq kind 'region) 5923 ((eq kind 'region)
5927 (ps-print-region (or from (point)) (or to (mark)) filename)) 5924 (ps-print-region (or from (point)) (or to (mark)) filename))
5928 )))) 5925 ))))
5929 5926
5930 5927
5931(defun pr-command (command) 5928(defun pr-command (command)
diff --git a/lisp/subr.el b/lisp/subr.el
index 6cfece1045f..fef33e726c3 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -3292,6 +3292,19 @@ The value returned is the value of the last form in BODY."
3292 ,@body) 3292 ,@body)
3293 (with-current-buffer ,old-buffer 3293 (with-current-buffer ,old-buffer
3294 (set-case-table ,old-case-table)))))) 3294 (set-case-table ,old-case-table))))))
3295
3296(defmacro with-file-modes (modes &rest body)
3297 "Execute BODY with default file permissions temporarily set to MODES.
3298MODES is as for `set-default-file-modes'."
3299 (declare (indent 1) (debug t))
3300 (let ((umask (make-symbol "umask")))
3301 `(let ((,umask (default-file-modes)))
3302 (unwind-protect
3303 (progn
3304 (set-default-file-modes ,modes)
3305 ,@body)
3306 (set-default-file-modes ,umask)))))
3307
3295 3308
3296;;; Matching and match data. 3309;;; Matching and match data.
3297 3310
diff --git a/lisp/url/ChangeLog b/lisp/url/ChangeLog
index aba4a2c53e8..b445ff6d1f1 100644
--- a/lisp/url/ChangeLog
+++ b/lisp/url/ChangeLog
@@ -1,3 +1,7 @@
12014-05-14 Glenn Morris <rgm@gnu.org>
2
3 * url-util.el (url-make-private-file): Use with-file-modes.
4
12014-05-12 Michael Albinus <michael.albinus@gmx.de> 52014-05-12 Michael Albinus <michael.albinus@gmx.de>
2 6
3 * url-handlers.el (url-file-handler-load-in-progress): New defvar. 7 * url-handlers.el (url-file-handler-load-in-progress): New defvar.
diff --git a/lisp/url/url-util.el b/lisp/url/url-util.el
index dd91ca46a0d..b796e769c60 100644
--- a/lisp/url/url-util.el
+++ b/lisp/url/url-util.el
@@ -628,14 +628,9 @@ Creates FILE and its parent directories if they do not exist."
628 (make-directory dir t))) 628 (make-directory dir t)))
629 ;; Based on doc-view-make-safe-dir. 629 ;; Based on doc-view-make-safe-dir.
630 (condition-case nil 630 (condition-case nil
631 (let ((umask (default-file-modes))) 631 (with-file-modes #o0600
632 (unwind-protect 632 (with-temp-buffer
633 (progn 633 (write-region (point-min) (point-max) file nil 'silent nil 'excl)))
634 (set-default-file-modes #o0600)
635 (with-temp-buffer
636 (write-region (point-min) (point-max)
637 file nil 'silent nil 'excl)))
638 (set-default-file-modes umask)))
639 (file-already-exists 634 (file-already-exists
640 (if (file-symlink-p file) 635 (if (file-symlink-p file)
641 (error "Danger: `%s' is a symbolic link" file)) 636 (error "Danger: `%s' is a symbolic link" file))