Bug 485390, try #2 - when a .jar file doesn't exist yet, there's a race creating it, r=ted

This commit is contained in:
Benjamin Smedberg 2009-03-31 12:47:38 -04:00
parent f7437dbe2c
commit faa05236ab
2 changed files with 13 additions and 8 deletions

View File

@ -257,13 +257,11 @@ class JarMaker(object):
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)

View File

@ -39,9 +39,9 @@ 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.
@ -55,6 +55,13 @@ class ZipFile(zipfile.ZipFile):
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()