[#189] blobstor: Implement DumpInfo method

Implement method to get the information about the BLOB storage.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-19 16:52:37 +03:00 committed by Alex Vanin
parent dae8d3de5b
commit eaa7068e3c
4 changed files with 29 additions and 11 deletions

View file

@ -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
}
}

View file

@ -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])

View file

@ -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
}

View file

@ -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)
}