[#727] Use util.MkdirAllX instead of os.MkdirAll

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-07-28 19:19:33 +03:00 committed by Alex Vanin
parent 51eeae3640
commit 7a10d902be
6 changed files with 21 additions and 20 deletions

View file

@ -3,13 +3,12 @@ package main
import ( import (
"context" "context"
"net" "net"
"os"
"path" "path"
"sync" "sync"
"time" "time"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/util" neogoutil "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg"
apiclient "github.com/nspcc-dev/neofs-api-go/pkg/client" apiclient "github.com/nspcc-dev/neofs-api-go/pkg/client"
"github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
@ -44,7 +43,7 @@ import (
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage" truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
tokenStorage "github.com/nspcc-dev/neofs-node/pkg/services/session/storage" tokenStorage "github.com/nspcc-dev/neofs-node/pkg/services/session/storage"
"github.com/nspcc-dev/neofs-node/pkg/services/util/response" "github.com/nspcc-dev/neofs-node/pkg/services/util/response"
util2 "github.com/nspcc-dev/neofs-node/pkg/util" util "github.com/nspcc-dev/neofs-node/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/nspcc-dev/neofs-node/pkg/util/logger"
"github.com/panjf2000/ants/v2" "github.com/panjf2000/ants/v2"
"go.etcd.io/bbolt" "go.etcd.io/bbolt"
@ -133,25 +132,25 @@ type cfgMorph struct {
} }
type cfgAccounting struct { type cfgAccounting struct {
scriptHash util.Uint160 scriptHash neogoutil.Uint160
} }
type cfgContainer struct { type cfgContainer struct {
scriptHash util.Uint160 scriptHash neogoutil.Uint160
parsers map[event.Type]event.Parser parsers map[event.Type]event.Parser
subscribers map[event.Type][]event.Handler subscribers map[event.Type][]event.Handler
workerPool util2.WorkerPool // pool for asynchronous handlers workerPool util.WorkerPool // pool for asynchronous handlers
} }
type cfgNetmap struct { type cfgNetmap struct {
scriptHash util.Uint160 scriptHash neogoutil.Uint160
wrapper *nmwrapper.Wrapper wrapper *nmwrapper.Wrapper
parsers map[event.Type]event.Parser parsers map[event.Type]event.Parser
subscribers map[event.Type][]event.Handler subscribers map[event.Type][]event.Handler
workerPool util2.WorkerPool // pool for asynchronous handlers workerPool util.WorkerPool // pool for asynchronous handlers
state *networkState state *networkState
@ -192,13 +191,13 @@ type cfgControlService struct {
} }
type cfgReputation struct { type cfgReputation struct {
workerPool util2.WorkerPool // pool for EigenTrust algorithm's iterations workerPool util.WorkerPool // pool for EigenTrust algorithm's iterations
localTrustStorage *truststorage.Storage localTrustStorage *truststorage.Storage
localTrustCtrl *trustcontroller.Controller localTrustCtrl *trustcontroller.Controller
scriptHash util.Uint160 scriptHash neogoutil.Uint160
} }
func initCfg(path string) *cfg { func initCfg(path string) *cfg {
@ -359,7 +358,7 @@ func initShardOptions(c *cfg) {
metaPath := metabaseCfg.Path() metaPath := metabaseCfg.Path()
metaPerm := metabaseCfg.Perm() metaPerm := metabaseCfg.Perm()
fatalOnErr(os.MkdirAll(path.Dir(metaPath), metaPerm)) fatalOnErr(util.MkdirAllX(path.Dir(metaPath), metaPerm))
opts = append(opts, []shard.Option{ opts = append(opts, []shard.Option{
shard.WithLogger(c.log), shard.WithLogger(c.log),
@ -387,7 +386,7 @@ func initShardOptions(c *cfg) {
shard.WithWriteCacheOptions(writeCacheOpts...), shard.WithWriteCacheOptions(writeCacheOpts...),
shard.WithRemoverBatchSize(gcCfg.RemoverBatchSize()), shard.WithRemoverBatchSize(gcCfg.RemoverBatchSize()),
shard.WithGCRemoverSleepInterval(gcCfg.RemoverSleepInterval()), shard.WithGCRemoverSleepInterval(gcCfg.RemoverSleepInterval()),
shard.WithGCWorkerPoolInitializer(func(sz int) util2.WorkerPool { shard.WithGCWorkerPoolInitializer(func(sz int) util.WorkerPool {
pool, err := ants.NewPool(sz) pool, err := ants.NewPool(sz)
fatalOnErr(err) fatalOnErr(err)

View file

@ -3,9 +3,9 @@ package blobovnicza
import ( import (
"errors" "errors"
"fmt" "fmt"
"os"
"path" "path"
"github.com/nspcc-dev/neofs-node/pkg/util"
"go.etcd.io/bbolt" "go.etcd.io/bbolt"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -18,7 +18,7 @@ func (b *Blobovnicza) Open() error {
zap.String("path", b.path), zap.String("path", b.path),
) )
err := os.MkdirAll(path.Dir(b.path), b.perm) err := util.MkdirAllX(path.Dir(b.path), b.perm)
if err == nil { if err == nil {
b.log.Debug("opening BoltDB", b.log.Debug("opening BoltDB",
zap.String("path", b.path), zap.String("path", b.path),

View file

@ -10,6 +10,7 @@ import (
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/util"
) )
// FSTree represents object storage as filesystem tree. // FSTree represents object storage as filesystem tree.
@ -157,7 +158,7 @@ func (t *FSTree) Exists(addr *objectSDK.Address) (string, error) {
func (t *FSTree) Put(addr *objectSDK.Address, data []byte) error { func (t *FSTree) Put(addr *objectSDK.Address, data []byte) error {
p := t.treePath(addr) p := t.treePath(addr)
if err := os.MkdirAll(path.Dir(p), t.Permissions); err != nil { if err := util.MkdirAllX(path.Dir(p), t.Permissions); err != nil {
return err return err
} }

View file

@ -2,16 +2,16 @@ package meta
import ( import (
"fmt" "fmt"
"os"
"path" "path"
"github.com/nspcc-dev/neofs-node/pkg/util"
"go.etcd.io/bbolt" "go.etcd.io/bbolt"
"go.uber.org/zap" "go.uber.org/zap"
) )
// Open boltDB instance for metabase. // Open boltDB instance for metabase.
func (db *DB) Open() error { func (db *DB) Open() error {
err := os.MkdirAll(path.Dir(db.info.Path), db.info.Permission) err := util.MkdirAllX(path.Dir(db.info.Path), db.info.Permission)
if err != nil { if err != nil {
return fmt.Errorf("can't create dir %s for metabase: %w", db.info.Path, err) return fmt.Errorf("can't create dir %s for metabase: %w", db.info.Path, err)
} }

View file

@ -10,6 +10,7 @@ import (
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
"github.com/nspcc-dev/neofs-node/pkg/util"
"go.etcd.io/bbolt" "go.etcd.io/bbolt"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -26,7 +27,7 @@ const lruKeysCount = 256 * 1024 * 8
const dbName = "small.bolt" const dbName = "small.bolt"
func (c *cache) openStore() error { func (c *cache) openStore() error {
if err := os.MkdirAll(c.path, os.ModePerm); err != nil { if err := util.MkdirAllX(c.path, os.ModePerm); err != nil {
return err return err
} }

View file

@ -4,9 +4,9 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"os"
"path" "path"
"github.com/nspcc-dev/neofs-node/pkg/util"
locodedb "github.com/nspcc-dev/neofs-node/pkg/util/locode/db" locodedb "github.com/nspcc-dev/neofs-node/pkg/util/locode/db"
"go.etcd.io/bbolt" "go.etcd.io/bbolt"
) )
@ -20,7 +20,7 @@ func (db *DB) Open() error {
// copy-paste from metabase: // copy-paste from metabase:
// consider universal Open/Close for BoltDB wrappers // consider universal Open/Close for BoltDB wrappers
err := os.MkdirAll(path.Dir(db.path), db.mode) err := util.MkdirAllX(path.Dir(db.path), db.mode)
if err != nil { if err != nil {
return fmt.Errorf("could not create dir for BoltDB: %w", err) return fmt.Errorf("could not create dir for BoltDB: %w", err)
} }