fixed linting

This commit is contained in:
Christian Goll
2022-02-16 12:24:08 +01:00
committed by jcsiadal
parent ac1718f1c0
commit 27b28a2a1a
2 changed files with 6 additions and 3 deletions

View File

@@ -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)

View File

@@ -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"))