Skip to content

Commit

Permalink
refactor: stop using deprecated io/ioutil
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Mar 29, 2023
1 parent d5a3ddb commit 48bbc40
Show file tree
Hide file tree
Showing 64 changed files with 156 additions and 215 deletions.
3 changes: 1 addition & 2 deletions blockstore/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package blockstore
import (
"bytes"
"context"
"io/ioutil"

"github.com/ipfs/go-cid"
httpapi "github.com/ipfs/go-ipfs-http-client"
Expand Down Expand Up @@ -103,7 +102,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 := os.ReadAll(rd)
if err != nil {
return nil, err
}
Expand Down
25 changes: 12 additions & 13 deletions chain/actors/agen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"go/format"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
}
Expand All @@ -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
Expand All @@ -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
}
}
Expand All @@ -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
Expand All @@ -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
}
}
Expand All @@ -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
Expand All @@ -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
}

Expand All @@ -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
Expand All @@ -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
}

Expand All @@ -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
Expand All @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions chain/gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"sync/atomic"
"time"

Expand Down Expand Up @@ -167,7 +167,7 @@ func NewGeneratorWithSectorsAndUpgradeSchedule(numSectors int, us stmgr.UpgradeS

maddr1 := genesis2.MinerAddress(0)

m1temp, err := ioutil.TempDir("", "preseal")
m1temp, err := os.TempDir("", "preseal")
if err != nil {
return nil, err
}
Expand All @@ -179,7 +179,7 @@ func NewGeneratorWithSectorsAndUpgradeSchedule(numSectors int, us stmgr.UpgradeS

maddr2 := genesis2.MinerAddress(1)

m2temp, err := ioutil.TempDir("", "preseal")
m2temp, err := os.TempDir("", "preseal")
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions cli/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"html/template"
"io"
"io/ioutil"
"os"
"reflect"
"sort"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions cli/util/retrieval.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"path"
Expand Down Expand Up @@ -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 := os.ReadAll(resp.Body)
if err != nil {
return nil, xerrors.Errorf("reading error body: %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions cli/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/lotus-bench/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"math"
"net/http"
_ "net/http/pprof"
Expand Down Expand Up @@ -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.TempDir("", "lotus-import-bench")
if err != nil {
return err
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/lotus-bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"math/big"
"math/rand"
"os"
Expand Down Expand Up @@ -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.TempDir(sdir, "bench")
if err != nil {
return err
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/lotus-bench/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strconv"
"time"
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/lotus-fountain/recaptcha.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package main

import (
"encoding/json"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -63,7 +62,7 @@ func VerifyToken(token, remoteIP string) (Response, error) {
return resp, err
}

b, err := ioutil.ReadAll(r.Body)
b, err := os.ReadAll(r.Body)
_ = r.Body.Close() // close immediately after reading finished
if err != nil {
return resp, err
Expand Down
5 changes: 2 additions & 3 deletions cmd/lotus-miner/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/binary"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/lotus-miner/init_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"encoding/json"
"io/ioutil"
"os"

"github.com/docker/go-units"
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/lotus-miner/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"math/bits"
"os"
"path/filepath"
Expand Down Expand Up @@ -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)
}
}
Expand Down
Loading

0 comments on commit 48bbc40

Please sign in to comment.