Fixed #4265: shutil.copyfile() was leaking file descriptors when disk fills

This commit is contained in:
Tarek Ziadé 2010-05-05 22:15:31 +00:00
parent 9319548e56
commit 38f81223ae
3 changed files with 112 additions and 10 deletions

View file

@ -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"""