remove ioutil usage in all project
Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
parent
1aa87538a7
commit
303ef9cd80
|
|
@ -3,7 +3,6 @@ package app
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
|
@ -87,7 +86,7 @@ func New(conf ConfigProvider) *App {
|
|||
}
|
||||
|
||||
func Init(app *App) *App {
|
||||
app.readFile = ioutil.ReadFile
|
||||
app.readFile = os.ReadFile
|
||||
app.deleteFile = os.Remove
|
||||
app.glob = filepath.Glob
|
||||
app.abs = filepath.Abs
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package app
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
|
|
@ -52,7 +51,7 @@ func (r *Run) withPreparedCharts(helmfileCommand string, opts state.ChartPrepare
|
|||
// Create tmp directory and bail immediately if it fails
|
||||
var dir string
|
||||
if len(opts.OutputDir) == 0 {
|
||||
tempDir, err := ioutil.TempDir("", "helmfile*")
|
||||
tempDir, err := os.MkdirTemp("", "helmfile*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
|
|
@ -24,7 +23,7 @@ func assertEqualsToSnapshot(t *testing.T, name string, data string) {
|
|||
return
|
||||
}
|
||||
|
||||
wantData, err := ioutil.ReadFile(snapshotFileName)
|
||||
wantData, err := os.ReadFile(snapshotFileName)
|
||||
if err != nil {
|
||||
t.Fatalf(
|
||||
"Snapshot file %q does not exist. Rerun this test with `HELMFILE_UPDATE_SNAPSHOT=1 go test -v -run %s %s` to create the snapshot",
|
||||
|
|
@ -53,7 +52,7 @@ func update(t *testing.T, snapshotFileName string, data []byte) {
|
|||
t.Fatalf("%v", err)
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(snapshotFileName, data, 0644); err != nil {
|
||||
if err := os.WriteFile(snapshotFileName, data, 0644); err != nil {
|
||||
t.Fatalf("%v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
|
@ -293,7 +292,7 @@ func (helm *execer) DecryptSecret(context HelmContext, name string, flags ...str
|
|||
decFilename = absPath + decSuffix
|
||||
}
|
||||
|
||||
secretBytes, err := ioutil.ReadFile(decFilename)
|
||||
secretBytes, err := os.ReadFile(decFilename)
|
||||
if err != nil {
|
||||
secret.err = err
|
||||
return "", err
|
||||
|
|
@ -323,7 +322,7 @@ func (helm *execer) DecryptSecret(context HelmContext, name string, flags ...str
|
|||
tempFile = func(content []byte) (string, error) {
|
||||
dir := filepath.Dir(name)
|
||||
extension := filepath.Ext(name)
|
||||
tmpFile, err := ioutil.TempFile(dir, "secret*"+extension)
|
||||
tmpFile, err := os.CreateTemp(dir, "secret*"+extension)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
@ -442,7 +441,7 @@ func (helm *execer) ChartPull(chart string, flags ...string) error {
|
|||
ociChartURLSplit := strings.Split(chart, ":")
|
||||
ociChartURL := fmt.Sprintf("oci://%s", ociChartURLSplit[0])
|
||||
ociChartTag := ociChartURLSplit[1]
|
||||
tempDir, err := ioutil.TempDir("", "chart*")
|
||||
tempDir, err := os.MkdirTemp("", "chart*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ type Remote struct {
|
|||
Getter Getter
|
||||
|
||||
// ReadFile is the implementation of the file reader that reads a local file from the specified path.
|
||||
// Inject any implementation of your choice, like an im-memory impl for testing, ioutil.ReadFile for the real-world use.
|
||||
// Inject any implementation of your choice, like an im-memory impl for testing, os.ReadFile for the real-world use.
|
||||
ReadFile func(string) ([]byte, error)
|
||||
DirExists func(string) bool
|
||||
FileExists func(string) bool
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package state
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
|
@ -273,8 +272,8 @@ type chartDependencyManager struct {
|
|||
func NewChartDependencyManager(name string, logger *zap.SugaredLogger) *chartDependencyManager {
|
||||
return &chartDependencyManager{
|
||||
Name: name,
|
||||
readFile: ioutil.ReadFile,
|
||||
writeFile: ioutil.WriteFile,
|
||||
readFile: os.ReadFile,
|
||||
writeFile: os.WriteFile,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package state
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
|
|
@ -20,7 +19,7 @@ import (
|
|||
func createFromYaml(content []byte, file string, env string, logger *zap.SugaredLogger) (*HelmState, error) {
|
||||
c := &StateCreator{
|
||||
logger: logger,
|
||||
readFile: ioutil.ReadFile,
|
||||
readFile: os.ReadFile,
|
||||
abs: filepath.Abs,
|
||||
|
||||
DeleteFile: os.Remove,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package state
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ func newLoader() *EnvironmentValuesLoader {
|
|||
readFile := func(s string) ([]byte, error) { return []byte{}, nil }
|
||||
dirExists := func(d string) bool { return false }
|
||||
fileExists := func(f string) bool { return false }
|
||||
return NewEnvironmentValuesLoader(storage, ioutil.ReadFile, sugar, remote.NewRemote(sugar, "/tmp", readFile, dirExists, fileExists))
|
||||
return NewEnvironmentValuesLoader(storage, os.ReadFile, sugar, remote.NewRemote(sugar, "/tmp", readFile, dirExists, fileExists))
|
||||
}
|
||||
|
||||
// See https://github.com/roboll/helmfile/pull/1169
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
|
@ -1499,7 +1498,7 @@ func (st *HelmState) WriteReleasesValues(helm helmexec.Interface, additionalValu
|
|||
return []error{err}
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(outputValuesFile, buf.Bytes(), 0644); err != nil {
|
||||
if err := os.WriteFile(outputValuesFile, buf.Bytes(), 0644); err != nil {
|
||||
return []error{fmt.Errorf("writing values file %s: %w", outputValuesFile, err)}
|
||||
}
|
||||
|
||||
|
|
@ -2285,7 +2284,7 @@ func (st *HelmState) UpdateDeps(helm helmexec.Interface, includeTransitiveNeeds
|
|||
if len(errs) == 0 {
|
||||
tempDir := st.tempDir
|
||||
if tempDir == nil {
|
||||
tempDir = ioutil.TempDir
|
||||
tempDir = os.MkdirTemp
|
||||
}
|
||||
_, err := st.updateDependenciesInTempDir(helm, tempDir)
|
||||
if err != nil {
|
||||
|
|
@ -2785,7 +2784,7 @@ func (st *HelmState) generateSecretValuesFiles(helm helmexec.Interface, release
|
|||
return nil, err
|
||||
}
|
||||
|
||||
path, err := ioutil.TempFile(os.TempDir(), "helmfile-embdedded-secrets-*.yaml.enc")
|
||||
path, err := os.CreateTemp(os.TempDir(), "helmfile-embdedded-secrets-*.yaml.enc")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -2794,7 +2793,7 @@ func (st *HelmState) generateSecretValuesFiles(helm helmexec.Interface, release
|
|||
_ = os.Remove(path.Name())
|
||||
}()
|
||||
|
||||
if err := ioutil.WriteFile(path.Name(), bs, 0644); err != nil {
|
||||
if err := os.WriteFile(path.Name(), bs, 0644); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package state
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
|
@ -31,7 +30,7 @@ func TestGoGetter(t *testing.T) {
|
|||
for i, tc := range testcases {
|
||||
test := tc
|
||||
t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) {
|
||||
d, err := ioutil.TempDir("", "testgogetter")
|
||||
d, err := os.MkdirTemp("", "testgogetter")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
@ -39,7 +38,7 @@ func TestGoGetter(t *testing.T) {
|
|||
|
||||
st := &HelmState{
|
||||
logger: logger,
|
||||
readFile: ioutil.ReadFile,
|
||||
readFile: os.ReadFile,
|
||||
basePath: d,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package state
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
|
|
@ -1798,7 +1797,7 @@ func TestHelmState_UpdateDeps(t *testing.T) {
|
|||
var generatedDir string
|
||||
tempDir := func(dir, prefix string) (string, error) {
|
||||
var err error
|
||||
generatedDir, err = ioutil.TempDir(dir, prefix)
|
||||
generatedDir, err = os.MkdirTemp(dir, prefix)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
@ -1815,7 +1814,7 @@ generated: 2019-05-16T15:42:45.50486+09:00
|
|||
`)
|
||||
filename := filepath.Join(generatedDir, "requirements.lock")
|
||||
logger.Debugf("test: writing %s: %s", filename, content)
|
||||
return ioutil.WriteFile(filename, content, 0644)
|
||||
return os.WriteFile(filename, content, 0644)
|
||||
}
|
||||
return generatedDir, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
|
@ -34,7 +33,7 @@ func tempValuesFilePath(release *ReleaseSpec, data interface{}) (*string, error)
|
|||
|
||||
workDir := os.Getenv("HELMFILE_TEMPDIR")
|
||||
if workDir == "" {
|
||||
workDir, err = ioutil.TempDir(os.TempDir(), "helmfile")
|
||||
workDir, err = os.MkdirTemp(os.TempDir(), "helmfile")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package tmpl
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"fmt"
|
||||
"strings"
|
||||
|
|
@ -27,11 +27,11 @@ func NewFileRenderer(readFile func(filename string) ([]byte, error), basePath st
|
|||
|
||||
func NewFirstPassRenderer(basePath string, data interface{}) *FileRenderer {
|
||||
return &FileRenderer{
|
||||
ReadFile: ioutil.ReadFile,
|
||||
ReadFile: os.ReadFile,
|
||||
Context: &Context{
|
||||
preRender: true,
|
||||
basePath: basePath,
|
||||
readFile: ioutil.ReadFile,
|
||||
readFile: os.ReadFile,
|
||||
},
|
||||
Data: data,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"strings"
|
||||
|
|
@ -79,9 +79,9 @@ func unmarshal(filename string) (interface{}, error) {
|
|||
var contents []byte
|
||||
var err error
|
||||
if filename == "-" {
|
||||
contents, err = ioutil.ReadAll(os.Stdin)
|
||||
contents, err = io.ReadAll(os.Stdin)
|
||||
} else {
|
||||
contents, err = ioutil.ReadFile(filename)
|
||||
contents, err = os.ReadFile(filename)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Reference in New Issue