summaryrefslogtreecommitdiffstats
path: root/Lib/shutil.py
diff options
context:
space:
mode:
authorTarek Ziadé <ziade.tarek@gmail.com>2010-05-05 22:15:31 (GMT)
committerTarek Ziadé <ziade.tarek@gmail.com>2010-05-05 22:15:31 (GMT)
commit38f81223ae3e26933faeef1e697d5e4ac978cf45 (patch)
tree54a454fc7b93df34fa5926e079ec18466745b8f7 /Lib/shutil.py
parent9319548e56f108ee46d0f14c06d39a9ff9612a40 (diff)
downloadcpython-38f81223ae3e26933faeef1e697d5e4ac978cf45.zip
cpython-38f81223ae3e26933faeef1e697d5e4ac978cf45.tar.gz
cpython-38f81223ae3e26933faeef1e697d5e4ac978cf45.tar.bz2
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 703b3b5..f02a2d9 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -79,15 +79,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"""