Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace ioutil with io and os #8969

Merged
merged 1 commit into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmd/ipfs/add_migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -154,7 +153,7 @@ func ipfsGet(ctx context.Context, ufs coreiface.UnixfsAPI, ipfsPath ipath.Path)
if !ok {
return fmt.Errorf("not a file node: %q", ipfsPath)
}
_, err = io.Copy(ioutil.Discard, fnd)
_, err = io.Copy(io.Discard, fnd)
if err != nil {
return fmt.Errorf("cannot read migration: %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
_ "expvar"
"fmt"
"io/ioutil"
"net"
"net/http"
_ "net/http/pprof"
Expand Down Expand Up @@ -331,7 +330,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment

if cacheMigrations || pinMigrations {
// Create temp directory to store downloaded migration archives
migrations.DownloadDirectory, err = ioutil.TempDir("", "migrations")
migrations.DownloadDirectory, err = os.MkdirTemp("", "migrations")
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/ipfs/runmain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"testing"
)
Expand All @@ -21,7 +20,7 @@ func TestRunMain(t *testing.T) {

p := os.Getenv("IPFS_COVER_RET_FILE")
if len(p) != 0 {
ioutil.WriteFile(p, []byte(fmt.Sprintf("%d\n", ret)), 0777)
os.WriteFile(p, []byte(fmt.Sprintf("%d\n", ret)), 0777)
}

// close outputs so go testing doesn't print anything
Expand Down
3 changes: 1 addition & 2 deletions core/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -192,7 +191,7 @@ NOTE: For security reasons, this command will omit your private key and remote s
return err
}

data, err := ioutil.ReadFile(fname)
data, err := os.ReadFile(fname)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions core/commands/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"time"

cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
Expand Down Expand Up @@ -580,7 +579,7 @@ identified by QmFoo.
}
defer file.Close()

data, err := ioutil.ReadAll(file)
data, err := io.ReadAll(file)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions core/commands/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/pem"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -276,7 +275,7 @@ elsewhere. For example, using openssl to get a PEM with public key:

switch exportFormat {
case keyFormatPemCleartextOption:
privKeyBytes, err := ioutil.ReadAll(outReader)
privKeyBytes, err := io.ReadAll(outReader)
if err != nil {
return err
}
Expand Down Expand Up @@ -344,7 +343,7 @@ The PEM format allows for key generation outside of the IPFS node:
}
defer file.Close()

data, err := ioutil.ReadAll(file)
data, err := io.ReadAll(file)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions core/commands/multibase.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package commands
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"strings"

cmds "github.com/ipfs/go-ipfs-cmds"
Expand Down Expand Up @@ -66,7 +66,7 @@ but one can customize used base with -b:
if err != nil {
return fmt.Errorf("failed to access file: %w", err)
}
buf, err := ioutil.ReadAll(file)
buf, err := io.ReadAll(file)
if err != nil {
return fmt.Errorf("failed to read file contents: %w", err)
}
Expand Down Expand Up @@ -105,7 +105,7 @@ This command expects multibase inside of a file or via stdin:
if err != nil {
return fmt.Errorf("failed to access file: %w", err)
}
encoded_data, err := ioutil.ReadAll(file)
encoded_data, err := io.ReadAll(file)
if err != nil {
return fmt.Errorf("failed to read file contents: %w", err)
}
Expand Down Expand Up @@ -156,7 +156,7 @@ but one can customize used base with -b:
if err != nil {
return fmt.Errorf("failed to access file: %w", err)
}
encoded_data, err := ioutil.ReadAll(file)
encoded_data, err := io.ReadAll(file)
if err != nil {
return fmt.Errorf("failed to read file contents: %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions core/commands/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"text/tabwriter"

cmds "github.com/ipfs/go-ipfs-cmds"
Expand Down Expand Up @@ -230,7 +229,7 @@ DEPRECATED and provided for legacy reasons. Use 'ipfs dag get' instead.
return err
}

data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions core/commands/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"sort"

Expand Down Expand Up @@ -191,7 +190,7 @@ HTTP RPC ENCODING
return err
}
defer file.Close()
data, err := ioutil.ReadAll(file)
data, err := io.ReadAll(file)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions core/coreapi/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"errors"
"io"
"io/ioutil"

blocks "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid"
Expand Down Expand Up @@ -36,7 +35,7 @@ func (api *BlockAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Bloc
return nil, err
}

data, err := ioutil.ReadAll(src)
data, err := io.ReadAll(src)
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions core/coreapi/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"

cid "github.com/ipfs/go-cid"
pin "github.com/ipfs/go-ipfs-pinner"
Expand Down Expand Up @@ -79,7 +78,7 @@ func (api *ObjectAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Obj
attribute.String("inputenc", options.InputEnc),
)

data, err := ioutil.ReadAll(io.LimitReader(src, inputLimit+10))
data, err := io.ReadAll(io.LimitReader(src, inputLimit+10))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -316,7 +315,7 @@ func (api *ObjectAPI) patchData(ctx context.Context, path ipath.Path, r io.Reade
return nil, dag.ErrNotProtobuf
}

data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions core/coredag/cbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package coredag

import (
"io"
"io/ioutil"

ipldcbor "github.com/ipfs/go-ipld-cbor"
ipld "github.com/ipfs/go-ipld-format"
Expand All @@ -18,7 +17,7 @@ func cborJSONParser(r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error)
}

func cborRawParser(r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error) {
data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions core/coredag/dagpb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package coredag

import (
"io"
"io/ioutil"
"math"

"github.com/ipfs/go-merkledag"
Expand All @@ -13,7 +12,7 @@ import (
)

func dagpbJSONParser(r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error) {
data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
return nil, err
}
Expand All @@ -31,7 +30,7 @@ func dagpbJSONParser(r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error)
}

func dagpbRawParser(r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error) {
data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions core/coredag/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package coredag

import (
"io"
"io/ioutil"
"math"

"github.com/ipfs/go-merkledag"
Expand All @@ -18,7 +17,7 @@ func rawRawParser(r io.Reader, mhType uint64, mhLen int) ([]ipld.Node, error) {
mhType = mh.SHA2_256
}

data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions core/corehttp/gateway_handler_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package corehttp
import (
"bytes"
"context"
"io/ioutil"
"io"
"net/http"
"time"

Expand All @@ -23,7 +23,7 @@ func (i *gatewayHandler) serveRawBlock(ctx context.Context, w http.ResponseWrite
webError(w, "ipfs block get "+blockCid.String(), err, http.StatusInternalServerError)
return
}
block, err := ioutil.ReadAll(blockReader)
block, err := io.ReadAll(blockReader)
if err != nil {
webError(w, "ipfs block get "+blockCid.String(), err, http.StatusInternalServerError)
return
Expand Down
14 changes: 7 additions & 7 deletions core/corehttp/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package corehttp
import (
"context"
"errors"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"regexp"
Expand Down Expand Up @@ -267,7 +267,7 @@ func TestGatewayGet(t *testing.T) {
if contentType != "text/plain; charset=utf-8" {
t.Errorf("expected content type to be text/plain, got %s", contentType)
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if resp.StatusCode != test.status {
t.Errorf("(%d) got %d, expected %d from %s", i, resp.StatusCode, test.status, urlstr)
t.Errorf("Body: %s", body)
Expand Down Expand Up @@ -335,7 +335,7 @@ func TestPretty404(t *testing.T) {
if resp.StatusCode != test.status {
t.Fatalf("got %d, expected %d, from %s", resp.StatusCode, test.status, test.path)
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("error reading response from %s: %s", test.path, err)
}
Expand Down Expand Up @@ -482,7 +482,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
}

// expect correct links
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Fatalf("error reading response: %s", err)
}
Expand Down Expand Up @@ -519,7 +519,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
}

// expect correct backlinks at root
body, err = ioutil.ReadAll(res.Body)
body, err = io.ReadAll(res.Body)
if err != nil {
t.Fatalf("error reading response: %s", err)
}
Expand Down Expand Up @@ -556,7 +556,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
}

// expect correct backlinks
body, err = ioutil.ReadAll(res.Body)
body, err = io.ReadAll(res.Body)
if err != nil {
t.Fatalf("error reading response: %s", err)
}
Expand Down Expand Up @@ -638,7 +638,7 @@ func TestVersion(t *testing.T) {
if err != nil {
t.Fatal(err)
}
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
t.Fatalf("error reading response: %s", err)
}
Expand Down
Loading