Bug 485390, try #2 - when a .jar file doesn't exist yet, there's a race creating it, r=ted
authorBenjamin Smedberg <benjamin@smedbergs.us>
Tue, 31 Mar 2009 12:47:38 -0400
changeset 26775 e1465ef7add6c1e7554dc767ac249b6f0285f512
parent 26774 e4c426478d47101acf9761ce2dc308543aacd095
child 26776 2e7a9959dd5b94697b29f5568371fcdcbe01e29d
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs485390
milestone1.9.2a1pre
Bug 485390, try #2 - when a .jar file doesn't exist yet, there's a race creating it, r=ted
config/JarMaker.py
config/MozZipFile.py
--- a/config/JarMaker.py
+++ b/config/JarMaker.py
@@ -252,23 +252,21 @@ class JarMaker(object):
       chromebasepath = 'jar:' + chromebasepath + '.jar!'
     chromebasepath += '/'
 
     jarfile = os.path.join(jardir, jarfile)
     jf = None
     if self.outputFormat == 'jar':
       #jar
       jarfilepath = jarfile + '.jar'
-      if os.path.isfile(jarfilepath) and \
-            os.path.getsize(jarfilepath) > 0:
-        jf = ZipFile(jarfilepath, 'a', lock = True)
-      else:
-        if not os.path.isdir(os.path.dirname(jarfilepath)):
-          os.makedirs(os.path.dirname(jarfilepath))
-        jf = ZipFile(jarfilepath, 'w', lock = True)
+      try:
+        os.makedirs(os.path.dirname(jarfilepath))
+      except OSError:
+        pass
+      jf = ZipFile(jarfilepath, 'a', lock = True)
       outHelper = self.OutputHelper_jar(jf)
     else:
       outHelper = getattr(self, 'OutputHelper_' + self.outputFormat)(jarfile)
     register = {}
     # This loop exits on either
     # - the end of the jar.mn file
     # - an line in the jar.mn file that's not part of a jar section
     # - on an exception raised, close the jf in that case in a finally
--- a/config/MozZipFile.py
+++ b/config/MozZipFile.py
@@ -34,32 +34,39 @@
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK *****
 
 import zipfile
 import time
 import binascii, struct
 import zlib
+import os
 from utils import lockFile
 
-
 class ZipFile(zipfile.ZipFile):
   """ Class with methods to open, read, write, close, list zip files.
 
   Subclassing zipfile.ZipFile to allow for overwriting of existing
   entries, though only for writestr, not for write.
   """
   def __init__(self, file, mode="r", compression=zipfile.ZIP_STORED,
                lock = False):
     if lock:
       assert isinstance(file, basestring)
       self.lockfile = lockFile(file + '.lck')
     else:
       self.lockfile = None
+
+    if mode == 'a' and lock:
+      # appending to a file which doesn't exist fails, but we can't check
+      # existence util we hold the lock
+      if (not os.path.isfile(file)) or os.path.getsize(file) == 0:
+        mode = 'w'
+
     zipfile.ZipFile.__init__(self, file, mode, compression)
     self._remove = []
     self.end = self.fp.tell()
     self.debug = 0
 
   def writestr(self, zinfo_or_arcname, bytes):
     """Write contents into the archive.