From 622ea4818f781d044ae19ccfa3238a907d8bdef5 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 18 Mar 2022 14:12:58 +0300 Subject: [PATCH] [#1250] *: Remove io/ioutil imports It is deprecated starting from go1.16. Signed-off-by: Evgenii Stratonikov --- .../internal/modules/morph/container.go | 6 +++--- .../internal/modules/morph/generate_test.go | 4 ++-- .../internal/modules/morph/initialize.go | 4 ++-- .../modules/morph/initialize_deploy.go | 9 ++++----- .../internal/modules/storagecfg/root.go | 3 +-- cmd/neofs-cli/modules/acl/extended/create.go | 5 ++--- cmd/neofs-cli/modules/key_test.go | 6 +++--- .../internal/commands/inspect/inspect.go | 4 ++-- pkg/local_object_storage/shard/dump_test.go | 19 +++++++++---------- 9 files changed, 28 insertions(+), 32 deletions(-) diff --git a/cmd/neofs-adm/internal/modules/morph/container.go b/cmd/neofs-adm/internal/modules/morph/container.go index 01472ff1..04581d6d 100644 --- a/cmd/neofs-adm/internal/modules/morph/container.go +++ b/cmd/neofs-adm/internal/modules/morph/container.go @@ -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) } diff --git a/cmd/neofs-adm/internal/modules/morph/generate_test.go b/cmd/neofs-adm/internal/modules/morph/generate_test.go index 7ff6e9ca..f1737c2d 100644 --- a/cmd/neofs-adm/internal/modules/morph/generate_test.go +++ b/cmd/neofs-adm/internal/modules/morph/generate_test.go @@ -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 }) diff --git a/cmd/neofs-adm/internal/modules/morph/initialize.go b/cmd/neofs-adm/internal/modules/morph/initialize.go index 0c22791b..132f4017 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize.go @@ -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) } diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go b/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go index 25b4601b..4473fe5e 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go @@ -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) } diff --git a/cmd/neofs-adm/internal/modules/storagecfg/root.go b/cmd/neofs-adm/internal/modules/storagecfg/root.go index f06d0911..3f68224c 100644 --- a/cmd/neofs-adm/internal/modules/storagecfg/root.go +++ b/cmd/neofs-adm/internal/modules/storagecfg/root.go @@ -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 + "`") } diff --git a/cmd/neofs-cli/modules/acl/extended/create.go b/cmd/neofs-cli/modules/acl/extended/create.go index da11fcc8..8c9e86bf 100644 --- a/cmd/neofs-cli/modules/acl/extended/create.go +++ b/cmd/neofs-cli/modules/acl/extended/create.go @@ -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 } diff --git a/cmd/neofs-cli/modules/key_test.go b/cmd/neofs-cli/modules/key_test.go index a7e129e3..b6052035 100644 --- a/cmd/neofs-cli/modules/key_test.go +++ b/cmd/neofs-cli/modules/key_test.go @@ -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) diff --git a/cmd/neofs-lens/internal/commands/inspect/inspect.go b/cmd/neofs-lens/internal/commands/inspect/inspect.go index d9a65eb6..556480a0 100644 --- a/cmd/neofs-lens/internal/commands/inspect/inspect.go +++ b/cmd/neofs-lens/internal/commands/inspect/inspect.go @@ -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)) } } diff --git a/pkg/local_object_storage/shard/dump_test.go b/pkg/local_object_storage/shard/dump_test.go index 90035743..966d6d28 100644 --- a/pkg/local_object_storage/shard/dump_test.go +++ b/pkg/local_object_storage/shard/dump_test.go @@ -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")