Skip to content
This repository has been archived by the owner on Jul 6, 2021. It is now read-only.

Commit

Permalink
Fixed infinite recursion in dodgy findfiles function
Browse files Browse the repository at this point in the history
  • Loading branch information
terricain committed Apr 28, 2020
1 parent f544d6d commit 8a2e841
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ func main() {
os.Exit(1)
}

files := FindFiles(cwd, cli.Recursive, cli.Paths)
paths := append([]string{}, cli.Paths...)
if len(paths) == 0 {
paths = append(paths, cwd)
}

files := FindFiles(cli.Recursive, paths)

modifyFiles := !cli.Check && !cli.Diff

Expand Down Expand Up @@ -90,13 +95,9 @@ func filePlural(count int) string {
}

// FindFiles Finds .tf files
func FindFiles(cwd string, recursive bool, paths []string) []string {
func FindFiles(recursive bool, paths []string) []string {
files := []string{}

if len(paths) == 0 {
paths = append(paths, cwd)
}

for _, currentPath := range paths {
if strings.HasSuffix(currentPath, ".git") || strings.HasSuffix(currentPath, ".terraform") {
continue
Expand Down Expand Up @@ -124,7 +125,7 @@ func FindFiles(cwd string, recursive bool, paths []string) []string {
}
}

files = append(files, FindFiles(cwd, recursive, newFiles)...)
files = append(files, FindFiles(recursive, newFiles)...)
case mode.IsRegular():
if strings.HasSuffix(currentPath, ".tf") {
files = append(files, currentPath)
Expand Down

0 comments on commit 8a2e841

Please sign in to comment.