Skip to content

Commit

Permalink
add support for puppetfile purge_level
Browse files Browse the repository at this point in the history
  • Loading branch information
xorpaul committed Aug 15, 2019
1 parent a4815e0 commit 42ec212
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions puppetfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,21 @@ func purgeUnmanagedContent(envBranch string, allBasedirs map[string]bool, allEnv
environments, _ := filepath.Glob(globPath)

for _, env := range environments {
envPath := strings.Split(env, "/")
envName := envPath[len(envPath)-1]
if stringSliceContains(config.PurgeLevels, "environment") {
checkForStaleContent(env)
if allEnvironments[envName] {
checkForStaleContent(env)
}
}
if stringSliceContains(config.PurgeLevels, "deployment") {
envPath := strings.Split(env, "/")
env = envPath[len(envPath)-1]
Debugf("Checking if environment should exist: " + env)
if allEnvironments[env] {
Debugf("Leaving environment: " + env)
Debugf("Checking if environment should exist: " + envName)
if allEnvironments[envName] {
Debugf("Leaving environment: " + envName)
} else {
Debugf("Deleting environment: " + env)
Debugf("Deleting environment: " + envName)
if !dryRun {
purgeDir(basedir+env, "purgeStaleContent()")
purgeDir(basedir+envName, "purgeStaleContent()")
}
}
}
Expand Down Expand Up @@ -463,9 +465,9 @@ func resolvePuppetfile(allPuppetfiles map[string]Puppetfile) {
if strings.HasSuffix(d, ".resource_types") && isDir(d) {
continue
}
Debugf("Removing unmanaged path " + d)
if err := os.RemoveAll(d); err != nil {
Debugf("Error while trying to remove unmanaged file " + d)
Infof("Removing unmanaged path " + d)
if !dryRun {
purgeDir(d, "purge_level puppetfile")
}
}
}
Expand Down

0 comments on commit 42ec212

Please sign in to comment.