all: replace non-trivial uses of package ioutil with os (#24886)
Co-authored-by: Martin Holst Swende <martin@swende.se>
This commit is contained in:
parent
e644d45c14
commit
4b309c7006
@ -18,7 +18,6 @@ package bind
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -1986,7 +1985,7 @@ func TestGolangBindings(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("test %d: failed to generate binding: %v", i, err)
|
t.Fatalf("test %d: failed to generate binding: %v", i, err)
|
||||||
}
|
}
|
||||||
if err = ioutil.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+".go"), []byte(bind), 0600); err != nil {
|
if err = os.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+".go"), []byte(bind), 0600); err != nil {
|
||||||
t.Fatalf("test %d: failed to write binding: %v", i, err)
|
t.Fatalf("test %d: failed to write binding: %v", i, err)
|
||||||
}
|
}
|
||||||
// Generate the test file with the injected test code
|
// Generate the test file with the injected test code
|
||||||
@ -2002,7 +2001,7 @@ func TestGolangBindings(t *testing.T) {
|
|||||||
%s
|
%s
|
||||||
}
|
}
|
||||||
`, tt.imports, tt.name, tt.tester)
|
`, tt.imports, tt.name, tt.tester)
|
||||||
if err := ioutil.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+"_test.go"), []byte(code), 0600); err != nil {
|
if err := os.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+"_test.go"), []byte(code), 0600); err != nil {
|
||||||
t.Fatalf("test %d: failed to write tests: %v", i, err)
|
t.Fatalf("test %d: failed to write tests: %v", i, err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package keystore
|
package keystore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -41,7 +40,7 @@ func (fc *fileCache) scan(keyDir string) (mapset.Set, mapset.Set, mapset.Set, er
|
|||||||
t0 := time.Now()
|
t0 := time.Now()
|
||||||
|
|
||||||
// List all the failes from the keystore folder
|
// List all the failes from the keystore folder
|
||||||
files, err := ioutil.ReadDir(keyDir)
|
files, err := os.ReadDir(keyDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
@ -65,7 +64,11 @@ func (fc *fileCache) scan(keyDir string) (mapset.Set, mapset.Set, mapset.Set, er
|
|||||||
// Gather the set of all and fresly modified files
|
// Gather the set of all and fresly modified files
|
||||||
all.Add(path)
|
all.Add(path)
|
||||||
|
|
||||||
modified := fi.ModTime()
|
info, err := fi.Info()
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, nil, err
|
||||||
|
}
|
||||||
|
modified := info.ModTime()
|
||||||
if modified.After(fc.lastMod) {
|
if modified.After(fc.lastMod) {
|
||||||
mods.Add(path)
|
mods.Add(path)
|
||||||
}
|
}
|
||||||
@ -89,13 +92,13 @@ func (fc *fileCache) scan(keyDir string) (mapset.Set, mapset.Set, mapset.Set, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
// nonKeyFile ignores editor backups, hidden files and folders/symlinks.
|
// nonKeyFile ignores editor backups, hidden files and folders/symlinks.
|
||||||
func nonKeyFile(fi os.FileInfo) bool {
|
func nonKeyFile(fi os.DirEntry) bool {
|
||||||
// Skip editor backups and UNIX-style hidden files.
|
// Skip editor backups and UNIX-style hidden files.
|
||||||
if strings.HasSuffix(fi.Name(), "~") || strings.HasPrefix(fi.Name(), ".") {
|
if strings.HasSuffix(fi.Name(), "~") || strings.HasPrefix(fi.Name(), ".") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// Skip misc special files, directories (yes, symlinks too).
|
// Skip misc special files, directories (yes, symlinks too).
|
||||||
if fi.IsDir() || fi.Mode()&os.ModeType != 0 {
|
if fi.IsDir() || !fi.Type().IsRegular() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -163,7 +162,7 @@ Password: {{.InputLine "foo"}}
|
|||||||
Address: {d4584b5f6229b7be90727b0fc8c6b91bb427821f}
|
Address: {d4584b5f6229b7be90727b0fc8c6b91bb427821f}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(filepath.Join(geth.Datadir, "keystore"))
|
files, err := os.ReadDir(filepath.Join(geth.Datadir, "keystore"))
|
||||||
if len(files) != 1 {
|
if len(files) != 1 {
|
||||||
t.Errorf("expected one key file in keystore directory, found %d files (error: %v)", len(files), err)
|
t.Errorf("expected one key file in keystore directory, found %d files (error: %v)", len(files), err)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -55,7 +54,7 @@ func testVerification(t *testing.T, pubkey, sigdir string) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// Signatures, with and without comments, both trusted and untrusted
|
// Signatures, with and without comments, both trusted and untrusted
|
||||||
files, err := ioutil.ReadDir(sigdir)
|
files, err := os.ReadDir(sigdir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package rawdb
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -472,7 +471,7 @@ func (f *Freezer) MigrateTable(kind string, convert convertLegacyFn) error {
|
|||||||
if err := newTable.Close(); err != nil {
|
if err := newTable.Close(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
files, err := ioutil.ReadDir(migrationPath)
|
files, err := os.ReadDir(migrationPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package tracetest
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -136,7 +135,7 @@ func TestCallTracerNative(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testCallTracer(tracerName string, dirPath string, t *testing.T) {
|
func testCallTracer(tracerName string, dirPath string, t *testing.T) {
|
||||||
files, err := ioutil.ReadDir(filepath.Join("testdata", dirPath))
|
files, err := os.ReadDir(filepath.Join("testdata", dirPath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to retrieve tracer test suite: %v", err)
|
t.Fatalf("failed to retrieve tracer test suite: %v", err)
|
||||||
}
|
}
|
||||||
@ -241,7 +240,7 @@ func camel(str string) string {
|
|||||||
return strings.Join(pieces, "")
|
return strings.Join(pieces, "")
|
||||||
}
|
}
|
||||||
func BenchmarkTracers(b *testing.B) {
|
func BenchmarkTracers(b *testing.B) {
|
||||||
files, err := ioutil.ReadDir(filepath.Join("testdata", "call_tracer"))
|
files, err := os.ReadDir(filepath.Join("testdata", "call_tracer"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatalf("failed to retrieve tracer test suite: %v", err)
|
b.Fatalf("failed to retrieve tracer test suite: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
"go/parser"
|
"go/parser"
|
||||||
"go/token"
|
"go/token"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -177,7 +176,7 @@ func UploadSFTP(identityFile, host, dir string, files []string) error {
|
|||||||
// package paths.
|
// package paths.
|
||||||
func FindMainPackages(dir string) []string {
|
func FindMainPackages(dir string) []string {
|
||||||
var commands []string
|
var commands []string
|
||||||
cmds, err := ioutil.ReadDir(dir)
|
cmds, err := os.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -53,7 +52,7 @@ func TestServerRegisterName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestServer(t *testing.T) {
|
func TestServer(t *testing.T) {
|
||||||
files, err := ioutil.ReadDir("testdata")
|
files, err := os.ReadDir("testdata")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("where'd my testdata go?")
|
t.Fatal("where'd my testdata go?")
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
@ -354,7 +353,7 @@ func sign(typedData apitypes.TypedData) ([]byte, []byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestJsonFiles(t *testing.T) {
|
func TestJsonFiles(t *testing.T) {
|
||||||
testfiles, err := ioutil.ReadDir("testdata/")
|
testfiles, err := os.ReadDir("testdata/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed reading files: %v", err)
|
t.Fatalf("failed reading files: %v", err)
|
||||||
}
|
}
|
||||||
@ -389,7 +388,7 @@ func TestJsonFiles(t *testing.T) {
|
|||||||
// crashes or hangs.
|
// crashes or hangs.
|
||||||
func TestFuzzerFiles(t *testing.T) {
|
func TestFuzzerFiles(t *testing.T) {
|
||||||
corpusdir := path.Join("testdata", "fuzzing")
|
corpusdir := path.Join("testdata", "fuzzing")
|
||||||
testfiles, err := ioutil.ReadDir(corpusdir)
|
testfiles, err := os.ReadDir(corpusdir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed reading files: %v", err)
|
t.Fatalf("failed reading files: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user