TempFileMunge by using mkstemp instead of mktemp. Includes
pre-Python-2.3 compat version of mkstemp. Thanks to Jim Randall.
git-svn-id: http://scons.tigris.org/svn/scons/trunk@4392
fdb21ef1-2011-0410-befe-
b5e4ea1792b1
RELEASE X.X.X - XXX
+ From Jim Randall:
+ - Fixed temp filename race condition on Windows with long cmd lines.
+
From David Cournapeau:
- Fixed tryRun when sconf directory is in a variant dir.
- Do not add -fPIC for ifort tool on non-posix platforms (darwin and
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import SCons.compat
+
import imp
import os
import string
# We use the .lnk suffix for the benefit of the Phar Lap
# linkloc linker, which likes to append an .lnk suffix if
# none is given.
- tmp = os.path.normpath(tempfile.mktemp('.lnk'))
- native_tmp = SCons.Util.get_native_path(tmp)
+ (fd, tmp) = tempfile.mkstemp('.lnk', text=True)
+ native_tmp = SCons.Util.get_native_path(os.path.normpath(tmp))
if env['SHELL'] and env['SHELL'] == 'sh':
# The sh shell will try to escape the backslashes in the
prefix = '@'
args = map(SCons.Subst.quote_spaces, cmd[1:])
- open(tmp, 'w').write(string.join(args, " ") + "\n")
+ os.write(fd, string.join(args, " ") + "\n")
+ os.close(fd)
# XXX Using the SCons.Action.print_actions value directly
# like this is bogus, but expedient. This class should
# really be rewritten as an Action that defines the
# 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