From 3ecd1056bc7f83e13295d35e8bd752c3bffb9d37 Mon Sep 17 00:00:00 2001 From: Gregory Kurtzer Date: Sun, 1 Nov 2020 22:06:03 -0800 Subject: [PATCH] Minor fixups around non existent files for timestamps --- cmd/wwbuild/wwbuild.go | 21 +++++++++++++++------ internal/pkg/util/util.go | 6 +++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/cmd/wwbuild/wwbuild.go b/cmd/wwbuild/wwbuild.go index 9094f740..f8e7e52c 100644 --- a/cmd/wwbuild/wwbuild.go +++ b/cmd/wwbuild/wwbuild.go @@ -9,6 +9,7 @@ import ( "os/exec" "path" "strings" + "time" ) @@ -72,11 +73,12 @@ func main(){ } } } else if os.Args[1] == "overlay" { - fmt.Printf("note: This needs to create an overlay for each node with macro expansions\n") - + //TODO: Move this all to warewulfd and generate on demand when needed for _, node := range assets.FindAllNodes() { overlayDir := fmt.Sprintf("/etc/warewulf/overlays/%s", node.Overlay) + + //TODO: Move this all to the Asset package replace := make(map[string]string) replace["HOSTNAME"] = node.HostName replace["FQDN"] = node.Fqdn @@ -94,13 +96,20 @@ func main(){ destFile := fmt.Sprintf("%s/provision/overlays/%s.img", LocalStateDir, node.Fqdn) - destMod, _ := os.Stat(destFile) - destModTime := destMod.ModTime() + destModTime := time.Time{} + destMod, err := os.Stat(destFile) + if err == nil { + destModTime = destMod.ModTime() + } - configMod, _ := os.Stat("/etc/warewulf/nodes.yaml") + configMod, err := os.Stat("/etc/warewulf/nodes.yaml") + if err != nil { + fmt.Printf("ERROR: could not find node file: /etc/warewulf/nodes.yaml") + os.Exit(1) + } configModTime := configMod.ModTime() - sourceModTime := util.DirModTime(overlayDir) + sourceModTime, _ := util.DirModTime(overlayDir) if sourceModTime.After(destModTime) || configModTime.After(destModTime) { fmt.Printf("BUILDING OVERLAY: %s\n", node.Fqdn) diff --git a/internal/pkg/util/util.go b/internal/pkg/util/util.go index ee771494..9bcc8c41 100644 --- a/internal/pkg/util/util.go +++ b/internal/pkg/util/util.go @@ -12,7 +12,7 @@ import ( ) -func DirModTime (path string) time.Time { +func DirModTime (path string) (time.Time, error) { var lastTime time.Time err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error { @@ -28,9 +28,9 @@ func DirModTime (path string) time.Time { return nil }) if err != nil { - return time.Now() + return time.Time{}, err } - return lastTime + return lastTime, nil } func RandomString(n int) string {