summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2017-08-05 21:27:45 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2017-08-05 21:28:09 -0700
commit785a4a1d52fd7da3f3169fda26841341667c1661 (patch)
tree456a79a178ba18701ad5f0b5d5b9993414f1e27d /lisp/emacs-lisp
parentc0df64db08b58cdac37cb38c16f2ba2f097fae92 (diff)
downloademacs-785a4a1d52fd7da3f3169fda26841341667c1661.tar.gz
emacs-785a4a1d52fd7da3f3169fda26841341667c1661.tar.bz2
emacs-785a4a1d52fd7da3f3169fda26841341667c1661.zip
Fix a couple of make-temp-file races
* lisp/emacs-lisp/autoload.el (autoload--save-buffer): * lisp/emacs-lisp/bytecomp.el (byte-compile-file): Use make-temp-file, not make-temp-name, to avoid an unlikely race that could lose data. Remove the deletion hook as quickly as possible after the file is renamed; though a race still remains here, it is smaller than before.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/autoload.el10
-rw-r--r--lisp/emacs-lisp/bytecomp.el40
2 files changed, 26 insertions, 24 deletions
diff --git a/lisp/emacs-lisp/autoload.el b/lisp/emacs-lisp/autoload.el
index 8fe94013700..4a9bd6d06b3 100644
--- a/lisp/emacs-lisp/autoload.el
+++ b/lisp/emacs-lisp/autoload.el
@@ -875,16 +875,16 @@ FILE's modification time."
"Save current buffer to its file, atomically."
;; Copied from byte-compile-file.
(let* ((version-control 'never)
- (tempfile (make-temp-name buffer-file-name))
+ (tempfile (make-temp-file buffer-file-name))
(kill-emacs-hook
(cons (lambda () (ignore-errors (delete-file tempfile)))
kill-emacs-hook)))
(write-region (point-min) (point-max) tempfile nil 1)
(backup-buffer)
- (rename-file tempfile buffer-file-name t)
- (set-buffer-modified-p nil)
- (set-visited-file-modtime)
- (or noninteractive (message "Wrote %s" buffer-file-name))))
+ (rename-file tempfile buffer-file-name t))
+ (set-buffer-modified-p nil)
+ (set-visited-file-modtime)
+ (or noninteractive (message "Wrote %s" buffer-file-name)))
(defun autoload-save-buffers ()
(while autoload-modified-buffers
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index fdd4276e4e7..5fa7389e431 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -1888,25 +1888,27 @@ The value is non-nil if there were no errors, nil if errors."
(insert "\n") ; aaah, unix.
(if (file-writable-p target-file)
;; We must disable any code conversion here.
- (let* ((coding-system-for-write 'no-conversion)
- ;; Write to a tempfile so that if another Emacs
- ;; process is trying to load target-file (eg in a
- ;; parallel bootstrap), it does not risk getting a
- ;; half-finished file. (Bug#4196)
- (tempfile (make-temp-name target-file))
- (kill-emacs-hook
- (cons (lambda () (ignore-errors (delete-file tempfile)))
- kill-emacs-hook)))
- (write-region (point-min) (point-max) tempfile nil 1)
- ;; This has the intentional side effect that any
- ;; hard-links to target-file continue to
- ;; point to the old file (this makes it possible
- ;; for installed files to share disk space with
- ;; the build tree, without causing problems when
- ;; emacs-lisp files in the build tree are
- ;; recompiled). Previously this was accomplished by
- ;; deleting target-file before writing it.
- (rename-file tempfile target-file t)
+ (progn
+ (let* ((coding-system-for-write 'no-conversion)
+ ;; Write to a tempfile so that if another Emacs
+ ;; process is trying to load target-file (eg in a
+ ;; parallel bootstrap), it does not risk getting a
+ ;; half-finished file. (Bug#4196)
+ (tempfile (make-temp-file target-file))
+ (kill-emacs-hook
+ (cons (lambda () (ignore-errors
+ (delete-file tempfile)))
+ kill-emacs-hook)))
+ (write-region (point-min) (point-max) tempfile nil 1)
+ ;; This has the intentional side effect that any
+ ;; hard-links to target-file continue to
+ ;; point to the old file (this makes it possible
+ ;; for installed files to share disk space with
+ ;; the build tree, without causing problems when
+ ;; emacs-lisp files in the build tree are
+ ;; recompiled). Previously this was accomplished by
+ ;; deleting target-file before writing it.
+ (rename-file tempfile target-file t))
(or noninteractive (message "Wrote %s" target-file)))
;; This is just to give a better error message than write-region
(let ((exists (file-exists-p target-file)))