More cleanups around finding parent paths for keep old.
This commit is contained in:
parent
779de7cd19
commit
ccda4ad4e6
@ -286,11 +286,7 @@ class PkgUninstallComponent(ComponentBase):
|
||||
def __init__(self, component_name, *args, **kargs):
|
||||
ComponentBase.__init__(self, component_name, *args, **kargs)
|
||||
self.tracereader = tr.TraceReader(self.tracedir, tr.IN_TRACE)
|
||||
self.keep_dirs = list()
|
||||
if kargs.get("keep_old"):
|
||||
self.keep_dirs.append(self.appdir)
|
||||
self.keep_dirs.append(self.component_root)
|
||||
self.keep_dirs.append(self.root)
|
||||
self.keep_old = kargs.get("keep_old")
|
||||
|
||||
def unconfigure(self):
|
||||
self._unconfigure_files()
|
||||
@ -346,12 +342,11 @@ class PkgUninstallComponent(ComponentBase):
|
||||
def _uninstall_dirs(self):
|
||||
dirsmade = self.tracereader.dirs_made()
|
||||
if dirsmade:
|
||||
if self.keep_old:
|
||||
dirsmade = sh.remove_parents(self.appdir, dirsmade)
|
||||
for dirname in dirsmade:
|
||||
if dirname in self.keep_dirs:
|
||||
LOG.info("Keeping created directory (%s)" % (dirname))
|
||||
else:
|
||||
LOG.info("Removing created directory (%s)" % (dirname))
|
||||
sh.deldir(dirname, run_as_root=True)
|
||||
LOG.info("Removing created directory (%s)" % (dirname))
|
||||
sh.deldir(dirname, run_as_root=True)
|
||||
|
||||
|
||||
class PythonUninstallComponent(PkgUninstallComponent):
|
||||
|
@ -42,6 +42,7 @@ SHELL_QUOTE_REPLACERS = {
|
||||
}
|
||||
SHELL_WRAPPER = "\"%s\""
|
||||
FALSE_VALS = ['f', 'false', '0', 'off']
|
||||
ROOT_PATH = os.sep
|
||||
|
||||
|
||||
#root context guard
|
||||
@ -266,16 +267,54 @@ def password(pw_prompt=None, pw_len=8):
|
||||
return pw
|
||||
|
||||
|
||||
def _explode_path(path):
|
||||
parts = list()
|
||||
while path != ROOT_PATH:
|
||||
(path, name) = os.path.split(path)
|
||||
parts.append(name)
|
||||
if path == ROOT_PATH:
|
||||
parts.append(path)
|
||||
parts.reverse()
|
||||
return parts
|
||||
|
||||
|
||||
def remove_parents(child_path, paths):
|
||||
if not paths:
|
||||
return list()
|
||||
paths = [abspth(p) for p in paths]
|
||||
paths = [_explode_path(p) for p in paths]
|
||||
child_path = abspth(child_path)
|
||||
child_path = _explode_path(child_path)
|
||||
new_paths = list()
|
||||
for p in paths:
|
||||
if _array_begins_with(p, child_path):
|
||||
pass
|
||||
else:
|
||||
new_paths.append(p)
|
||||
ret_paths = list()
|
||||
for p in new_paths:
|
||||
ret_paths.append("".join(p))
|
||||
return ret_paths
|
||||
|
||||
|
||||
def _array_begins_with(haystack, needle):
|
||||
if len(haystack) >= len(needle):
|
||||
return False
|
||||
for i in range(len(haystack)):
|
||||
if haystack[i] != needle[i]:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def mkdirslist(path):
|
||||
LOG.debug("Determining potential paths to create for target path \"%s\"" % (path))
|
||||
dirs_possible = set()
|
||||
dirs_possible.add(path)
|
||||
|
||||
while True:
|
||||
(base, _) = os.path.split(path)
|
||||
dirs_possible.add(base)
|
||||
path = base
|
||||
if path == os.sep:
|
||||
if path == ROOT_PATH:
|
||||
break
|
||||
#sorting is important so that we go in the right order.. (/ before /tmp and so on)
|
||||
dirs_made = list()
|
||||
|
Loading…
x
Reference in New Issue
Block a user