Refactor softlink functions to remove repetition and add flexibility
Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
@@ -125,10 +125,14 @@ func createIgnitionJson(node *node.Node) string {
|
||||
}
|
||||
|
||||
func importSoftlink(lnk string) string {
|
||||
path, err := filepath.EvalSymlinks(lnk)
|
||||
target, err := filepath.EvalSymlinks(lnk)
|
||||
if err != nil {
|
||||
return "abort"
|
||||
}
|
||||
wwlog.Debug("importing softlink pointing to: %s", path)
|
||||
return fmt.Sprintf("{{ /* softlink \"%s\" */ }}", path)
|
||||
wwlog.Debug("importing softlink pointing to: %s", target)
|
||||
return softlink(target)
|
||||
}
|
||||
|
||||
func softlink(target string) string {
|
||||
return fmt.Sprintf("{{ /* softlink \"%s\" */ }}", target)
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ func BuildOverlayIndir(nodeData node.Node, overlayNames []string, outputDir stri
|
||||
wwlog.Debug("Creating soft link %s -> %s", destFileName, softlinkFromTemplate[0][1])
|
||||
return os.Symlink(softlinkFromTemplate[0][1], path.Join(outputDir, destFileName))
|
||||
} else if len(filenameFromTemplate) != 0 {
|
||||
wwlog.Debug("Found multiple comment, new filename %s", filenameFromTemplate[0][1])
|
||||
wwlog.Debug("Writing file %s", filenameFromTemplate[0][1])
|
||||
if foundFileComment {
|
||||
err = CarefulWriteBuffer(path.Join(outputDir, destFileName),
|
||||
fileBuffer, backupFile, info.Mode())
|
||||
@@ -381,7 +381,8 @@ func RenderTemplateFile(fileName string, data TemplateStruct) (
|
||||
"inc": func(i int) int { return i + 1 },
|
||||
"dec": func(i int) int { return i - 1 },
|
||||
"file": func(str string) string { return fmt.Sprintf("{{ /* file \"%s\" */ }}", str) },
|
||||
"softlink": func(str string) string { return fmt.Sprintf("{{ /* softlink \"%s\" */ }}", str) },
|
||||
"softlink": softlink,
|
||||
"readlink": filepath.EvalSymlinks,
|
||||
"IgnitionJson": func() string {
|
||||
str := createIgnitionJson(data.ThisNode)
|
||||
if str != "" {
|
||||
|
||||
Reference in New Issue
Block a user