changeset 110311:6388b1d1793a

Close bug#4196. * lisp/emacs-lisp/bytecomp.el (byte-compile-file): Create .elc files atomically, to avoid parallel build errors.
author Glenn Morris <rgm@gnu.org>
date Sat, 11 Sep 2010 11:52:04 -0700
parents 9b5623e06689
children 9ac0232d85db
files lisp/ChangeLog lisp/emacs-lisp/bytecomp.el
diffstat 2 files changed, 21 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Sat Sep 11 15:58:57 2010 +0200
+++ b/lisp/ChangeLog	Sat Sep 11 11:52:04 2010 -0700
@@ -1,3 +1,8 @@
+2010-09-11  Glenn Morris  <rgm@gnu.org>
+
+	* emacs-lisp/bytecomp.el (byte-compile-file): Create .elc files
+	atomically, to avoid parallel build errors.  (Bug#4196)
+
 2010-09-11  Michael R. Mauger  <mmaug@yahoo.com>
 
 	* progmodes/sql.el: Version 2.6
--- a/lisp/emacs-lisp/bytecomp.el	Sat Sep 11 15:58:57 2010 +0200
+++ b/lisp/emacs-lisp/bytecomp.el	Sat Sep 11 11:52:04 2010 -0700
@@ -1698,17 +1698,24 @@
 	  (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"