art: Move from io/ioutil to io and os packages (#470)

refactor: move from io/ioutil to io and os packages

The io/ioutil package has been deprecated as of Go 1.16 [1]. This commit
replaces the existing io/ioutil functions with their new definitions in
io and os packages.

[1]: https://golang.org/doc/go1.16#ioutil
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun
2022-11-22 01:11:03 +08:00
committed by Itxaka
parent 9011ce3419
commit c868bbaf9e
4 changed files with 11 additions and 14 deletions

View File

@@ -2,7 +2,6 @@ package agent
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
@@ -46,7 +45,7 @@ func Run(opts ...Option) error {
// Create if not exist
if _, err := os.Stat(fileName); err != nil {
err = ioutil.WriteFile(fileName, []byte{}, os.ModePerm)
err = os.WriteFile(fileName, []byte{}, os.ModePerm)
if err != nil {
return err
}

View File

@@ -1,7 +1,7 @@
package agent
import (
"io/ioutil"
"os"
"github.com/kairos-io/kairos/internal/kairos"
@@ -29,35 +29,35 @@ func LoadConfig(path ...string) (*Config, error) {
cfg := &Config{}
for _, p := range path {
f, err := ioutil.ReadFile(p)
f, err := os.ReadFile(p)
if err == nil {
yaml.Unmarshal(f, cfg) //nolint:errcheck
}
}
if cfg.Branding.InteractiveInstall == "" {
f, err := ioutil.ReadFile(kairos.BrandingFile("interactive_install_text"))
f, err := os.ReadFile(kairos.BrandingFile("interactive_install_text"))
if err == nil {
cfg.Branding.InteractiveInstall = string(f)
}
}
if cfg.Branding.Install == "" {
f, err := ioutil.ReadFile(kairos.BrandingFile("install_text"))
f, err := os.ReadFile(kairos.BrandingFile("install_text"))
if err == nil {
cfg.Branding.Install = string(f)
}
}
if cfg.Branding.Recovery == "" {
f, err := ioutil.ReadFile(kairos.BrandingFile("recovery_text"))
f, err := os.ReadFile(kairos.BrandingFile("recovery_text"))
if err == nil {
cfg.Branding.Recovery = string(f)
}
}
if cfg.Branding.Reset == "" {
f, err := ioutil.ReadFile(kairos.BrandingFile("reset_text"))
f, err := os.ReadFile(kairos.BrandingFile("reset_text"))
if err == nil {
cfg.Branding.Reset = string(f)
}

View File

@@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"syscall"
@@ -40,7 +39,7 @@ func optsToArgs(options map[string]string) (res []string) {
}
func ManualInstall(config string, options map[string]string) error {
dat, err := ioutil.ReadFile(config)
dat, err := os.ReadFile(config)
if err != nil {
return err
}
@@ -195,7 +194,7 @@ func RunInstall(options map[string]string) error {
utils.SH("elemental run-stage kairos-install.pre") //nolint:errcheck
events.RunHookScript("/usr/bin/kairos-agent.install.pre.hook") //nolint:errcheck
f, _ := ioutil.TempFile("", "xxxx")
f, _ := os.CreateTemp("", "xxxx")
defer os.RemoveAll(f.Name())
device, ok := options["device"]
@@ -232,7 +231,7 @@ func RunInstall(options map[string]string) error {
env := append(c.Install.Env, c.Env...)
utils.SetEnv(env)
err := ioutil.WriteFile(f.Name(), []byte(cloudInit), os.ModePerm)
err := os.WriteFile(f.Name(), []byte(cloudInit), os.ModePerm)
if err != nil {
fmt.Printf("could not write cloud init: %s\n", err.Error())
os.Exit(1)

View File

@@ -2,7 +2,6 @@ package cmd
import (
"fmt"
"io/ioutil"
"os"
"github.com/kairos-io/kairos/internal/kairos"
@@ -19,7 +18,7 @@ func PrintText(f string, banner string) {
func PrintBranding(b []byte) {
brandingFile := kairos.BrandingFile("banner")
if _, err := os.Stat(brandingFile); err == nil {
f, err := ioutil.ReadFile(brandingFile)
f, err := os.ReadFile(brandingFile)
if err == nil {
fmt.Println(string(f))
}