# HG changeset patch # User cmlenz # Date 1144834689 0 # Node ID cb5219f9d3b70cea69b89b05a4c6f68a7076b257 # Parent 222c77e55315d29a969dde3685447ba790c832fc * 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 diff --git a/bitten/slave.py b/bitten/slave.py --- 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' diff --git a/bitten/snapshot.py b/bitten/snapshot.py --- 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