diff options
author | Zac Medico <zmedico@gentoo.org> | 2006-02-18 02:25:24 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2006-02-18 02:25:24 +0000 |
commit | d3a25383afc3d97f528800701847ba4edfd38193 (patch) | |
tree | 177731077dd9f96253c9c0607d60ba71530170b8 | |
parent | cedd37d9e27625b3b92b7efcd4630cb7e1481563 (diff) | |
download | portage-d3a25383afc3d97f528800701847ba4edfd38193.tar.gz portage-d3a25383afc3d97f528800701847ba4edfd38193.tar.bz2 portage-d3a25383afc3d97f528800701847ba4edfd38193.zip |
Add a cleanup() method to xpak.tbz2 and do a sanity check there.
svn path=/main/trunk/; revision=2730
-rw-r--r-- | pym/portage.py | 2 | ||||
-rw-r--r-- | pym/xpak.py | 23 |
2 files changed, 19 insertions, 6 deletions
diff --git a/pym/portage.py b/pym/portage.py index 91ed17e71..9ead23fdb 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -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): diff --git a/pym/xpak.py b/pym/xpak.py index ef6d2905a..5cb2d61ab 100644 --- a/pym/xpak.py +++ b/pym/xpak.py @@ -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.""" |