Update linter for golang v1.25 compatibility
Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
committed by
Christian Goll
parent
019408d076
commit
081d2ec61e
@@ -246,7 +246,7 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
}
|
||||
}
|
||||
}()
|
||||
var finishedInitialSync bool = false
|
||||
finishedInitialSync := false
|
||||
ipaddr := os.Getenv("WW_IPADDR")
|
||||
if ipaddr == "" {
|
||||
if conf.Ipaddr6 != "" {
|
||||
@@ -361,7 +361,11 @@ func updateSystem(target string, ipaddr string, port int, wwid string, tag strin
|
||||
wwlog.Error("failed to create temp directory: %s", err)
|
||||
return nil
|
||||
}
|
||||
defer os.RemoveAll(tempDir)
|
||||
defer func() {
|
||||
if err := os.RemoveAll(tempDir); err != nil {
|
||||
wwlog.Warn("failed to remove temp directory %s: %s", tempDir, err)
|
||||
}
|
||||
}()
|
||||
wwlog.Debug("unpacking runtime overlay to %s", tempDir)
|
||||
command := exec.Command("/bin/sh", "-c", fmt.Sprintf("gzip -dc | cpio -imu --directory=%s", tempDir))
|
||||
command.Stdin = resp.Body
|
||||
@@ -469,7 +473,7 @@ func atomicApplyOverlay(srcDir, destDir string) error {
|
||||
wwlog.Debug("moving symlink %s to %s", tempPath, destPath)
|
||||
err = os.Rename(tempPath, destPath)
|
||||
if err != nil {
|
||||
os.Remove(tempPath)
|
||||
_ = os.Remove(tempPath)
|
||||
return fmt.Errorf("failed to atomically move symlink %s to %s: %w", tempPath, destPath, err)
|
||||
}
|
||||
|
||||
@@ -508,7 +512,7 @@ func atomicApplyOverlay(srcDir, destDir string) error {
|
||||
wwlog.Debug("copying file from %s to temp location %s", srcPath, tempPath)
|
||||
err = copyFile(srcPath, tempPath, info)
|
||||
if err != nil {
|
||||
os.Remove(tempPath)
|
||||
_ = os.Remove(tempPath)
|
||||
return fmt.Errorf("failed to copy %s to temp location: %w", srcPath, err)
|
||||
}
|
||||
|
||||
@@ -523,7 +527,7 @@ func atomicApplyOverlay(srcDir, destDir string) error {
|
||||
wwlog.Debug("moving %s to %s", tempPath, destPath)
|
||||
err = os.Rename(tempPath, destPath)
|
||||
if err != nil {
|
||||
os.Remove(tempPath)
|
||||
_ = os.Remove(tempPath)
|
||||
return fmt.Errorf("failed to atomically move %s to %s: %w", tempPath, destPath, err)
|
||||
}
|
||||
}
|
||||
@@ -532,18 +536,22 @@ func atomicApplyOverlay(srcDir, destDir string) error {
|
||||
})
|
||||
}
|
||||
|
||||
func copyFile(src, dst string, srcInfo os.FileInfo) error {
|
||||
func copyFile(src, dst string, srcInfo os.FileInfo) (err error) {
|
||||
srcFile, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer srcFile.Close()
|
||||
defer func() { _ = srcFile.Close() }()
|
||||
|
||||
dstFile, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, srcInfo.Mode())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer dstFile.Close()
|
||||
defer func() {
|
||||
if cerr := dstFile.Close(); cerr != nil && err == nil {
|
||||
err = cerr
|
||||
}
|
||||
}()
|
||||
|
||||
_, err = io.Copy(dstFile, srcFile)
|
||||
if err != nil {
|
||||
|
||||
@@ -67,7 +67,7 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
if err != nil {
|
||||
wwlog.Warn("couldn't create directory for mounts: %s", err)
|
||||
}
|
||||
defer desc.Close()
|
||||
defer func() { _ = desc.Close() }()
|
||||
}
|
||||
}
|
||||
imagePath := image.RootFsDir(imageName)
|
||||
@@ -170,25 +170,25 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
return fmt.Errorf("failed to mount /run: %w", err)
|
||||
}
|
||||
|
||||
os.Setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin")
|
||||
_ = os.Setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin")
|
||||
|
||||
var ps1Base string
|
||||
if v, ok := os.LookupEnv("WW_PS1"); ok {
|
||||
ps1Base = v
|
||||
} else {
|
||||
ps1Base = `\w\$ `
|
||||
os.Setenv("WW_PS1", ps1Base)
|
||||
_ = os.Setenv("WW_PS1", ps1Base)
|
||||
}
|
||||
os.Setenv("PS1", fmt.Sprintf("%s %s", ps1Prefix, ps1Base))
|
||||
_ = os.Setenv("PS1", fmt.Sprintf("%s %s", ps1Prefix, ps1Base))
|
||||
|
||||
var histfile string
|
||||
if v, ok := os.LookupEnv("WW_HISTFILE"); ok {
|
||||
histfile = v
|
||||
} else {
|
||||
histfile = "/dev/null"
|
||||
os.Setenv("WW_HISTFILE", histfile)
|
||||
_ = os.Setenv("WW_HISTFILE", histfile)
|
||||
}
|
||||
os.Setenv("HISTFILE", histfile)
|
||||
_ = os.Setenv("HISTFILE", histfile)
|
||||
|
||||
wwlog.Debug("Exec: %s %s", args[1], args[1:])
|
||||
return syscall.Exec(args[1], args[1:], os.Environ())
|
||||
|
||||
@@ -99,8 +99,8 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
if !image.ValidSource(imageName) {
|
||||
return fmt.Errorf("unknown Warewulf image: %s", imageName)
|
||||
}
|
||||
os.Setenv("WW_CONTAINER_SHELL", imageName)
|
||||
os.Setenv("WW_IMAGE_SHELL", imageName)
|
||||
_ = os.Setenv("WW_CONTAINER_SHELL", imageName)
|
||||
_ = os.Setenv("WW_IMAGE_SHELL", imageName)
|
||||
|
||||
imagePath := image.RootFsDir(imageName)
|
||||
|
||||
@@ -213,7 +213,7 @@ func (cf *copyFile) shouldRemoveFromImage(imageName string) bool {
|
||||
} else if destStat, err := os.Stat(imageDest); err != nil {
|
||||
wwlog.Verbose("file is no longer present: %s (%s)", cf.fileName, err)
|
||||
return false
|
||||
} else if destStat.ModTime() == cf.modTime {
|
||||
} else if destStat.ModTime().Equal(cf.modTime) {
|
||||
wwlog.Verbose("don't remove modified file:", cf.fileName)
|
||||
return false
|
||||
} else {
|
||||
|
||||
@@ -82,8 +82,8 @@ func Test_Exec(t *testing.T) {
|
||||
nodeName = ""
|
||||
Build = true
|
||||
SyncUser = false
|
||||
os.Remove(env.GetPath("/srv/warewulf/images/test.img"))
|
||||
os.Remove(env.GetPath("/srv/warewulf/images/test.img.gz"))
|
||||
_ = os.Remove(env.GetPath("/srv/warewulf/images/test.img"))
|
||||
_ = os.Remove(env.GetPath("/srv/warewulf/images/test.img.gz"))
|
||||
}()
|
||||
cmd := GetCommand()
|
||||
cmd.SetArgs(tt.args)
|
||||
|
||||
@@ -108,7 +108,7 @@ func createDummyDockerArchive(t *testing.T, path string) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
archiveTw := tar.NewWriter(f)
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ func GetCommand() *cobra.Command {
|
||||
}
|
||||
vars.nodeConf.CreateFlags(baseCmd)
|
||||
vars.nodeAdd.CreateAddFlags(baseCmd)
|
||||
flags.AddContainer(baseCmd, &(vars.nodeConf.Profile.ImageName))
|
||||
flags.AddContainer(baseCmd, &(vars.nodeConf.ImageName))
|
||||
flags.AddWwinit(baseCmd, &(vars.nodeConf.SystemOverlay))
|
||||
flags.AddRuntime(baseCmd, &(vars.nodeConf.RuntimeOverlay))
|
||||
// register the command line completions
|
||||
|
||||
@@ -44,7 +44,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
if tempErr != nil {
|
||||
return fmt.Errorf("could not create temp file: %s", tempErr)
|
||||
}
|
||||
defer os.Remove(tempFile.Name())
|
||||
defer func() { _ = os.Remove(tempFile.Name()) }()
|
||||
|
||||
if !NoHeader {
|
||||
yamlTemplate := node.ConfToYaml(node.Node{}, nil)
|
||||
|
||||
@@ -18,7 +18,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not open file: %s", err)
|
||||
}
|
||||
defer file.Close()
|
||||
defer func() { _ = file.Close() }()
|
||||
|
||||
importMap := make(map[string]*node.Node)
|
||||
buffer, err := io.ReadAll(file)
|
||||
|
||||
@@ -34,7 +34,7 @@ func GetCommand() *cobra.Command {
|
||||
vars.nodeConf.CreateFlags(baseCmd)
|
||||
vars.nodeAdd.CreateAddFlags(baseCmd)
|
||||
vars.nodeDel.CreateDelFlags(baseCmd)
|
||||
flags.AddContainer(baseCmd, &(vars.nodeConf.Profile.ImageName))
|
||||
flags.AddContainer(baseCmd, &(vars.nodeConf.ImageName))
|
||||
flags.AddWwinit(baseCmd, &(vars.nodeConf.SystemOverlay))
|
||||
flags.AddRuntime(baseCmd, &(vars.nodeConf.RuntimeOverlay))
|
||||
baseCmd.PersistentFlags().BoolVarP(&vars.setNodeAll, "all", "a", false, "Set all nodes")
|
||||
|
||||
@@ -97,7 +97,7 @@ func Test_OverlayChown(t *testing.T) {
|
||||
filePath := filepath.Join(overlayDir, tt.fileName)
|
||||
f, err := os.Create(filePath)
|
||||
assert.NoError(t, err)
|
||||
f.Close()
|
||||
_ = f.Close()
|
||||
// get initial owner
|
||||
stat, err := os.Stat(filePath)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -43,7 +43,7 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
overlayFile := myOverlay.File(fileName)
|
||||
wwlog.Debug("Will edit overlay file: %s", overlayFile)
|
||||
overlayFileDir := path.Dir(overlayFile)
|
||||
if !(util.IsDir(overlayFileDir) || CreateDirs) {
|
||||
if !util.IsDir(overlayFileDir) && !CreateDirs {
|
||||
return fmt.Errorf("%s does not exist. Use '--parents' option to create automatically", overlayFileDir)
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
if tempFileErr != nil {
|
||||
return fmt.Errorf("unable to create temporary file for editing: %s", tempFileErr)
|
||||
}
|
||||
defer os.Remove(tempFile.Name())
|
||||
defer func() { _ = os.Remove(tempFile.Name()) }()
|
||||
wwlog.Debug("Using temporary file %s", tempFile.Name())
|
||||
|
||||
if util.IsFile(overlayFile) {
|
||||
@@ -62,20 +62,22 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
if _, err := io.Copy(tempFile, originalFile); err != nil {
|
||||
return fmt.Errorf("unable to copy %s to %s for editing: %s", originalFile.Name(), tempFile.Name(), err)
|
||||
}
|
||||
originalFile.Close()
|
||||
_ = originalFile.Close()
|
||||
} else if filepath.Ext(overlayFile) == ".ww" {
|
||||
if _, err := tempFile.Write([]byte(initialTemplate)); err != nil {
|
||||
return fmt.Errorf("unable to write to %s: %s", tempFile.Name(), err)
|
||||
}
|
||||
}
|
||||
tempFile.Close()
|
||||
if err := tempFile.Close(); err != nil {
|
||||
return fmt.Errorf("failed to close temp file %s: %w", tempFile.Name(), err)
|
||||
}
|
||||
|
||||
initialFile, err := os.Open(tempFile.Name())
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to open temp file for hashing: %s", err)
|
||||
}
|
||||
initialHash, err := util.HashFile(initialFile)
|
||||
initialFile.Close()
|
||||
_ = initialFile.Close()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to calculate initial hash of %s: %s", tempFile.Name(), err)
|
||||
}
|
||||
@@ -93,7 +95,7 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
|
||||
return fmt.Errorf("unable to open temp file for final hashing: %s", err)
|
||||
}
|
||||
finalHash, err := util.HashFile(finalFile)
|
||||
finalFile.Close()
|
||||
_ = finalFile.Close()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to calculate final hash of %s: %s", tempFile.Name(), err)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func Test_List(t *testing.T) {
|
||||
t.Errorf("Could not create temp folder: %v", err)
|
||||
t.FailNow()
|
||||
}
|
||||
defer os.RemoveAll(tmpdir)
|
||||
defer func() { _ = os.RemoveAll(tmpdir) }()
|
||||
|
||||
overlayDir := fmt.Sprintf("%s/overlay", tmpdir)
|
||||
err = os.MkdirAll(overlayDir, 0o755)
|
||||
@@ -40,7 +40,7 @@ func Test_List(t *testing.T) {
|
||||
t.Errorf("Could not create tempfile")
|
||||
t.FailNow()
|
||||
}
|
||||
file.Close()
|
||||
_ = file.Close()
|
||||
err = os.Chmod(file.Name(), 0o755)
|
||||
if err != nil {
|
||||
t.Errorf("Could not change the file %s mode: %v", file.Name(), err)
|
||||
|
||||
@@ -42,7 +42,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
|
||||
// Add newline after wwdoc lines if they exist
|
||||
if hasWwdoc {
|
||||
fmt.Fprintln(cmd.OutOrStdout())
|
||||
_, _ = fmt.Fprintln(cmd.OutOrStdout())
|
||||
}
|
||||
|
||||
// Sort variables by name for consistent output
|
||||
|
||||
@@ -41,7 +41,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
if tempErr != nil {
|
||||
return fmt.Errorf("could not create temp file: %s", tempErr)
|
||||
}
|
||||
defer os.Remove(tempFile.Name())
|
||||
defer func() { _ = os.Remove(tempFile.Name()) }()
|
||||
|
||||
if !NoHeader {
|
||||
yamlTemplate := node.ConfToYaml(node.Profile{}, nil)
|
||||
|
||||
@@ -119,7 +119,7 @@ nodes:
|
||||
_, _ = io.Copy(&buf, stdoutR)
|
||||
stdoutC <- buf.String()
|
||||
}()
|
||||
stdoutW.Close()
|
||||
_ = stdoutW.Close()
|
||||
os.Stdout = oriout
|
||||
|
||||
stdout := <-stdoutC
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/warewulf/warewulf/internal/pkg/api/routes/wwapiv1"
|
||||
"github.com/warewulf/warewulf/internal/pkg/version"
|
||||
)
|
||||
|
||||
@@ -12,7 +11,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
|
||||
fmt.Println("wwctl version:\t", version.GetVersion())
|
||||
|
||||
var wwVersionResponse *wwapiv1.VersionResponse = version.Version()
|
||||
wwVersionResponse := version.Version()
|
||||
fmt.Println("rpc version:", wwVersionResponse.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user