From eaa7068e3c585946aef0bb12c886c98249905e28 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 19 Nov 2020 16:52:37 +0300 Subject: [PATCH] [#189] blobstor: Implement DumpInfo method Implement method to get the information about the BLOB storage. Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/blobstor/blobstor.go | 10 ++++++---- pkg/local_object_storage/blobstor/fstree.go | 7 ++----- pkg/local_object_storage/blobstor/info.go | 19 +++++++++++++++++++ pkg/local_object_storage/blobstor/put.go | 4 ++-- 4 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 pkg/local_object_storage/blobstor/info.go diff --git a/pkg/local_object_storage/blobstor/blobstor.go b/pkg/local_object_storage/blobstor/blobstor.go index 946566428..e74f84681 100644 --- a/pkg/local_object_storage/blobstor/blobstor.go +++ b/pkg/local_object_storage/blobstor/blobstor.go @@ -37,8 +37,10 @@ func defaultCfg() *cfg { fsTree: fsTree{ depth: defaultShallowDepth, dirNameLen: hex.EncodedLen(dirNameLen), - perm: defaultPerm, - rootDir: "./", + Info: Info{ + Permissions: defaultPerm, + RootPath: "./", + }, }, compressor: noOpCompressor, decompressor: noOpDecompressor, @@ -108,7 +110,7 @@ func WithCompressObjects(comp bool, log *logger.Logger) Option { // of the fs tree to write the objects. func WithTreeRootPath(rootDir string) Option { return func(c *cfg) { - c.fsTree.rootDir = rootDir + c.fsTree.RootPath = rootDir } } @@ -116,6 +118,6 @@ func WithTreeRootPath(rootDir string) Option { // bits of the fs tree. func WithTreeRootPerm(perm os.FileMode) Option { return func(c *cfg) { - c.fsTree.perm = perm + c.fsTree.Permissions = perm } } diff --git a/pkg/local_object_storage/blobstor/fstree.go b/pkg/local_object_storage/blobstor/fstree.go index d7476389f..4dabc80a5 100644 --- a/pkg/local_object_storage/blobstor/fstree.go +++ b/pkg/local_object_storage/blobstor/fstree.go @@ -4,7 +4,6 @@ import ( "crypto/sha256" "encoding/hex" "errors" - "os" "path" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" @@ -15,9 +14,7 @@ type fsTree struct { dirNameLen int - perm os.FileMode - - rootDir string + Info } const dirNameLen = 1 // in bytes @@ -36,7 +33,7 @@ func (t *fsTree) treePath(addr *objectSDK.Address) string { sAddr := stringifyAddress(addr) dirs := make([]string, 0, t.depth+1+1) // 1 for root, 1 for file - dirs = append(dirs, t.rootDir) + dirs = append(dirs, t.RootPath) for i := 0; i < t.depth; i++ { dirs = append(dirs, sAddr[:t.dirNameLen]) diff --git a/pkg/local_object_storage/blobstor/info.go b/pkg/local_object_storage/blobstor/info.go new file mode 100644 index 000000000..c52901788 --- /dev/null +++ b/pkg/local_object_storage/blobstor/info.go @@ -0,0 +1,19 @@ +package blobstor + +import ( + "os" +) + +// Info groups the information about BlobStor. +type Info struct { + // Permission bits of the root directory. + Permissions os.FileMode + + // Full path to the root directory. + RootPath string +} + +// DumpInfo returns information about the BlobStor. +func (b *BlobStor) DumpInfo() Info { + return b.fsTree.Info +} diff --git a/pkg/local_object_storage/blobstor/put.go b/pkg/local_object_storage/blobstor/put.go index 112988bda..05c52abd7 100644 --- a/pkg/local_object_storage/blobstor/put.go +++ b/pkg/local_object_storage/blobstor/put.go @@ -53,9 +53,9 @@ func (b *BlobStor) Put(prm *PutPrm) (*PutRes, error) { func (t *fsTree) put(addr *objectSDK.Address, data []byte) error { p := t.treePath(addr) - if err := os.MkdirAll(path.Dir(p), t.perm); err != nil { + if err := os.MkdirAll(path.Dir(p), t.Permissions); err != nil { return err } - return ioutil.WriteFile(p, data, t.perm) + return ioutil.WriteFile(p, data, t.Permissions) }