From 27b28a2a1a00bed4d7acc8b1a26be72f7002b87e Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Wed, 16 Feb 2022 12:24:08 +0100 Subject: [PATCH] fixed linting --- internal/pkg/overlay/funcmap.go | 2 +- internal/pkg/overlay/overlay.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/pkg/overlay/funcmap.go b/internal/pkg/overlay/funcmap.go index 3a2477e7..e40e0c98 100644 --- a/internal/pkg/overlay/funcmap.go +++ b/internal/pkg/overlay/funcmap.go @@ -41,10 +41,10 @@ func templateFileBlock(inc string, abortStr string) (string, error) { } wwlog.Printf(wwlog.DEBUG, "Including file block into template: %s\n", inc) readFile, err := os.Open(inc) - defer readFile.Close() if err != nil { return "", err } + defer readFile.Close() var cont string fileScanner := bufio.NewScanner(readFile) fileScanner.Split(bufio.ScanLines) diff --git a/internal/pkg/overlay/overlay.go b/internal/pkg/overlay/overlay.go index 789d48fd..323f4a96 100644 --- a/internal/pkg/overlay/overlay.go +++ b/internal/pkg/overlay/overlay.go @@ -273,18 +273,21 @@ func BuildOverlay(nodeInfo node.NodeInfo, overlayName string) error { return errors.Wrap(err, "could not parse template "+location) } var buffer bytes.Buffer - err = tmpl.Execute(&buffer, tstruct) backupFile := true + writeFile := true + err = tmpl.Execute(&buffer, tstruct) if err != nil { // complicated workarround as error is not exported correctly: https://github.com/golang/go/issues/34201 if strings.Contains(fmt.Sprint(err), "abort_template") { wwlog.Printf(wwlog.VERBOSE, "Aborting template file due to abort call in template: %s\n", location) + writeFile = false } else if strings.Contains(fmt.Sprint(err), "nobackup_template") { backupFile = false } else { return errors.Wrap(err, "could not execute template") } - } else { + } + if writeFile { if backupFile { if !util.IsFile(path.Join(destDir, destFile+".wwbackup")) { err = util.CopyFile(path.Join(destDir, destFile), path.Join(destDir, destFile+".wwbackup"))