This repository has been archived by the owner on Feb 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Now using Go's `MkdirAll` and `RemoveAll` instead of exec'ing shell commands
- Loading branch information
Showing
5 changed files
with
85 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package util | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
) | ||
|
||
// ListComponentInstallDirectories returns all subdirectories in `directory` which have have the name | ||
// "components" or "helm_repos"; this is mainly used as a helper function for cleaning up test `Install`s | ||
func ListComponentInstallDirectories(directory string) (componentDirs []string, err error) { | ||
err = filepath.Walk(directory, func(path string, file os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if file.IsDir() { | ||
if match, err := regexp.MatchString("/(components|helm_repos)$", path); match && err == nil { | ||
componentDirs = append(componentDirs, path) | ||
} | ||
} | ||
return nil | ||
}) | ||
|
||
return componentDirs, err | ||
} | ||
|
||
// UninstallComponents uninstalls any components in any subdirectory under `path`. | ||
// Equivalent to `rm -rf **/components **/helm_repos` | ||
func UninstallComponents(path string) (err error) { | ||
dirsToClean, err := ListComponentInstallDirectories(path) | ||
if err != nil { | ||
return err | ||
} | ||
for _, dir := range dirsToClean { | ||
if err = os.RemoveAll(dir); err != nil { | ||
return err | ||
} | ||
} | ||
return err | ||
} |