mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Issue #16800: tempfile.gettempdir() no longer left temporary files when
the disk is full. Original patch by Amir Szekely.
This commit is contained in:
parent
cdc7a91dde
commit
0127de0b87
5 changed files with 93 additions and 12 deletions
|
@ -29,6 +29,7 @@ __all__ = [
|
|||
|
||||
# Imports.
|
||||
|
||||
import io as _io
|
||||
import os as _os
|
||||
import errno as _errno
|
||||
from random import Random as _Random
|
||||
|
@ -193,14 +194,17 @@ def _get_default_tempdir():
|
|||
name = namer.next()
|
||||
filename = _os.path.join(dir, name)
|
||||
try:
|
||||
fd = _os.open(filename, flags, 0600)
|
||||
fp = _os.fdopen(fd, 'w')
|
||||
fp.write('blat')
|
||||
fp.close()
|
||||
_os.unlink(filename)
|
||||
del fp, fd
|
||||
fd = _os.open(filename, flags, 0o600)
|
||||
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 (OSError, IOError), e:
|
||||
except (OSError, IOError) as e:
|
||||
if e[0] != _errno.EEXIST:
|
||||
break # no point trying more names in this directory
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue