]> git.decadent.org.uk Git - dak.git/blobdiff - daklib/binary.py
Merge branch 'master' into content_generation
[dak.git] / daklib / binary.py
index 70133db693e3f731f930187fe6039894f2b49b69..f9cf2437fe55f09ffed0218bf735628b07a2c764 100755 (executable)
@@ -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()