Message133153
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. |
|
Date |
User |
Action |
Args |
2011-04-06 18:42:55 | shahpr | set | recipients:
+ shahpr |
2011-04-06 18:42:55 | shahpr | set | messageid: <1302115375.88.0.984018215443.issue11787@psf.upfronthosting.co.za> |
2011-04-06 18:42:54 | shahpr | link | issue11787 messages |
2011-04-06 18:42:53 | shahpr | create | |
|