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
+2 -2
View File
@@ -18,7 +18,7 @@ package main
import (
"fmt"
"io/ioutil"
"os"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
@@ -320,7 +320,7 @@ func importWallet(ctx *cli.Context) error {
if len(keyfile) == 0 {
utils.Fatalf("keyfile must be given as argument")
}
keyJSON, err := ioutil.ReadFile(keyfile)
keyJSON, err := os.ReadFile(keyfile)
if err != nil {
utils.Fatalf("Could not read wallet file: %v", err)
}
+3 -2
View File
@@ -18,6 +18,7 @@ package main
import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
@@ -113,11 +114,11 @@ func TestAccountImport(t *testing.T) {
func importAccountWithExpect(t *testing.T, key string, expected string) {
dir := t.TempDir()
keyfile := filepath.Join(dir, "key.prv")
if err := ioutil.WriteFile(keyfile, []byte(key), 0600); err != nil {
if err := os.WriteFile(keyfile, []byte(key), 0600); err != nil {
t.Error(err)
}
passwordFile := filepath.Join(dir, "password.txt")
if err := ioutil.WriteFile(passwordFile, []byte("foobar"), 0600); err != nil {
if err := os.WriteFile(passwordFile, []byte("foobar"), 0600); err != nil {
t.Error(err)
}
geth := runGeth(t, "--lightkdf", "account", "import", keyfile, "-password", passwordFile)
+2 -2
View File
@@ -17,8 +17,8 @@
package main
import (
"io/ioutil"
"math/big"
"os"
"path/filepath"
"testing"
@@ -110,7 +110,7 @@ func testDAOForkBlockNewChain(t *testing.T, test int, genesis string, expectBloc
// Start a Geth instance with the requested flags set and immediately terminate
if genesis != "" {
json := filepath.Join(datadir, "genesis.json")
if err := ioutil.WriteFile(json, []byte(genesis), 0600); err != nil {
if err := os.WriteFile(json, []byte(genesis), 0600); err != nil {
t.Fatalf("test %d: failed to write genesis file: %v", test, err)
}
runGeth(t, "--datadir", datadir, "--networkid", "1337", "init", json).WaitExit()
+2 -2
View File
@@ -17,7 +17,7 @@
package main
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)
@@ -76,7 +76,7 @@ func TestCustomGenesis(t *testing.T) {
// Initialize the data directory with the custom genesis block
json := filepath.Join(datadir, "genesis.json")
if err := ioutil.WriteFile(json, []byte(tt.genesis), 0600); err != nil {
if err := os.WriteFile(json, []byte(tt.genesis), 0600); err != nil {
t.Fatalf("test %d: failed to write genesis file: %v", i, err)
}
runGeth(t, "--datadir", datadir, "init", json).WaitExit()
+4 -3
View File
@@ -20,8 +20,9 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"regexp"
"strings"
@@ -112,14 +113,14 @@ func checkCurrent(url, current string) error {
// fetch makes an HTTP request to the given url and returns the response body
func fetch(url string) ([]byte, error) {
if filep := strings.TrimPrefix(url, "file://"); filep != url {
return ioutil.ReadFile(filep)
return os.ReadFile(filep)
}
res, err := http.Get(url)
if err != nil {
return nil, err
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}
+4 -3
View File
@@ -20,6 +20,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strconv"
@@ -49,7 +50,7 @@ func TestVerification(t *testing.T) {
func testVerification(t *testing.T, pubkey, sigdir string) {
// Data to verify
data, err := ioutil.ReadFile("./testdata/vcheck/data.json")
data, err := os.ReadFile("./testdata/vcheck/data.json")
if err != nil {
t.Fatal(err)
}
@@ -59,7 +60,7 @@ func testVerification(t *testing.T, pubkey, sigdir string) {
t.Fatal(err)
}
for _, f := range files {
sig, err := ioutil.ReadFile(filepath.Join(sigdir, f.Name()))
sig, err := os.ReadFile(filepath.Join(sigdir, f.Name()))
if err != nil {
t.Fatal(err)
}
@@ -87,7 +88,7 @@ func versionUint(v string) int {
// TestMatching can be used to check that the regexps are correct
func TestMatching(t *testing.T) {
data, _ := ioutil.ReadFile("./testdata/vcheck/vulnerabilities.json")
data, _ := os.ReadFile("./testdata/vcheck/vulnerabilities.json")
var vulns []vulnJson
if err := json.Unmarshal(data, &vulns); err != nil {
t.Fatal(err)