[#1770] fstree: Depth parameter int -> uint64

Negative values have no sense. On the other hand it differs from the
blobovnicza's configuration and prevents unification.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-09-26 19:38:03 +03:00 committed by fyrchik
parent 4aa4694152
commit 5c69e19016
3 changed files with 7 additions and 7 deletions

View file

@ -26,14 +26,14 @@ func (x *Config) Type() string {
// //
// Returns DepthDefault if the value is out of // Returns DepthDefault if the value is out of
// [1:fstree.MaxDepth] range. // [1:fstree.MaxDepth] range.
func (x *Config) Depth() int { func (x *Config) Depth() uint64 {
d := config.IntSafe( d := config.UintSafe(
(*config.Config)(x), (*config.Config)(x),
"depth", "depth",
) )
if d >= 1 && d <= fstree.MaxDepth { if d >= 1 && d <= fstree.MaxDepth {
return int(d) return d
} }
return DepthDefault return DepthDefault

View file

@ -23,7 +23,7 @@ type FSTree struct {
Info Info
*compression.Config *compression.Config
Depth int Depth uint64
DirNameLen int DirNameLen int
readOnly bool readOnly bool
@ -96,7 +96,7 @@ func (t *FSTree) Iterate(prm common.IteratePrm) (common.IterateRes, error) {
return common.IterateRes{}, t.iterate(0, []string{t.RootPath}, prm) return common.IterateRes{}, t.iterate(0, []string{t.RootPath}, prm)
} }
func (t *FSTree) iterate(depth int, curPath []string, prm common.IteratePrm) error { func (t *FSTree) iterate(depth uint64, curPath []string, prm common.IteratePrm) error {
curName := strings.Join(curPath[1:], "") curName := strings.Join(curPath[1:], "")
des, err := os.ReadDir(filepath.Join(curPath...)) des, err := os.ReadDir(filepath.Join(curPath...))
if err != nil { if err != nil {
@ -172,7 +172,7 @@ func (t *FSTree) treePath(addr oid.Address) string {
dirs := make([]string, 0, t.Depth+1+1) // 1 for root, 1 for file dirs := make([]string, 0, t.Depth+1+1) // 1 for root, 1 for file
dirs = append(dirs, t.RootPath) dirs = append(dirs, t.RootPath)
for i := 0; i < t.Depth; i++ { for i := 0; uint64(i) < t.Depth; i++ {
dirs = append(dirs, sAddr[:t.DirNameLen]) dirs = append(dirs, sAddr[:t.DirNameLen])
sAddr = sAddr[t.DirNameLen:] sAddr = sAddr[t.DirNameLen:]
} }

View file

@ -6,7 +6,7 @@ import (
type Option func(*FSTree) type Option func(*FSTree)
func WithDepth(d int) Option { func WithDepth(d uint64) Option {
return func(f *FSTree) { return func(f *FSTree) {
f.Depth = d f.Depth = d
} }