Issue #16800: tempfile.gettempdir() no longer left temporary files when

the disk is full.  Original patch by Amir Szekely.
This commit is contained in:
Serhiy Storchaka 2013-02-13 00:38:48 +02:00
commit 94cd10fa19
4 changed files with 51 additions and 6 deletions

View file

@ -174,11 +174,14 @@ def _get_default_tempdir():
filename = _os.path.join(dir, name)
try:
fd = _os.open(filename, _bin_openflags, 0o600)
fp = _io.open(fd, 'wb')
fp.write(b'blat')
fp.close()
_os.unlink(filename)
del fp, fd
try:
try:
fp = _io.open(fd, 'wb', buffering=0, closefd=False)
fp.write(b'blat')
finally:
_os.close(fd)
finally:
_os.unlink(filename)
return dir
except FileExistsError:
pass