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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
97 changed files with 203 additions and 257 deletions

View File

@ -21,7 +21,6 @@ import (
"crypto/ecdsa" "crypto/ecdsa"
"errors" "errors"
"io" "io"
"io/ioutil"
"math/big" "math/big"
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
@ -45,7 +44,7 @@ var ErrNotAuthorized = errors.New("not authorized to sign this account")
// Deprecated: Use NewTransactorWithChainID instead. // Deprecated: Use NewTransactorWithChainID instead.
func NewTransactor(keyin io.Reader, passphrase string) (*TransactOpts, error) { func NewTransactor(keyin io.Reader, passphrase string) (*TransactOpts, error) {
log.Warn("WARNING: NewTransactor has been deprecated in favour of NewTransactorWithChainID") log.Warn("WARNING: NewTransactor has been deprecated in favour of NewTransactorWithChainID")
json, err := ioutil.ReadAll(keyin) json, err := io.ReadAll(keyin)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -106,7 +105,7 @@ func NewKeyedTransactor(key *ecdsa.PrivateKey) *TransactOpts {
// NewTransactorWithChainID is a utility method to easily create a transaction signer from // NewTransactorWithChainID is a utility method to easily create a transaction signer from
// an encrypted json key stream and the associated passphrase. // an encrypted json key stream and the associated passphrase.
func NewTransactorWithChainID(keyin io.Reader, passphrase string, chainID *big.Int) (*TransactOpts, error) { func NewTransactorWithChainID(keyin io.Reader, passphrase string, chainID *big.Int) (*TransactOpts, error) {
json, err := ioutil.ReadAll(keyin) json, err := io.ReadAll(keyin)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -18,7 +18,6 @@ package keystore
import ( import (
"fmt" "fmt"
"io/ioutil"
"math/rand" "math/rand"
"os" "os"
"path/filepath" "path/filepath"
@ -380,11 +379,11 @@ func TestUpdatedKeyfileContents(t *testing.T) {
return return
} }
// needed so that modTime of `file` is different to its current value after ioutil.WriteFile // needed so that modTime of `file` is different to its current value after os.WriteFile
time.Sleep(1000 * time.Millisecond) time.Sleep(1000 * time.Millisecond)
// Now replace file contents with crap // Now replace file contents with crap
if err := ioutil.WriteFile(file, []byte("foo"), 0644); err != nil { if err := os.WriteFile(file, []byte("foo"), 0644); err != nil {
t.Fatal(err) t.Fatal(err)
return return
} }
@ -397,9 +396,9 @@ func TestUpdatedKeyfileContents(t *testing.T) {
// forceCopyFile is like cp.CopyFile, but doesn't complain if the destination exists. // forceCopyFile is like cp.CopyFile, but doesn't complain if the destination exists.
func forceCopyFile(dst, src string) error { func forceCopyFile(dst, src string) error {
data, err := ioutil.ReadFile(src) data, err := os.ReadFile(src)
if err != nil { if err != nil {
return err return err
} }
return ioutil.WriteFile(dst, data, 0644) return os.WriteFile(dst, data, 0644)
} }

View File

@ -23,7 +23,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -197,7 +196,7 @@ func writeTemporaryKeyFile(file string, content []byte) (string, error) {
} }
// Atomic write: create a temporary hidden file first // Atomic write: create a temporary hidden file first
// then move it into place. TempFile assigns mode 0600. // then move it into place. TempFile assigns mode 0600.
f, err := ioutil.TempFile(filepath.Dir(file), "."+filepath.Base(file)+".tmp") f, err := os.CreateTemp(filepath.Dir(file), "."+filepath.Base(file)+".tmp")
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -34,7 +34,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -82,7 +81,7 @@ type keyStorePassphrase struct {
func (ks keyStorePassphrase) GetKey(addr common.Address, filename, auth string) (*Key, error) { func (ks keyStorePassphrase) GetKey(addr common.Address, filename, auth string) (*Key, error) {
// Load the key from the keystore and decrypt its contents // Load the key from the keystore and decrypt its contents
keyjson, err := ioutil.ReadFile(filename) keyjson, err := os.ReadFile(filename)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -17,7 +17,7 @@
package keystore package keystore
import ( import (
"io/ioutil" "os"
"testing" "testing"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -30,7 +30,7 @@ const (
// Tests that a json key file can be decrypted and encrypted in multiple rounds. // Tests that a json key file can be decrypted and encrypted in multiple rounds.
func TestKeyEncryptDecrypt(t *testing.T) { func TestKeyEncryptDecrypt(t *testing.T) {
keyjson, err := ioutil.ReadFile("testdata/very-light-scrypt.json") keyjson, err := os.ReadFile("testdata/very-light-scrypt.json")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -34,7 +34,7 @@ package scwallet
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "io"
"os" "os"
"path/filepath" "path/filepath"
"sort" "sort"
@ -96,7 +96,7 @@ func (hub *Hub) readPairings() error {
return err return err
} }
pairingData, err := ioutil.ReadAll(pairingFile) pairingData, err := io.ReadAll(pairingFile)
if err != nil { if err != nil {
return err return err
} }

View File

@ -46,7 +46,6 @@ import (
"encoding/base64" "encoding/base64"
"flag" "flag"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os" "os"
"os/exec" "os/exec"
@ -736,7 +735,7 @@ func ppaUpload(workdir, ppa, sshUser string, files []string) {
if sshkey := getenvBase64("PPA_SSH_KEY"); len(sshkey) > 0 { if sshkey := getenvBase64("PPA_SSH_KEY"); len(sshkey) > 0 {
idfile = filepath.Join(workdir, "sshkey") idfile = filepath.Join(workdir, "sshkey")
if !common.FileExist(idfile) { if !common.FileExist(idfile) {
ioutil.WriteFile(idfile, sshkey, 0600) os.WriteFile(idfile, sshkey, 0600)
} }
} }
// Upload // Upload
@ -759,7 +758,7 @@ func makeWorkdir(wdflag string) string {
if wdflag != "" { if wdflag != "" {
err = os.MkdirAll(wdflag, 0744) err = os.MkdirAll(wdflag, 0744)
} else { } else {
wdflag, err = ioutil.TempDir("", "geth-build-") wdflag, err = os.MkdirTemp("", "geth-build-")
} }
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -39,7 +39,6 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os" "os"
"os/exec" "os/exec"
@ -241,7 +240,7 @@ func gitAuthors(files []string) []string {
} }
func readAuthors() []string { func readAuthors() []string {
content, err := ioutil.ReadFile("AUTHORS") content, err := os.ReadFile("AUTHORS")
if err != nil && !os.IsNotExist(err) { if err != nil && !os.IsNotExist(err) {
log.Fatalln("error reading AUTHORS:", err) log.Fatalln("error reading AUTHORS:", err)
} }
@ -305,7 +304,7 @@ func writeAuthors(files []string) {
content.WriteString("\n") content.WriteString("\n")
} }
fmt.Println("writing AUTHORS") fmt.Println("writing AUTHORS")
if err := ioutil.WriteFile("AUTHORS", content.Bytes(), 0644); err != nil { if err := os.WriteFile("AUTHORS", content.Bytes(), 0644); err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
} }
@ -381,7 +380,7 @@ func writeLicense(info *info) {
if err != nil { if err != nil {
log.Fatalf("error stat'ing %s: %v\n", info.file, err) log.Fatalf("error stat'ing %s: %v\n", info.file, err)
} }
content, err := ioutil.ReadFile(info.file) content, err := os.ReadFile(info.file)
if err != nil { if err != nil {
log.Fatalf("error reading %s: %v\n", info.file, err) log.Fatalf("error reading %s: %v\n", info.file, err)
} }
@ -400,7 +399,7 @@ func writeLicense(info *info) {
return return
} }
fmt.Println("writing", info.ShortLicense(), info.file) fmt.Println("writing", info.ShortLicense(), info.file)
if err := ioutil.WriteFile(info.file, buf.Bytes(), fi.Mode()); err != nil { if err := os.WriteFile(info.file, buf.Bytes(), fi.Mode()); err != nil {
log.Fatalf("error writing %s: %v", info.file, err) log.Fatalf("error writing %s: %v", info.file, err)
} }
} }

View File

@ -19,7 +19,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
@ -155,9 +155,9 @@ func abigen(c *cli.Context) error {
) )
input := c.GlobalString(abiFlag.Name) input := c.GlobalString(abiFlag.Name)
if input == "-" { if input == "-" {
abi, err = ioutil.ReadAll(os.Stdin) abi, err = io.ReadAll(os.Stdin)
} else { } else {
abi, err = ioutil.ReadFile(input) abi, err = os.ReadFile(input)
} }
if err != nil { if err != nil {
utils.Fatalf("Failed to read input ABI: %v", err) utils.Fatalf("Failed to read input ABI: %v", err)
@ -166,7 +166,7 @@ func abigen(c *cli.Context) error {
var bin []byte var bin []byte
if binFile := c.GlobalString(binFlag.Name); binFile != "" { if binFile := c.GlobalString(binFlag.Name); binFile != "" {
if bin, err = ioutil.ReadFile(binFile); err != nil { if bin, err = os.ReadFile(binFile); err != nil {
utils.Fatalf("Failed to read input bytecode: %v", err) utils.Fatalf("Failed to read input bytecode: %v", err)
} }
if strings.Contains(string(bin), "//") { if strings.Contains(string(bin), "//") {
@ -213,7 +213,7 @@ func abigen(c *cli.Context) error {
} }
case c.GlobalIsSet(jsonFlag.Name): case c.GlobalIsSet(jsonFlag.Name):
jsonOutput, err := ioutil.ReadFile(c.GlobalString(jsonFlag.Name)) jsonOutput, err := os.ReadFile(c.GlobalString(jsonFlag.Name))
if err != nil { if err != nil {
utils.Fatalf("Failed to read combined-json from compiler: %v", err) utils.Fatalf("Failed to read combined-json from compiler: %v", err)
} }
@ -263,7 +263,7 @@ func abigen(c *cli.Context) error {
fmt.Printf("%s\n", code) fmt.Printf("%s\n", code)
return nil return nil
} }
if err := ioutil.WriteFile(c.GlobalString(outFlag.Name), []byte(code), 0600); err != nil { if err := os.WriteFile(c.GlobalString(outFlag.Name), []byte(code), 0600); err != nil {
utils.Fatalf("Failed to write ABI binding: %v", err) utils.Fatalf("Failed to write ABI binding: %v", err)
} }
return nil return nil

View File

@ -25,7 +25,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math/big" "math/big"
"os" "os"
"os/signal" "os/signal"
@ -374,7 +373,7 @@ func initializeSecrets(c *cli.Context) error {
return fmt.Errorf("master key %v already exists, will not overwrite", location) return fmt.Errorf("master key %v already exists, will not overwrite", location)
} }
// Write the file and print the usual warning message // Write the file and print the usual warning message
if err = ioutil.WriteFile(location, cipherSeed, 0400); err != nil { if err = os.WriteFile(location, cipherSeed, 0400); err != nil {
return err return err
} }
fmt.Printf("A master seed has been generated into %s\n", location) fmt.Printf("A master seed has been generated into %s\n", location)
@ -593,7 +592,7 @@ func signer(c *cli.Context) error {
// Do we have a rule-file? // Do we have a rule-file?
if ruleFile := c.GlobalString(ruleFlag.Name); ruleFile != "" { if ruleFile := c.GlobalString(ruleFlag.Name); ruleFile != "" {
ruleJS, err := ioutil.ReadFile(ruleFile) ruleJS, err := os.ReadFile(ruleFile)
if err != nil { if err != nil {
log.Warn("Could not load rules, disabling", "file", ruleFile, "err", err) log.Warn("Could not load rules, disabling", "file", ruleFile, "err", err)
} else { } else {
@ -751,7 +750,7 @@ func readMasterKey(ctx *cli.Context, ui core.UIClientAPI) ([]byte, error) {
if err := checkFile(file); err != nil { if err := checkFile(file); err != nil {
return nil, err return nil, err
} }
cipherKey, err := ioutil.ReadFile(file) cipherKey, err := os.ReadFile(file)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -20,7 +20,6 @@ import (
"crypto/ecdsa" "crypto/ecdsa"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"time" "time"
@ -253,7 +252,7 @@ func dnsNukeRoute53(ctx *cli.Context) error {
// loadSigningKey loads a private key in Ethereum keystore format. // loadSigningKey loads a private key in Ethereum keystore format.
func loadSigningKey(keyfile string) *ecdsa.PrivateKey { func loadSigningKey(keyfile string) *ecdsa.PrivateKey {
keyjson, err := ioutil.ReadFile(keyfile) keyjson, err := os.ReadFile(keyfile)
if err != nil { if err != nil {
exit(fmt.Errorf("failed to read the keyfile at '%s': %v", keyfile, err)) exit(fmt.Errorf("failed to read the keyfile at '%s': %v", keyfile, err))
} }
@ -382,7 +381,7 @@ func writeTreeMetadata(directory string, def *dnsDefinition) {
exit(err) exit(err)
} }
metaFile, _ := treeDefinitionFiles(directory) metaFile, _ := treeDefinitionFiles(directory)
if err := ioutil.WriteFile(metaFile, metaJSON, 0644); err != nil { if err := os.WriteFile(metaFile, metaJSON, 0644); err != nil {
exit(err) exit(err)
} }
} }
@ -411,7 +410,7 @@ func writeTXTJSON(file string, txt map[string]string) {
fmt.Println() fmt.Println()
return return
} }
if err := ioutil.WriteFile(file, txtJSON, 0644); err != nil { if err := os.WriteFile(file, txtJSON, 0644); err != nil {
exit(err) exit(err)
} }
} }

View File

@ -22,7 +22,6 @@ import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"os" "os"
"strconv" "strconv"
@ -54,9 +53,9 @@ func enrdump(ctx *cli.Context) error {
var b []byte var b []byte
var err error var err error
if file == "-" { if file == "-" {
b, err = ioutil.ReadAll(os.Stdin) b, err = io.ReadAll(os.Stdin)
} else { } else {
b, err = ioutil.ReadFile(file) b, err = os.ReadFile(file)
} }
if err != nil { if err != nil {
return err return err

View File

@ -21,7 +21,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math/big" "math/big"
"os" "os"
"strings" "strings"
@ -153,7 +152,7 @@ func loadChain(chainfile string, genesis string) (*Chain, error) {
} }
func loadGenesis(genesisFile string) (core.Genesis, error) { func loadGenesis(genesisFile string) (core.Genesis, error) {
chainConfig, err := ioutil.ReadFile(genesisFile) chainConfig, err := os.ReadFile(genesisFile)
if err != nil { if err != nil {
return core.Genesis{}, err return core.Genesis{}, err
} }

View File

@ -20,7 +20,6 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"sort" "sort"
"time" "time"
@ -66,7 +65,7 @@ func writeNodesJSON(file string, nodes nodeSet) {
os.Stdout.Write(nodesJSON) os.Stdout.Write(nodesJSON)
return return
} }
if err := ioutil.WriteFile(file, nodesJSON, 0644); err != nil { if err := os.WriteFile(file, nodesJSON, 0644); err != nil {
exit(err) exit(err)
} }
} }

View File

@ -18,7 +18,7 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil" "os"
"strings" "strings"
"github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/accounts/keystore"
@ -45,7 +45,7 @@ Change the password of a keyfile.`,
keyfilepath := ctx.Args().First() keyfilepath := ctx.Args().First()
// Read key from file. // Read key from file.
keyjson, err := ioutil.ReadFile(keyfilepath) keyjson, err := os.ReadFile(keyfilepath)
if err != nil { if err != nil {
utils.Fatalf("Failed to read the keyfile at '%s': %v", keyfilepath, err) utils.Fatalf("Failed to read the keyfile at '%s': %v", keyfilepath, err)
} }
@ -61,7 +61,7 @@ Change the password of a keyfile.`,
fmt.Println("Please provide a new password") fmt.Println("Please provide a new password")
var newPhrase string var newPhrase string
if passFile := ctx.String(newPassphraseFlag.Name); passFile != "" { if passFile := ctx.String(newPassphraseFlag.Name); passFile != "" {
content, err := ioutil.ReadFile(passFile) content, err := os.ReadFile(passFile)
if err != nil { if err != nil {
utils.Fatalf("Failed to read new password file '%s': %v", passFile, err) utils.Fatalf("Failed to read new password file '%s': %v", passFile, err)
} }
@ -77,7 +77,7 @@ Change the password of a keyfile.`,
} }
// Then write the new keyfile in place of the old one. // Then write the new keyfile in place of the old one.
if err := ioutil.WriteFile(keyfilepath, newJson, 0600); err != nil { if err := os.WriteFile(keyfilepath, newJson, 0600); err != nil {
utils.Fatalf("Error writing new keyfile to disk: %v", err) utils.Fatalf("Error writing new keyfile to disk: %v", err)
} }

View File

@ -19,7 +19,6 @@ package main
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -116,7 +115,7 @@ If you want to encrypt an existing private key, it can be specified by setting
if err := os.MkdirAll(filepath.Dir(keyfilepath), 0700); err != nil { if err := os.MkdirAll(filepath.Dir(keyfilepath), 0700); err != nil {
utils.Fatalf("Could not create directory %s", filepath.Dir(keyfilepath)) utils.Fatalf("Could not create directory %s", filepath.Dir(keyfilepath))
} }
if err := ioutil.WriteFile(keyfilepath, keyjson, 0600); err != nil { if err := os.WriteFile(keyfilepath, keyjson, 0600); err != nil {
utils.Fatalf("Failed to write keyfile to %s: %v", keyfilepath, err) utils.Fatalf("Failed to write keyfile to %s: %v", keyfilepath, err)
} }

View File

@ -19,7 +19,7 @@ package main
import ( import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"io/ioutil" "os"
"github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
@ -58,7 +58,7 @@ make sure to use this feature with great caution!`,
keyfilepath := ctx.Args().First() keyfilepath := ctx.Args().First()
// Read key from file. // Read key from file.
keyjson, err := ioutil.ReadFile(keyfilepath) keyjson, err := os.ReadFile(keyfilepath)
if err != nil { if err != nil {
utils.Fatalf("Failed to read the keyfile at '%s': %v", keyfilepath, err) utils.Fatalf("Failed to read the keyfile at '%s': %v", keyfilepath, err)
} }

View File

@ -19,7 +19,7 @@ package main
import ( import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"io/ioutil" "os"
"github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
@ -56,7 +56,7 @@ To sign a message contained in a file, use the --msgfile flag.
// Load the keyfile. // Load the keyfile.
keyfilepath := ctx.Args().First() keyfilepath := ctx.Args().First()
keyjson, err := ioutil.ReadFile(keyfilepath) keyjson, err := os.ReadFile(keyfilepath)
if err != nil { if err != nil {
utils.Fatalf("Failed to read the keyfile at '%s': %v", keyfilepath, err) utils.Fatalf("Failed to read the keyfile at '%s': %v", keyfilepath, err)
} }
@ -146,7 +146,7 @@ func getMessage(ctx *cli.Context, msgarg int) []byte {
if len(ctx.Args()) > msgarg { if len(ctx.Args()) > msgarg {
utils.Fatalf("Can't use --msgfile and message argument at the same time.") utils.Fatalf("Can't use --msgfile and message argument at the same time.")
} }
msg, err := ioutil.ReadFile(file) msg, err := os.ReadFile(file)
if err != nil { if err != nil {
utils.Fatalf("Can't read message file: %v", err) utils.Fatalf("Can't read message file: %v", err)
} }

View File

@ -19,7 +19,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "os"
"strings" "strings"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
@ -34,7 +34,7 @@ func getPassphrase(ctx *cli.Context, confirmation bool) string {
// Look for the --passwordfile flag. // Look for the --passwordfile flag.
passphraseFile := ctx.String(passphraseFlag.Name) passphraseFile := ctx.String(passphraseFlag.Name)
if passphraseFile != "" { if passphraseFile != "" {
content, err := ioutil.ReadFile(passphraseFile) content, err := os.ReadFile(passphraseFile)
if err != nil { if err != nil {
utils.Fatalf("Failed to read password file '%s': %v", utils.Fatalf("Failed to read password file '%s': %v",
passphraseFile, err) passphraseFile, err)

View File

@ -19,7 +19,7 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "os"
"github.com/ethereum/go-ethereum/cmd/evm/internal/compiler" "github.com/ethereum/go-ethereum/cmd/evm/internal/compiler"
@ -41,7 +41,7 @@ func compileCmd(ctx *cli.Context) error {
} }
fn := ctx.Args().First() fn := ctx.Args().First()
src, err := ioutil.ReadFile(fn) src, err := os.ReadFile(fn)
if err != nil { if err != nil {
return err return err
} }

View File

@ -19,7 +19,7 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "os"
"strings" "strings"
"github.com/ethereum/go-ethereum/core/asm" "github.com/ethereum/go-ethereum/core/asm"
@ -38,7 +38,7 @@ func disasmCmd(ctx *cli.Context) error {
switch { switch {
case len(ctx.Args().First()) > 0: case len(ctx.Args().First()) > 0:
fn := ctx.Args().First() fn := ctx.Args().First()
input, err := ioutil.ReadFile(fn) input, err := os.ReadFile(fn)
if err != nil { if err != nil {
return err return err
} }

View File

@ -21,7 +21,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"math/big" "math/big"
"os" "os"
"path" "path"
@ -401,7 +400,7 @@ func saveFile(baseDir, filename string, data interface{}) error {
return NewError(ErrorJson, fmt.Errorf("failed marshalling output: %v", err)) return NewError(ErrorJson, fmt.Errorf("failed marshalling output: %v", err))
} }
location := path.Join(baseDir, filename) location := path.Join(baseDir, filename)
if err = ioutil.WriteFile(location, b, 0644); err != nil { if err = os.WriteFile(location, b, 0644); err != nil {
return NewError(ErrorIO, fmt.Errorf("failed writing output: %v", err)) return NewError(ErrorIO, fmt.Errorf("failed writing output: %v", err))
} }
log.Info("Wrote file", "file", location) log.Info("Wrote file", "file", location)

View File

@ -20,7 +20,7 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"math/big" "math/big"
"os" "os"
goruntime "runtime" goruntime "runtime"
@ -165,13 +165,13 @@ func runCmd(ctx *cli.Context) error {
// If - is specified, it means that code comes from stdin // If - is specified, it means that code comes from stdin
if codeFileFlag == "-" { if codeFileFlag == "-" {
//Try reading from stdin //Try reading from stdin
if hexcode, err = ioutil.ReadAll(os.Stdin); err != nil { if hexcode, err = io.ReadAll(os.Stdin); err != nil {
fmt.Printf("Could not load code from stdin: %v\n", err) fmt.Printf("Could not load code from stdin: %v\n", err)
os.Exit(1) os.Exit(1)
} }
} else { } else {
// Codefile with hex assembly // Codefile with hex assembly
if hexcode, err = ioutil.ReadFile(codeFileFlag); err != nil { if hexcode, err = os.ReadFile(codeFileFlag); err != nil {
fmt.Printf("Could not load code from file: %v\n", err) fmt.Printf("Could not load code from file: %v\n", err)
os.Exit(1) os.Exit(1)
} }
@ -187,7 +187,7 @@ func runCmd(ctx *cli.Context) error {
code = common.FromHex(string(hexcode)) code = common.FromHex(string(hexcode))
} else if fn := ctx.Args().First(); len(fn) > 0 { } else if fn := ctx.Args().First(); len(fn) > 0 {
// EASM-file to compile // EASM-file to compile
src, err := ioutil.ReadFile(fn) src, err := os.ReadFile(fn)
if err != nil { if err != nil {
return err return err
} }
@ -239,7 +239,7 @@ func runCmd(ctx *cli.Context) error {
var hexInput []byte var hexInput []byte
if inputFileFlag := ctx.GlobalString(InputFileFlag.Name); inputFileFlag != "" { if inputFileFlag := ctx.GlobalString(InputFileFlag.Name); inputFileFlag != "" {
var err error var err error
if hexInput, err = ioutil.ReadFile(inputFileFlag); err != nil { if hexInput, err = os.ReadFile(inputFileFlag); err != nil {
fmt.Printf("could not load input from file: %v\n", err) fmt.Printf("could not load input from file: %v\n", err)
os.Exit(1) os.Exit(1)
} }

View File

@ -20,7 +20,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/state"
@ -81,7 +80,7 @@ func stateTestCmd(ctx *cli.Context) error {
debugger = logger.NewStructLogger(config) debugger = logger.NewStructLogger(config)
} }
// Load the test content from the input file // Load the test content from the input file
src, err := ioutil.ReadFile(ctx.Args().First()) src, err := os.ReadFile(ctx.Args().First())
if err != nil { if err != nil {
return err return err
} }

View File

@ -26,7 +26,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"html/template" "html/template"
"io/ioutil" "io"
"math" "math"
"math/big" "math/big"
"net/http" "net/http"
@ -157,14 +157,14 @@ func main() {
} }
} }
// Load up the account key and decrypt its password // Load up the account key and decrypt its password
blob, err := ioutil.ReadFile(*accPassFlag) blob, err := os.ReadFile(*accPassFlag)
if err != nil { if err != nil {
log.Crit("Failed to read account password contents", "file", *accPassFlag, "err", err) log.Crit("Failed to read account password contents", "file", *accPassFlag, "err", err)
} }
pass := strings.TrimSuffix(string(blob), "\n") pass := strings.TrimSuffix(string(blob), "\n")
ks := keystore.NewKeyStore(filepath.Join(os.Getenv("HOME"), ".faucet", "keys"), keystore.StandardScryptN, keystore.StandardScryptP) ks := keystore.NewKeyStore(filepath.Join(os.Getenv("HOME"), ".faucet", "keys"), keystore.StandardScryptN, keystore.StandardScryptP)
if blob, err = ioutil.ReadFile(*accJSONFlag); err != nil { if blob, err = os.ReadFile(*accJSONFlag); err != nil {
log.Crit("Failed to read account key contents", "file", *accJSONFlag, "err", err) log.Crit("Failed to read account key contents", "file", *accJSONFlag, "err", err)
} }
acc, err := ks.Import(blob, pass, pass) acc, err := ks.Import(blob, pass, pass)
@ -727,7 +727,7 @@ func authTwitter(url string, tokenV1, tokenV2 string) (string, string, string, c
} }
username := parts[len(parts)-3] username := parts[len(parts)-3]
body, err := ioutil.ReadAll(res.Body) body, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
return "", "", "", common.Address{}, err return "", "", "", common.Address{}, err
} }
@ -853,7 +853,7 @@ func authFacebook(url string) (string, string, common.Address, error) {
} }
defer res.Body.Close() defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body) body, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
return "", "", common.Address{}, err return "", "", common.Address{}, err
} }

View File

@ -18,7 +18,7 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil" "os"
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/accounts/keystore"
@ -320,7 +320,7 @@ func importWallet(ctx *cli.Context) error {
if len(keyfile) == 0 { if len(keyfile) == 0 {
utils.Fatalf("keyfile must be given as argument") utils.Fatalf("keyfile must be given as argument")
} }
keyJSON, err := ioutil.ReadFile(keyfile) keyJSON, err := os.ReadFile(keyfile)
if err != nil { if err != nil {
utils.Fatalf("Could not read wallet file: %v", err) utils.Fatalf("Could not read wallet file: %v", err)
} }

View File

@ -18,6 +18,7 @@ package main
import ( import (
"io/ioutil" "io/ioutil"
"os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
@ -113,11 +114,11 @@ func TestAccountImport(t *testing.T) {
func importAccountWithExpect(t *testing.T, key string, expected string) { func importAccountWithExpect(t *testing.T, key string, expected string) {
dir := t.TempDir() dir := t.TempDir()
keyfile := filepath.Join(dir, "key.prv") 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) t.Error(err)
} }
passwordFile := filepath.Join(dir, "password.txt") 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) t.Error(err)
} }
geth := runGeth(t, "--lightkdf", "account", "import", keyfile, "-password", passwordFile) geth := runGeth(t, "--lightkdf", "account", "import", keyfile, "-password", passwordFile)

View File

@ -17,8 +17,8 @@
package main package main
import ( import (
"io/ioutil"
"math/big" "math/big"
"os"
"path/filepath" "path/filepath"
"testing" "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 // Start a Geth instance with the requested flags set and immediately terminate
if genesis != "" { if genesis != "" {
json := filepath.Join(datadir, "genesis.json") 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) t.Fatalf("test %d: failed to write genesis file: %v", test, err)
} }
runGeth(t, "--datadir", datadir, "--networkid", "1337", "init", json).WaitExit() runGeth(t, "--datadir", datadir, "--networkid", "1337", "init", json).WaitExit()

View File

@ -17,7 +17,7 @@
package main package main
import ( import (
"io/ioutil" "os"
"path/filepath" "path/filepath"
"testing" "testing"
) )
@ -76,7 +76,7 @@ func TestCustomGenesis(t *testing.T) {
// Initialize the data directory with the custom genesis block // Initialize the data directory with the custom genesis block
json := filepath.Join(datadir, "genesis.json") 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) t.Fatalf("test %d: failed to write genesis file: %v", i, err)
} }
runGeth(t, "--datadir", datadir, "init", json).WaitExit() runGeth(t, "--datadir", datadir, "init", json).WaitExit()

View File

@ -20,8 +20,9 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"os"
"regexp" "regexp"
"strings" "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 // fetch makes an HTTP request to the given url and returns the response body
func fetch(url string) ([]byte, error) { func fetch(url string) ([]byte, error) {
if filep := strings.TrimPrefix(url, "file://"); filep != url { if filep := strings.TrimPrefix(url, "file://"); filep != url {
return ioutil.ReadFile(filep) return os.ReadFile(filep)
} }
res, err := http.Get(url) res, err := http.Get(url)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body) body, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -20,6 +20,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strconv" "strconv"
@ -49,7 +50,7 @@ func TestVerification(t *testing.T) {
func testVerification(t *testing.T, pubkey, sigdir string) { func testVerification(t *testing.T, pubkey, sigdir string) {
// Data to verify // Data to verify
data, err := ioutil.ReadFile("./testdata/vcheck/data.json") data, err := os.ReadFile("./testdata/vcheck/data.json")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -59,7 +60,7 @@ func testVerification(t *testing.T, pubkey, sigdir string) {
t.Fatal(err) t.Fatal(err)
} }
for _, f := range files { 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -87,7 +88,7 @@ func versionUint(v string) int {
// TestMatching can be used to check that the regexps are correct // TestMatching can be used to check that the regexps are correct
func TestMatching(t *testing.T) { func TestMatching(t *testing.T) {
data, _ := ioutil.ReadFile("./testdata/vcheck/vulnerabilities.json") data, _ := os.ReadFile("./testdata/vcheck/vulnerabilities.json")
var vulns []vulnJson var vulns []vulnJson
if err := json.Unmarshal(data, &vulns); err != nil { if err := json.Unmarshal(data, &vulns); err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -19,7 +19,7 @@ package main
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"io/ioutil" "os"
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
@ -30,7 +30,7 @@ import (
// Tests the go-ethereum to Aleth chainspec conversion for the Stureby testnet. // Tests the go-ethereum to Aleth chainspec conversion for the Stureby testnet.
func TestAlethSturebyConverter(t *testing.T) { func TestAlethSturebyConverter(t *testing.T) {
blob, err := ioutil.ReadFile("testdata/stureby_geth.json") blob, err := os.ReadFile("testdata/stureby_geth.json")
if err != nil { if err != nil {
t.Fatalf("could not read file: %v", err) t.Fatalf("could not read file: %v", err)
} }
@ -43,7 +43,7 @@ func TestAlethSturebyConverter(t *testing.T) {
t.Fatalf("failed creating chainspec: %v", err) t.Fatalf("failed creating chainspec: %v", err)
} }
expBlob, err := ioutil.ReadFile("testdata/stureby_aleth.json") expBlob, err := os.ReadFile("testdata/stureby_aleth.json")
if err != nil { if err != nil {
t.Fatalf("could not read file: %v", err) t.Fatalf("could not read file: %v", err)
} }
@ -69,7 +69,7 @@ func TestAlethSturebyConverter(t *testing.T) {
// Tests the go-ethereum to Parity chainspec conversion for the Stureby testnet. // Tests the go-ethereum to Parity chainspec conversion for the Stureby testnet.
func TestParitySturebyConverter(t *testing.T) { func TestParitySturebyConverter(t *testing.T) {
blob, err := ioutil.ReadFile("testdata/stureby_geth.json") blob, err := os.ReadFile("testdata/stureby_geth.json")
if err != nil { if err != nil {
t.Fatalf("could not read file: %v", err) t.Fatalf("could not read file: %v", err)
} }
@ -85,7 +85,7 @@ func TestParitySturebyConverter(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("failed encoding chainspec: %v", err) t.Fatalf("failed encoding chainspec: %v", err)
} }
expBlob, err := ioutil.ReadFile("testdata/stureby_parity.json") expBlob, err := os.ReadFile("testdata/stureby_parity.json")
if err != nil { if err != nil {
t.Fatalf("could not read file: %v", err) t.Fatalf("could not read file: %v", err)
} }

View File

@ -21,7 +21,6 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"net" "net"
"os" "os"
"os/user" "os/user"
@ -96,7 +95,7 @@ func dial(server string, pubkey []byte) (*sshClient, error) {
} }
if err != nil { if err != nil {
path := filepath.Join(user.HomeDir, ".ssh", identity) path := filepath.Join(user.HomeDir, ".ssh", identity)
if buf, err := ioutil.ReadFile(path); err != nil { if buf, err := os.ReadFile(path); err != nil {
log.Warn("No SSH key, falling back to passwords", "path", path, "err", err) log.Warn("No SSH key, falling back to passwords", "path", path, "err", err)
} else { } else {
key, err := ssh.ParsePrivateKey(buf) key, err := ssh.ParsePrivateKey(buf)

View File

@ -19,7 +19,6 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"math/big" "math/big"
"net" "net"
"net/url" "net/url"
@ -65,7 +64,7 @@ func (c config) flush() {
os.MkdirAll(filepath.Dir(c.path), 0755) os.MkdirAll(filepath.Dir(c.path), 0755)
out, _ := json.MarshalIndent(c, "", " ") out, _ := json.MarshalIndent(c, "", " ")
if err := ioutil.WriteFile(c.path, out, 0644); err != nil { if err := os.WriteFile(c.path, out, 0644); err != nil {
log.Warn("Failed to save puppeth configs", "file", c.path, "err", err) log.Warn("Failed to save puppeth configs", "file", c.path, "err", err)
} }
} }

View File

@ -21,7 +21,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math/big" "math/big"
"math/rand" "math/rand"
"net/http" "net/http"
@ -263,7 +262,7 @@ func (w *wizard) manageGenesis() {
// Export the native genesis spec used by puppeth and Geth // Export the native genesis spec used by puppeth and Geth
gethJson := filepath.Join(folder, fmt.Sprintf("%s.json", w.network)) gethJson := filepath.Join(folder, fmt.Sprintf("%s.json", w.network))
if err := ioutil.WriteFile(gethJson, out, 0644); err != nil { if err := os.WriteFile(gethJson, out, 0644); err != nil {
log.Error("Failed to save genesis file", "err", err) log.Error("Failed to save genesis file", "err", err)
return return
} }
@ -305,7 +304,7 @@ func saveGenesis(folder, network, client string, spec interface{}) {
path := filepath.Join(folder, fmt.Sprintf("%s-%s.json", network, client)) path := filepath.Join(folder, fmt.Sprintf("%s-%s.json", network, client))
out, _ := json.MarshalIndent(spec, "", " ") out, _ := json.MarshalIndent(spec, "", " ")
if err := ioutil.WriteFile(path, out, 0644); err != nil { if err := os.WriteFile(path, out, 0644); err != nil {
log.Error("Failed to save genesis file", "client", client, "err", err) log.Error("Failed to save genesis file", "client", client, "err", err)
return return
} }

View File

@ -19,7 +19,6 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -73,7 +72,7 @@ func (w *wizard) run() {
// Load initial configurations and connect to all live servers // Load initial configurations and connect to all live servers
w.conf.path = filepath.Join(os.Getenv("HOME"), ".puppeth", w.network) w.conf.path = filepath.Join(os.Getenv("HOME"), ".puppeth", w.network)
blob, err := ioutil.ReadFile(w.conf.path) blob, err := os.ReadFile(w.conf.path)
if err != nil { if err != nil {
log.Warn("No previous configurations found", "path", w.conf.path) log.Warn("No previous configurations found", "path", w.conf.path)
} else if err := json.Unmarshal(blob, &w.conf); err != nil { } else if err := json.Unmarshal(blob, &w.conf); err != nil {

View File

@ -21,7 +21,6 @@ import (
"crypto/ecdsa" "crypto/ecdsa"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math" "math"
"math/big" "math/big"
"os" "os"
@ -1213,7 +1212,7 @@ func MakePasswordList(ctx *cli.Context) []string {
if path == "" { if path == "" {
return nil return nil
} }
text, err := ioutil.ReadFile(path) text, err := os.ReadFile(path)
if err != nil { if err != nil {
Fatalf("Failed to read password file: %v", err) Fatalf("Failed to read password file: %v", err)
} }

View File

@ -19,7 +19,7 @@ package compiler
import ( import (
"bytes" "bytes"
"io/ioutil" "os"
"regexp" "regexp"
) )
@ -55,7 +55,7 @@ type ContractInfo struct {
func slurpFiles(files []string) (string, error) { func slurpFiles(files []string) (string, error) {
var concat bytes.Buffer var concat bytes.Buffer
for _, file := range files { for _, file := range files {
content, err := ioutil.ReadFile(file) content, err := os.ReadFile(file)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -19,12 +19,12 @@ package common
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "os"
) )
// LoadJSON reads the given file and unmarshals its content. // LoadJSON reads the given file and unmarshals its content.
func LoadJSON(file string, val interface{}) error { func LoadJSON(file string, val interface{}) error {
content, err := ioutil.ReadFile(file) content, err := os.ReadFile(file)
if err != nil { if err != nil {
return err return err
} }

View File

@ -19,7 +19,6 @@ package ethash
import ( import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"io/ioutil"
"math/big" "math/big"
"os" "os"
"reflect" "reflect"
@ -700,7 +699,7 @@ func TestConcurrentDiskCacheGeneration(t *testing.T) {
// Create a temp folder to generate the caches into // Create a temp folder to generate the caches into
// TODO: t.TempDir fails to remove the directory on Windows // TODO: t.TempDir fails to remove the directory on Windows
// \AppData\Local\Temp\1\TestConcurrentDiskCacheGeneration2382060137\001\cache-R23-1dca8a85e74aa763: Access is denied. // \AppData\Local\Temp\1\TestConcurrentDiskCacheGeneration2382060137\001\cache-R23-1dca8a85e74aa763: Access is denied.
cachedir, err := ioutil.TempDir("", "") cachedir, err := os.MkdirTemp("", "")
if err != nil { if err != nil {
t.Fatalf("Failed to create temporary cache dir: %v", err) t.Fatalf("Failed to create temporary cache dir: %v", err)
} }

View File

@ -17,7 +17,6 @@
package ethash package ethash
import ( import (
"io/ioutil"
"math/big" "math/big"
"math/rand" "math/rand"
"os" "os"
@ -59,7 +58,7 @@ func TestTestMode(t *testing.T) {
func TestCacheFileEvict(t *testing.T) { func TestCacheFileEvict(t *testing.T) {
// TODO: t.TempDir fails to remove the directory on Windows // TODO: t.TempDir fails to remove the directory on Windows
// \AppData\Local\Temp\1\TestCacheFileEvict2179435125\001\cache-R23-0000000000000000: Access is denied. // \AppData\Local\Temp\1\TestCacheFileEvict2179435125\001\cache-R23-0000000000000000: Access is denied.
tmpdir, err := ioutil.TempDir("", "ethash-test") tmpdir, err := os.MkdirTemp("", "ethash-test")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -18,7 +18,7 @@ package ethash
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "io"
"math/big" "math/big"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -37,7 +37,7 @@ func TestRemoteNotify(t *testing.T) {
// Start a simple web server to capture notifications. // Start a simple web server to capture notifications.
sink := make(chan [3]string) sink := make(chan [3]string)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
blob, err := ioutil.ReadAll(req.Body) blob, err := io.ReadAll(req.Body)
if err != nil { if err != nil {
t.Errorf("failed to read miner notification: %v", err) t.Errorf("failed to read miner notification: %v", err)
} }
@ -80,7 +80,7 @@ func TestRemoteNotifyFull(t *testing.T) {
// Start a simple web server to capture notifications. // Start a simple web server to capture notifications.
sink := make(chan map[string]interface{}) sink := make(chan map[string]interface{})
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
blob, err := ioutil.ReadAll(req.Body) blob, err := io.ReadAll(req.Body)
if err != nil { if err != nil {
t.Errorf("failed to read miner notification: %v", err) t.Errorf("failed to read miner notification: %v", err)
} }
@ -125,7 +125,7 @@ func TestRemoteMultiNotify(t *testing.T) {
// Start a simple web server to capture notifications. // Start a simple web server to capture notifications.
sink := make(chan [3]string, 64) sink := make(chan [3]string, 64)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
blob, err := ioutil.ReadAll(req.Body) blob, err := io.ReadAll(req.Body)
if err != nil { if err != nil {
t.Errorf("failed to read miner notification: %v", err) t.Errorf("failed to read miner notification: %v", err)
} }
@ -170,7 +170,7 @@ func TestRemoteMultiNotifyFull(t *testing.T) {
// Start a simple web server to capture notifications. // Start a simple web server to capture notifications.
sink := make(chan map[string]interface{}, 64) sink := make(chan map[string]interface{}, 64)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
blob, err := ioutil.ReadAll(req.Body) blob, err := io.ReadAll(req.Body)
if err != nil { if err != nil {
t.Errorf("failed to read miner notification: %v", err) t.Errorf("failed to read miner notification: %v", err)
} }

View File

@ -20,7 +20,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"os/signal" "os/signal"
"path/filepath" "path/filepath"
@ -158,7 +157,7 @@ func (c *Console) init(preload []string) error {
// Configure the input prompter for history and tab completion. // Configure the input prompter for history and tab completion.
if c.prompter != nil { if c.prompter != nil {
if content, err := ioutil.ReadFile(c.histPath); err != nil { if content, err := os.ReadFile(c.histPath); err != nil {
c.prompter.SetHistory(nil) c.prompter.SetHistory(nil)
} else { } else {
c.history = strings.Split(string(content), "\n") c.history = strings.Split(string(content), "\n")
@ -559,7 +558,7 @@ func (c *Console) Stop(graceful bool) error {
} }
func (c *Console) writeHistory() error { func (c *Console) writeHistory() error {
if err := ioutil.WriteFile(c.histPath, []byte(strings.Join(c.history, "\n")), 0600); err != nil { if err := os.WriteFile(c.histPath, []byte(strings.Join(c.history, "\n")), 0600); err != nil {
return err return err
} }
return os.Chmod(c.histPath, 0600) // Force 0600, even if it was different previously return os.Chmod(c.histPath, 0600) // Force 0600, even if it was different previously

View File

@ -20,9 +20,9 @@ import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"io/ioutil"
"math/big" "math/big"
"math/rand" "math/rand"
"os"
"reflect" "reflect"
"testing" "testing"
@ -852,7 +852,7 @@ func TestDeriveLogFields(t *testing.T) {
func BenchmarkDecodeRLPLogs(b *testing.B) { func BenchmarkDecodeRLPLogs(b *testing.B) {
// Encoded receipts from block 0x14ee094309fbe8f70b65f45ebcc08fb33f126942d97464aad5eb91cfd1e2d269 // Encoded receipts from block 0x14ee094309fbe8f70b65f45ebcc08fb33f126942d97464aad5eb91cfd1e2d269
buf, err := ioutil.ReadFile("testdata/stored_receipts.bin") buf, err := os.ReadFile("testdata/stored_receipts.bin")
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }

View File

@ -17,13 +17,12 @@
package rawdb package rawdb
import ( import (
"io/ioutil"
"os" "os"
"testing" "testing"
) )
func TestReadWriteFreezerTableMeta(t *testing.T) { func TestReadWriteFreezerTableMeta(t *testing.T) {
f, err := ioutil.TempFile(os.TempDir(), "*") f, err := os.CreateTemp(os.TempDir(), "*")
if err != nil { if err != nil {
t.Fatalf("Failed to create file %v", err) t.Fatalf("Failed to create file %v", err)
} }
@ -44,7 +43,7 @@ func TestReadWriteFreezerTableMeta(t *testing.T) {
} }
func TestInitializeFreezerTableMeta(t *testing.T) { func TestInitializeFreezerTableMeta(t *testing.T) {
f, err := ioutil.TempFile(os.TempDir(), "*") f, err := os.CreateTemp(os.TempDir(), "*")
if err != nil { if err != nil {
t.Fatalf("Failed to create file %v", err) t.Fatalf("Failed to create file %v", err)
} }

View File

@ -18,7 +18,6 @@ package rawdb
import ( import (
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
) )
@ -30,7 +29,7 @@ import (
// It is perfectly valid to have destPath == srcPath. // It is perfectly valid to have destPath == srcPath.
func copyFrom(srcPath, destPath string, offset uint64, before func(f *os.File) error) error { func copyFrom(srcPath, destPath string, offset uint64, before func(f *os.File) error) error {
// Create a temp file in the same dir where we want it to wind up // Create a temp file in the same dir where we want it to wind up
f, err := ioutil.TempFile(filepath.Dir(destPath), "*") f, err := os.CreateTemp(filepath.Dir(destPath), "*")
if err != nil { if err != nil {
return err return err
} }

View File

@ -18,7 +18,6 @@ package rawdb
import ( import (
"bytes" "bytes"
"io/ioutil"
"os" "os"
"testing" "testing"
) )
@ -44,7 +43,7 @@ func TestCopyFrom(t *testing.T) {
{"foo", "bar", 8, true}, {"foo", "bar", 8, true},
} }
for _, c := range cases { for _, c := range cases {
ioutil.WriteFile(c.src, content, 0644) os.WriteFile(c.src, content, 0644)
if err := copyFrom(c.src, c.dest, c.offset, func(f *os.File) error { if err := copyFrom(c.src, c.dest, c.offset, func(f *os.File) error {
if !c.writePrefix { if !c.writePrefix {
@ -57,7 +56,7 @@ func TestCopyFrom(t *testing.T) {
t.Fatalf("Failed to copy %v", err) t.Fatalf("Failed to copy %v", err)
} }
blob, err := ioutil.ReadFile(c.dest) blob, err := os.ReadFile(c.dest)
if err != nil { if err != nil {
os.Remove(c.src) os.Remove(c.src)
os.Remove(c.dest) os.Remove(c.dest)

View File

@ -20,7 +20,6 @@ import (
"crypto/ecdsa" "crypto/ecdsa"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"math/big" "math/big"
"math/rand" "math/rand"
"os" "os"
@ -2243,7 +2242,7 @@ func testTransactionJournaling(t *testing.T, nolocals bool) {
t.Parallel() t.Parallel()
// Create a temporary file for the journal // Create a temporary file for the journal
file, err := ioutil.TempFile("", "") file, err := os.CreateTemp("", "")
if err != nil { if err != nil {
t.Fatalf("failed to create temporary journal: %v", err) t.Fatalf("failed to create temporary journal: %v", err)
} }

View File

@ -20,7 +20,7 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "os"
"testing" "testing"
"time" "time"
@ -334,7 +334,7 @@ func TestPrecompiledBLS12381MapG1Fail(t *testing.T) { testJsonFail("blsMapG
func TestPrecompiledBLS12381MapG2Fail(t *testing.T) { testJsonFail("blsMapG2", "12", t) } func TestPrecompiledBLS12381MapG2Fail(t *testing.T) { testJsonFail("blsMapG2", "12", t) }
func loadJson(name string) ([]precompiledTest, error) { func loadJson(name string) ([]precompiledTest, error) {
data, err := ioutil.ReadFile(fmt.Sprintf("testdata/precompiles/%v.json", name)) data, err := os.ReadFile(fmt.Sprintf("testdata/precompiles/%v.json", name))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -344,7 +344,7 @@ func loadJson(name string) ([]precompiledTest, error) {
} }
func loadJsonFail(name string) ([]precompiledFailureTest, error) { func loadJsonFail(name string) ([]precompiledFailureTest, error) {
data, err := ioutil.ReadFile(fmt.Sprintf("testdata/precompiles/fail-%v.json", name)) data, err := os.ReadFile(fmt.Sprintf("testdata/precompiles/fail-%v.json", name))
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -20,8 +20,8 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"math/big" "math/big"
"os"
"testing" "testing"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -260,7 +260,7 @@ func TestWriteExpectedValues(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
_ = ioutil.WriteFile(fmt.Sprintf("testdata/testcases_%v.json", name), data, 0644) _ = os.WriteFile(fmt.Sprintf("testdata/testcases_%v.json", name), data, 0644)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -270,7 +270,7 @@ func TestWriteExpectedValues(t *testing.T) {
// TestJsonTestcases runs through all the testcases defined as json-files // TestJsonTestcases runs through all the testcases defined as json-files
func TestJsonTestcases(t *testing.T) { func TestJsonTestcases(t *testing.T) {
for name := range twoOpMethods { for name := range twoOpMethods {
data, err := ioutil.ReadFile(fmt.Sprintf("testdata/testcases_%v.json", name)) data, err := os.ReadFile(fmt.Sprintf("testdata/testcases_%v.json", name))
if err != nil { if err != nil {
t.Fatal("Failed to read file", err) t.Fatal("Failed to read file", err)
} }

View File

@ -26,7 +26,6 @@ import (
"fmt" "fmt"
"hash" "hash"
"io" "io"
"io/ioutil"
"math/big" "math/big"
"os" "os"
@ -250,7 +249,7 @@ func checkKeyFileEnd(r *bufio.Reader) error {
// restrictive permissions. The key data is saved hex-encoded. // restrictive permissions. The key data is saved hex-encoded.
func SaveECDSA(file string, key *ecdsa.PrivateKey) error { func SaveECDSA(file string, key *ecdsa.PrivateKey) error {
k := hex.EncodeToString(FromECDSA(key)) k := hex.EncodeToString(FromECDSA(key))
return ioutil.WriteFile(file, []byte(k), 0600) return os.WriteFile(file, []byte(k), 0600)
} }
// GenerateKey generates a new private key. // GenerateKey generates a new private key.

View File

@ -20,7 +20,6 @@ import (
"bytes" "bytes"
"crypto/ecdsa" "crypto/ecdsa"
"encoding/hex" "encoding/hex"
"io/ioutil"
"math/big" "math/big"
"os" "os"
"reflect" "reflect"
@ -182,7 +181,7 @@ func TestLoadECDSA(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
f, err := ioutil.TempFile("", "loadecdsa_test.*.txt") f, err := os.CreateTemp("", "loadecdsa_test.*.txt")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -203,7 +202,7 @@ func TestLoadECDSA(t *testing.T) {
} }
func TestSaveECDSA(t *testing.T) { func TestSaveECDSA(t *testing.T) {
f, err := ioutil.TempFile("", "saveecdsa_test.*.txt") f, err := os.CreateTemp("", "saveecdsa_test.*.txt")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -25,7 +25,7 @@ import (
"encoding/base64" "encoding/base64"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "os"
"strings" "strings"
"time" "time"
) )
@ -68,7 +68,7 @@ func SignFile(input string, output string, key string, untrustedComment string,
trustedComment = fmt.Sprintf("timestamp:%d", time.Now().Unix()) trustedComment = fmt.Sprintf("timestamp:%d", time.Now().Unix())
} }
filedata, err := ioutil.ReadFile(input) filedata, err := os.ReadFile(input)
if err != nil { if err != nil {
return err return err
} }
@ -96,5 +96,5 @@ func SignFile(input string, output string, key string, untrustedComment string,
fmt.Fprintln(out, base64.StdEncoding.EncodeToString(dataSig)) fmt.Fprintln(out, base64.StdEncoding.EncodeToString(dataSig))
fmt.Fprintln(out, "trusted comment:", trustedComment) fmt.Fprintln(out, "trusted comment:", trustedComment)
fmt.Fprintln(out, base64.StdEncoding.EncodeToString(commentSig)) fmt.Fprintln(out, base64.StdEncoding.EncodeToString(commentSig))
return ioutil.WriteFile(output, out.Bytes(), 0644) return os.WriteFile(output, out.Bytes(), 0644)
} }

View File

@ -22,7 +22,6 @@ package signify
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os" "os"
"os/exec" "os/exec"
@ -35,7 +34,7 @@ func Fuzz(data []byte) int {
if len(data) < 32 { if len(data) < 32 {
return -1 return -1
} }
tmpFile, err := ioutil.TempFile("", "") tmpFile, err := os.CreateTemp("", "")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -76,7 +75,7 @@ func Fuzz(data []byte) int {
// Write the public key into the file to pass it as // Write the public key into the file to pass it as
// an argument to signify-openbsd // an argument to signify-openbsd
pubKeyFile, err := ioutil.TempFile("", "") pubKeyFile, err := os.CreateTemp("", "")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -128,7 +127,7 @@ func getKey(fileS string) (string, error) {
func createKeyPair() (string, string) { func createKeyPair() (string, string) {
// Create key and put it in correct format // Create key and put it in correct format
tmpKey, err := ioutil.TempFile("", "") tmpKey, err := os.CreateTemp("", "")
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -20,7 +20,6 @@
package signify package signify
import ( import (
"io/ioutil"
"math/rand" "math/rand"
"os" "os"
"testing" "testing"
@ -35,7 +34,7 @@ var (
) )
func TestSignify(t *testing.T) { func TestSignify(t *testing.T) {
tmpFile, err := ioutil.TempFile("", "") tmpFile, err := os.CreateTemp("", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -79,7 +78,7 @@ func TestSignify(t *testing.T) {
} }
func TestSignifyTrustedCommentTooManyLines(t *testing.T) { func TestSignifyTrustedCommentTooManyLines(t *testing.T) {
tmpFile, err := ioutil.TempFile("", "") tmpFile, err := os.CreateTemp("", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -104,7 +103,7 @@ func TestSignifyTrustedCommentTooManyLines(t *testing.T) {
} }
func TestSignifyTrustedCommentTooManyLinesLF(t *testing.T) { func TestSignifyTrustedCommentTooManyLinesLF(t *testing.T) {
tmpFile, err := ioutil.TempFile("", "") tmpFile, err := os.CreateTemp("", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -129,7 +128,7 @@ func TestSignifyTrustedCommentTooManyLinesLF(t *testing.T) {
} }
func TestSignifyTrustedCommentEmpty(t *testing.T) { func TestSignifyTrustedCommentEmpty(t *testing.T) {
tmpFile, err := ioutil.TempFile("", "") tmpFile, err := os.CreateTemp("", "")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -22,7 +22,6 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"runtime" "runtime"
"sync" "sync"
@ -463,7 +462,7 @@ func (api *API) TraceBlock(ctx context.Context, blob hexutil.Bytes, config *Trac
// TraceBlockFromFile returns the structured logs created during the execution of // TraceBlockFromFile returns the structured logs created during the execution of
// EVM and returns them as a JSON object. // EVM and returns them as a JSON object.
func (api *API) TraceBlockFromFile(ctx context.Context, file string, config *TraceConfig) ([]*txTraceResult, error) { func (api *API) TraceBlockFromFile(ctx context.Context, file string, config *TraceConfig) ([]*txTraceResult, error) {
blob, err := ioutil.ReadFile(file) blob, err := os.ReadFile(file)
if err != nil { if err != nil {
return nil, fmt.Errorf("could not read file: %v", err) return nil, fmt.Errorf("could not read file: %v", err)
} }
@ -722,7 +721,7 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
if !canon { if !canon {
prefix = fmt.Sprintf("%valt-", prefix) prefix = fmt.Sprintf("%valt-", prefix)
} }
dump, err = ioutil.TempFile(os.TempDir(), prefix) dump, err = os.CreateTemp(os.TempDir(), prefix)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -20,6 +20,7 @@ import (
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
"math/big" "math/big"
"os"
"path/filepath" "path/filepath"
"reflect" "reflect"
"strings" "strings"
@ -152,7 +153,7 @@ func testCallTracer(tracerName string, dirPath string, t *testing.T) {
tx = new(types.Transaction) tx = new(types.Transaction)
) )
// Call tracer test found, read if from disk // Call tracer test found, read if from disk
if blob, err := ioutil.ReadFile(filepath.Join("testdata", dirPath, file.Name())); err != nil { if blob, err := os.ReadFile(filepath.Join("testdata", dirPath, file.Name())); err != nil {
t.Fatalf("failed to read testcase: %v", err) t.Fatalf("failed to read testcase: %v", err)
} else if err := json.Unmarshal(blob, test); err != nil { } else if err := json.Unmarshal(blob, test); err != nil {
t.Fatalf("failed to parse testcase: %v", err) t.Fatalf("failed to parse testcase: %v", err)
@ -250,7 +251,7 @@ func BenchmarkTracers(b *testing.B) {
} }
file := file // capture range variable file := file // capture range variable
b.Run(camel(strings.TrimSuffix(file.Name(), ".json")), func(b *testing.B) { b.Run(camel(strings.TrimSuffix(file.Name(), ".json")), func(b *testing.B) {
blob, err := ioutil.ReadFile(filepath.Join("testdata", "call_tracer", file.Name())) blob, err := os.ReadFile(filepath.Join("testdata", "call_tracer", file.Name()))
if err != nil { if err != nil {
b.Fatalf("failed to read testcase: %v", err) b.Fatalf("failed to read testcase: %v", err)
} }

View File

@ -18,7 +18,7 @@ package graphql
import ( import (
"fmt" "fmt"
"io/ioutil" "io"
"math/big" "math/big"
"net/http" "net/http"
"strings" "strings"
@ -146,7 +146,7 @@ func TestGraphQLBlockSerialization(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("could not post: %v", err) t.Fatalf("could not post: %v", err)
} }
bodyBytes, err := ioutil.ReadAll(resp.Body) bodyBytes, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatalf("could not read from response body: %v", err) t.Fatalf("could not read from response body: %v", err)
} }
@ -182,7 +182,7 @@ func TestGraphQLBlockSerializationEIP2718(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("could not post: %v", err) t.Fatalf("could not post: %v", err)
} }
bodyBytes, err := ioutil.ReadAll(resp.Body) bodyBytes, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatalf("could not read from response body: %v", err) t.Fatalf("could not read from response body: %v", err)
} }

View File

@ -22,7 +22,6 @@ import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
"net/http" "net/http"
"os" "os"
@ -37,7 +36,7 @@ type ChecksumDB struct {
// MustLoadChecksums loads a file containing checksums. // MustLoadChecksums loads a file containing checksums.
func MustLoadChecksums(file string) *ChecksumDB { func MustLoadChecksums(file string) *ChecksumDB {
content, err := ioutil.ReadFile(file) content, err := os.ReadFile(file)
if err != nil { if err != nil {
log.Fatal("can't load checksum file: " + err.Error()) log.Fatal("can't load checksum file: " + err.Error())
} }

View File

@ -77,7 +77,7 @@ func RunGit(args ...string) string {
// readGitFile returns content of file in .git directory. // readGitFile returns content of file in .git directory.
func readGitFile(file string) string { func readGitFile(file string) string {
content, err := ioutil.ReadFile(path.Join(".git", file)) content, err := os.ReadFile(path.Join(".git", file))
if err != nil { if err != nil {
return "" return ""
} }

View File

@ -21,7 +21,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"regexp" "regexp"
@ -184,7 +183,7 @@ func (tt *TestCmd) ExpectRegexp(regex string) (*regexp.Regexp, []string) {
func (tt *TestCmd) ExpectExit() { func (tt *TestCmd) ExpectExit() {
var output []byte var output []byte
tt.withKillTimeout(func() { tt.withKillTimeout(func() {
output, _ = ioutil.ReadAll(tt.stdout) output, _ = io.ReadAll(tt.stdout)
}) })
tt.WaitExit() tt.WaitExit()
if tt.Cleanup != nil { if tt.Cleanup != nil {

View File

@ -23,8 +23,8 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"os"
"time" "time"
"github.com/dop251/goja" "github.com/dop251/goja"
@ -254,7 +254,7 @@ func (re *JSRE) Stop(waitForCallbacks bool) {
// Exec(file) loads and runs the contents of a file // Exec(file) loads and runs the contents of a file
// if a relative path is given, the jsre's assetPath is used // if a relative path is given, the jsre's assetPath is used
func (re *JSRE) Exec(file string) error { func (re *JSRE) Exec(file string) error {
code, err := ioutil.ReadFile(common.AbsolutePath(re.assetPath, file)) code, err := os.ReadFile(common.AbsolutePath(re.assetPath, file))
if err != nil { if err != nil {
return err return err
} }
@ -320,7 +320,7 @@ func (re *JSRE) Compile(filename string, src string) (err error) {
func (re *JSRE) loadScript(call Call) (goja.Value, error) { func (re *JSRE) loadScript(call Call) (goja.Value, error) {
file := call.Argument(0).ToString().String() file := call.Argument(0).ToString().String()
file = common.AbsolutePath(re.assetPath, file) file = common.AbsolutePath(re.assetPath, file)
source, err := ioutil.ReadFile(file) source, err := os.ReadFile(file)
if err != nil { if err != nil {
return nil, fmt.Errorf("Could not read file %s: %v", file, err) return nil, fmt.Errorf("Could not read file %s: %v", file, err)
} }

View File

@ -17,7 +17,6 @@
package jsre package jsre
import ( import (
"io/ioutil"
"os" "os"
"path" "path"
"reflect" "reflect"
@ -43,7 +42,7 @@ func (no *testNativeObjectBinding) TestMethod(call goja.FunctionCall) goja.Value
func newWithTestJS(t *testing.T, testjs string) *JSRE { func newWithTestJS(t *testing.T, testjs string) *JSRE {
dir := t.TempDir() dir := t.TempDir()
if testjs != "" { if testjs != "" {
if err := ioutil.WriteFile(path.Join(dir, "test.js"), []byte(testjs), os.ModePerm); err != nil { if err := os.WriteFile(path.Join(dir, "test.js"), []byte(testjs), os.ModePerm); err != nil {
t.Fatal("cannot create test.js:", err) t.Fatal("cannot create test.js:", err)
} }
} }

View File

@ -25,7 +25,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"regexp" "regexp"
"runtime" "runtime"
"sync" "sync"
@ -65,7 +64,7 @@ func MatchTests(tests []Test, expr string) []Test {
// If the report writer is non-nil, a test report is written to it in real time. // If the report writer is non-nil, a test report is written to it in real time.
func RunTests(tests []Test, report io.Writer) []Result { func RunTests(tests []Test, report io.Writer) []Result {
if report == nil { if report == nil {
report = ioutil.Discard report = io.Discard
} }
results := run(tests, newConsoleOutput(report)) results := run(tests, newConsoleOutput(report))
fails := CountFailures(results) fails := CountFailures(results)

View File

@ -20,7 +20,6 @@ import (
"context" "context"
"errors" "errors"
"flag" "flag"
"io/ioutil"
"math/rand" "math/rand"
"os" "os"
"sync" "sync"
@ -423,7 +422,7 @@ func NewAdapter(adapterType string, services adapters.LifecycleConstructors) (ad
// case "socket": // case "socket":
// adapter = adapters.NewSocketAdapter(services) // adapter = adapters.NewSocketAdapter(services)
case "exec": case "exec":
baseDir, err0 := ioutil.TempDir("", "les-test") baseDir, err0 := os.MkdirTemp("", "les-test")
if err0 != nil { if err0 != nil {
return nil, teardown, err0 return nil, teardown, err0
} }

View File

@ -4,7 +4,7 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
) )
@ -93,7 +93,7 @@ func (c *LibratoClient) PostMetrics(batch Batch) (err error) {
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
var body []byte var body []byte
if body, err = ioutil.ReadAll(resp.Body); err != nil { if body, err = io.ReadAll(resp.Body); err != nil {
body = []byte(fmt.Sprintf("(could not fetch response body for error: %s)", err)) body = []byte(fmt.Sprintf("(could not fetch response body for error: %s)", err))
} }
err = fmt.Errorf("unable to post to Librato: %d %s %s", resp.StatusCode, resp.Status, string(body)) err = fmt.Errorf("unable to post to Librato: %d %s %s", resp.StatusCode, resp.Status, string(body))

View File

@ -2,7 +2,7 @@ package metrics
import ( import (
"fmt" "fmt"
"io/ioutil" "io"
"log" "log"
"sync" "sync"
"testing" "testing"
@ -13,7 +13,7 @@ const FANOUT = 128
// Stop the compiler from complaining during debugging. // Stop the compiler from complaining during debugging.
var ( var (
_ = ioutil.Discard _ = io.Discard
_ = log.LstdFlags _ = log.LstdFlags
) )
@ -78,7 +78,7 @@ func BenchmarkMetrics(b *testing.B) {
//log.Println("done Write") //log.Println("done Write")
return return
default: default:
WriteOnce(r, ioutil.Discard) WriteOnce(r, io.Discard)
} }
} }
}() }()

View File

@ -19,7 +19,6 @@ package main
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
"io/ioutil"
"math/big" "math/big"
"math/rand" "math/rand"
"os" "os"
@ -222,7 +221,7 @@ func makeGenesis(faucets []*ecdsa.PrivateKey) *core.Genesis {
func makeMiner(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) { func makeMiner(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) {
// Define the basic configurations for the Ethereum node // Define the basic configurations for the Ethereum node
datadir, _ := ioutil.TempDir("", "") datadir, _ := os.MkdirTemp("", "")
config := &node.Config{ config := &node.Config{
Name: "geth", Name: "geth",

View File

@ -20,7 +20,6 @@ package main
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
"errors" "errors"
"io/ioutil"
"math/big" "math/big"
"math/rand" "math/rand"
"os" "os"
@ -461,7 +460,7 @@ func makeGenesis(faucets []*ecdsa.PrivateKey) *core.Genesis {
func makeFullNode(genesis *core.Genesis) (*node.Node, *eth.Ethereum, *ethcatalyst.ConsensusAPI, error) { func makeFullNode(genesis *core.Genesis) (*node.Node, *eth.Ethereum, *ethcatalyst.ConsensusAPI, error) {
// Define the basic configurations for the Ethereum node // Define the basic configurations for the Ethereum node
datadir, _ := ioutil.TempDir("", "") datadir, _ := os.MkdirTemp("", "")
config := &node.Config{ config := &node.Config{
Name: "geth", Name: "geth",
@ -512,7 +511,7 @@ func makeFullNode(genesis *core.Genesis) (*node.Node, *eth.Ethereum, *ethcatalys
func makeLightNode(genesis *core.Genesis) (*node.Node, *les.LightEthereum, *lescatalyst.ConsensusAPI, error) { func makeLightNode(genesis *core.Genesis) (*node.Node, *les.LightEthereum, *lescatalyst.ConsensusAPI, error) {
// Define the basic configurations for the Ethereum node // Define the basic configurations for the Ethereum node
datadir, _ := ioutil.TempDir("", "") datadir, _ := os.MkdirTemp("", "")
config := &node.Config{ config := &node.Config{
Name: "geth", Name: "geth",

View File

@ -20,7 +20,6 @@ package main
import ( import (
"bytes" "bytes"
"crypto/ecdsa" "crypto/ecdsa"
"io/ioutil"
"math/big" "math/big"
"math/rand" "math/rand"
"os" "os"
@ -183,7 +182,7 @@ func makeGenesis(faucets []*ecdsa.PrivateKey, sealers []*ecdsa.PrivateKey) *core
func makeSealer(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) { func makeSealer(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) {
// Define the basic configurations for the Ethereum node // Define the basic configurations for the Ethereum node
datadir, _ := ioutil.TempDir("", "") datadir, _ := os.MkdirTemp("", "")
config := &node.Config{ config := &node.Config{
Name: "geth", Name: "geth",

View File

@ -19,7 +19,6 @@ package main
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
"io/ioutil"
"math/big" "math/big"
"math/rand" "math/rand"
"os" "os"
@ -152,7 +151,7 @@ func makeGenesis(faucets []*ecdsa.PrivateKey) *core.Genesis {
func makeMiner(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) { func makeMiner(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) {
// Define the basic configurations for the Ethereum node // Define the basic configurations for the Ethereum node
datadir, _ := ioutil.TempDir("", "") datadir, _ := os.MkdirTemp("", "")
config := &node.Config{ config := &node.Config{
Name: "geth", Name: "geth",

View File

@ -17,7 +17,6 @@
package geth package geth
import ( import (
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -210,14 +209,14 @@ func TestAndroid(t *testing.T) {
} }
cp.CopyFile(filepath.Join("libs", "geth.aar"), "geth.aar") cp.CopyFile(filepath.Join("libs", "geth.aar"), "geth.aar")
if err = ioutil.WriteFile(filepath.Join("src", "androidTest", "java", "org", "ethereum", "gethtest", "AndroidTest.java"), []byte(androidTestClass), os.ModePerm); err != nil { if err = os.WriteFile(filepath.Join("src", "androidTest", "java", "org", "ethereum", "gethtest", "AndroidTest.java"), []byte(androidTestClass), os.ModePerm); err != nil {
t.Fatalf("failed to write Android test class: %v", err) t.Fatalf("failed to write Android test class: %v", err)
} }
// Finish creating the project and run the tests via gradle // Finish creating the project and run the tests via gradle
if err = ioutil.WriteFile(filepath.Join("src", "main", "AndroidManifest.xml"), []byte(androidManifest), os.ModePerm); err != nil { if err = os.WriteFile(filepath.Join("src", "main", "AndroidManifest.xml"), []byte(androidManifest), os.ModePerm); err != nil {
t.Fatalf("failed to write Android manifest: %v", err) t.Fatalf("failed to write Android manifest: %v", err)
} }
if err = ioutil.WriteFile("build.gradle", []byte(gradleConfig), os.ModePerm); err != nil { if err = os.WriteFile("build.gradle", []byte(gradleConfig), os.ModePerm); err != nil {
t.Fatalf("failed to write gradle build file: %v", err) t.Fatalf("failed to write gradle build file: %v", err)
} }
if output, err := exec.Command("gradle", "connectedAndroidTest").CombinedOutput(); err != nil { if output, err := exec.Command("gradle", "connectedAndroidTest").CombinedOutput(); err != nil {

View File

@ -19,7 +19,6 @@ package node
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -470,7 +469,7 @@ func getKeyStoreDir(conf *Config) (string, bool, error) {
isEphemeral := false isEphemeral := false
if keydir == "" { if keydir == "" {
// There is no datadir. // There is no datadir.
keydir, err = ioutil.TempDir("", "go-ethereum-keystore") keydir, err = os.MkdirTemp("", "go-ethereum-keystore")
isEphemeral = true isEphemeral = true
} }

View File

@ -18,7 +18,6 @@ package node
import ( import (
"bytes" "bytes"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -54,7 +53,7 @@ func TestDatadirCreation(t *testing.T) {
t.Fatalf("freshly created datadir not accessible: %v", err) t.Fatalf("freshly created datadir not accessible: %v", err)
} }
// Verify that an impossible datadir fails creation // Verify that an impossible datadir fails creation
file, err := ioutil.TempFile("", "") file, err := os.CreateTemp("", "")
if err != nil { if err != nil {
t.Fatalf("failed to create temporary file: %v", err) t.Fatalf("failed to create temporary file: %v", err)
} }
@ -132,7 +131,7 @@ func TestNodeKeyPersistency(t *testing.T) {
if _, err = crypto.LoadECDSA(keyfile); err != nil { if _, err = crypto.LoadECDSA(keyfile); err != nil {
t.Fatalf("failed to load freshly persisted node key: %v", err) t.Fatalf("failed to load freshly persisted node key: %v", err)
} }
blob1, err := ioutil.ReadFile(keyfile) blob1, err := os.ReadFile(keyfile)
if err != nil { if err != nil {
t.Fatalf("failed to read freshly persisted node key: %v", err) t.Fatalf("failed to read freshly persisted node key: %v", err)
} }
@ -140,7 +139,7 @@ func TestNodeKeyPersistency(t *testing.T) {
// Configure a new node and ensure the previously persisted key is loaded // Configure a new node and ensure the previously persisted key is loaded
config = &Config{Name: "unit-test", DataDir: dir} config = &Config{Name: "unit-test", DataDir: dir}
config.NodeKey() config.NodeKey()
blob2, err := ioutil.ReadFile(filepath.Join(keyfile)) blob2, err := os.ReadFile(filepath.Join(keyfile))
if err != nil { if err != nil {
t.Fatalf("failed to read previously persisted node key: %v", err) t.Fatalf("failed to read previously persisted node key: %v", err)
} }

View File

@ -21,7 +21,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"sort" "sort"
@ -444,7 +443,7 @@ func (h *virtualHostHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var gzPool = sync.Pool{ var gzPool = sync.Pool{
New: func() interface{} { New: func() interface{} {
w := gzip.NewWriter(ioutil.Discard) w := gzip.NewWriter(io.Discard)
return w return w
}, },
} }

View File

@ -23,7 +23,6 @@ import (
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
"io/ioutil"
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
@ -580,7 +579,7 @@ func (n *handshakeTestNode) id() enode.ID {
// hexFile reads the given file and decodes the hex data contained in it. // hexFile reads the given file and decodes the hex data contained in it.
// Whitespace and any lines beginning with the # character are ignored. // Whitespace and any lines beginning with the # character are ignored.
func hexFile(file string) []byte { func hexFile(file string) []byte {
fileContent, err := ioutil.ReadFile(file) fileContent, err := os.ReadFile(file)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -21,7 +21,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"sync/atomic" "sync/atomic"
"time" "time"
@ -66,7 +65,7 @@ func (msg Msg) String() string {
// Discard reads any remaining payload data into a black hole. // Discard reads any remaining payload data into a black hole.
func (msg Msg) Discard() error { func (msg Msg) Discard() error {
_, err := io.Copy(ioutil.Discard, msg.Payload) _, err := io.Copy(io.Discard, msg.Payload)
return err return err
} }
@ -245,7 +244,7 @@ func ExpectMsg(r MsgReader, code uint64, content interface{}) error {
if int(msg.Size) != len(contentEnc) { if int(msg.Size) != len(contentEnc) {
return fmt.Errorf("message size mismatch: got %d, want %d", msg.Size, len(contentEnc)) return fmt.Errorf("message size mismatch: got %d, want %d", msg.Size, len(contentEnc))
} }
actualContent, err := ioutil.ReadAll(msg.Payload) actualContent, err := io.ReadAll(msg.Payload)
if err != nil { if err != nil {
return err return err
} }

View File

@ -19,7 +19,7 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"os" "os"
"sync/atomic" "sync/atomic"
@ -63,7 +63,7 @@ func main() {
adapter = adapters.NewSimAdapter(services) adapter = adapters.NewSimAdapter(services)
case "exec": case "exec":
tmpdir, err := ioutil.TempDir("", "p2p-example") tmpdir, err := os.MkdirTemp("", "p2p-example")
if err != nil { if err != nil {
log.Crit("error creating temp dir", "err", err) log.Crit("error creating temp dir", "err", err)
} }
@ -156,7 +156,7 @@ func (p *pingPongService) Run(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
errC <- err errC <- err
return return
} }
payload, err := ioutil.ReadAll(msg.Payload) payload, err := io.ReadAll(msg.Payload)
if err != nil { if err != nil {
errC <- err errC <- err
return return

View File

@ -24,7 +24,6 @@ import (
"fmt" "fmt"
"html" "html"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
@ -112,7 +111,7 @@ func (c *Client) SubscribeNetwork(events chan *Event, opts SubscribeOpts) (event
return nil, err return nil, err
} }
if res.StatusCode != http.StatusOK { if res.StatusCode != http.StatusOK {
response, _ := ioutil.ReadAll(res.Body) response, _ := io.ReadAll(res.Body)
res.Body.Close() res.Body.Close()
return nil, fmt.Errorf("unexpected HTTP status: %s: %s", res.Status, response) return nil, fmt.Errorf("unexpected HTTP status: %s: %s", res.Status, response)
} }
@ -252,7 +251,7 @@ func (c *Client) Send(method, path string, in, out interface{}) error {
} }
defer res.Body.Close() defer res.Body.Close()
if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusCreated { if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusCreated {
response, _ := ioutil.ReadAll(res.Body) response, _ := io.ReadAll(res.Body)
return fmt.Errorf("unexpected HTTP status: %s: %s", res.Status, response) return fmt.Errorf("unexpected HTTP status: %s: %s", res.Status, response)
} }
if out != nil { if out != nil {

View File

@ -21,7 +21,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math/big" "math/big"
"runtime" "runtime"
"sync" "sync"
@ -420,7 +419,7 @@ func TestEncodeToReader(t *testing.T) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return ioutil.ReadAll(r) return io.ReadAll(r)
}) })
} }
@ -461,7 +460,7 @@ func TestEncodeToReaderReturnToPool(t *testing.T) {
go func() { go func() {
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
_, r, _ := EncodeToReader("foo") _, r, _ := EncodeToReader("foo")
ioutil.ReadAll(r) io.ReadAll(r)
r.Read(buf) r.Read(buf)
r.Read(buf) r.Read(buf)
r.Read(buf) r.Read(buf)

View File

@ -8,7 +8,6 @@ import (
"go/parser" "go/parser"
"go/token" "go/token"
"go/types" "go/types"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -51,11 +50,11 @@ func TestOutput(t *testing.T) {
// Set this environment variable to regenerate the test outputs. // Set this environment variable to regenerate the test outputs.
if os.Getenv("WRITE_TEST_FILES") != "" { if os.Getenv("WRITE_TEST_FILES") != "" {
ioutil.WriteFile(outputFile, output, 0644) os.WriteFile(outputFile, output, 0644)
} }
// Check if output matches. // Check if output matches.
wantOutput, err := ioutil.ReadFile(outputFile) wantOutput, err := os.ReadFile(outputFile)
if err != nil { if err != nil {
t.Fatal("error loading expected test output:", err) t.Fatal("error loading expected test output:", err)
} }
@ -68,7 +67,7 @@ func TestOutput(t *testing.T) {
func loadTestSource(file string, typeName string) (*buildContext, *types.Named, error) { func loadTestSource(file string, typeName string) (*buildContext, *types.Named, error) {
// Load the test input. // Load the test input.
content, err := ioutil.ReadFile(file) content, err := os.ReadFile(file)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

View File

@ -22,7 +22,6 @@ import (
"flag" "flag"
"fmt" "fmt"
"go/types" "go/types"
"io/ioutil"
"os" "os"
"golang.org/x/tools/go/packages" "golang.org/x/tools/go/packages"
@ -52,7 +51,7 @@ func main() {
} }
if *output == "-" { if *output == "-" {
os.Stdout.Write(code) os.Stdout.Write(code)
} else if err := ioutil.WriteFile(*output, code, 0644); err != nil { } else if err := os.WriteFile(*output, code, 0644); err != nil {
fatal(err) fatal(err)
} }
} }

View File

@ -23,7 +23,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"mime" "mime"
"net/http" "net/http"
"net/url" "net/url"
@ -176,12 +175,12 @@ func (hc *httpConn) doRequest(ctx context.Context, msg interface{}) (io.ReadClos
if err != nil { if err != nil {
return nil, err return nil, err
} }
req, err := http.NewRequestWithContext(ctx, "POST", hc.url, ioutil.NopCloser(bytes.NewReader(body))) req, err := http.NewRequestWithContext(ctx, "POST", hc.url, io.NopCloser(bytes.NewReader(body)))
if err != nil { if err != nil {
return nil, err return nil, err
} }
req.ContentLength = int64(len(body)) req.ContentLength = int64(len(body))
req.GetBody = func() (io.ReadCloser, error) { return ioutil.NopCloser(bytes.NewReader(body)), nil } req.GetBody = func() (io.ReadCloser, error) { return io.NopCloser(bytes.NewReader(body)), nil }
// set headers // set headers
hc.mu.Lock() hc.mu.Lock()

View File

@ -22,6 +22,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"net" "net"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
"testing" "testing"
@ -70,7 +71,7 @@ func TestServer(t *testing.T) {
func runTestScript(t *testing.T, file string) { func runTestScript(t *testing.T, file string) {
server := newTestServer() server := newTestServer()
content, err := ioutil.ReadFile(file) content, err := os.ReadFile(file)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -22,6 +22,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os"
"path" "path"
"strings" "strings"
"testing" "testing"
@ -362,7 +363,7 @@ func TestJsonFiles(t *testing.T) {
continue continue
} }
expectedFailure := strings.HasPrefix(fInfo.Name(), "expfail") 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 { if err != nil {
t.Errorf("Failed to read file %v: %v", fInfo.Name(), err) t.Errorf("Failed to read file %v: %v", fInfo.Name(), err)
continue continue
@ -394,7 +395,7 @@ func TestFuzzerFiles(t *testing.T) {
} }
verbose := false verbose := false
for i, fInfo := range testfiles { 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 { if err != nil {
t.Errorf("Failed to read file %v: %v", fInfo.Name(), err) t.Errorf("Failed to read file %v: %v", fInfo.Name(), err)
continue continue

View File

@ -21,8 +21,8 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"math/big" "math/big"
"os"
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore" "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 { if wallet.URL().Scheme != keystore.KeyStoreScheme {
return nil, fmt.Errorf("account is not a keystore-account") 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 // Import tries to import the given keyJSON in the local keystore. The keyJSON data is expected to be

View File

@ -22,7 +22,6 @@ import (
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"os" "os"
) )
@ -83,7 +82,7 @@ func NewWithFile(path string) (*Database, error) {
// Custom file may not exist. Will be created during save, if needed. // Custom file may not exist. Will be created during save, if needed.
if _, err := os.Stat(path); err == nil { if _, err := os.Stat(path); err == nil {
var blob []byte var blob []byte
if blob, err = ioutil.ReadFile(path); err != nil { if blob, err = os.ReadFile(path); err != nil {
return nil, err return nil, err
} }
if err := json.Unmarshal(blob, &db.custom); err != nil { 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 { if err != nil {
return err return err
} }
return ioutil.WriteFile(db.customPath, blob, 0600) return os.WriteFile(db.customPath, blob, 0600)
} }

View File

@ -22,7 +22,6 @@ import (
"crypto/rand" "crypto/rand"
"encoding/json" "encoding/json"
"io" "io"
"io/ioutil"
"os" "os"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
@ -114,7 +113,7 @@ func (s *AESEncryptedStorage) Del(key string) {
// readEncryptedStorage reads the file with encrypted creds // readEncryptedStorage reads the file with encrypted creds
func (s *AESEncryptedStorage) readEncryptedStorage() (map[string]storedCredential, error) { func (s *AESEncryptedStorage) readEncryptedStorage() (map[string]storedCredential, error) {
creds := make(map[string]storedCredential) creds := make(map[string]storedCredential)
raw, err := ioutil.ReadFile(s.filename) raw, err := os.ReadFile(s.filename)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
@ -136,7 +135,7 @@ func (s *AESEncryptedStorage) writeEncryptedStorage(creds map[string]storedCrede
if err != nil { if err != nil {
return err 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 err
} }
return nil return nil

View File

@ -20,7 +20,7 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "os"
"testing" "testing"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -125,7 +125,7 @@ func TestSwappedKeys(t *testing.T) {
// Now make a modified copy // Now make a modified copy
creds := make(map[string]storedCredential) creds := make(map[string]storedCredential)
raw, err := ioutil.ReadFile(s1.filename) raw, err := os.ReadFile(s1.filename)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -140,7 +140,7 @@ func TestSwappedKeys(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) 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) t.Fatal(err)
} }
} }

View File

@ -36,7 +36,7 @@ func TestGenerateCorpus(t *testing.T) {
data := common.FromHex(corpusHex) data := common.FromHex(corpusHex)
checksum := sha1.Sum(data) checksum := sha1.Sum(data)
outf := fmt.Sprintf("corpus/%x", checksum) outf := fmt.Sprintf("corpus/%x", checksum)
if err := ioutil.WriteFile(outf, data, 0777); err != nil { if err := os.WriteFile(outf, data, 0777); err != nil {
panic(err) panic(err)
} }
*/ */

View File

@ -2,7 +2,6 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"github.com/ethereum/go-ethereum/tests/fuzzers/difficulty" "github.com/ethereum/go-ethereum/tests/fuzzers/difficulty"
@ -14,7 +13,7 @@ func main() {
os.Exit(1) os.Exit(1)
} }
crasher := os.Args[1] crasher := os.Args[1]
data, err := ioutil.ReadFile(crasher) data, err := os.ReadFile(crasher)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err) fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err)
os.Exit(1) os.Exit(1)

View File

@ -18,7 +18,6 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"github.com/ethereum/go-ethereum/tests/fuzzers/les" "github.com/ethereum/go-ethereum/tests/fuzzers/les"
@ -32,7 +31,7 @@ func main() {
os.Exit(1) os.Exit(1)
} }
crasher := os.Args[1] crasher := os.Args[1]
data, err := ioutil.ReadFile(crasher) data, err := os.ReadFile(crasher)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err) fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err)
os.Exit(1) os.Exit(1)

View File

@ -18,7 +18,6 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"github.com/ethereum/go-ethereum/tests/fuzzers/rangeproof" "github.com/ethereum/go-ethereum/tests/fuzzers/rangeproof"
@ -32,7 +31,7 @@ func main() {
os.Exit(1) os.Exit(1)
} }
crasher := os.Args[1] crasher := os.Args[1]
data, err := ioutil.ReadFile(crasher) data, err := os.ReadFile(crasher)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err) fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err)
os.Exit(1) os.Exit(1)

View File

@ -18,7 +18,6 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"github.com/ethereum/go-ethereum/tests/fuzzers/snap" "github.com/ethereum/go-ethereum/tests/fuzzers/snap"
@ -30,7 +29,7 @@ func main() {
os.Exit(1) os.Exit(1)
} }
crasher := os.Args[1] crasher := os.Args[1]
data, err := ioutil.ReadFile(crasher) data, err := os.ReadFile(crasher)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err) fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err)
os.Exit(1) os.Exit(1)

View File

@ -2,7 +2,6 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"github.com/ethereum/go-ethereum/tests/fuzzers/stacktrie" "github.com/ethereum/go-ethereum/tests/fuzzers/stacktrie"
@ -14,7 +13,7 @@ func main() {
os.Exit(1) os.Exit(1)
} }
crasher := os.Args[1] crasher := os.Args[1]
data, err := ioutil.ReadFile(crasher) data, err := os.ReadFile(crasher)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err) fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err)
os.Exit(1) os.Exit(1)

View File

@ -18,7 +18,6 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
@ -35,7 +34,7 @@ func main() {
os.Exit(1) os.Exit(1)
} }
crasher := os.Args[1] crasher := os.Args[1]
data, err := ioutil.ReadFile(crasher) data, err := os.ReadFile(crasher)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err) fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err)
os.Exit(1) os.Exit(1)

View File

@ -20,7 +20,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
@ -45,7 +44,7 @@ var (
) )
func readJSON(reader io.Reader, value interface{}) error { func readJSON(reader io.Reader, value interface{}) error {
data, err := ioutil.ReadAll(reader) data, err := io.ReadAll(reader)
if err != nil { if err != nil {
return fmt.Errorf("error reading JSON file: %v", err) return fmt.Errorf("error reading JSON file: %v", err)
} }