changeset 341:cb5219f9d3b7

* Don't use `os.path.commonprefix()` to detect the base directory in the snapshort archive. Fixes #103. * Catch exceptions other than `BuildError`s in the build, and make them fail the build. Closes #97. * An attempt to address the memory leak reported in #76. Not sure whether this actually has any effect :-P
author cmlenz
date Wed, 12 Apr 2006 09:38:09 +0000
parents 222c77e55315
children 59d770fefae1
files bitten/slave.py bitten/snapshot.py
diffstat 2 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/bitten/slave.py
+++ b/bitten/slave.py
@@ -166,18 +166,19 @@
         try:
             tar_file = tarfile.open(path, 'r:bz2')
             tar_file.chown = lambda *args: None # Don't chown extracted members
+            basedir = None
             try:
-                names = []
                 for tarinfo in tar_file:
                     if tarinfo.isfile() or tarinfo.isdir():
                         if tarinfo.name.startswith('/') or '..' in tarinfo.name:
                             continue
-                        names.append(tarinfo.name)
                         tar_file.extract(tarinfo, project_dir)
+                        if basedir is None:
+                            basedir = tarinfo.name.split('/', 1)[0]
             finally:
                 tar_file.close()
 
-            basedir = os.path.join(project_dir,  os.path.commonprefix(names))
+            basedir = os.path.join(project_dir,  basedir)
             log.debug('Unpacked snapshot to %s' % basedir)
             return basedir
 
@@ -221,8 +222,12 @@
                                 output
                             ])
                     except BuildError, e:
-                        log.error('Build step %s failed', step.id)
-                        failed = True
+                        log.error('Build step %s failed (%s)', step.id, e)
+                        failed = step_failed = True
+                    except Exception, e:
+                        log.error('Internal error in build step %s',
+                                  step.id, exc_info=True)
+                        failed = step_failed = True
                     xml.attr['duration'] = (datetime.utcnow() - started).seconds
                     if step_failed:
                         xml.attr['result'] = 'failure'
--- a/bitten/snapshot.py
+++ b/bitten/snapshot.py
@@ -229,6 +229,8 @@
                     base_info.name = new_path
                     fileobj = base_tar.extractfile(base_info)
                     new_tar.addfile(base_info, fileobj)
+                    fileobj.close()
+                    del base_info, fileobj
 
                 else:
                     # Create entry from repository
Copyright (C) 2012-2017 Edgewall Software