summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-02-18 02:25:24 +0000
committerZac Medico <zmedico@gentoo.org>2006-02-18 02:25:24 +0000
commitd3a25383afc3d97f528800701847ba4edfd38193 (patch)
tree177731077dd9f96253c9c0607d60ba71530170b8 /pym/xpak.py
parentAdd a return value to fixdbentries that indicates whether or not modification... (diff)
downloadportage-idfetch-d3a25383afc3d97f528800701847ba4edfd38193.tar.gz
portage-idfetch-d3a25383afc3d97f528800701847ba4edfd38193.tar.bz2
portage-idfetch-d3a25383afc3d97f528800701847ba4edfd38193.zip
Add a cleanup() method to xpak.tbz2 and do a sanity check there.
svn path=/main/trunk/; revision=2730
Diffstat (limited to 'pym/xpak.py')
-rw-r--r--pym/xpak.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/pym/xpak.py b/pym/xpak.py
index ef6d2905..5cb2d61a 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."""