Commit 785a4a1d authored by Paul Eggert's avatar Paul Eggert
Browse files

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.
parent c0df64db
......@@ -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))
(cons (lambda () (ignore-errors (delete-file tempfile)))
(write-region (point-min) (point-max) tempfile nil 1)
(rename-file tempfile buffer-file-name t)
(rename-file tempfile buffer-file-name t))
(set-buffer-modified-p nil)
(or noninteractive (message "Wrote %s" buffer-file-name))))
(or noninteractive (message "Wrote %s" buffer-file-name)))
(defun autoload-save-buffers ()
(while autoload-modified-buffers
......@@ -1888,14 +1888,16 @@ 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))
(tempfile (make-temp-file target-file))
(cons (lambda () (ignore-errors (delete-file tempfile)))
(cons (lambda () (ignore-errors
(delete-file tempfile)))
(write-region (point-min) (point-max) tempfile nil 1)
;; This has the intentional side effect that any
......@@ -1906,7 +1908,7 @@ The value is non-nil if there were no errors, nil if errors."
;; 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)
(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)))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment