Skip to content

Commit

Permalink
cluster: not deleting anythin if data dir is under log dir
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroProfundis committed Dec 10, 2020
1 parent 5bb5a04 commit a1d60ea
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pkg/cluster/operation/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,19 +308,33 @@ func CleanupComponent(getter ExecutorGetter, instances []spec.Instance, cls spec
log.Infof("Cleanup instance %s", ins.GetHost())

delFiles := set.NewStringSet()
dataPaths := set.NewStringSet()
logPaths := set.NewStringSet()

if options.CleanupData && len(ins.DataDir()) > 0 {
for _, dataDir := range strings.Split(ins.DataDir(), ",") {
delFiles.Insert(path.Join(dataDir, "*"))
dataPaths.Insert(path.Join(dataDir, "*"))
}
}

if options.CleanupLog && len(ins.LogDir()) > 0 {
for _, logDir := range strings.Split(ins.LogDir(), ",") {
delFiles.Insert(path.Join(logDir, "*"))
logPaths.Insert(path.Join(logDir, "*.log"))
}
}

for _, lp := range logPaths.Slice() {
for _, dp := range dataPaths.Slice() {
// remove path of log dir from list if any data dir is under it
if strings.HasPrefix(dp, lp) {
logPaths.Remove(lp)
break
}
}
}

delFiles.Join(logPaths).Join(dataPaths)

log.Debugf("Deleting paths on %s: %s", ins.GetHost(), strings.Join(delFiles.Slice(), " "))
c := module.ShellModuleConfig{
Command: fmt.Sprintf("rm -rf %s;", strings.Join(delFiles.Slice(), " ")),
Expand Down
8 changes: 8 additions & 0 deletions pkg/set/string_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ func (s StringSet) Insert(val string) {
s[val] = struct{}{}
}

// Join add all elements of `add` to `s`.
func (s StringSet) Join(add StringSet) StringSet {
for elt := range add {
s.Insert(elt)
}
return s
}

// Intersection returns the intersection of two sets
func (s StringSet) Intersection(rhs StringSet) StringSet {
newSet := NewStringSet()
Expand Down

0 comments on commit a1d60ea

Please sign in to comment.