Add a cleanup() method to xpak.tbz2 and do a sanity check there.
authorZac Medico <zmedico@gentoo.org>
Sat, 18 Feb 2006 02:25:24 +0000 (02:25 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 18 Feb 2006 02:25:24 +0000 (02:25 -0000)
svn path=/main/trunk/; revision=2730

pym/portage.py
pym/xpak.py

index 91ed17e71e4ada820fae730f8b4f46c65c4b7dd6..9ead23fdb9456c113539eee9419d969927b16121 100644 (file)
@@ -5377,6 +5377,8 @@ class binarytree(packagetree):
                        mytbz2.decompose(mytmpdir,cleanup=1)
                        if fixdbentries(mybiglist, mytmpdir):
                                mytbz2.recompose(mytmpdir,cleanup=1)
+                       else:
+                               mytbz2.cleanup(mytmpdir)
                return 1
 
        def populate(self, getbinpkgs=0,getbinpkgsonly=0):
index ef6d2905a8341696041ed01cbda380cf23831bad..5cb2d61ab7af813320700808570d6071fecbac0c 100644 (file)
@@ -16,7 +16,7 @@
 # (integer) == encodeint(integer)  ===> 4 characters (big-endian copy)
 # '+' means concatenate the fields ===> All chunks are strings
 
-import sys,os,string
+import sys,os,string,shutil,errno
 from stat import *
 
 def addtolist(mylist,curdir):
@@ -239,9 +239,8 @@ class tbz2:
                Returns result of upackinfo()."""
                if not self.scan():
                        raise IOError
-               if cleanup and os.path.exists(datadir):
-                       # XXX: Potentially bad
-                       os.system("rm -Rf "+datadir+"/*")
+               if cleanup:
+                       self.cleanup(datadir)
                if not os.path.exists(datadir):
                        os.makedirs(datadir)
                return self.unpackinfo(datadir)
@@ -263,10 +262,22 @@ class tbz2:
                myfile.flush()
                myfile.close()
                if cleanup:
-                       # XXX: Potentially bad
-                       os.system("rm -Rf "+datadir)
+                       self.cleanup(datadir)
                return 1
 
+       def cleanup(self, datadir):
+               datadir_split = os.path.split(datadir)
+               if len(datadir_split) >= 2 and len(datadir_split[1]) > 0:
+                       # This is potentially dangerous,
+                       # thus the above sanity check.
+                       try:
+                               shutil.rmtree(datadir)
+                       except OSError, oe:
+                               if oe.errno == errno.ENOENT:
+                                       pass
+                               else:
+                                       raise oe
+
        def scan(self):
                """Scans the tbz2 to locate the xpak segment and setup internal values.
                This function is called by relevant functions already."""