diff options
Diffstat (limited to 'morphlib/bins.py')
-rw-r--r-- | morphlib/bins.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/morphlib/bins.py b/morphlib/bins.py index 95566f39..622aa165 100644 --- a/morphlib/bins.py +++ b/morphlib/bins.py @@ -26,9 +26,24 @@ import os import re import errno import stat +import shutil import tarfile +# Work around http://bugs.python.org/issue16477 +def safe_makefile(self, tarinfo, targetpath): + '''Create a file, closing correctly in case of exception''' + + source = self.extractfile(tarinfo) + try: + with open(targetpath, "wb") as target: + shutil.copyfileobj(source, target) + finally: + source.close() + +tarfile.TarFile.makefile = safe_makefile + + def create_chunk(rootdir, f, regexps, dump_memory_profile=None): '''Create a chunk from the contents of a directory. |