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: Remove dependency on io/ioutil package #355

Merged
merged 1 commit into from
Jun 28, 2023
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 cli/storage-deals.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -244,7 +243,7 @@ part states:
}

fpath := cctx.Args().Get(0)
data, err := ioutil.ReadFile(fpath)
data, err := os.ReadFile(fpath)
if err != nil {
return fmt.Errorf("read deal file(%s) failed: %v", fpath, err)
}
Expand Down
9 changes: 4 additions & 5 deletions cli/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"os/signal"
"path"
Expand Down Expand Up @@ -88,12 +87,12 @@ func NewMarketNode(cctx *cli.Context) (marketapi.IMarket, jsonrpc.ClientCloser,
return nil, nil, err
}

apiUrl, err := ioutil.ReadFile(path.Join(homePath, "api"))
apiUrl, err := os.ReadFile(path.Join(homePath, "api"))
if err != nil {
return nil, nil, err
}

token, err := ioutil.ReadFile(path.Join(homePath, "token"))
token, err := os.ReadFile(path.Join(homePath, "token"))
if err != nil {
return nil, nil, err
}
Expand All @@ -111,12 +110,12 @@ func NewMarketClientNode(cctx *cli.Context) (clientapi.IMarketClient, jsonrpc.Cl
if err != nil {
return nil, nil, err
}
apiUrl, err := ioutil.ReadFile(path.Join(homePath, "api"))
apiUrl, err := os.ReadFile(path.Join(homePath, "api"))
if err != nil {
return nil, nil, err
}

token, err := ioutil.ReadFile(path.Join(homePath, "token"))
token, err := os.ReadFile(path.Join(homePath, "token"))
if err != nil {
return nil, nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"embed"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -73,7 +73,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)

Expand Down Expand Up @@ -124,7 +124,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.
Expand Down
3 changes: 1 addition & 2 deletions client/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"

"github.com/filecoin-project/go-fil-markets/stores"
Expand Down Expand Up @@ -62,7 +61,7 @@ func (a *API) createUnixFSFilestore(ctx context.Context, srcPath string, dstPath
return cid.Undef, fmt.Errorf("failed to create reader path file: %w", err)
}

f, err := ioutil.TempFile("", "")
f, err := os.CreateTemp("", "")
if err != nil {
return cid.Undef, fmt.Errorf("failed to create temp file: %w", err)
}
Expand Down
5 changes: 2 additions & 3 deletions client/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"io"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -109,7 +108,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)
Expand Down
5 changes: 2 additions & 3 deletions config/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"bytes"
"io/ioutil"
"os"
"path"

Expand All @@ -25,7 +24,7 @@ func SaveConfig(cfg IHome) error {
}

_ = os.MkdirAll(path.Dir(cfgPath), os.ModePerm)
return ioutil.WriteFile(cfgPath, buf.Bytes(), 0o644)
return os.WriteFile(cfgPath, buf.Bytes(), 0o644)
}

func LoadConfig(cfgPath string, cfg IHome) error {
Expand All @@ -34,7 +33,7 @@ func LoadConfig(cfgPath string, cfg IHome) error {
return err
}

cfgBytes, err := ioutil.ReadFile(homeDir)
cfgBytes, err := os.ReadFile(homeDir)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions dagstore/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dagstore
import (
"bytes"
"context"
"io/ioutil"
"io"
"net/url"
"testing"

Expand Down Expand Up @@ -44,7 +44,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)
Expand All @@ -63,7 +63,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)
Expand Down
3 changes: 1 addition & 2 deletions piecestorage/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"path"

Expand Down Expand Up @@ -54,7 +53,7 @@ func (f *fsPieceStorage) SaveTo(_ context.Context, resourceId string, r io.Reade
}

dstPath := path.Join(f.baseUrl, resourceId)
tempFile, err := ioutil.TempFile("", "piece-*")
tempFile, err := os.CreateTemp("", "piece-*")
if err != nil {
return 0, err
}
Expand Down
3 changes: 1 addition & 2 deletions piecestorage/memstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"sync"

"github.com/filecoin-project/venus/venus-shared/types/market"
Expand Down Expand Up @@ -44,7 +43,7 @@ func (m *MemPieceStore) GetName() string {
func (m *MemPieceStore) SaveTo(ctx context.Context, resourceId string, reader io.Reader) (int64, error) {
m.dataLk.Lock()
defer m.dataLk.Unlock()
bytes, err := ioutil.ReadAll(reader)
bytes, err := io.ReadAll(reader)
if err != nil {
return 0, err
}
Expand Down
4 changes: 2 additions & 2 deletions rpc/piece_storage_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -59,7 +59,7 @@ func TestResouceDownload(t *testing.T) {
psm.ServeHTTP(w, req)

assert.Equal(t, http.StatusOK, w.Code)
result, err := ioutil.ReadAll(w.Body)
result, err := io.ReadAll(w.Body)
assert.Nil(t, err)
assert.Equal(t, "mock resource2 content", string(result))
})
Expand Down
6 changes: 3 additions & 3 deletions rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"encoding/hex"
"fmt"
"io/ioutil"
"net/http"
"os"
"path"
"regexp"

Expand Down Expand Up @@ -140,7 +140,7 @@ func saveAPIInfo(home config.IHome, apiCfg *config.API, token []byte) error {
if err != nil {
return fmt.Errorf("unable to home path to save api/token")
}
_ = ioutil.WriteFile(path.Join(string(homePath), "api"), []byte(apiCfg.ListenAddress), 0o644)
_ = ioutil.WriteFile(path.Join(string(homePath), "token"), token, 0o644)
_ = os.WriteFile(path.Join(string(homePath), "api"), []byte(apiCfg.ListenAddress), 0o644)
_ = os.WriteFile(path.Join(string(homePath), "token"), token, 0o644)
return nil
}
3 changes: 1 addition & 2 deletions utils/algn_zero_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package utils
import (
"bytes"
"io"
"io/ioutil"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -92,7 +91,7 @@ func TestReadALl(t *testing.T) {

r := getPayloadReader(payloadSize)
algnR := NewAlgnZeroMountReader(r, payloadSize, size)
p, err := ioutil.ReadAll(algnR)
p, err := io.ReadAll(algnR)
assert.Nil(t, err)
countOne := 0
for i := 0; i < len(p); i++ {
Expand Down