summaryrefslogtreecommitdiffstats
path: root/Lib/shutil.py
diff options
context:
space:
mode:
authorTarek Ziadé <ziade.tarek@gmail.com>2010-05-05 22:27:31 (GMT)
committerTarek Ziadé <ziade.tarek@gmail.com>2010-05-05 22:27:31 (GMT)
commitae4d5c6b643c3efeb5f7b43ca9108978b388ab34 (patch)
tree3c90532bd61cd839e57c9577aae0bfa63977d8ca /Lib/shutil.py
parent55f8ae28a1c3364a8f637b9f1301697cb6926253 (diff)
downloadcpython-ae4d5c6b643c3efeb5f7b43ca9108978b388ab34.zip
cpython-ae4d5c6b643c3efeb5f7b43ca9108978b388ab34.tar.gz
cpython-ae4d5c6b643c3efeb5f7b43ca9108978b388ab34.tar.bz2
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.py12
1 files changed, 3 insertions, 9 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py
index 601d9c2..74a4db8 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -96,15 +96,9 @@ 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"""