From d3a25383afc3d97f528800701847ba4edfd38193 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 18 Feb 2006 02:25:24 +0000 Subject: Add a cleanup() method to xpak.tbz2 and do a sanity check there. svn path=/main/trunk/; revision=2730 --- pym/xpak.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'pym/xpak.py') 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.""" -- cgit v1.2.3-1-g7c22