Message75530
If the disk fills up during the copy operation, shutil.copyfile() leaks
file descriptors.
The problem is the order of the close() statements in the finally block.
In the event the copy operation runs out of disk space, the fdst.close()
call triggers an IOError, which prevents the fsrc.close() call from being
called.
Swapping the two calls, so that fsrc is closed first prevents this issue,
though it doesn't solve the underlying problem that IOErrors raised during
the close() operation will prevent the second close() from being called.
A probably better solution:
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)
fsrc = None
fdst = None
try:
fsrc = open(src, 'rb')
fdst = open(dst, 'wb')
copyfileobj(fsrc, fdst)
finally:
try:
if fsrc:
fsrc.close()
finally:
if fdst:
fdst.close() |
|
Date |
User |
Action |
Args |
2008-11-05 20:26:18 | ammon_riley | set | recipients:
+ ammon_riley |
2008-11-05 20:26:18 | ammon_riley | set | messageid: <1225916778.37.0.308517210859.issue4265@psf.upfronthosting.co.za> |
2008-11-05 20:24:46 | ammon_riley | link | issue4265 messages |
2008-11-05 20:24:45 | ammon_riley | create | |
|