2020-11-17 16:29:00 +00:00
|
|
|
package blobstor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/sha256"
|
|
|
|
"encoding/hex"
|
|
|
|
"errors"
|
|
|
|
"path"
|
|
|
|
|
|
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
|
|
|
)
|
|
|
|
|
|
|
|
type fsTree struct {
|
|
|
|
depth int
|
|
|
|
|
|
|
|
dirNameLen int
|
|
|
|
|
2020-11-19 13:52:37 +00:00
|
|
|
Info
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
2020-11-18 14:58:16 +00:00
|
|
|
const dirNameLen = 1 // in bytes
|
2020-11-17 16:29:00 +00:00
|
|
|
|
2020-11-18 11:48:47 +00:00
|
|
|
var maxDepth = (sha256.Size - 1) / dirNameLen
|
2020-11-17 16:29:00 +00:00
|
|
|
|
|
|
|
var errFileNotFound = errors.New("file not found")
|
|
|
|
|
|
|
|
func stringifyAddress(addr *objectSDK.Address) string {
|
|
|
|
h := sha256.Sum256([]byte(addr.String()))
|
|
|
|
|
|
|
|
return hex.EncodeToString(h[:])
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2020-11-19 13:52:37 +00:00
|
|
|
dirs = append(dirs, t.RootPath)
|
2020-11-17 16:29:00 +00:00
|
|
|
|
|
|
|
for i := 0; i < t.depth; i++ {
|
|
|
|
dirs = append(dirs, sAddr[:t.dirNameLen])
|
|
|
|
sAddr = sAddr[t.dirNameLen:]
|
|
|
|
}
|
|
|
|
|
|
|
|
dirs = append(dirs, sAddr)
|
|
|
|
|
|
|
|
return path.Join(dirs...)
|
|
|
|
}
|