diff options
author | Gary Oberbrunner <garyo@oberbrunner.com> | 2009-11-15 14:32:02 (GMT) |
---|---|---|
committer | Gary Oberbrunner <garyo@oberbrunner.com> | 2009-11-15 14:32:02 (GMT) |
commit | ff6d2e6539e0a3672f0ec0cc807173045cac1941 (patch) | |
tree | e45c285f90db155fd9a0afd9e21f7133a7b038de /src/engine/SCons/compat | |
parent | 6aed9ff532245afdfdf426fcc7b9fddf84bd7e2b (diff) | |
download | SCons-ff6d2e6539e0a3672f0ec0cc807173045cac1941.zip SCons-ff6d2e6539e0a3672f0ec0cc807173045cac1941.tar.gz SCons-ff6d2e6539e0a3672f0ec0cc807173045cac1941.tar.bz2 |
Apply patch submitted in issue #947 to fix race condition in
TempFileMunge by using mkstemp instead of mktemp. Includes
pre-Python-2.3 compat version of mkstemp. Thanks to Jim Randall.
Diffstat (limited to 'src/engine/SCons/compat')
-rw-r--r-- | src/engine/SCons/compat/__init__.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/engine/SCons/compat/__init__.py b/src/engine/SCons/compat/__init__.py index 2a86324..553fcf3 100644 --- a/src/engine/SCons/compat/__init__.py +++ b/src/engine/SCons/compat/__init__.py @@ -250,6 +250,41 @@ except ImportError: # Pre-1.6 Python has no UserString module. import_as('_scons_UserString', 'UserString') +import tempfile +try: + tempfile.mkstemp +except AttributeError: + # Pre-2.3 Python has no tempfile.mkstemp function, so try to simulate it. + # adapted from the mkstemp implementation in python 3. + import os + import errno + def mkstemp( *args, **kw ) : + text = False + if 'text' in kw : + text = kw['text'] + del kw['text'] + elif len( args ) == 4 : + text = args[3] + args = args[:3] + flags = os.O_RDWR | os.O_CREAT | os.O_EXCL + if not text and hasattr( os, 'O_BINARY' ) : + flags |= os.O_BINARY + while True: + try : + name = tempfile.mktemp( *args, **kw ) + fd = os.open( name, flags, 0600 ) + return (fd, os.path.abspath(name)) + except OSError, e: + if e.errno == errno.EEXIST: + continue + raise + + tempfile.mkstemp = mkstemp + del mkstemp + + + + # Local Variables: # tab-width:4 # indent-tabs-mode:nil |