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
........
This commit is contained in:
Tarek Ziadé 2010-05-05 22:21:13 +00:00
parent 6bb7c4f2ef
commit 06f78cd91e
3 changed files with 113 additions and 13 deletions

View file

@ -45,19 +45,11 @@ def _samefile(src, dst):
def copyfile(src, dst):
"""Copy data from src to dst"""
if _samefile(src, dst):
raise Error, "`%s` and `%s` are the same file" % (src, dst)
raise Error("`%s` and `%s` are the same file" % (src, dst))
fsrc = None
fdst = None
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"""