In utils.tempdir, pass CONF.tempdir as an argument.

It's ugly, and potentially racy, to mess around with other modules'
global variables.  Instead, pass CONF.tempdir into tempfile.mkdtemp
as the 'dir' keyword argument.

Because we already pass **kwargs to mkdtemp, inspect **kwargs and
only set 'dir' if it's not already there.

Change-Id: I8a2b34cd051919db29facabc1664cf357073b1d7
This commit is contained in:
David Ripton
2013-05-28 10:49:19 -04:00
parent ca3d4590d3
commit a3f2880400

View File

@@ -920,8 +920,10 @@ def temporary_chown(path, owner_uid=None):
@contextlib.contextmanager
def tempdir(**kwargs):
tempfile.tempdir = CONF.tempdir
tmpdir = tempfile.mkdtemp(**kwargs)
argdict = kwargs.copy()
if 'dir' not in argdict:
argdict['dir'] = CONF.tempdir
tmpdir = tempfile.mkdtemp(**argdict)
try:
yield tmpdir
finally: