From 8a2e841b8d211f117c56e4d9936a198d42874ceb Mon Sep 17 00:00:00 2001 From: Terry Cain Date: Tue, 28 Apr 2020 15:26:39 +0100 Subject: [PATCH] Fixed infinite recursion in dodgy findfiles function --- main.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 60fea64..919649d 100644 --- a/main.go +++ b/main.go @@ -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 @@ -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 @@ -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)