Mercurial > cpython-lru_cache-weakref
diff Lib/tempfile.py @ 9447:25b6929ffb13 legacy-trunk
Improvement to the previous fix suggested by Thomas Bellman: if the
unlink() or fdopen() fail, close the file descriptor and re-raise the
exception.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sat, 24 Oct 1998 15:02:59 +0000 |
| parents | 56217eabc07a |
| children | 17ca2f64b6d6 |
line wrap: on
line diff
--- a/Lib/tempfile.py Sat Oct 24 14:03:48 1998 +0000 +++ b/Lib/tempfile.py Sat Oct 24 15:02:59 1998 +0000 @@ -129,8 +129,12 @@ if os.name == 'posix': # Unix -- be very careful fd = os.open(name, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0700) - os.unlink(name) - return os.fdopen(fd, mode, bufsize) + try: + os.unlink(name) + return os.fdopen(fd, mode, bufsize) + except: + os.close(fd) + raise else: # Non-unix -- can't unlink file that's still open, use wrapper file = open(name, mode, bufsize)
