[#1250] *: Remove io/ioutil imports

It is deprecated starting from go1.16.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
remotes/1719431299552484977/neofs-adm-notary-disabled
Evgenii Stratonikov 2022-03-18 14:12:58 +03:00 committed by Alex Vanin
parent 3bdab77c42
commit 622ea4818f
9 changed files with 28 additions and 32 deletions

View File

@ -4,7 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"sort"
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
@ -112,7 +112,7 @@ func dumpContainers(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
return ioutil.WriteFile(filename, out, 0o660)
return os.WriteFile(filename, out, 0o660)
}
func restoreContainers(cmd *cobra.Command, _ []string) error {
@ -136,7 +136,7 @@ func restoreContainers(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("can't fetch container contract hash: %w", err)
}
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
return fmt.Errorf("can't read dump file: %w", err)
}

View File

@ -2,7 +2,7 @@ package morph
import (
"bytes"
"io/ioutil"
"io"
"math/rand"
"os"
"path/filepath"
@ -101,7 +101,7 @@ func setupTestTerminal(t *testing.T) *bytes.Buffer {
in := bytes.NewBuffer(nil)
input.Terminal = term.NewTerminal(input.ReadWriter{
Reader: in,
Writer: ioutil.Discard,
Writer: io.Discard,
}, "")
t.Cleanup(func() { input.Terminal = nil })

View File

@ -3,7 +3,7 @@ package morph
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
@ -186,7 +186,7 @@ func (c *initializeContext) nativeHash(name string) util.Uint160 {
}
func openAlphabetWallets(walletDir string) ([]*wallet.Wallet, error) {
walletFiles, err := ioutil.ReadDir(walletDir)
walletFiles, err := os.ReadDir(walletDir)
if err != nil {
return nil, fmt.Errorf("can't read alphabet wallets dir: %w", err)
}

View File

@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -392,11 +391,11 @@ func (c *initializeContext) readContracts(names []string) error {
if c.ContractPath != "" && fi.IsDir() {
for _, ctrName := range names {
cs := new(contractState)
cs.RawNEF, err = ioutil.ReadFile(filepath.Join(c.ContractPath, ctrName, ctrName+"_contract.nef"))
cs.RawNEF, err = os.ReadFile(filepath.Join(c.ContractPath, ctrName, ctrName+"_contract.nef"))
if err != nil {
return fmt.Errorf("can't read NEF file for %s contract: %w", ctrName, err)
}
cs.RawManifest, err = ioutil.ReadFile(filepath.Join(c.ContractPath, ctrName, "config.json"))
cs.RawManifest, err = os.ReadFile(filepath.Join(c.ContractPath, ctrName, "config.json"))
if err != nil {
return fmt.Errorf("can't read manifest file for %s contract: %w", ctrName, err)
}
@ -481,12 +480,12 @@ func readContractsFromArchive(file io.Reader, names []string) (map[string]*contr
switch {
case strings.HasSuffix(h.Name, filepath.Join(ctrName, ctrName+"_contract.nef")):
cs.RawNEF, err = ioutil.ReadAll(r)
cs.RawNEF, err = io.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("can't read NEF file for %s contract: %w", ctrName, err)
}
case strings.HasSuffix(h.Name, "config.json"):
cs.RawManifest, err = ioutil.ReadAll(r)
cs.RawManifest, err = io.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("can't read manifest file for %s contract: %w", ctrName, err)
}

View File

@ -6,7 +6,6 @@ import (
"encoding/hex"
"errors"
"fmt"
"io/ioutil"
"math/big"
"math/rand"
"net"
@ -200,7 +199,7 @@ func storageConfig(cmd *cobra.Command, args []string) {
}
out := applyTemplate(c)
fatalOnErr(ioutil.WriteFile(outPath, out, 0644))
fatalOnErr(os.WriteFile(outPath, out, 0644))
cmd.Println("Node is ready for work! Run `neofs-node -config " + outPath + "`")
}

View File

@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
@ -123,7 +122,7 @@ func createEACL(cmd *cobra.Command, _ []string) {
return
}
err = ioutil.WriteFile(outArg, buf.Bytes(), 0644)
err = os.WriteFile(outArg, buf.Bytes(), 0644)
if err != nil {
cmd.PrintErrln(err)
os.Exit(1)
@ -135,7 +134,7 @@ func getRulesFromFile(filename string) ([]string, error) {
return nil, nil
}
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
return nil, err
}

View File

@ -3,7 +3,7 @@ package cmd
import (
"bytes"
"errors"
"io/ioutil"
"io"
"os"
"path/filepath"
"testing"
@ -39,7 +39,7 @@ func Test_getKey(t *testing.T) {
keyPath := filepath.Join(dir, "binary.key")
rawKey, err := keys.NewPrivateKey()
require.NoError(t, err)
require.NoError(t, ioutil.WriteFile(keyPath, rawKey.Bytes(), os.ModePerm))
require.NoError(t, os.WriteFile(keyPath, rawKey.Bytes(), os.ModePerm))
wifKey, err := keys.NewPrivateKey()
require.NoError(t, err)
@ -52,7 +52,7 @@ func Test_getKey(t *testing.T) {
in := bytes.NewBuffer(nil)
input.Terminal = term.NewTerminal(input.ReadWriter{
Reader: in,
Writer: ioutil.Discard,
Writer: io.Discard,
}, "")
checkKeyError(t, filepath.Join(dir, "badfile"), errInvalidKey)

View File

@ -2,7 +2,7 @@ package inspect
import (
"fmt"
"io/ioutil"
"os"
common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
@ -111,7 +111,7 @@ func printObjectInfo(cmd *cobra.Command, data []byte) {
}
if vOut != "" {
err := ioutil.WriteFile(vOut, obj.Payload(), 0644)
err := os.WriteFile(vOut, obj.Payload(), 0644)
common.ExitOnErr(cmd, common.Errf("couldn't write payload: %w", err))
}
}

View File

@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"io"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
@ -126,19 +125,19 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) {
t.Run("invalid file", func(t *testing.T) {
t.Run("invalid magic", func(t *testing.T) {
out := out + ".wrongmagic"
require.NoError(t, ioutil.WriteFile(out, []byte{0, 0, 0, 0}, os.ModePerm))
require.NoError(t, os.WriteFile(out, []byte{0, 0, 0, 0}, os.ModePerm))
_, err := sh.Restore(new(shard.RestorePrm).WithPath(out))
require.True(t, errors.Is(err, shard.ErrInvalidMagic), "got: %v", err)
})
fileData, err := ioutil.ReadFile(out)
fileData, err := os.ReadFile(out)
require.NoError(t, err)
t.Run("incomplete size", func(t *testing.T) {
out := out + ".wrongsize"
fileData := append(fileData, 1)
require.NoError(t, ioutil.WriteFile(out, fileData, os.ModePerm))
require.NoError(t, os.WriteFile(out, fileData, os.ModePerm))
_, err := sh.Restore(new(shard.RestorePrm).WithPath(out))
require.True(t, errors.Is(err, io.ErrUnexpectedEOF), "got: %v", err)
@ -146,7 +145,7 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) {
t.Run("incomplete object data", func(t *testing.T) {
out := out + ".wrongsize"
fileData := append(fileData, 1, 0, 0, 0)
require.NoError(t, ioutil.WriteFile(out, fileData, os.ModePerm))
require.NoError(t, os.WriteFile(out, fileData, os.ModePerm))
_, err := sh.Restore(new(shard.RestorePrm).WithPath(out))
require.True(t, errors.Is(err, io.EOF), "got: %v", err)
@ -154,7 +153,7 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) {
t.Run("invalid object", func(t *testing.T) {
out := out + ".wrongobj"
fileData := append(fileData, 1, 0, 0, 0, 0xFF, 4, 0, 0, 0, 1, 2, 3, 4)
require.NoError(t, ioutil.WriteFile(out, fileData, os.ModePerm))
require.NoError(t, os.WriteFile(out, fileData, os.ModePerm))
_, err := sh.Restore(new(shard.RestorePrm).WithPath(out))
require.Error(t, err)
@ -300,7 +299,7 @@ func TestDumpIgnoreErrors(t *testing.T) {
addr := cidtest.ID().String() + "." + generateOID().String()
dirName := filepath.Join(bsPath, addr[:2])
require.NoError(t, os.MkdirAll(dirName, os.ModePerm))
require.NoError(t, ioutil.WriteFile(filepath.Join(dirName, addr[2:]), corruptedData, os.ModePerm))
require.NoError(t, os.WriteFile(filepath.Join(dirName, addr[2:]), corruptedData, os.ModePerm))
// 1.2. Unreadable file.
addr = cidtest.ID().String() + "." + generateOID().String()
@ -308,7 +307,7 @@ func TestDumpIgnoreErrors(t *testing.T) {
require.NoError(t, os.MkdirAll(dirName, os.ModePerm))
fname := filepath.Join(dirName, addr[2:])
require.NoError(t, ioutil.WriteFile(fname, []byte{}, 0))
require.NoError(t, os.WriteFile(fname, []byte{}, 0))
// 1.3. Unreadable dir.
require.NoError(t, os.MkdirAll(filepath.Join(bsPath, "ZZ"), 0))
@ -324,7 +323,7 @@ func TestDumpIgnoreErrors(t *testing.T) {
bTree := filepath.Join(bsPath, "blobovnicza")
data := make([]byte, 1024)
rand.Read(data)
require.NoError(t, ioutil.WriteFile(filepath.Join(bTree, "0", "2"), data, 0))
require.NoError(t, os.WriteFile(filepath.Join(bTree, "0", "2"), data, 0))
// 2.2. Invalid object in valid blobovnicza.
prm := new(blobovnicza.PutPrm)
@ -343,7 +342,7 @@ func TestDumpIgnoreErrors(t *testing.T) {
addr := cidtest.ID().String() + "." + objecttest.ID().String()
dir := filepath.Join(wcPath, addr[:1])
require.NoError(t, os.MkdirAll(dir, os.ModePerm))
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, addr[1:]), nil, 0))
require.NoError(t, os.WriteFile(filepath.Join(dir, addr[1:]), nil, 0))
}
out := filepath.Join(t.TempDir(), "out.dump")