summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/bytecomp.el
diff options
context:
space:
mode:
authorGlenn Morris <rgm@gnu.org>2010-09-11 11:52:04 -0700
committerGlenn Morris <rgm@gnu.org>2010-09-11 11:52:04 -0700
commit0f34ae289a051cb6e92b350f984c23502ff5929f (patch)
treed8d567000f21da0709750b5922b3ec9718345a95 /lisp/emacs-lisp/bytecomp.el
parent7cf78aac59d289cdabcf835f1b8c4321d6e50469 (diff)
downloademacs-0f34ae289a051cb6e92b350f984c23502ff5929f.tar.gz
emacs-0f34ae289a051cb6e92b350f984c23502ff5929f.tar.bz2
emacs-0f34ae289a051cb6e92b350f984c23502ff5929f.zip
Close bug#4196.
* lisp/emacs-lisp/bytecomp.el (byte-compile-file): Create .elc files atomically, to avoid parallel build errors.
Diffstat (limited to 'lisp/emacs-lisp/bytecomp.el')
-rw-r--r--lisp/emacs-lisp/bytecomp.el25
1 files changed, 16 insertions, 9 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index cb1deb9a762..04bc254b319 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -1698,17 +1698,24 @@ 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))
+ (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)))
(if (memq system-type '(ms-dos 'windows-nt))
(setq buffer-file-type t))
- (when (file-exists-p target-file)
- ;; Remove the target before writing it, so that any
- ;; hard-links 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).
- (delete-file target-file))
- (write-region (point-min) (point-max) target-file))
+ (write-region (point-min) (point-max) tempfile)
+ ;; 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))
;; This is just to give a better error message than write-region
(signal 'file-error
(list "Opening output file"