diff options
author | Tarek Ziadé <ziade.tarek@gmail.com> | 2010-05-05 22:39:31 (GMT) |
---|---|---|
committer | Tarek Ziadé <ziade.tarek@gmail.com> | 2010-05-05 22:39:31 (GMT) |
commit | 9623980d01dae6218ef74d00bb9b1e866cfce135 (patch) | |
tree | ba80d8c10fb5d3ba9e736a4262ad8358e2ab29e9 /Lib/shutil.py | |
parent | bc5f75cca215fa52cb6f5dec1c3045ecf6fe24cd (diff) | |
download | cpython-9623980d01dae6218ef74d00bb9b1e866cfce135.zip cpython-9623980d01dae6218ef74d00bb9b1e866cfce135.tar.gz cpython-9623980d01dae6218ef74d00bb9b1e866cfce135.tar.bz2 |
Merged revisions 80833 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r80833 | tarek.ziade | 2010-05-06 00:27:31 +0200 (Thu, 06 May 2010) | 9 lines
Merged revisions 80830 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r80830 | tarek.ziade | 2010-05-06 00:15:31 +0200 (Thu, 06 May 2010) | 1 line
Fixed #4265: shutil.copyfile() was leaking file descriptors when disk fills
........
................
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r-- | Lib/shutil.py | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py index 78504b9..2befb47 100644 --- a/Lib/shutil.py +++ b/Lib/shutil.py @@ -63,15 +63,10 @@ def copyfile(src, dst): # XXX What about other special files? (sockets, devices...) if stat.S_ISFIFO(st.st_mode): raise SpecialFileError("`%s` is a named pipe" % fn) - try: - fsrc = open(src, 'rb') - fdst = open(dst, 'wb') - copyfileobj(fsrc, fdst) - finally: - if fdst: - fdst.close() - if fsrc: - fsrc.close() + + with open(src, 'rb') as fsrc: + with open(dst, 'wb') as fdst: + copyfileobj(fsrc, fdst) def copymode(src, dst): """Copy mode bits from src to dst""" |