X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;ds=inline;f=daklib%2Fbinary.py;h=f9cf2437fe55f09ffed0218bf735628b07a2c764;hb=f96dff8bac6b5d13eceb2bf1bbe59d5998a27cce;hp=70133db693e3f731f930187fe6039894f2b49b69;hpb=fdf3c42445b4f11f4cd71634dd2b57cb7d7a4f36;p=dak.git diff --git a/daklib/binary.py b/daklib/binary.py index 70133db6..f9cf2437 100755 --- a/daklib/binary.py +++ b/daklib/binary.py @@ -30,6 +30,7 @@ import tempfile import tarfile import commands import traceback +import atexit from debian_bundle import deb822 from dbconn import DBConn @@ -40,9 +41,18 @@ class Binary(object): self.chunks = None def __del__(self): - # we need to remove the temporary directory, if we created one + """ + make sure we cleanup when we are garbage collected. + """ + self._cleanup() + + def _cleanup(self): + """ + we need to remove the temporary directory, if we created one + """ if self.tmpdir and os.path.exists(self.tmpdir): shutil.rmtree(self.tmpdir) + self.tmpdir = None def __scan_ar(self): # get a list of the ar contents @@ -75,6 +85,7 @@ class Binary(object): reject(utils.prefix_multi_line_string(output, " [ar output:] "), "") else: self.tmpdir = tmpdir + atexit.register( self._cleanup ) finally: os.chdir( cwd ) @@ -123,8 +134,6 @@ class Binary(object): os.chdir(self.tmpdir) if self.chunks[1] == "control.tar.gz": control = tarfile.open(os.path.join(self.tmpdir, "control.tar.gz" ), "r:gz") - elif self.chunks[1] == "control.tar.bz2": - control = tarfile.open(os.path.join(self.tmpdir, "control.tar.bz2" ), "r:bz2") pkg = deb822.Packages.iter_paragraphs( control.extractfile('./control') ).next() @@ -133,7 +142,7 @@ class Binary(object): elif self.chunks[2] == "data.tar.bz2": data = tarfile.open(os.path.join(self.tmpdir, "data.tar.bz2" ), "r:bz2") - return DBConn().insert_content_paths(pkg, [ tarinfo.name for tarinfo in data if tarinfo.isdir()]) + return DBConn().insert_content_paths(pkg, [ tarinfo.name for tarinfo in data if not tarinfo.isdir()]) except: traceback.print_exc()