This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ammon_riley
Recipients ammon_riley
Date 2008-11-05.20:24:45
SpamBayes Score 0.00024622545
Marked as misclassified No
Message-id <1225916778.37.0.308517210859.issue4265@psf.upfronthosting.co.za>
In-reply-to
Content
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()
History
Date User Action Args
2008-11-05 20:26:18ammon_rileysetrecipients: + ammon_riley
2008-11-05 20:26:18ammon_rileysetmessageid: <1225916778.37.0.308517210859.issue4265@psf.upfronthosting.co.za>
2008-11-05 20:24:46ammon_rileylinkissue4265 messages
2008-11-05 20:24:45ammon_rileycreate