From 7a10d902be7b59f3025c86ddc0596c21c5bf2b2c Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 28 Jul 2021 19:19:33 +0300 Subject: [PATCH] [#727] Use `util.MkdirAllX` instead of `os.MkdirAll` Signed-off-by: Pavel Karpy --- cmd/neofs-node/config.go | 23 +++++++++---------- .../blobovnicza/control.go | 4 ++-- .../blobstor/fstree/fstree.go | 3 ++- pkg/local_object_storage/metabase/control.go | 4 ++-- .../writecache/storage.go | 3 ++- pkg/util/locode/db/boltdb/calls.go | 4 ++-- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index d17b2848e..e0bc3aff2 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -3,13 +3,12 @@ package main import ( "context" "net" - "os" "path" "sync" "time" "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" apiclient "github.com/nspcc-dev/neofs-api-go/pkg/client" "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" tokenStorage "github.com/nspcc-dev/neofs-node/pkg/services/session/storage" "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/panjf2000/ants/v2" "go.etcd.io/bbolt" @@ -133,25 +132,25 @@ type cfgMorph struct { } type cfgAccounting struct { - scriptHash util.Uint160 + scriptHash neogoutil.Uint160 } type cfgContainer struct { - scriptHash util.Uint160 + scriptHash neogoutil.Uint160 parsers map[event.Type]event.Parser subscribers map[event.Type][]event.Handler - workerPool util2.WorkerPool // pool for asynchronous handlers + workerPool util.WorkerPool // pool for asynchronous handlers } type cfgNetmap struct { - scriptHash util.Uint160 + scriptHash neogoutil.Uint160 wrapper *nmwrapper.Wrapper parsers map[event.Type]event.Parser subscribers map[event.Type][]event.Handler - workerPool util2.WorkerPool // pool for asynchronous handlers + workerPool util.WorkerPool // pool for asynchronous handlers state *networkState @@ -192,13 +191,13 @@ type cfgControlService 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 localTrustCtrl *trustcontroller.Controller - scriptHash util.Uint160 + scriptHash neogoutil.Uint160 } func initCfg(path string) *cfg { @@ -359,7 +358,7 @@ func initShardOptions(c *cfg) { metaPath := metabaseCfg.Path() metaPerm := metabaseCfg.Perm() - fatalOnErr(os.MkdirAll(path.Dir(metaPath), metaPerm)) + fatalOnErr(util.MkdirAllX(path.Dir(metaPath), metaPerm)) opts = append(opts, []shard.Option{ shard.WithLogger(c.log), @@ -387,7 +386,7 @@ func initShardOptions(c *cfg) { shard.WithWriteCacheOptions(writeCacheOpts...), shard.WithRemoverBatchSize(gcCfg.RemoverBatchSize()), shard.WithGCRemoverSleepInterval(gcCfg.RemoverSleepInterval()), - shard.WithGCWorkerPoolInitializer(func(sz int) util2.WorkerPool { + shard.WithGCWorkerPoolInitializer(func(sz int) util.WorkerPool { pool, err := ants.NewPool(sz) fatalOnErr(err) diff --git a/pkg/local_object_storage/blobovnicza/control.go b/pkg/local_object_storage/blobovnicza/control.go index 3137907e3..7c39717cb 100644 --- a/pkg/local_object_storage/blobovnicza/control.go +++ b/pkg/local_object_storage/blobovnicza/control.go @@ -3,9 +3,9 @@ package blobovnicza import ( "errors" "fmt" - "os" "path" + "github.com/nspcc-dev/neofs-node/pkg/util" "go.etcd.io/bbolt" "go.uber.org/zap" ) @@ -18,7 +18,7 @@ func (b *Blobovnicza) Open() error { 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 { b.log.Debug("opening BoltDB", zap.String("path", b.path), diff --git a/pkg/local_object_storage/blobstor/fstree/fstree.go b/pkg/local_object_storage/blobstor/fstree/fstree.go index d22fd73cc..8fcb7a385 100644 --- a/pkg/local_object_storage/blobstor/fstree/fstree.go +++ b/pkg/local_object_storage/blobstor/fstree/fstree.go @@ -10,6 +10,7 @@ import ( cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" 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. @@ -157,7 +158,7 @@ func (t *FSTree) Exists(addr *objectSDK.Address) (string, error) { func (t *FSTree) Put(addr *objectSDK.Address, data []byte) error { 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 } diff --git a/pkg/local_object_storage/metabase/control.go b/pkg/local_object_storage/metabase/control.go index 2e6223884..55769fa32 100644 --- a/pkg/local_object_storage/metabase/control.go +++ b/pkg/local_object_storage/metabase/control.go @@ -2,16 +2,16 @@ package meta import ( "fmt" - "os" "path" + "github.com/nspcc-dev/neofs-node/pkg/util" "go.etcd.io/bbolt" "go.uber.org/zap" ) // Open boltDB instance for metabase. 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 { return fmt.Errorf("can't create dir %s for metabase: %w", db.info.Path, err) } diff --git a/pkg/local_object_storage/writecache/storage.go b/pkg/local_object_storage/writecache/storage.go index aa7386cb4..413ec86a5 100644 --- a/pkg/local_object_storage/writecache/storage.go +++ b/pkg/local_object_storage/writecache/storage.go @@ -10,6 +10,7 @@ import ( 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/local_object_storage/blobstor/fstree" + "github.com/nspcc-dev/neofs-node/pkg/util" "go.etcd.io/bbolt" "go.uber.org/zap" ) @@ -26,7 +27,7 @@ const lruKeysCount = 256 * 1024 * 8 const dbName = "small.bolt" 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 } diff --git a/pkg/util/locode/db/boltdb/calls.go b/pkg/util/locode/db/boltdb/calls.go index 6d6c4333c..b121d8619 100644 --- a/pkg/util/locode/db/boltdb/calls.go +++ b/pkg/util/locode/db/boltdb/calls.go @@ -4,9 +4,9 @@ import ( "encoding/json" "errors" "fmt" - "os" "path" + "github.com/nspcc-dev/neofs-node/pkg/util" locodedb "github.com/nspcc-dev/neofs-node/pkg/util/locode/db" "go.etcd.io/bbolt" ) @@ -20,7 +20,7 @@ func (db *DB) Open() error { // copy-paste from metabase: // 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 { return fmt.Errorf("could not create dir for BoltDB: %w", err) }