Files
warewulf/internal/app/wwctl/overlay/imprt/main.go
Jonathon Anderson 0b3e862bea Remove trailing newline from wwlog
I noticed that some wwlog calls included a trailing newline, but others
did not. I tested both in isolation and discovered that the behavior was
consistent regardless of whether a trailing newline was included. I
further confirmed in code that wwlog appends a trailing newline
automatically if it is not present; so a trailing newline is unnecessary
in individual calls.

This commit removes trailing newlines from all calls to make them
consistent. It also replaces two calls to wwlog.Printf. (see #534)

Signed-off-by: Jonathon Anderson <janderson@ciq.co>
2022-09-15 12:38:03 -06:00

78 lines
1.7 KiB
Go

package imprt
import (
"os"
"path"
"github.com/hpcng/warewulf/internal/pkg/node"
"github.com/hpcng/warewulf/internal/pkg/overlay"
"github.com/hpcng/warewulf/internal/pkg/util"
"github.com/hpcng/warewulf/internal/pkg/wwlog"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
func CobraRunE(cmd *cobra.Command, args []string) error {
var dest string
var overlaySource string
overlayName := args[0]
source := args[1]
if len(args) == 3 {
dest = args[2]
} else {
dest = source
}
wwlog.Verbose("Copying '%s' into overlay '%s:%s'", source, overlayName, dest)
overlaySource = overlay.OverlaySourceDir(overlayName)
if !util.IsDir(overlaySource) {
wwlog.Error("Overlay does not exist: %s", overlayName)
os.Exit(1)
}
if util.IsDir(path.Join(overlaySource, dest)) {
dest = path.Join(dest, path.Base(source))
}
if util.IsFile(path.Join(overlaySource, dest)) {
wwlog.Error("A file with that name already exists in the overlay %s\n:", overlayName)
os.Exit(1)
}
err := util.CopyFile(source, path.Join(overlaySource, dest))
if err != nil {
return errors.Wrap(err, "could not copy file into overlay")
}
if !NoOverlayUpdate {
n, err := node.New()
if err != nil {
wwlog.Error("Could not open node configuration: %s", err)
os.Exit(1)
}
nodes, err := n.FindAllNodes()
if err != nil {
wwlog.Error("Could not get node list: %s", err)
os.Exit(1)
}
var updateNodes []node.NodeInfo
for _, node := range nodes {
if node.SystemOverlay.Get() == overlayName {
updateNodes = append(updateNodes, node)
} else if node.RuntimeOverlay.Get() == overlayName {
updateNodes = append(updateNodes, node)
}
}
return overlay.BuildSpecificOverlays(updateNodes, []string{overlayName})
}
return nil
}