From 6362fad61f0d53cfe95d3c3bec54642b0e198742 Mon Sep 17 00:00:00 2001 From: Wyatt Dahlenburg Date: Fri, 24 Jul 2020 15:29:08 -0500 Subject: [PATCH] Updated runner to ensure relative path was respected in configuration file when using wildcards --- v2/internal/runner/runner.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/v2/internal/runner/runner.go b/v2/internal/runner/runner.go index dc88d462..71e1a157 100644 --- a/v2/internal/runner/runner.go +++ b/v2/internal/runner/runner.go @@ -125,19 +125,30 @@ func (r *Runner) RunEnumeration() { // parses user input, handle file/directory cases and produce a list of unique templates for _, t := range r.options.Templates { - // resolve and convert relative to absolute path - absPath, err := r.resolvePathIfRelative(t) - if err != nil && !strings.Contains(t, "*") { + var absPath string + var err error + + if strings.Contains(t, "*") { + dirs := strings.Split(t, "/") + priorDir := strings.Join(dirs[:len(dirs)-1], "/") + absPath, err = r.resolvePathIfRelative(priorDir) + absPath += "/" + dirs[len(dirs)-1] + } else { + // resolve and convert relative to absolute path + absPath, err = r.resolvePathIfRelative(t) + } + + if err != nil { gologger.Errorf("Could not find template file '%s': %s\n", t, err) continue } // Template input includes a wildcard - if strings.Contains(t, "*") { + if strings.Contains(absPath, "*") { matches := []string{} - matches, err = filepath.Glob(t) + matches, err = filepath.Glob(absPath) if err != nil { - gologger.Labelf("Wildcard found, but unable to glob '%s': %s\n", t, err) + gologger.Labelf("Wildcard found, but unable to glob '%s': %s\n", absPath, err) continue } @@ -147,7 +158,7 @@ func (r *Runner) RunEnumeration() { // couldn't find templates in directory if len(matches) == 0 { - gologger.Labelf("Error, no templates were found with '%s'.\n", t) + gologger.Labelf("Error, no templates were found with '%s'.\n", absPath) continue } else { gologger.Labelf("Identified %d templates\n", len(matches))