Replace ioutil with io and os (#10541)

* Replace ioutil with io and os

* Fix build errors
This commit is contained in:
Håvard Anda Estensen
2022-04-18 22:42:07 +02:00
committed by GitHub
parent 982de94428
commit d2f4a8cc7c
102 changed files with 256 additions and 291 deletions

View File

@@ -8,7 +8,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
@@ -110,7 +109,7 @@ func decrypt(cliCtx *cli.Context) error {
return errors.Wrapf(err, "could not check if path exists: %s", fullPath)
}
if isDir {
files, err := ioutil.ReadDir(fullPath)
files, err := os.ReadDir(fullPath)
if err != nil {
return errors.Wrapf(err, "could not read directory: %s", fullPath)
}
@@ -224,7 +223,7 @@ func encrypt(cliCtx *cli.Context) error {
// Reads the keystore file at the provided path and attempts
// to decrypt it with the specified passwords.
func readAndDecryptKeystore(fullPath, password string) error {
file, err := ioutil.ReadFile(fullPath) // #nosec G304
file, err := os.ReadFile(fullPath) // #nosec G304
if err != nil {
return errors.Wrapf(err, "could not read file at path: %s", fullPath)
}

View File

@@ -4,7 +4,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"strings"
@@ -77,7 +77,7 @@ func TestDecrypt(t *testing.T) {
encodedKeystore, err := json.MarshalIndent(keystore, "", "\t")
require.NoError(t, err)
keystoreFilePath := filepath.Join(keystoresDir, "keystore.json")
require.NoError(t, ioutil.WriteFile(
require.NoError(t, os.WriteFile(
keystoreFilePath, encodedKeystore, params.BeaconIoConfig().ReadWritePermissions),
)
@@ -95,7 +95,7 @@ func TestDecrypt(t *testing.T) {
require.NoError(t, decrypt(cliCtx))
require.NoError(t, w.Close())
out, err := ioutil.ReadAll(r)
out, err := io.ReadAll(r)
require.NoError(t, err)
// We capture output from stdout.
@@ -129,7 +129,7 @@ func TestEncrypt(t *testing.T) {
require.NoError(t, encrypt(cliCtx))
require.NoError(t, w.Close())
out, err := ioutil.ReadAll(r)
out, err := io.ReadAll(r)
require.NoError(t, err)
// We capture output from stdout.