forked from TrueCloudLab/frostfs-node
[#1132] *: Use path/filepath
package when working with files
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
0decb95591
commit
674f520da7
20 changed files with 73 additions and 77 deletions
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"text/template"
|
||||
|
||||
|
@ -51,7 +50,7 @@ func initConfig(cmd *cobra.Command, args []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
pathDir := path.Dir(configPath)
|
||||
pathDir := filepath.Dir(configPath)
|
||||
err = os.MkdirAll(pathDir, 0700)
|
||||
if err != nil {
|
||||
return fmt.Errorf("create dir %s: %w", pathDir, err)
|
||||
|
@ -97,7 +96,7 @@ func defaultConfigPath() (string, error) {
|
|||
return "", fmt.Errorf("getting home dir path: %w", err)
|
||||
}
|
||||
|
||||
return path.Join(home, ".neofs", "adm", "config.yml"), nil
|
||||
return filepath.Join(home, ".neofs", "adm", "config.yml"), nil
|
||||
}
|
||||
|
||||
// generateConfigExample builds .yml representation of the config file. It is
|
||||
|
@ -122,7 +121,7 @@ func generateConfigExample(appDir string, credSize int) (string, error) {
|
|||
if err != nil {
|
||||
return "", fmt.Errorf("making absolute path for %s: %w", appDir, err)
|
||||
}
|
||||
tmpl.AlphabetDir = path.Join(appDir, "alphabet-wallets")
|
||||
tmpl.AlphabetDir = filepath.Join(appDir, "alphabet-wallets")
|
||||
|
||||
var i innerring.GlagoliticLetter
|
||||
for i = 0; i < innerring.GlagoliticLetter(credSize); i++ {
|
||||
|
|
|
@ -2,7 +2,7 @@ package config
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/innerring"
|
||||
|
@ -25,7 +25,7 @@ func TestGenerateConfigExample(t *testing.T) {
|
|||
require.NoError(t, v.ReadConfig(bytes.NewBufferString(configText)))
|
||||
|
||||
require.Equal(t, "https://neo.rpc.node:30333", v.GetString("rpc-endpoint"))
|
||||
require.Equal(t, path.Join(appDir, "alphabet-wallets"), v.GetString("alphabet-wallets"))
|
||||
require.Equal(t, filepath.Join(appDir, "alphabet-wallets"), v.GetString("alphabet-wallets"))
|
||||
require.Equal(t, 67108864, v.GetInt("network.max_object_size"))
|
||||
require.Equal(t, 240, v.GetInt("network.epoch_duration"))
|
||||
require.Equal(t, 100000000, v.GetInt("network.basic_income_rate"))
|
||||
|
|
|
@ -3,7 +3,7 @@ package morph
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/cli/input"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||
|
@ -62,7 +62,7 @@ func initializeWallets(walletDir string, size int) ([]string, error) {
|
|||
return nil, fmt.Errorf("can't fetch password: %w", err)
|
||||
}
|
||||
|
||||
p := path.Join(walletDir, innerring.GlagoliticLetter(i).String()+".json")
|
||||
p := filepath.Join(walletDir, innerring.GlagoliticLetter(i).String()+".json")
|
||||
// TODO(@fyrchik): file is created with 0666 permissions, consider changing.
|
||||
w, err := wallet.NewWallet(p)
|
||||
if err != nil {
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"io/ioutil"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
|
@ -42,7 +42,7 @@ func TestGenerateAlphabet(t *testing.T) {
|
|||
})
|
||||
t.Run("missing directory", func(t *testing.T) {
|
||||
buf.Reset()
|
||||
dir := path.Join(os.TempDir(), "notexist."+strconv.FormatUint(rand.Uint64(), 10))
|
||||
dir := filepath.Join(os.TempDir(), "notexist."+strconv.FormatUint(rand.Uint64(), 10))
|
||||
v.Set(alphabetWalletsFlag, dir)
|
||||
require.NoError(t, cmd.Flags().Set(alphabetSizeFlag, "1"))
|
||||
buf.WriteString("pass\r")
|
||||
|
@ -59,7 +59,7 @@ func TestGenerateAlphabet(t *testing.T) {
|
|||
require.NoError(t, generateAlphabetCreds(cmd, nil))
|
||||
|
||||
for i := uint64(0); i < size; i++ {
|
||||
p := path.Join(walletDir, innerring.GlagoliticLetter(i).String()+".json")
|
||||
p := filepath.Join(walletDir, innerring.GlagoliticLetter(i).String()+".json")
|
||||
w, err := wallet.NewWalletFromFile(p)
|
||||
require.NoError(t, err, "wallet doesn't exist")
|
||||
require.Equal(t, 3, len(w.Accounts), "not all accounts were created")
|
||||
|
@ -91,7 +91,7 @@ func setupTestTerminal(t *testing.T) *bytes.Buffer {
|
|||
}
|
||||
|
||||
func newTempDir(t *testing.T) string {
|
||||
dir := path.Join(os.TempDir(), "neofs-adm.test."+strconv.FormatUint(rand.Uint64(), 10))
|
||||
dir := filepath.Join(os.TempDir(), "neofs-adm.test."+strconv.FormatUint(rand.Uint64(), 10))
|
||||
require.NoError(t, os.Mkdir(dir, os.ModePerm))
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, os.RemoveAll(dir))
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -192,7 +192,7 @@ loop:
|
|||
|
||||
wallets := make([]*wallet.Wallet, size)
|
||||
for i := 0; i < size; i++ {
|
||||
p := path.Join(walletDir, innerring.GlagoliticLetter(i).String()+".json")
|
||||
p := filepath.Join(walletDir, innerring.GlagoliticLetter(i).String()+".json")
|
||||
w, err := wallet.NewWalletFromFile(p)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't open wallet: %w", err)
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
||||
|
@ -370,11 +370,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(path.Join(c.ContractPath, ctrName, ctrName+"_contract.nef"))
|
||||
cs.RawNEF, err = ioutil.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(path.Join(c.ContractPath, ctrName, "config.json"))
|
||||
cs.RawManifest, err = ioutil.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)
|
||||
}
|
||||
|
@ -449,8 +449,8 @@ func readContractsFromArchive(file io.Reader, names []string) (map[string]*contr
|
|||
break
|
||||
}
|
||||
|
||||
dir, _ := path.Split(h.Name)
|
||||
ctrName := path.Base(dir)
|
||||
dir, _ := filepath.Split(h.Name)
|
||||
ctrName := filepath.Base(dir)
|
||||
|
||||
cs, ok := m[ctrName]
|
||||
if !ok {
|
||||
|
@ -458,7 +458,7 @@ func readContractsFromArchive(file io.Reader, names []string) (map[string]*contr
|
|||
}
|
||||
|
||||
switch {
|
||||
case strings.HasSuffix(h.Name, path.Join(ctrName, ctrName+"_contract.nef")):
|
||||
case strings.HasSuffix(h.Name, filepath.Join(ctrName, ctrName+"_contract.nef")):
|
||||
cs.RawNEF, err = ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't read NEF file for %s contract: %w", ctrName, err)
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
|
@ -20,7 +19,7 @@ import (
|
|||
func Test_getKey(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
|
||||
wallPath := path.Join(dir, "wallet.json")
|
||||
wallPath := filepath.Join(dir, "wallet.json")
|
||||
w, err := wallet.NewWallet(wallPath)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -37,7 +36,7 @@ func Test_getKey(t *testing.T) {
|
|||
require.NoError(t, w.Save())
|
||||
w.Close()
|
||||
|
||||
keyPath := path.Join(dir, "binary.key")
|
||||
keyPath := filepath.Join(dir, "binary.key")
|
||||
rawKey, err := keys.NewPrivateKey()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, ioutil.WriteFile(keyPath, rawKey.Bytes(), os.ModePerm))
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"net"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -390,7 +390,7 @@ func initShardOptions(c *cfg) {
|
|||
|
||||
metaPath := metabaseCfg.Path()
|
||||
metaPerm := metabaseCfg.Perm()
|
||||
fatalOnErr(util.MkdirAllX(path.Dir(metaPath), metaPerm))
|
||||
fatalOnErr(util.MkdirAllX(filepath.Dir(metaPath), metaPerm))
|
||||
|
||||
opts = append(opts, []shard.Option{
|
||||
shard.WithLogger(c.log),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue