about summary refs log tree commit diff
path: root/templater/templater.go
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-09-04T09·56+0100
committerVincent Ambo <github@tazj.in>2019-09-04T10·15+0100
commitd0f52766b35a9ccccb131fbbb33f6398ea6042d2 (patch)
treeb62ab71d395159f3c858f1144e5987ac41968b35 /templater/templater.go
parent75a3cd2534bb9138b3f42f4591a65a954c2be9b4 (diff)
fix(context): Ensure resource set paths are made absolute
Resolving of files (for `insertFile` and `insertTemplate`) should
always be relative to the resource set location, the previous
behaviour was considered a bug.

This is fixed by ensuring that resource set paths are absolute at
context loading time.
Diffstat (limited to 'templater/templater.go')
-rw-r--r--templater/templater.go9
1 files changed, 4 insertions, 5 deletions
diff --git a/templater/templater.go b/templater/templater.go
index 55b64766ce8c..6cf8a4c2e2de 100644
--- a/templater/templater.go
+++ b/templater/templater.go
@@ -62,8 +62,7 @@ func LoadAndApplyTemplates(include *[]string, exclude *[]string, c *context.Cont
 func processResourceSet(ctx *context.Context, rs *context.ResourceSet) (*RenderedResourceSet, error) {
 	fmt.Fprintf(os.Stderr, "Loading resources for %s\n", rs.Name)
 
-	resourcePath := path.Join(ctx.BaseDir, rs.Path)
-	fileInfo, err := os.Stat(resourcePath)
+	fileInfo, err := os.Stat(rs.Path)
 	if err != nil {
 		return nil, err
 	}
@@ -78,13 +77,13 @@ func processResourceSet(ctx *context.Context, rs *context.ResourceSet) (*Rendere
 		// list of files instead.
 		// This will end up printing a warning to the user, but it
 		// won't stop the rest of the process.
-		files, _ = ioutil.ReadDir(resourcePath)
+		files, _ = ioutil.ReadDir(rs.Path)
 		resources, err = processFiles(ctx, rs, files)
 		if err != nil {
 			return nil, err
 		}
 	} else {
-		resource, err := templateFile(ctx, rs, resourcePath)
+		resource, err := templateFile(ctx, rs, rs.Path)
 		if err != nil {
 			return nil, err
 		}
@@ -104,7 +103,7 @@ func processFiles(ctx *context.Context, rs *context.ResourceSet, files []os.File
 
 	for _, file := range files {
 		if !file.IsDir() && isResourceFile(file) {
-			path := path.Join(ctx.BaseDir, rs.Path, file.Name())
+			path := path.Join(rs.Path, file.Name())
 			res, err := templateFile(ctx, rs, path)
 
 			if err != nil {