From a724a713daad960b64a44414a90043be31f8840f Mon Sep 17 00:00:00 2001 From: Aayush Date: Wed, 29 Mar 2023 15:24:07 -0400 Subject: [PATCH] refactor: stop using deprecated io/ioutil --- blockstore/ipfs.go | 4 +-- chain/actors/agen/main.go | 25 ++++++++-------- chain/gen/gen.go | 6 ++-- cli/state.go | 3 +- cli/util/retrieval.go | 3 +- cli/wallet.go | 3 +- cmd/lotus-bench/import.go | 3 +- cmd/lotus-bench/main.go | 9 +++--- cmd/lotus-bench/simple.go | 9 +++--- cmd/lotus-fountain/recaptcha.go | 4 +-- cmd/lotus-miner/init.go | 5 ++-- cmd/lotus-miner/init_restore.go | 3 +- cmd/lotus-miner/storage.go | 3 +- cmd/lotus-pcr/main.go | 5 ++-- cmd/lotus-seed/genesis.go | 29 +++++++++---------- cmd/lotus-seed/main.go | 3 +- cmd/lotus-seed/seed/seed.go | 7 ++--- cmd/lotus-shed/base16.go | 3 +- cmd/lotus-shed/base32.go | 3 +- cmd/lotus-shed/base64.go | 3 +- cmd/lotus-shed/bitfield.go | 3 +- cmd/lotus-shed/fip-0036.go | 4 +-- cmd/lotus-shed/jwt.go | 9 +++--- cmd/lotus-shed/keyinfo.go | 7 ++--- cmd/lotus-shed/rpc.go | 3 +- cmd/lotus-worker/main.go | 3 +- cmd/lotus-worker/storage.go | 3 +- cmd/lotus/daemon.go | 5 ++-- conformance/corpus_test.go | 3 +- conformance/runner.go | 3 +- gen/inline-gen/main.go | 7 ++--- .../deals_partial_retrieval_dm-level_test.go | 5 ++-- itests/kit/client.go | 7 ++--- itests/kit/ensemble.go | 4 +-- itests/kit/node_miner.go | 3 +- itests/kit/node_worker.go | 3 +- lib/backupds/backupds_test.go | 3 +- lib/consensus/raft/config.go | 6 ++-- lib/rpcenc/reader.go | 5 ++-- lib/unixfs/filestore.go | 3 +- lib/unixfs/filestore_test.go | 5 ++-- markets/dagstore/mount_test.go | 9 +++--- node/config/cfgdocgen/gen.go | 3 +- node/config/load.go | 3 +- node/config/load_test.go | 7 ++--- node/config/storage.go | 3 +- node/impl/client/client_test.go | 6 ++-- node/modules/core.go | 3 +- node/modules/testing/genesis.go | 3 +- node/repo/fsrepo.go | 15 +++++----- node/repo/memrepo.go | 5 ++-- storage/paths/http_handler_test.go | 8 ++--- storage/paths/local.go | 5 ++-- storage/paths/local_test.go | 3 +- storage/paths/remote.go | 7 ++--- storage/paths/remote_test.go | 11 ++++--- storage/sealer/ffiwrapper/sealer_cgo.go | 3 +- storage/sealer/ffiwrapper/sealer_test.go | 29 +++++++++---------- storage/sealer/fr32/fr32_ffi_cmp_test.go | 5 ++-- storage/sealer/fr32/fr32_test.go | 5 ++-- storage/sealer/fr32/readers_test.go | 4 +-- storage/sealer/manager_test.go | 5 ++-- storage/sealer/mock/mock.go | 3 +- storage/sealer/piece_provider_test.go | 4 +-- 64 files changed, 161 insertions(+), 215 deletions(-) diff --git a/blockstore/ipfs.go b/blockstore/ipfs.go index 756314f2d..c7dbb480a 100644 --- a/blockstore/ipfs.go +++ b/blockstore/ipfs.go @@ -3,7 +3,7 @@ package blockstore import ( "bytes" "context" - "io/ioutil" + "io" "github.com/ipfs/go-cid" httpapi "github.com/ipfs/go-ipfs-http-client" @@ -103,7 +103,7 @@ func (i *IPFSBlockstore) Get(ctx context.Context, cid cid.Cid) (blocks.Block, er return nil, xerrors.Errorf("getting ipfs block: %w", err) } - data, err := ioutil.ReadAll(rd) + data, err := io.ReadAll(rd) if err != nil { return nil, err } diff --git a/chain/actors/agen/main.go b/chain/actors/agen/main.go index b9f3a22a4..811ea27e9 100644 --- a/chain/actors/agen/main.go +++ b/chain/actors/agen/main.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "go/format" - "io/ioutil" "os" "path/filepath" "strconv" @@ -66,7 +65,7 @@ func generateAdapters() error { } { - af, err := ioutil.ReadFile(filepath.Join(actDir, "actor.go.template")) + af, err := os.ReadFile(filepath.Join(actDir, "actor.go.template")) if err != nil { return xerrors.Errorf("loading actor template: %w", err) } @@ -90,7 +89,7 @@ func generateAdapters() error { return err } - if err := ioutil.WriteFile(filepath.Join(actDir, fmt.Sprintf("%s.go", act)), fmted, 0666); err != nil { + if err := os.WriteFile(filepath.Join(actDir, fmt.Sprintf("%s.go", act)), fmted, 0666); err != nil { return err } } @@ -100,7 +99,7 @@ func generateAdapters() error { } func generateState(actDir string, versions []int) error { - af, err := ioutil.ReadFile(filepath.Join(actDir, "state.go.template")) + af, err := os.ReadFile(filepath.Join(actDir, "state.go.template")) if err != nil { if os.IsNotExist(err) { return nil // skip @@ -123,7 +122,7 @@ func generateState(actDir string, versions []int) error { return err } - if err := ioutil.WriteFile(filepath.Join(actDir, fmt.Sprintf("v%d.go", version)), b.Bytes(), 0666); err != nil { + if err := os.WriteFile(filepath.Join(actDir, fmt.Sprintf("v%d.go", version)), b.Bytes(), 0666); err != nil { return err } } @@ -132,7 +131,7 @@ func generateState(actDir string, versions []int) error { } func generateMessages(actDir string) error { - af, err := ioutil.ReadFile(filepath.Join(actDir, "message.go.template")) + af, err := os.ReadFile(filepath.Join(actDir, "message.go.template")) if err != nil { if os.IsNotExist(err) { return nil // skip @@ -155,7 +154,7 @@ func generateMessages(actDir string) error { return err } - if err := ioutil.WriteFile(filepath.Join(actDir, fmt.Sprintf("message%d.go", version)), b.Bytes(), 0666); err != nil { + if err := os.WriteFile(filepath.Join(actDir, fmt.Sprintf("message%d.go", version)), b.Bytes(), 0666); err != nil { return err } } @@ -165,7 +164,7 @@ func generateMessages(actDir string) error { func generatePolicy(policyPath string) error { - pf, err := ioutil.ReadFile(policyPath + ".template") + pf, err := os.ReadFile(policyPath + ".template") if err != nil { if os.IsNotExist(err) { return nil // skip @@ -187,7 +186,7 @@ func generatePolicy(policyPath string) error { return err } - if err := ioutil.WriteFile(policyPath, b.Bytes(), 0666); err != nil { + if err := os.WriteFile(policyPath, b.Bytes(), 0666); err != nil { return err } @@ -196,7 +195,7 @@ func generatePolicy(policyPath string) error { func generateBuiltin(builtinPath string) error { - bf, err := ioutil.ReadFile(builtinPath + ".template") + bf, err := os.ReadFile(builtinPath + ".template") if err != nil { if os.IsNotExist(err) { return nil // skip @@ -218,7 +217,7 @@ func generateBuiltin(builtinPath string) error { return err } - if err := ioutil.WriteFile(builtinPath, b.Bytes(), 0666); err != nil { + if err := os.WriteFile(builtinPath, b.Bytes(), 0666); err != nil { return err } @@ -227,7 +226,7 @@ func generateBuiltin(builtinPath string) error { func generateRegistry(registryPath string) error { - bf, err := ioutil.ReadFile(registryPath + ".template") + bf, err := os.ReadFile(registryPath + ".template") if err != nil { if os.IsNotExist(err) { return nil // skip @@ -248,7 +247,7 @@ func generateRegistry(registryPath string) error { return err } - if err := ioutil.WriteFile(registryPath, b.Bytes(), 0666); err != nil { + if err := os.WriteFile(registryPath, b.Bytes(), 0666); err != nil { return err } diff --git a/chain/gen/gen.go b/chain/gen/gen.go index de2df97c2..8e3c41a89 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -5,7 +5,7 @@ import ( "context" "fmt" "io" - "io/ioutil" + "os" "sync/atomic" "time" @@ -167,7 +167,7 @@ func NewGeneratorWithSectorsAndUpgradeSchedule(numSectors int, us stmgr.UpgradeS maddr1 := genesis2.MinerAddress(0) - m1temp, err := ioutil.TempDir("", "preseal") + m1temp, err := os.MkdirTemp("", "preseal") if err != nil { return nil, err } @@ -179,7 +179,7 @@ func NewGeneratorWithSectorsAndUpgradeSchedule(numSectors int, us stmgr.UpgradeS maddr2 := genesis2.MinerAddress(1) - m2temp, err := ioutil.TempDir("", "preseal") + m2temp, err := os.MkdirTemp("", "preseal") if err != nil { return nil, err } diff --git a/cli/state.go b/cli/state.go index c039cb80a..3099bff17 100644 --- a/cli/state.go +++ b/cli/state.go @@ -9,7 +9,6 @@ import ( "fmt" "html/template" "io" - "io/ioutil" "os" "reflect" "sort" @@ -1090,7 +1089,7 @@ var StateComputeStateCmd = &cli.Command{ var stout *lapi.ComputeStateOutput if csofile := cctx.String("compute-state-output"); csofile != "" { - data, err := ioutil.ReadFile(csofile) + data, err := os.ReadFile(csofile) if err != nil { return err } diff --git a/cli/util/retrieval.go b/cli/util/retrieval.go index 3a2ef6077..ac34fcf3a 100644 --- a/cli/util/retrieval.go +++ b/cli/util/retrieval.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "path" @@ -65,7 +64,7 @@ func ClientExportStream(apiAddr string, apiAuth http.Header, eref api.ExportRef, } if resp.StatusCode != http.StatusOK { - em, err := ioutil.ReadAll(resp.Body) + em, err := io.ReadAll(resp.Body) if err != nil { return nil, xerrors.Errorf("reading error body: %w", err) } diff --git a/cli/wallet.go b/cli/wallet.go index a936efa94..c66275cdd 100644 --- a/cli/wallet.go +++ b/cli/wallet.go @@ -6,7 +6,6 @@ import ( "encoding/hex" "encoding/json" "fmt" - "io/ioutil" "os" "strings" @@ -337,7 +336,7 @@ var walletImport = &cli.Command{ inpdata = indata } else { - fdata, err := ioutil.ReadFile(cctx.Args().First()) + fdata, err := os.ReadFile(cctx.Args().First()) if err != nil { return err } diff --git a/cmd/lotus-bench/import.go b/cmd/lotus-bench/import.go index 51c567d90..babf9342b 100644 --- a/cmd/lotus-bench/import.go +++ b/cmd/lotus-bench/import.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "math" "net/http" _ "net/http/pprof" @@ -158,7 +157,7 @@ var importBenchCmd = &cli.Command{ if rdir := cctx.String("repodir"); rdir != "" { tdir = rdir } else { - tmp, err := ioutil.TempDir("", "lotus-import-bench") + tmp, err := os.MkdirTemp("", "lotus-import-bench") if err != nil { return err } diff --git a/cmd/lotus-bench/main.go b/cmd/lotus-bench/main.go index 279f2d5fd..43972b187 100644 --- a/cmd/lotus-bench/main.go +++ b/cmd/lotus-bench/main.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" "math/big" "math/rand" "os" @@ -197,7 +196,7 @@ var sealBenchCmd = &cli.Command{ return xerrors.Errorf("creating sectorbuilder dir: %w", err) } - tsdir, err := ioutil.TempDir(sdir, "bench") + tsdir, err := os.MkdirTemp(sdir, "bench") if err != nil { return err } @@ -287,7 +286,7 @@ var sealBenchCmd = &cli.Command{ // sectorbuilder directory... we need a better way to handle // this in other cases - fdata, err := ioutil.ReadFile(filepath.Join(sbdir, "pre-seal-"+maddr.String()+".json")) + fdata, err := os.ReadFile(filepath.Join(sbdir, "pre-seal-"+maddr.String()+".json")) if err != nil { return err } @@ -637,7 +636,7 @@ func runSeals(sb *ffiwrapper.Sealer, sbfs *basicfs.Provider, numSectors int, par return err } - if err := ioutil.WriteFile(saveC2inp, b, 0664); err != nil { + if err := os.WriteFile(saveC2inp, b, 0664); err != nil { log.Warnf("%+v", err) } } @@ -751,7 +750,7 @@ var proveCmd = &cli.Command{ return xerrors.Errorf("Usage: lotus-bench prove [input.json]") } - inb, err := ioutil.ReadFile(c.Args().First()) + inb, err := os.ReadFile(c.Args().First()) if err != nil { return xerrors.Errorf("reading input file: %w", err) } diff --git a/cmd/lotus-bench/simple.go b/cmd/lotus-bench/simple.go index 87e2c3bc0..a742b0fb3 100644 --- a/cmd/lotus-bench/simple.go +++ b/cmd/lotus-bench/simple.go @@ -5,7 +5,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "io/ioutil" "os" "strconv" "time" @@ -444,7 +443,7 @@ var simpleCommit1 = &cli.Command{ return err } - if err := ioutil.WriteFile(cctx.Args().Get(4), b, 0664); err != nil { + if err := os.WriteFile(cctx.Args().Get(4), b, 0664); err != nil { log.Warnf("%+v", err) } @@ -478,7 +477,7 @@ var simpleCommit2 = &cli.Command{ return xerrors.Errorf("Usage: lotus-bench prove [input.json]") } - inb, err := ioutil.ReadFile(c.Args().First()) + inb, err := os.ReadFile(c.Args().First()) if err != nil { return xerrors.Errorf("reading input file: %w", err) } @@ -861,7 +860,7 @@ var simpleProveReplicaUpdate1 = &cli.Command{ return xerrors.Errorf("json marshal vanilla proofs: %w", err) } - if err := ioutil.WriteFile(cctx.Args().Get(7), vpjb, 0666); err != nil { + if err := os.WriteFile(cctx.Args().Get(7), vpjb, 0666); err != nil { return xerrors.Errorf("writing vanilla proofs file: %w", err) } @@ -934,7 +933,7 @@ var simpleProveReplicaUpdate2 = &cli.Command{ return xerrors.Errorf("parse commr: %w", err) } - vpb, err := ioutil.ReadFile(cctx.Args().Get(3)) + vpb, err := os.ReadFile(cctx.Args().Get(3)) if err != nil { return xerrors.Errorf("reading valilla proof file: %w", err) } diff --git a/cmd/lotus-fountain/recaptcha.go b/cmd/lotus-fountain/recaptcha.go index 69359faa3..6b2327a03 100644 --- a/cmd/lotus-fountain/recaptcha.go +++ b/cmd/lotus-fountain/recaptcha.go @@ -6,7 +6,7 @@ package main import ( "encoding/json" - "io/ioutil" + "io" "net/http" "net/url" "os" @@ -63,7 +63,7 @@ func VerifyToken(token, remoteIP string) (Response, error) { return resp, err } - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) _ = r.Body.Close() // close immediately after reading finished if err != nil { return resp, err diff --git a/cmd/lotus-miner/init.go b/cmd/lotus-miner/init.go index 66a6691af..e752839ec 100644 --- a/cmd/lotus-miner/init.go +++ b/cmd/lotus-miner/init.go @@ -7,7 +7,6 @@ import ( "encoding/binary" "encoding/json" "fmt" - "io/ioutil" "net/http" "os" "path/filepath" @@ -246,7 +245,7 @@ var initCmd = &cli.Command{ return xerrors.Errorf("marshaling storage config: %w", err) } - if err := ioutil.WriteFile(filepath.Join(lr.Path(), "sectorstore.json"), b, 0644); err != nil { + if err := os.WriteFile(filepath.Join(lr.Path(), "sectorstore.json"), b, 0644); err != nil { return xerrors.Errorf("persisting storage metadata (%s): %w", filepath.Join(lr.Path(), "sectorstore.json"), err) } @@ -292,7 +291,7 @@ func migratePreSealMeta(ctx context.Context, api v1api.FullNode, metadata string return xerrors.Errorf("expanding preseal dir: %w", err) } - b, err := ioutil.ReadFile(metadata) + b, err := os.ReadFile(metadata) if err != nil { return xerrors.Errorf("reading preseal metadata: %w", err) } diff --git a/cmd/lotus-miner/init_restore.go b/cmd/lotus-miner/init_restore.go index f3ab9d04a..7e28729bb 100644 --- a/cmd/lotus-miner/init_restore.go +++ b/cmd/lotus-miner/init_restore.go @@ -3,7 +3,6 @@ package main import ( "context" "encoding/json" - "io/ioutil" "os" "github.com/docker/go-units" @@ -59,7 +58,7 @@ var restoreCmd = &cli.Command{ return xerrors.Errorf("expanding storage config path: %w", err) } - cfb, err := ioutil.ReadFile(cf) + cfb, err := os.ReadFile(cf) if err != nil { return xerrors.Errorf("reading storage config: %w", err) } diff --git a/cmd/lotus-miner/storage.go b/cmd/lotus-miner/storage.go index a5aa354f8..89353497d 100644 --- a/cmd/lotus-miner/storage.go +++ b/cmd/lotus-miner/storage.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" "math/bits" "os" "path/filepath" @@ -167,7 +166,7 @@ over time return xerrors.Errorf("marshaling storage config: %w", err) } - if err := ioutil.WriteFile(filepath.Join(p, metaFile), b, 0644); err != nil { + if err := os.WriteFile(filepath.Join(p, metaFile), b, 0644); err != nil { return xerrors.Errorf("persisting storage metadata (%s): %w", filepath.Join(p, metaFile), err) } } diff --git a/cmd/lotus-pcr/main.go b/cmd/lotus-pcr/main.go index 57eaf0ad6..199810e03 100644 --- a/cmd/lotus-pcr/main.go +++ b/cmd/lotus-pcr/main.go @@ -7,7 +7,6 @@ import ( "encoding/csv" "fmt" "io" - "io/ioutil" "net/http" _ "net/http/pprof" "os" @@ -759,7 +758,7 @@ func (r *refunder) EnsureMinerMinimums(ctx context.Context, tipset *types.TipSet return nil, err } - w := ioutil.Discard + w := io.Discard if len(output) != 0 { f, err := os.Create(output) if err != nil { @@ -1299,7 +1298,7 @@ func loadChainEpoch(fn string) (abi.ChainEpoch, error) { err = f.Close() }() - raw, err := ioutil.ReadAll(f) + raw, err := io.ReadAll(f) if err != nil { return 0, err } diff --git a/cmd/lotus-seed/genesis.go b/cmd/lotus-seed/genesis.go index 1ab6a465a..9fdce456b 100644 --- a/cmd/lotus-seed/genesis.go +++ b/cmd/lotus-seed/genesis.go @@ -4,7 +4,6 @@ import ( "encoding/csv" "encoding/json" "fmt" - "io/ioutil" "os" "strconv" "strings" @@ -80,7 +79,7 @@ var genesisNewCmd = &cli.Command{ return err } - if err := ioutil.WriteFile(genf, genb, 0644); err != nil { + if err := os.WriteFile(genf, genb, 0644); err != nil { return err } @@ -103,7 +102,7 @@ var genesisAddMinerCmd = &cli.Command{ } var template genesis.Template - genb, err := ioutil.ReadFile(genf) + genb, err := os.ReadFile(genf) if err != nil { return xerrors.Errorf("read genesis template: %w", err) } @@ -117,7 +116,7 @@ var genesisAddMinerCmd = &cli.Command{ return xerrors.Errorf("expand preseal file path: %w", err) } miners := map[string]genesis.Miner{} - minb, err := ioutil.ReadFile(minf) + minb, err := os.ReadFile(minf) if err != nil { return xerrors.Errorf("read preseal file: %w", err) } @@ -156,7 +155,7 @@ var genesisAddMinerCmd = &cli.Command{ return err } - if err := ioutil.WriteFile(genf, genb, 0644); err != nil { + if err := os.WriteFile(genf, genb, 0644); err != nil { return err } @@ -196,7 +195,7 @@ var genesisAddMsigsCmd = &cli.Command{ } var template genesis.Template - b, err := ioutil.ReadFile(genf) + b, err := os.ReadFile(genf) if err != nil { return xerrors.Errorf("read genesis template: %w", err) } @@ -237,7 +236,7 @@ var genesisAddMsigsCmd = &cli.Command{ return err } - if err := ioutil.WriteFile(genf, b, 0644); err != nil { + if err := os.WriteFile(genf, b, 0644); err != nil { return err } return nil @@ -339,7 +338,7 @@ var genesisSetVRKCmd = &cli.Command{ } var template genesis.Template - b, err := ioutil.ReadFile(genf) + b, err := os.ReadFile(genf) if err != nil { return xerrors.Errorf("read genesis template: %w", err) } @@ -404,7 +403,7 @@ var genesisSetVRKCmd = &cli.Command{ return err } - if err := ioutil.WriteFile(genf, b, 0644); err != nil { + if err := os.WriteFile(genf, b, 0644); err != nil { return err } return nil @@ -435,7 +434,7 @@ var genesisSetRemainderCmd = &cli.Command{ } var template genesis.Template - b, err := ioutil.ReadFile(genf) + b, err := os.ReadFile(genf) if err != nil { return xerrors.Errorf("read genesis template: %w", err) } @@ -500,7 +499,7 @@ var genesisSetRemainderCmd = &cli.Command{ return err } - if err := ioutil.WriteFile(genf, b, 0644); err != nil { + if err := os.WriteFile(genf, b, 0644); err != nil { return err } return nil @@ -529,7 +528,7 @@ var genesisSetActorVersionCmd = &cli.Command{ } var template genesis.Template - b, err := ioutil.ReadFile(genf) + b, err := os.ReadFile(genf) if err != nil { return xerrors.Errorf("read genesis template: %w", err) } @@ -550,7 +549,7 @@ var genesisSetActorVersionCmd = &cli.Command{ return err } - if err := ioutil.WriteFile(genf, b, 0644); err != nil { + if err := os.WriteFile(genf, b, 0644); err != nil { return err } return nil @@ -607,7 +606,7 @@ var genesisSetVRKSignersCmd = &cli.Command{ } var template genesis.Template - b, err := ioutil.ReadFile(genf) + b, err := os.ReadFile(genf) if err != nil { return xerrors.Errorf("read genesis template: %w", err) } @@ -662,7 +661,7 @@ var genesisSetVRKSignersCmd = &cli.Command{ return err } - if err := ioutil.WriteFile(genf, b, 0644); err != nil { + if err := os.WriteFile(genf, b, 0644); err != nil { return err } return nil diff --git a/cmd/lotus-seed/main.go b/cmd/lotus-seed/main.go index 7567f6393..863a508f2 100644 --- a/cmd/lotus-seed/main.go +++ b/cmd/lotus-seed/main.go @@ -4,7 +4,6 @@ import ( "encoding/hex" "encoding/json" "fmt" - "io/ioutil" "os" "github.com/docker/go-units" @@ -114,7 +113,7 @@ var preSealCmd = &cli.Command{ var k *types.KeyInfo if c.String("key") != "" { k = new(types.KeyInfo) - kh, err := ioutil.ReadFile(c.String("key")) + kh, err := os.ReadFile(c.String("key")) if err != nil { return err } diff --git a/cmd/lotus-seed/seed/seed.go b/cmd/lotus-seed/seed/seed.go index b98673712..48f00f8a6 100644 --- a/cmd/lotus-seed/seed/seed.go +++ b/cmd/lotus-seed/seed/seed.go @@ -6,7 +6,6 @@ import ( "encoding/hex" "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" @@ -135,7 +134,7 @@ func PreSeal(maddr address.Address, spt abi.RegisteredSealProof, offset abi.Sect return nil, nil, xerrors.Errorf("marshaling storage config: %w", err) } - if err := ioutil.WriteFile(filepath.Join(sbroot, "sectorstore.json"), b, 0644); err != nil { + if err := os.WriteFile(filepath.Join(sbroot, "sectorstore.json"), b, 0644); err != nil { return nil, nil, xerrors.Errorf("persisting storage metadata (%s): %w", filepath.Join(sbroot, "storage.json"), err) } } @@ -228,7 +227,7 @@ func WriteGenesisMiner(maddr address.Address, sbroot string, gm *genesis.Miner, log.Infof("Writing preseal manifest to %s", filepath.Join(sbroot, "pre-seal-"+maddr.String()+".json")) - if err := ioutil.WriteFile(filepath.Join(sbroot, "pre-seal-"+maddr.String()+".json"), out, 0664); err != nil { + if err := os.WriteFile(filepath.Join(sbroot, "pre-seal-"+maddr.String()+".json"), out, 0664); err != nil { return err } @@ -239,7 +238,7 @@ func WriteGenesisMiner(maddr address.Address, sbroot string, gm *genesis.Miner, } // TODO: allow providing key - if err := ioutil.WriteFile(filepath.Join(sbroot, "pre-seal-"+maddr.String()+".key"), []byte(hex.EncodeToString(b)), 0664); err != nil { + if err := os.WriteFile(filepath.Join(sbroot, "pre-seal-"+maddr.String()+".key"), []byte(hex.EncodeToString(b)), 0664); err != nil { return err } } diff --git a/cmd/lotus-shed/base16.go b/cmd/lotus-shed/base16.go index a5d384815..28ea4916f 100644 --- a/cmd/lotus-shed/base16.go +++ b/cmd/lotus-shed/base16.go @@ -4,7 +4,6 @@ import ( "encoding/hex" "fmt" "io" - "io/ioutil" "os" "strings" @@ -30,7 +29,7 @@ var base16Cmd = &cli.Command{ input = strings.NewReader(cctx.Args().First()) } - bytes, err := ioutil.ReadAll(input) + bytes, err := io.ReadAll(input) if err != nil { return nil } diff --git a/cmd/lotus-shed/base32.go b/cmd/lotus-shed/base32.go index 66e180ddc..d2ea3dd7a 100644 --- a/cmd/lotus-shed/base32.go +++ b/cmd/lotus-shed/base32.go @@ -3,7 +3,6 @@ package main import ( "fmt" "io" - "io/ioutil" "os" "strings" @@ -30,7 +29,7 @@ var base32Cmd = &cli.Command{ input = strings.NewReader(cctx.Args().First()) } - bytes, err := ioutil.ReadAll(input) + bytes, err := io.ReadAll(input) if err != nil { return nil } diff --git a/cmd/lotus-shed/base64.go b/cmd/lotus-shed/base64.go index cacc60152..19afa6613 100644 --- a/cmd/lotus-shed/base64.go +++ b/cmd/lotus-shed/base64.go @@ -4,7 +4,6 @@ import ( "encoding/base64" "fmt" "io" - "io/ioutil" "os" "strings" @@ -38,7 +37,7 @@ var base64Cmd = &cli.Command{ input = strings.NewReader(cctx.Args().First()) } - bytes, err := ioutil.ReadAll(input) + bytes, err := io.ReadAll(input) if err != nil { return nil } diff --git a/cmd/lotus-shed/bitfield.go b/cmd/lotus-shed/bitfield.go index f0824de4f..5ac75b2c6 100644 --- a/cmd/lotus-shed/bitfield.go +++ b/cmd/lotus-shed/bitfield.go @@ -5,7 +5,6 @@ import ( "encoding/hex" "fmt" "io" - "io/ioutil" "os" "github.com/urfave/cli/v2" @@ -318,7 +317,7 @@ func decodeToByte(cctx *cli.Context, i int) ([]byte, error) { if i > 0 { return nil, xerrors.Errorf("need more than %d args", i) } - r, err := ioutil.ReadAll(os.Stdin) + r, err := io.ReadAll(os.Stdin) if err != nil { return nil, err } diff --git a/cmd/lotus-shed/fip-0036.go b/cmd/lotus-shed/fip-0036.go index 485302b9b..4c8456c04 100644 --- a/cmd/lotus-shed/fip-0036.go +++ b/cmd/lotus-shed/fip-0036.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" + "os" "sort" "strconv" @@ -537,7 +537,7 @@ var finalResultCmd = &cli.Command{ // Returns voted sorted by votes from earliest to latest func getVotesMap(file string) ([]Vote, error) { var votes []Vote - vb, err := ioutil.ReadFile(file) + vb, err := os.ReadFile(file) if err != nil { return nil, xerrors.Errorf("read vote: %w", err) } diff --git a/cmd/lotus-shed/jwt.go b/cmd/lotus-shed/jwt.go index e8853b419..2a24c2569 100644 --- a/cmd/lotus-shed/jwt.go +++ b/cmd/lotus-shed/jwt.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "strings" @@ -81,7 +80,7 @@ var jwtTokenCmd = &cli.Command{ defer inputFile.Close() //nolint:errcheck input := bufio.NewReader(inputFile) - encoded, err := ioutil.ReadAll(input) + encoded, err := io.ReadAll(input) if err != nil { return err } @@ -123,7 +122,7 @@ var jwtTokenCmd = &cli.Command{ return err } - return ioutil.WriteFile(cctx.String("output"), token, 0600) + return os.WriteFile(cctx.String("output"), token, 0600) }, } @@ -142,7 +141,7 @@ var jwtNewCmd = &cli.Command{ keyName := cctx.Args().First() - sk, err := ioutil.ReadAll(io.LimitReader(rand.Reader, 32)) + sk, err := io.ReadAll(io.LimitReader(rand.Reader, 32)) if err != nil { return err } @@ -184,6 +183,6 @@ var jwtNewCmd = &cli.Command{ } filenameToken := fmt.Sprintf("jwt-%s.token", keyName) - return ioutil.WriteFile(filenameToken, token, 0600) + return os.WriteFile(filenameToken, token, 0600) }, } diff --git a/cmd/lotus-shed/keyinfo.go b/cmd/lotus-shed/keyinfo.go index 38f5ee6fe..15b584f3d 100644 --- a/cmd/lotus-shed/keyinfo.go +++ b/cmd/lotus-shed/keyinfo.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "path" "strings" @@ -68,7 +67,7 @@ var keyinfoVerifyCmd = &cli.Command{ defer inputFile.Close() //nolint:errcheck input := bufio.NewReader(inputFile) - keyContent, err := ioutil.ReadAll(input) + keyContent, err := io.ReadAll(input) if err != nil { return err } @@ -162,7 +161,7 @@ var keyinfoImportCmd = &cli.Command{ input = bufio.NewReader(inputFile) } - encoded, err := ioutil.ReadAll(input) + encoded, err := io.ReadAll(input) if err != nil { return err } @@ -274,7 +273,7 @@ var keyinfoInfoCmd = &cli.Command{ input = bufio.NewReader(inputFile) } - encoded, err := ioutil.ReadAll(input) + encoded, err := io.ReadAll(input) if err != nil { return err } diff --git a/cmd/lotus-shed/rpc.go b/cmd/lotus-shed/rpc.go index 3be269358..8ef799129 100644 --- a/cmd/lotus-shed/rpc.go +++ b/cmd/lotus-shed/rpc.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "os" @@ -97,7 +96,7 @@ var rpcCmd = &cli.Command{ return err } - rb, err := ioutil.ReadAll(resp.Body) + rb, err := io.ReadAll(resp.Body) if err != nil { return err } diff --git a/cmd/lotus-worker/main.go b/cmd/lotus-worker/main.go index 42f46c9d8..e0a931274 100644 --- a/cmd/lotus-worker/main.go +++ b/cmd/lotus-worker/main.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" "net" "net/http" "os" @@ -464,7 +463,7 @@ var runCmd = &cli.Command{ return xerrors.Errorf("marshaling storage config: %w", err) } - if err := ioutil.WriteFile(filepath.Join(lr.Path(), "sectorstore.json"), b, 0644); err != nil { + if err := os.WriteFile(filepath.Join(lr.Path(), "sectorstore.json"), b, 0644); err != nil { return xerrors.Errorf("persisting storage metadata (%s): %w", filepath.Join(lr.Path(), "sectorstore.json"), err) } diff --git a/cmd/lotus-worker/storage.go b/cmd/lotus-worker/storage.go index 6b5994c17..9e4bf1c9b 100644 --- a/cmd/lotus-worker/storage.go +++ b/cmd/lotus-worker/storage.go @@ -2,7 +2,6 @@ package main import ( "encoding/json" - "io/ioutil" "os" "path/filepath" @@ -121,7 +120,7 @@ var storageAttachCmd = &cli.Command{ return xerrors.Errorf("marshaling storage config: %w", err) } - if err := ioutil.WriteFile(filepath.Join(p, metaFile), b, 0644); err != nil { + if err := os.WriteFile(filepath.Join(p, metaFile), b, 0644); err != nil { return xerrors.Errorf("persisting storage metadata (%s): %w", filepath.Join(p, metaFile), err) } } diff --git a/cmd/lotus/daemon.go b/cmd/lotus/daemon.go index b3341bd79..3803c0f5d 100644 --- a/cmd/lotus/daemon.go +++ b/cmd/lotus/daemon.go @@ -10,7 +10,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "os" "runtime/pprof" @@ -244,7 +243,7 @@ var DaemonCmd = &cli.Command{ var genBytes []byte if cctx.String("genesis") != "" { - genBytes, err = ioutil.ReadFile(cctx.String("genesis")) + genBytes, err = os.ReadFile(cctx.String("genesis")) if err != nil { return xerrors.Errorf("reading genesis: %w", err) } @@ -400,7 +399,7 @@ func importKey(ctx context.Context, api lapi.FullNode, f string) error { return err } - hexdata, err := ioutil.ReadFile(f) + hexdata, err := os.ReadFile(f) if err != nil { return err } diff --git a/conformance/corpus_test.go b/conformance/corpus_test.go index adbebbcc7..ec9f9d516 100644 --- a/conformance/corpus_test.go +++ b/conformance/corpus_test.go @@ -5,7 +5,6 @@ package conformance import ( "encoding/json" - "io/ioutil" "os" "path/filepath" "strings" @@ -107,7 +106,7 @@ func TestConformance(t *testing.T) { // Run a test for each vector. for _, v := range vectors { path := filepath.Join(corpusRoot, v) - raw, err := ioutil.ReadFile(path) + raw, err := os.ReadFile(path) if err != nil { t.Fatalf("failed to read test raw file: %s", path) } diff --git a/conformance/runner.go b/conformance/runner.go index ff738a4a5..827c10a5c 100644 --- a/conformance/runner.go +++ b/conformance/runner.go @@ -6,7 +6,6 @@ import ( "context" "encoding/base64" "fmt" - "io/ioutil" "math" "os" "os/exec" @@ -328,7 +327,7 @@ func dumpThreeWayStateDiff(r Reporter, vector *schema.TestVector, bs blockstore. // writeStateToTempCAR writes the provided roots to a temporary CAR that'll be // cleaned up via t.Cleanup(). It returns the full path of the temp file. func writeStateToTempCAR(bs blockstore.Blockstore, roots ...cid.Cid) (string, error) { - tmp, err := ioutil.TempFile("", "lotus-tests-*.car") + tmp, err := os.CreateTemp("", "lotus-tests-*.car") if err != nil { return "", fmt.Errorf("failed to create temp file to dump CAR for diffing: %w", err) } diff --git a/gen/inline-gen/main.go b/gen/inline-gen/main.go index d97134cdd..4e55816f6 100644 --- a/gen/inline-gen/main.go +++ b/gen/inline-gen/main.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io/fs" - "io/ioutil" "os" "path/filepath" "strings" @@ -19,7 +18,7 @@ const ( ) func main() { - db, err := ioutil.ReadFile(os.Args[2]) + db, err := os.ReadFile(os.Args[2]) if err != nil { panic(err) } @@ -38,7 +37,7 @@ func main() { if filepath.Ext(path) != ".go" { return nil } - fb, err := ioutil.ReadFile(path) + fb, err := os.ReadFile(path) if err != nil { return err } @@ -110,7 +109,7 @@ func main() { if rewrite { fmt.Printf("write %s\n", path) - if err := ioutil.WriteFile(path, []byte(strings.Join(outLines, "\n")), 0664); err != nil { + if err := os.WriteFile(path, []byte(strings.Join(outLines, "\n")), 0664); err != nil { return err } } diff --git a/itests/deals_partial_retrieval_dm-level_test.go b/itests/deals_partial_retrieval_dm-level_test.go index 156ed67fe..e3414c191 100644 --- a/itests/deals_partial_retrieval_dm-level_test.go +++ b/itests/deals_partial_retrieval_dm-level_test.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "testing" "time" @@ -196,7 +195,7 @@ func validateDMUnixFile(r io.Reader) error { } func testDMExportAsCar(ctx context.Context, client *kit.TestFullNode, expDirective api.ExportRef, tempDir string) error { - out, err := ioutil.TempFile(tempDir, "exp-test") + out, err := os.CreateTemp(tempDir, "exp-test") if err != nil { return err } @@ -214,7 +213,7 @@ func testDMExportAsCar(ctx context.Context, client *kit.TestFullNode, expDirecti return validateDMCar(out) } func tesV0RetrievalAsCar(ctx context.Context, client *kit.TestFullNode, retOrder api0.RetrievalOrder, tempDir string) error { - out, err := ioutil.TempFile(tempDir, "exp-test") + out, err := os.CreateTemp(tempDir, "exp-test") if err != nil { return err } diff --git a/itests/kit/client.go b/itests/kit/client.go index f29fecfeb..134b6b1ce 100644 --- a/itests/kit/client.go +++ b/itests/kit/client.go @@ -3,7 +3,6 @@ package kit import ( "context" "fmt" - "io/ioutil" "math/rand" "os" "path/filepath" @@ -110,7 +109,7 @@ func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode *TestFullNode) // Retrieve the first file from the Miner // client retrieve - tmpdir, err := ioutil.TempDir(os.TempDir(), "test-cli-client") + tmpdir, err := os.MkdirTemp(os.TempDir(), "test-cli-client") require.NoError(t, err) path := filepath.Join(tmpdir, "outfile.dat") @@ -144,13 +143,13 @@ func createRandomFile(rseed, size int) ([]byte, string, error) { data := make([]byte, size) rand.New(rand.NewSource(int64(rseed))).Read(data) - dir, err := ioutil.TempDir(os.TempDir(), "test-make-deal-") + dir, err := os.MkdirTemp(os.TempDir(), "test-make-deal-") if err != nil { return nil, "", err } path := filepath.Join(dir, "sourcefile.dat") - err = ioutil.WriteFile(path, data, 0644) + err = os.WriteFile(path, data, 0644) if err != nil { return nil, "", err } diff --git a/itests/kit/ensemble.go b/itests/kit/ensemble.go index a96aa60ff..d38518be8 100644 --- a/itests/kit/ensemble.go +++ b/itests/kit/ensemble.go @@ -6,9 +6,9 @@ import ( "crypto/rand" "encoding/binary" "fmt" - "io/ioutil" "net" "net/http" + "os" "sync" "testing" "time" @@ -234,7 +234,7 @@ func (n *Ensemble) MinerEnroll(minerNode *TestMiner, full *TestFullNode, opts .. peerId, err := peer.IDFromPrivateKey(privkey) require.NoError(n.t, err) - tdir, err := ioutil.TempDir("", "preseal-memgen") + tdir, err := os.MkdirTemp("", "preseal-memgen") require.NoError(n.t, err) minerCnt := len(n.inactive.miners) + len(n.active.miners) diff --git a/itests/kit/node_miner.go b/itests/kit/node_miner.go index dd6f3088c..4b81c9df0 100644 --- a/itests/kit/node_miner.go +++ b/itests/kit/node_miner.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" "net" "os" "path/filepath" @@ -204,7 +203,7 @@ func (tm *TestMiner) AddStorage(ctx context.Context, t *testing.T, conf func(*st b, err := json.MarshalIndent(cfg, "", " ") require.NoError(t, err) - err = ioutil.WriteFile(filepath.Join(p, metaFile), b, 0644) + err = os.WriteFile(filepath.Join(p, metaFile), b, 0644) require.NoError(t, err) err = tm.StorageAddLocal(ctx, p) diff --git a/itests/kit/node_worker.go b/itests/kit/node_worker.go index ac200fb0f..3674763ed 100644 --- a/itests/kit/node_worker.go +++ b/itests/kit/node_worker.go @@ -3,7 +3,6 @@ package kit import ( "context" "encoding/json" - "io/ioutil" "net" "net/http" "os" @@ -67,7 +66,7 @@ func (tm *TestWorker) AddStorage(ctx context.Context, t *testing.T, conf func(*s b, err := json.MarshalIndent(cfg, "", " ") require.NoError(t, err) - err = ioutil.WriteFile(filepath.Join(p, metaFile), b, 0644) + err = os.WriteFile(filepath.Join(p, metaFile), b, 0644) require.NoError(t, err) err = tm.StorageAddLocal(ctx, p) diff --git a/lib/backupds/backupds_test.go b/lib/backupds/backupds_test.go index b76799bfb..8909a5f3b 100644 --- a/lib/backupds/backupds_test.go +++ b/lib/backupds/backupds_test.go @@ -5,7 +5,6 @@ import ( "bytes" "context" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -77,7 +76,7 @@ func TestLogRestore(t *testing.T) { require.NoError(t, err) require.Equal(t, 1, len(fls)) - bf, err := ioutil.ReadFile(filepath.Join(logdir, fls[0].Name())) + bf, err := os.ReadFile(filepath.Join(logdir, fls[0].Name())) require.NoError(t, err) ds2 := datastore.NewMapDatastore() diff --git a/lib/consensus/raft/config.go b/lib/consensus/raft/config.go index 81bdb7fdc..bdd82c108 100644 --- a/lib/consensus/raft/config.go +++ b/lib/consensus/raft/config.go @@ -1,7 +1,7 @@ package consensus import ( - "io/ioutil" + "io" "path/filepath" "time" @@ -69,7 +69,7 @@ func DefaultClusterRaftConfig() *ClusterRaftConfig { cfg.RaftConfig.LocalID = "will_be_set_automatically" // Set up logging - cfg.RaftConfig.LogOutput = ioutil.Discard + cfg.RaftConfig.LogOutput = io.Discard return &cfg } @@ -91,7 +91,7 @@ func NewClusterRaftConfig(userRaftConfig *config.UserRaftConfig) *ClusterRaftCon cfg.RaftConfig.LocalID = "will_be_set_automatically" // Set up logging - cfg.RaftConfig.LogOutput = ioutil.Discard + cfg.RaftConfig.LogOutput = io.Discard return &cfg diff --git a/lib/rpcenc/reader.go b/lib/rpcenc/reader.go index 34b9fcfb4..2dd64473e 100644 --- a/lib/rpcenc/reader.go +++ b/lib/rpcenc/reader.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/url" "path" @@ -158,7 +157,7 @@ func ReaderParamEncoder(addr string) jsonrpc.Option { } if resp.StatusCode != http.StatusOK { - b, _ := ioutil.ReadAll(resp.Body) + b, _ := io.ReadAll(resp.Body) log.Errorf("sending reader param (%s): non-200 status: %s, msg: '%s'", u.String(), resp.Status, string(b)) return } @@ -182,7 +181,7 @@ func ReaderParamEncoder(addr string) jsonrpc.Option { defer resp.Body.Close() //nolint if resp.StatusCode != http.StatusOK { - b, _ := ioutil.ReadAll(resp.Body) + b, _ := io.ReadAll(resp.Body) log.Errorf("sending reader param (%s): non-200 status: %s, msg: '%s'", u.String(), resp.Status, string(b)) return } diff --git a/lib/unixfs/filestore.go b/lib/unixfs/filestore.go index acd0a62ac..0a0b61c4c 100644 --- a/lib/unixfs/filestore.go +++ b/lib/unixfs/filestore.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "github.com/ipfs/go-blockservice" @@ -68,7 +67,7 @@ func CreateFilestore(ctx context.Context, srcPath string, dstPath string) (cid.C return cid.Undef, xerrors.Errorf("failed to create reader path file: %w", err) } - f, err := ioutil.TempFile("", "") + f, err := os.CreateTemp("", "") if err != nil { return cid.Undef, xerrors.Errorf("failed to create temp file: %w", err) } diff --git a/lib/unixfs/filestore_test.go b/lib/unixfs/filestore_test.go index f9d5ed656..67d380701 100644 --- a/lib/unixfs/filestore_test.go +++ b/lib/unixfs/filestore_test.go @@ -5,7 +5,6 @@ import ( "bytes" "context" "io" - "io/ioutil" "os" "strings" "testing" @@ -67,7 +66,7 @@ func TestRoundtripUnixFS_Dense(t *testing.T) { // ensure contents of the initial input file and the output file are identical. fo, err := os.Open(tmpOutput) require.NoError(t, err) - bz2, err := ioutil.ReadAll(fo) + bz2, err := io.ReadAll(fo) require.NoError(t, err) require.NoError(t, fo.Close()) require.Equal(t, inputContents, bz2) @@ -107,7 +106,7 @@ func TestRoundtripUnixFS_Filestore(t *testing.T) { // ensure contents of the initial input file and the output file are identical. fo, err := os.Open(tmpOutput) require.NoError(t, err) - bz2, err := ioutil.ReadAll(fo) + bz2, err := io.ReadAll(fo) require.NoError(t, err) require.NoError(t, fo.Close()) require.Equal(t, inputContents, bz2) diff --git a/markets/dagstore/mount_test.go b/markets/dagstore/mount_test.go index e044603d4..d415f8d88 100644 --- a/markets/dagstore/mount_test.go +++ b/markets/dagstore/mount_test.go @@ -4,7 +4,6 @@ package dagstore import ( "context" "io" - "io/ioutil" "net/url" "strings" "testing" @@ -39,7 +38,7 @@ func TestLotusMount(t *testing.T) { io.ReaderAt io.Seeker }{ - ReadCloser: ioutil.NopCloser(strings.NewReader("testing")), + ReadCloser: io.NopCloser(strings.NewReader("testing")), ReaderAt: nil, Seeker: nil, } @@ -48,7 +47,7 @@ func TestLotusMount(t *testing.T) { io.ReaderAt io.Seeker }{ - ReadCloser: ioutil.NopCloser(strings.NewReader("testing")), + ReadCloser: io.NopCloser(strings.NewReader("testing")), ReaderAt: nil, Seeker: nil, } @@ -66,7 +65,7 @@ func TestLotusMount(t *testing.T) { rd, err := mnt.Fetch(context.Background()) require.NoError(t, err) - bz, err := ioutil.ReadAll(rd) + bz, err := io.ReadAll(rd) require.NoError(t, err) require.NoError(t, rd.Close()) require.Equal(t, []byte("testing"), bz) @@ -85,7 +84,7 @@ func TestLotusMount(t *testing.T) { // fetching on this mount should get us back the same data. rd, err = mnt2.Fetch(context.Background()) require.NoError(t, err) - bz, err = ioutil.ReadAll(rd) + bz, err = io.ReadAll(rd) require.NoError(t, err) require.NoError(t, rd.Close()) require.Equal(t, []byte("testing"), bz) diff --git a/node/config/cfgdocgen/gen.go b/node/config/cfgdocgen/gen.go index 513350152..577e85f9d 100644 --- a/node/config/cfgdocgen/gen.go +++ b/node/config/cfgdocgen/gen.go @@ -2,14 +2,13 @@ package main import ( "fmt" - "io/ioutil" "os" "sort" "strings" ) func run() error { - tfb, err := ioutil.ReadFile("./node/config/types.go") + tfb, err := os.ReadFile("./node/config/types.go") if err != nil { return err } diff --git a/node/config/load.go b/node/config/load.go index 29cb15d27..913350912 100644 --- a/node/config/load.go +++ b/node/config/load.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "os" "reflect" "regexp" @@ -47,7 +46,7 @@ func FromFile(path string, opts ...LoadCfgOpt) (interface{}, error) { return nil, err } defer file.Close() //nolint:errcheck,staticcheck // The file is RO - cfgBs, err := ioutil.ReadAll(file) + cfgBs, err := io.ReadAll(file) if err != nil { return nil, xerrors.Errorf("failed to read config for validation checks %w", err) } diff --git a/node/config/load_test.go b/node/config/load_test.go index cab5268df..e17660c19 100644 --- a/node/config/load_test.go +++ b/node/config/load_test.go @@ -3,7 +3,6 @@ package config import ( "bytes" - "io/ioutil" "os" "testing" "time" @@ -50,7 +49,7 @@ func TestParitalConfig(t *testing.T) { } { - f, err := ioutil.TempFile("", "config-*.toml") + f, err := os.CreateTemp("", "config-*.toml") fname := f.Name() assert.NoError(err, "tmp file shold not error") @@ -115,7 +114,7 @@ func TestValidateConfigSetsEnableSplitstore(t *testing.T) { assert.False(t, MatchEnableSplitstoreField(string(cfgCommentedOutEnableSS))) // write config with commented out EnableSplitstore to file - f, err := ioutil.TempFile("", "config.toml") + f, err := os.CreateTemp("", "config.toml") fname := f.Name() assert.NoError(t, err) defer func() { @@ -132,7 +131,7 @@ func TestValidateConfigSetsEnableSplitstore(t *testing.T) { // Loading without a config file and a default fails if the default fallback is disabled func TestFailToFallbackToDefault(t *testing.T) { - dir, err := ioutil.TempDir("", "dirWithNoFiles") + dir, err := os.MkdirTemp("", "dirWithNoFiles") assert.NoError(t, err) defer assert.NoError(t, os.RemoveAll(dir)) nonExistantFileName := dir + "/notarealfile" diff --git a/node/config/storage.go b/node/config/storage.go index 2c9d880f9..dfe067840 100644 --- a/node/config/storage.go +++ b/node/config/storage.go @@ -3,7 +3,6 @@ package config import ( "encoding/json" "io" - "io/ioutil" "os" "golang.org/x/xerrors" @@ -43,7 +42,7 @@ func WriteStorageFile(path string, config storiface.StorageConfig) error { return xerrors.Errorf("marshaling storage config: %w", err) } - if err := ioutil.WriteFile(path, b, 0644); err != nil { + if err := os.WriteFile(path, b, 0644); err != nil { return xerrors.Errorf("persisting storage config (%s): %w", path, err) } diff --git a/node/impl/client/client_test.go b/node/impl/client/client_test.go index 98092bc93..032fef55a 100644 --- a/node/impl/client/client_test.go +++ b/node/impl/client/client_test.go @@ -5,7 +5,7 @@ import ( "bytes" "context" "embed" - "io/ioutil" + "os" "path/filepath" "strings" "testing" @@ -77,7 +77,7 @@ func TestImportLocal(t *testing.T) { }) require.NoError(t, err) - outBytes, err := ioutil.ReadFile(out1) + outBytes, err := os.ReadFile(out1) require.NoError(t, err) require.Equal(t, b, outBytes) @@ -128,7 +128,7 @@ func TestImportLocal(t *testing.T) { err = files.WriteTo(file, exportedPath) require.NoError(t, err) - exportedBytes, err := ioutil.ReadFile(exportedPath) + exportedBytes, err := os.ReadFile(exportedPath) require.NoError(t, err) // compare original file to recreated unixfs file. diff --git a/node/modules/core.go b/node/modules/core.go index c74cc2143..a0d52c291 100644 --- a/node/modules/core.go +++ b/node/modules/core.go @@ -5,7 +5,6 @@ import ( "crypto/rand" "errors" "io" - "io/ioutil" "os" "path/filepath" "time" @@ -147,7 +146,7 @@ func APISecret(keystore types.KeyStore, lr repo.LockedRepo) (*dtypes.APIAlg, err if errors.Is(err, types.ErrKeyInfoNotFound) { log.Warn("Generating new API secret") - sk, err := ioutil.ReadAll(io.LimitReader(rand.Reader, 32)) + sk, err := io.ReadAll(io.LimitReader(rand.Reader, 32)) if err != nil { return nil, err } diff --git a/node/modules/testing/genesis.go b/node/modules/testing/genesis.go index a3d25e36a..3876775df 100644 --- a/node/modules/testing/genesis.go +++ b/node/modules/testing/genesis.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "github.com/ipfs/go-blockservice" @@ -60,7 +59,7 @@ func MakeGenesis(outFile, genesisTemplate string) func(bs dtypes.ChainBlockstore return nil, err } - fdata, err := ioutil.ReadFile(genesisTemplate) + fdata, err := os.ReadFile(genesisTemplate) if err != nil { return nil, xerrors.Errorf("reading preseals json: %w", err) } diff --git a/node/repo/fsrepo.go b/node/repo/fsrepo.go index 2dbedd5e7..03ddd2d6c 100644 --- a/node/repo/fsrepo.go +++ b/node/repo/fsrepo.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -329,7 +328,7 @@ func (fsr *FsRepo) APIEndpoint() (multiaddr.Multiaddr, error) { } defer f.Close() //nolint: errcheck // Read only op - data, err := ioutil.ReadAll(f) + data, err := io.ReadAll(f) if err != nil { return nil, xerrors.Errorf("failed to read %q: %w", p, err) } @@ -354,7 +353,7 @@ func (fsr *FsRepo) APIToken() ([]byte, error) { } defer f.Close() //nolint: errcheck // Read only op - tb, err := ioutil.ReadAll(f) + tb, err := io.ReadAll(f) if err != nil { return nil, err } @@ -582,7 +581,7 @@ func (fsr *fsLockedRepo) SetConfig(c func(interface{})) error { } // write buffer of TOML bytes to config file - err = ioutil.WriteFile(fsr.configPath, buf.Bytes(), 0644) + err = os.WriteFile(fsr.configPath, buf.Bytes(), 0644) if err != nil { return err } @@ -635,14 +634,14 @@ func (fsr *fsLockedRepo) SetAPIEndpoint(ma multiaddr.Multiaddr) error { if err := fsr.stillValid(); err != nil { return err } - return ioutil.WriteFile(fsr.join(fsAPI), []byte(ma.String()), 0644) + return os.WriteFile(fsr.join(fsAPI), []byte(ma.String()), 0644) } func (fsr *fsLockedRepo) SetAPIToken(token []byte) error { if err := fsr.stillValid(); err != nil { return err } - return ioutil.WriteFile(fsr.join(fsAPIToken), token, 0600) + return os.WriteFile(fsr.join(fsAPIToken), token, 0600) } func (fsr *fsLockedRepo) KeyStore() (types.KeyStore, error) { @@ -711,7 +710,7 @@ func (fsr *fsLockedRepo) Get(name string) (types.KeyInfo, error) { } defer file.Close() //nolint: errcheck // read only op - data, err := ioutil.ReadAll(file) + data, err := io.ReadAll(file) if err != nil { return types.KeyInfo{}, xerrors.Errorf("reading key '%s': %w", name, err) } @@ -760,7 +759,7 @@ func (fsr *fsLockedRepo) put(rawName string, info types.KeyInfo, retries int) er return xerrors.Errorf("encoding key '%s': %w", name, err) } - err = ioutil.WriteFile(keyPath, keyData, 0600) + err = os.WriteFile(keyPath, keyData, 0600) if err != nil { return xerrors.Errorf("writing key '%s': %w", name, err) } diff --git a/node/repo/memrepo.go b/node/repo/memrepo.go index 7817776a9..6a4b416e2 100644 --- a/node/repo/memrepo.go +++ b/node/repo/memrepo.go @@ -3,7 +3,6 @@ package repo import ( "context" "encoding/json" - "io/ioutil" "os" "path/filepath" "sync" @@ -103,7 +102,7 @@ func (lmem *lockedMemRepo) Path() string { return lmem.mem.tempDir } - t, err := ioutil.TempDir(os.TempDir(), "lotus-memrepo-temp-") + t, err := os.MkdirTemp(os.TempDir(), "lotus-memrepo-temp-") if err != nil { panic(err) // only used in tests, probably fine } @@ -142,7 +141,7 @@ func (lmem *lockedMemRepo) initSectorStore(t string) { panic(err) } - if err := ioutil.WriteFile(filepath.Join(t, "sectorstore.json"), b, 0644); err != nil { + if err := os.WriteFile(filepath.Join(t, "sectorstore.json"), b, 0644); err != nil { panic(err) } } diff --git a/storage/paths/http_handler_test.go b/storage/paths/http_handler_test.go index b03fd20ee..4987936dd 100644 --- a/storage/paths/http_handler_test.go +++ b/storage/paths/http_handler_test.go @@ -2,7 +2,7 @@ package paths_test import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "os" @@ -378,7 +378,7 @@ func TestRemoteGetSector(t *testing.T) { if !tc.isDir { // create file - tempFile, err := ioutil.TempFile("", "TestRemoteGetSector-") + tempFile, err := os.CreateTemp("", "TestRemoteGetSector-") require.NoError(t, err) defer func() { @@ -390,7 +390,7 @@ func TestRemoteGetSector(t *testing.T) { path = tempFile.Name() } else { // create dir with a file - tempFile2, err := ioutil.TempFile("", "TestRemoteGetSector-") + tempFile2, err := os.CreateTemp("", "TestRemoteGetSector-") require.NoError(t, err) defer func() { _ = os.Remove(tempFile2.Name()) @@ -435,7 +435,7 @@ func TestRemoteGetSector(t *testing.T) { _ = resp.Body.Close() }() - bz, err := ioutil.ReadAll(resp.Body) + bz, err := io.ReadAll(resp.Body) require.NoError(t, err) // assert expected status code diff --git a/storage/paths/local.go b/storage/paths/local.go index 2182f24ef..a866f5bbe 100644 --- a/storage/paths/local.go +++ b/storage/paths/local.go @@ -3,7 +3,6 @@ package paths import ( "context" "encoding/json" - "io/ioutil" "math/bits" "math/rand" "os" @@ -151,7 +150,7 @@ func (st *Local) OpenPath(ctx context.Context, p string) error { st.localLk.Lock() defer st.localLk.Unlock() - mb, err := ioutil.ReadFile(filepath.Join(p, MetaFile)) + mb, err := os.ReadFile(filepath.Join(p, MetaFile)) if err != nil { return xerrors.Errorf("reading storage metadata for %s: %w", p, err) } @@ -247,7 +246,7 @@ func (st *Local) Redeclare(ctx context.Context, filterId *storiface.ID, dropMiss defer st.localLk.Unlock() for id, p := range st.paths { - mb, err := ioutil.ReadFile(filepath.Join(p.local, MetaFile)) + mb, err := os.ReadFile(filepath.Join(p.local, MetaFile)) if err != nil { return xerrors.Errorf("reading storage metadata for %s: %w", p.local, err) } diff --git a/storage/paths/local_test.go b/storage/paths/local_test.go index 6b9f4a545..bfa138ff6 100644 --- a/storage/paths/local_test.go +++ b/storage/paths/local_test.go @@ -3,7 +3,6 @@ package paths import ( "context" "encoding/json" - "io/ioutil" "os" "path/filepath" "testing" @@ -63,7 +62,7 @@ func (t *TestingLocalStorage) init(subpath string) error { return err } - if err := ioutil.WriteFile(metaFile, mb, 0644); err != nil { + if err := os.WriteFile(metaFile, mb, 0644); err != nil { return err } diff --git a/storage/paths/remote.go b/storage/paths/remote.go index 06d1080b3..852936153 100644 --- a/storage/paths/remote.go +++ b/storage/paths/remote.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "math/bits" "net/http" "net/url" @@ -412,7 +411,7 @@ func (r *Remote) FsStat(ctx context.Context, id storiface.ID) (fsutil.FsStat, er case 404: return fsutil.FsStat{}, errPathNotFound case 500: - b, err := ioutil.ReadAll(resp.Body) + b, err := io.ReadAll(resp.Body) if err != nil { return fsutil.FsStat{}, xerrors.Errorf("fsstat: got http 500, then failed to read the error: %w", err) } @@ -768,7 +767,7 @@ func (r *Remote) GenerateSingleVanillaProof(ctx context.Context, minerID abi.Act log.Debugw("reading vanilla proof from remote not-found response", "url", url, "store", info.ID) continue } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, xerrors.Errorf("resp.Body ReadAll: %w", err) } @@ -780,7 +779,7 @@ func (r *Remote) GenerateSingleVanillaProof(ctx context.Context, minerID abi.Act return nil, xerrors.Errorf("non-200 code from %s: '%s'", url, strings.TrimSpace(string(body))) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { if err := resp.Body.Close(); err != nil { log.Error("response close: ", err) diff --git a/storage/paths/remote_test.go b/storage/paths/remote_test.go index 2d7fe2c73..41d5e8a17 100644 --- a/storage/paths/remote_test.go +++ b/storage/paths/remote_test.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/http/httptest" "os" @@ -48,7 +47,7 @@ func createTestStorage(t *testing.T, p string, seal bool, att ...*paths.Local) s b, err := json.MarshalIndent(cfg, "", " ") require.NoError(t, err) - require.NoError(t, ioutil.WriteFile(filepath.Join(p, metaFile), b, 0644)) + require.NoError(t, os.WriteFile(filepath.Join(p, metaFile), b, 0644)) for _, s := range att { require.NoError(t, s.OpenPath(context.Background(), p)) @@ -130,7 +129,7 @@ func TestMoveShared(t *testing.T) { data := make([]byte, 2032) data[1] = 54 - require.NoError(t, ioutil.WriteFile(sp.Sealed, data, 0666)) + require.NoError(t, os.WriteFile(sp.Sealed, data, 0666)) fmt.Println("write to ", sp.Sealed) require.NoError(t, index.StorageDeclareSector(ctx, storiface.ID(sid.Sealed), s1ref.ID, storiface.FTSealed, true)) @@ -145,7 +144,7 @@ func TestMoveShared(t *testing.T) { require.Equal(t, id1, storiface.ID(sid.Sealed)) fmt.Println("read from ", sp.Sealed) - read, err := ioutil.ReadFile(sp.Sealed) + read, err := os.ReadFile(sp.Sealed) require.NoError(t, err) require.EqualValues(t, data, read) } @@ -357,7 +356,7 @@ func TestReader(t *testing.T) { mockCheckAllocation(pf, offset, size, emptyPartialFile, true, nil) - f, err := ioutil.TempFile("", "TestReader-") + f, err := os.CreateTemp("", "TestReader-") require.NoError(t, err) _, err = f.Write(bz) require.NoError(t, err) @@ -502,7 +501,7 @@ func TestReader(t *testing.T) { require.NoError(t, os.Remove(f.Name())) } - bz, err := ioutil.ReadAll(rd) + bz, err := io.ReadAll(rd) require.NoError(t, err) require.Equal(t, tc.expectedSectorBytes, bz) } diff --git a/storage/sealer/ffiwrapper/sealer_cgo.go b/storage/sealer/ffiwrapper/sealer_cgo.go index e9ce5746e..871012d0b 100644 --- a/storage/sealer/ffiwrapper/sealer_cgo.go +++ b/storage/sealer/ffiwrapper/sealer_cgo.go @@ -11,7 +11,6 @@ import ( "encoding/base64" "encoding/json" "io" - "io/ioutil" "math/bits" "os" "path/filepath" @@ -1095,7 +1094,7 @@ func (sb *Sealer) FinalizeSectorInto(ctx context.Context, sector storiface.Secto } defer done() - files, err := ioutil.ReadDir(paths.Cache) + files, err := os.ReadDir(paths.Cache) if err != nil { return err } diff --git a/storage/sealer/ffiwrapper/sealer_test.go b/storage/sealer/ffiwrapper/sealer_test.go index dd0c1e184..34dea3b1b 100644 --- a/storage/sealer/ffiwrapper/sealer_test.go +++ b/storage/sealer/ffiwrapper/sealer_test.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "math/rand" "os" "path/filepath" @@ -130,7 +129,7 @@ func (s *seal) unseal(t *testing.T, sb *Sealer, sp *basicfs.Provider, si storifa t.Fatal(err) } - expect, _ := ioutil.ReadAll(data(si.ID.Number, 1016)) + expect, _ := io.ReadAll(data(si.ID.Number, 1016)) if !bytes.Equal(b.Bytes(), expect) { t.Fatal("read wrong bytes") } @@ -160,7 +159,7 @@ func (s *seal) unseal(t *testing.T, sb *Sealer, sp *basicfs.Provider, si storifa t.Fatal(err) } - expect, _ = ioutil.ReadAll(data(si.ID.Number, 1016)) + expect, _ = io.ReadAll(data(si.ID.Number, 1016)) require.Equal(t, expect, b.Bytes()) b.Reset() @@ -240,12 +239,12 @@ func corrupt(t *testing.T, sealer *Sealer, id storiface.SectorRef) { } func getGrothParamFileAndVerifyingKeys(s abi.SectorSize) { - dat, err := ioutil.ReadFile("../../../build/proof-params/parameters.json") + dat, err := os.ReadFile("../../../build/proof-params/parameters.json") if err != nil { panic(err) } - datSrs, err := ioutil.ReadFile("../../../build/proof-params/srs-inner-product.json") + datSrs, err := os.ReadFile("../../../build/proof-params/srs-inner-product.json") if err != nil { panic(err) } @@ -281,7 +280,7 @@ func TestSealAndVerify(t *testing.T) { getGrothParamFileAndVerifyingKeys(sectorSize) - cdir, err := ioutil.TempDir("", "sbtest-c-") + cdir, err := os.MkdirTemp("", "sbtest-c-") if err != nil { t.Fatal(err) } @@ -352,7 +351,7 @@ func TestSealPoStNoCommit(t *testing.T) { getGrothParamFileAndVerifyingKeys(sectorSize) - dir, err := ioutil.TempDir("", "sbtest") + dir, err := os.MkdirTemp("", "sbtest") if err != nil { t.Fatal(err) } @@ -416,7 +415,7 @@ func TestSealAndVerify3(t *testing.T) { getGrothParamFileAndVerifyingKeys(sectorSize) - dir, err := ioutil.TempDir("", "sbtest") + dir, err := os.MkdirTemp("", "sbtest") if err != nil { t.Fatal(err) } @@ -494,7 +493,7 @@ func TestSealAndVerifyAggregate(t *testing.T) { getGrothParamFileAndVerifyingKeys(sectorSize) - cdir, err := ioutil.TempDir("", "sbtest-c-") + cdir, err := os.MkdirTemp("", "sbtest-c-") if err != nil { t.Fatal(err) } @@ -576,7 +575,7 @@ func BenchmarkWriteWithAlignment(b *testing.B) { for i := 0; i < b.N; i++ { b.StopTimer() rf, w, _ := commpffi.ToReadableFile(bytes.NewReader(bytes.Repeat([]byte{0xff, 0}, int(bt/2))), int64(bt)) - tf, _ := ioutil.TempFile("/tmp/", "scrb-") + tf, _ := os.CreateTemp("/tmp/", "scrb-") b.StartTimer() ffi.WriteWithAlignment(abi.RegisteredSealProof_StackedDrg2KiBV1, rf, bt, tf, nil) // nolint:errcheck @@ -735,7 +734,7 @@ func TestGenerateUnsealedCID(t *testing.T) { func TestAddPiece512M(t *testing.T) { sz := abi.PaddedPieceSize(512 << 20).Unpadded() - cdir, err := ioutil.TempDir("", "sbtest-c-") + cdir, err := os.MkdirTemp("", "sbtest-c-") if err != nil { t.Fatal(err) } @@ -779,7 +778,7 @@ func BenchmarkAddPiece512M(b *testing.B) { sz := abi.PaddedPieceSize(512 << 20).Unpadded() b.SetBytes(int64(sz)) - cdir, err := ioutil.TempDir("", "sbtest-c-") + cdir, err := os.MkdirTemp("", "sbtest-c-") if err != nil { b.Fatal(err) } @@ -821,7 +820,7 @@ func BenchmarkAddPiece512M(b *testing.B) { func TestAddPiece512MPadded(t *testing.T) { sz := abi.PaddedPieceSize(512 << 20).Unpadded() - cdir, err := ioutil.TempDir("", "sbtest-c-") + cdir, err := os.MkdirTemp("", "sbtest-c-") if err != nil { t.Fatal(err) } @@ -890,7 +889,7 @@ func TestMulticoreSDR(t *testing.T) { getGrothParamFileAndVerifyingKeys(sectorSize) - dir, err := ioutil.TempDir("", "sbtest") + dir, err := os.MkdirTemp("", "sbtest") if err != nil { t.Fatal(err) } @@ -995,7 +994,7 @@ func TestPoStChallengeAssumptions(t *testing.T) { func TestDCAPCloses(t *testing.T) { sz := abi.PaddedPieceSize(2 << 10).Unpadded() - cdir, err := ioutil.TempDir("", "sbtest-c-") + cdir, err := os.MkdirTemp("", "sbtest-c-") if err != nil { t.Fatal(err) } diff --git a/storage/sealer/fr32/fr32_ffi_cmp_test.go b/storage/sealer/fr32/fr32_ffi_cmp_test.go index 7dece4723..32afa470e 100644 --- a/storage/sealer/fr32/fr32_ffi_cmp_test.go +++ b/storage/sealer/fr32/fr32_ffi_cmp_test.go @@ -3,7 +3,6 @@ package fr32_test import ( "bytes" "io" - "io/ioutil" "os" "testing" @@ -17,7 +16,7 @@ import ( ) func TestWriteTwoPcs(t *testing.T) { - tf, _ := ioutil.TempFile("/tmp/", "scrb-") + tf, _ := os.CreateTemp("/tmp/", "scrb-") paddedSize := abi.PaddedPieceSize(16 << 20) n := 2 @@ -43,7 +42,7 @@ func TestWriteTwoPcs(t *testing.T) { panic(err) } - ffiBytes, err := ioutil.ReadAll(tf) + ffiBytes, err := io.ReadAll(tf) if err != nil { panic(err) } diff --git a/storage/sealer/fr32/fr32_test.go b/storage/sealer/fr32/fr32_test.go index f9150e550..437fa4e43 100644 --- a/storage/sealer/fr32/fr32_test.go +++ b/storage/sealer/fr32/fr32_test.go @@ -3,7 +3,6 @@ package fr32_test import ( "bytes" "io" - "io/ioutil" "math/rand" "os" "testing" @@ -19,7 +18,7 @@ import ( func padFFI(buf []byte) []byte { rf, w, _ := commpffi.ToReadableFile(bytes.NewReader(buf), int64(len(buf))) - tf, _ := ioutil.TempFile("/tmp/", "scrb-") + tf, _ := os.CreateTemp("/tmp/", "scrb-") _, _, _, err := ffi.WriteWithAlignment(abi.RegisteredSealProof_StackedDrg32GiBV1, rf, abi.UnpaddedPieceSize(len(buf)), tf, nil) if err != nil { @@ -33,7 +32,7 @@ func padFFI(buf []byte) []byte { panic(err) } - padded, err := ioutil.ReadAll(tf) + padded, err := io.ReadAll(tf) if err != nil { panic(err) } diff --git a/storage/sealer/fr32/readers_test.go b/storage/sealer/fr32/readers_test.go index 21a5cd9cd..f84b9d67a 100644 --- a/storage/sealer/fr32/readers_test.go +++ b/storage/sealer/fr32/readers_test.go @@ -3,7 +3,7 @@ package fr32_test import ( "bufio" "bytes" - "io/ioutil" + "io" "testing" "github.com/stretchr/testify/require" @@ -27,7 +27,7 @@ func TestUnpadReader(t *testing.T) { } // using bufio reader to make sure reads are big enough for the padreader - it can't handle small reads right now - readered, err := ioutil.ReadAll(bufio.NewReaderSize(r, 512)) + readered, err := io.ReadAll(bufio.NewReaderSize(r, 512)) if err != nil { t.Fatal(err) } diff --git a/storage/sealer/manager_test.go b/storage/sealer/manager_test.go index a44f69a89..cdc135916 100644 --- a/storage/sealer/manager_test.go +++ b/storage/sealer/manager_test.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -46,7 +45,7 @@ func (t testStorage) DiskUsage(path string) (int64, error) { } func newTestStorage(t *testing.T) *testStorage { - tp, err := ioutil.TempDir(os.TempDir(), "sealer-test-") + tp, err := os.MkdirTemp(os.TempDir(), "sealer-test-") require.NoError(t, err) { @@ -58,7 +57,7 @@ func newTestStorage(t *testing.T) *testStorage { }, "", " ") require.NoError(t, err) - err = ioutil.WriteFile(filepath.Join(tp, "sectorstore.json"), b, 0644) + err = os.WriteFile(filepath.Join(tp, "sectorstore.json"), b, 0644) require.NoError(t, err) } diff --git a/storage/sealer/mock/mock.go b/storage/sealer/mock/mock.go index 6e88b86a5..ab973b3b4 100644 --- a/storage/sealer/mock/mock.go +++ b/storage/sealer/mock/mock.go @@ -6,7 +6,6 @@ import ( "crypto/sha256" "fmt" "io" - "io/ioutil" "math/rand" "sync" @@ -461,7 +460,7 @@ func (mgr *SectorMgr) ReadPiece(ctx context.Context, sector storiface.SectorRef, io.Seeker io.ReaderAt }{ - ReadCloser: ioutil.NopCloser(br), + ReadCloser: io.NopCloser(br), Seeker: br, ReaderAt: br, }, false, nil diff --git a/storage/sealer/piece_provider_test.go b/storage/sealer/piece_provider_test.go index ea2866e5d..4cbc79a93 100644 --- a/storage/sealer/piece_provider_test.go +++ b/storage/sealer/piece_provider_test.go @@ -3,7 +3,7 @@ package sealer import ( "bytes" "context" - "io/ioutil" + "io" "math/rand" "net" "net/http" @@ -346,7 +346,7 @@ func (p *pieceProviderTestHarness) readPiece(t *testing.T, offset storiface.Unpa defer func() { _ = rd.Close() }() // Make sure the input matches the output - readData, err := ioutil.ReadAll(rd) + readData, err := io.ReadAll(rd) require.NoError(t, err) require.Equal(t, expectedBytes, readData) }