all: replace uses of ioutil with io and os (#24869)

This commit is contained in:
Håvard Anda Estensen
2022-05-16 11:59:35 +02:00
committed by GitHub
parent 330e53fbb9
commit 07508ac0e9
97 changed files with 203 additions and 257 deletions
+3 -2
View File
@@ -22,6 +22,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
"strings"
"testing"
@@ -362,7 +363,7 @@ func TestJsonFiles(t *testing.T) {
continue
}
expectedFailure := strings.HasPrefix(fInfo.Name(), "expfail")
data, err := ioutil.ReadFile(path.Join("testdata", fInfo.Name()))
data, err := os.ReadFile(path.Join("testdata", fInfo.Name()))
if err != nil {
t.Errorf("Failed to read file %v: %v", fInfo.Name(), err)
continue
@@ -394,7 +395,7 @@ func TestFuzzerFiles(t *testing.T) {
}
verbose := false
for i, fInfo := range testfiles {
data, err := ioutil.ReadFile(path.Join(corpusdir, fInfo.Name()))
data, err := os.ReadFile(path.Join(corpusdir, fInfo.Name()))
if err != nil {
t.Errorf("Failed to read file %v: %v", fInfo.Name(), err)
continue
+2 -2
View File
@@ -21,8 +21,8 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"math/big"
"os"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
@@ -175,7 +175,7 @@ func (s *UIServerAPI) Export(ctx context.Context, addr common.Address) (json.Raw
if wallet.URL().Scheme != keystore.KeyStoreScheme {
return nil, fmt.Errorf("account is not a keystore-account")
}
return ioutil.ReadFile(wallet.URL().Path)
return os.ReadFile(wallet.URL().Path)
}
// Import tries to import the given keyJSON in the local keystore. The keyJSON data is expected to be
+2 -3
View File
@@ -22,7 +22,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"os"
)
@@ -83,7 +82,7 @@ func NewWithFile(path string) (*Database, error) {
// Custom file may not exist. Will be created during save, if needed.
if _, err := os.Stat(path); err == nil {
var blob []byte
if blob, err = ioutil.ReadFile(path); err != nil {
if blob, err = os.ReadFile(path); err != nil {
return nil, err
}
if err := json.Unmarshal(blob, &db.custom); err != nil {
@@ -137,5 +136,5 @@ func (db *Database) AddSelector(selector string, data []byte) error {
if err != nil {
return err
}
return ioutil.WriteFile(db.customPath, blob, 0600)
return os.WriteFile(db.customPath, blob, 0600)
}
+2 -3
View File
@@ -22,7 +22,6 @@ import (
"crypto/rand"
"encoding/json"
"io"
"io/ioutil"
"os"
"github.com/ethereum/go-ethereum/log"
@@ -114,7 +113,7 @@ func (s *AESEncryptedStorage) Del(key string) {
// readEncryptedStorage reads the file with encrypted creds
func (s *AESEncryptedStorage) readEncryptedStorage() (map[string]storedCredential, error) {
creds := make(map[string]storedCredential)
raw, err := ioutil.ReadFile(s.filename)
raw, err := os.ReadFile(s.filename)
if err != nil {
if os.IsNotExist(err) {
@@ -136,7 +135,7 @@ func (s *AESEncryptedStorage) writeEncryptedStorage(creds map[string]storedCrede
if err != nil {
return err
}
if err = ioutil.WriteFile(s.filename, raw, 0600); err != nil {
if err = os.WriteFile(s.filename, raw, 0600); err != nil {
return err
}
return nil
+3 -3
View File
@@ -20,7 +20,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"testing"
"github.com/ethereum/go-ethereum/common"
@@ -125,7 +125,7 @@ func TestSwappedKeys(t *testing.T) {
// Now make a modified copy
creds := make(map[string]storedCredential)
raw, err := ioutil.ReadFile(s1.filename)
raw, err := os.ReadFile(s1.filename)
if err != nil {
t.Fatal(err)
}
@@ -140,7 +140,7 @@ func TestSwappedKeys(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if err = ioutil.WriteFile(s1.filename, raw, 0600); err != nil {
if err = os.WriteFile(s1.filename, raw, 0600); err != nil {
t.Fatal(err)
}
}