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 shahpr
Recipients shahpr
Date 2011-04-06.18:42:53
SpamBayes Score 3.2449539e-09
Marked as misclassified No
Message-id <1302115375.88.0.984018215443.issue11787@psf.upfronthosting.co.za>
In-reply-to
Content
I ran into a problem the other day while trying to extract a slightly corrupted tar file.  I suspect this problem is really only an issue on Windows systems.  I am running Python 2.7.1 r271:86832 win32.

The following code (simplified) snipet

try:
	tar = tarfile.open(args.file)
	tar.extractall(basefolder)
	tar.close()
except tarfile.ReadError:
	shutil.rmtree(basefolder)
except IOError:
	shutil.rmtree(basefolder)

was throwing a WindowsError on the rmtree calls.

This is due to the tarfile library not closing file handles in the case of an exception in the copyfileobj function, and Windows inability to delete open files.  

I was able to patch the issue locally by modifying tarfile's makefile function as follows:

    def makefile(self, tarinfo, targetpath):
        """Make a file called targetpath.
        """
        source = self.extractfile(tarinfo)
        target = bltn_open(targetpath, "wb")
        try:
            copyfileobj(source, target)
        except:
            source.close()
            target.close()
            raise
        source.close()
        target.close()

There is probably a cleaner way of implementing it.

I'm hoping you can integrate this patch into later versions of the lib.

Thanks.
History
Date User Action Args
2011-04-06 18:42:55shahprsetrecipients: + shahpr
2011-04-06 18:42:55shahprsetmessageid: <1302115375.88.0.984018215443.issue11787@psf.upfronthosting.co.za>
2011-04-06 18:42:54shahprlinkissue11787 messages
2011-04-06 18:42:53shahprcreate