Kaydet (Commit) f4aaf862 authored tarafından Guido van Rossum's avatar Guido van Rossum

Be more careful about default temp dir

üst 7a623d7e
......@@ -18,14 +18,24 @@ template = None
def gettempdir():
global tempdir
if tempdir == None:
attempdirs = ['/usr/tmp', '/tmp', os.getcwd(), os.curdir]
if os.environ.has_key('TMPDIR'):
attempdirs.insert(0, os.environ['TMPDIR'])
testfile = gettempprefix() + '-*-writetest-*-'
for dir in attempdirs:
try:
tempdir = os.environ['TMPDIR']
except (KeyError, AttributeError):
if os.name == 'posix':
tempdir = '/usr/tmp' # XXX Why not /tmp?
else:
tempdir = os.getcwd() # XXX Is this OK?
filename = os.path.join(dir, testfile)
fp = open(filename, 'w')
fp.write('blat')
fp.close()
os.unlink(filename)
tempdir = dir
break
except IOError:
pass
if tempdir is None:
msg = "Can't find a usable temporary directory amongst " + `attempdirs`
raise IOError, msg
return tempdir
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment