From 38ffb9dd2897d16893402ac2c1eafe4435383553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Minier?= Date: Tue, 26 Aug 2025 12:19:45 +0000 Subject: [PATCH] fix: Using a deprecated function, variable, constant or field (SA1019) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported by staticcheck Signed-off-by: Loïc Minier --- actions/filesystem_deploy_action.go | 3 +-- actions/pacstrap_action.go | 6 +++--- actions/raw_action.go | 3 +-- actions/recipe_test.go | 7 +++---- cmd/debos/debos.go | 3 +-- commands.go | 7 +++---- filesystem.go | 3 +-- 7 files changed, 13 insertions(+), 19 deletions(-) diff --git a/actions/filesystem_deploy_action.go b/actions/filesystem_deploy_action.go index c0b9b8f..87c2cfe 100644 --- a/actions/filesystem_deploy_action.go +++ b/actions/filesystem_deploy_action.go @@ -31,7 +31,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "os" "path" @@ -93,7 +92,7 @@ func (fd *FilesystemDeployAction) setupKernelCmdline(context *debos.DebosContext return fmt.Errorf("couldn't create etc/kernel in image: %v", err) } path := path.Join(context.Rootdir, "etc/kernel/cmdline") - current, _ := ioutil.ReadFile(path) + current, _ := os.ReadFile(path) f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0755) defer f.Close() diff --git a/actions/pacstrap_action.go b/actions/pacstrap_action.go index b018104..1c74b52 100644 --- a/actions/pacstrap_action.go +++ b/actions/pacstrap_action.go @@ -17,7 +17,7 @@ package actions import ( "fmt" - "io/ioutil" + "io/fs" "os" "path" @@ -95,12 +95,12 @@ func (d *PacstrapAction) Run(context *debos.DebosContext) error { return err } - read, err := ioutil.ReadFile(src) + read, err := os.ReadFile(src) if err != nil { return err } - if err = ioutil.WriteFile(dest, read, 0644); err != nil { + if err = os.WriteFile(dest, read, fs.FileMode(0644)); err != nil { return err } } diff --git a/actions/raw_action.go b/actions/raw_action.go index c09eab2..a63a055 100644 --- a/actions/raw_action.go +++ b/actions/raw_action.go @@ -32,7 +32,6 @@ package actions import ( "errors" "fmt" - "io/ioutil" "log" "os" "path" @@ -92,7 +91,7 @@ func (raw *RawAction) Run(context *debos.DebosContext) error { return fmt.Errorf("origin `%s` doesn't exist", raw.Origin) } s := path.Join(origin, raw.Source) - content, err := ioutil.ReadFile(s) + content, err := os.ReadFile(s) if err != nil { return fmt.Errorf("failed to read %s", s) diff --git a/actions/recipe_test.go b/actions/recipe_test.go index 0a4a324..45d37a0 100644 --- a/actions/recipe_test.go +++ b/actions/recipe_test.go @@ -4,7 +4,6 @@ import ( "github.com/go-debos/debos" "github.com/go-debos/debos/actions" "github.com/stretchr/testify/assert" - "io/ioutil" "os" "strings" "testing" @@ -153,7 +152,7 @@ actions: } func runTest(t *testing.T, test testRecipe, templateVars ...map[string]string) actions.Recipe { - file, err := ioutil.TempFile(os.TempDir(), "recipe") + file, err := os.CreateTemp(os.TempDir(), "recipe") assert.Empty(t, err) defer os.Remove(file.Name()) @@ -308,11 +307,11 @@ actions: func runTestWithSubRecipes(t *testing.T, test testSubRecipe, templateVars ...map[string]string) actions.Recipe { context := debos.DebosContext{&debos.CommonContext{}, "", "", 512} - dir, err := ioutil.TempDir("", "go-debos") + dir, err := os.MkdirTemp("", "go-debos") assert.Empty(t, err) defer os.RemoveAll(dir) - file, err := ioutil.TempFile(dir, "recipe") + file, err := os.CreateTemp(dir, "recipe") assert.Empty(t, err) defer os.Remove(file.Name()) diff --git a/cmd/debos/debos.go b/cmd/debos/debos.go index 6672463..b62d944 100644 --- a/cmd/debos/debos.go +++ b/cmd/debos/debos.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "io/ioutil" "log" "os" "path" @@ -224,7 +223,7 @@ func main() { if !runInFakeMachine && !fakemachine.InMachine() { log.Printf("fakemachine not supported, running on the host!") cwd, _ := os.Getwd() - context.Scratchdir, err = ioutil.TempDir(cwd, ".debos-") + context.Scratchdir, err = os.MkdirTemp(cwd, ".debos-") defer os.RemoveAll(context.Scratchdir) } diff --git a/commands.go b/commands.go index 5963d80..f48301a 100644 --- a/commands.go +++ b/commands.go @@ -5,7 +5,6 @@ import ( "crypto/sha256" "fmt" "io" - "io/ioutil" "log" "os" "os/exec" @@ -136,7 +135,7 @@ func (cmd *Command) saveResolvConf() (*[sha256.Size]byte, error) { } /* Expect a relatively small file here */ - data, err := ioutil.ReadFile(hostconf) + data, err := os.ReadFile(hostconf) if err != nil { return nil, err } @@ -145,7 +144,7 @@ func (cmd *Command) saveResolvConf() (*[sha256.Size]byte, error) { sum = sha256.Sum256(out) - err = ioutil.WriteFile(chrootedconf, out, 0644) + err = os.WriteFile(chrootedconf, out, 0644) if err != nil { return nil, err } @@ -177,7 +176,7 @@ func (cmd *Command) restoreResolvConf(sum *[sha256.Size]byte) error { switch { case mode.IsRegular(): // Try to calculate checksum - data, err := ioutil.ReadFile(chrootedconf) + data, err := os.ReadFile(chrootedconf) if err != nil { return err } diff --git a/filesystem.go b/filesystem.go index 4206dbc..deb6ea9 100644 --- a/filesystem.go +++ b/filesystem.go @@ -3,7 +3,6 @@ package debos import ( "fmt" "io" - "io/ioutil" "os" "path" "path/filepath" @@ -29,7 +28,7 @@ func CopyFile(src, dst string, mode os.FileMode) error { return err } defer in.Close() - tmp, err := ioutil.TempFile(filepath.Dir(dst), "") + tmp, err := os.CreateTemp(filepath.Dir(dst), "") if err != nil { return err }