From b18f21cce178b60531086f164d24e832a7b6eb86 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 12 Oct 2020 21:58:37 -0700 Subject: mount: fix bound tree with filer.path fix https://github.com/chrislusf/seaweedfs/issues/1528 --- weed/util/bounded_tree/bounded_tree.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'weed/util/bounded_tree/bounded_tree.go') diff --git a/weed/util/bounded_tree/bounded_tree.go b/weed/util/bounded_tree/bounded_tree.go index 0e023c0d1..0182aeba1 100644 --- a/weed/util/bounded_tree/bounded_tree.go +++ b/weed/util/bounded_tree/bounded_tree.go @@ -16,13 +16,15 @@ type Node struct { type BoundedTree struct { root *Node sync.RWMutex + baseDir util.FullPath } -func NewBoundedTree() *BoundedTree { +func NewBoundedTree(baseDir util.FullPath) *BoundedTree { return &BoundedTree{ root: &Node{ Name: "/", }, + baseDir: baseDir, } } @@ -39,9 +41,12 @@ func (t *BoundedTree) EnsureVisited(p util.FullPath, visitFn VisitNodeFunc) { if t.root == nil { return } + if t.baseDir != "/" { + p = p[len(t.baseDir):] + } components := p.Split() // fmt.Printf("components %v %d\n", components, len(components)) - if canDelete := t.ensureVisited(t.root, util.FullPath("/"), components, 0, visitFn); canDelete { + if canDelete := t.ensureVisited(t.root, t.baseDir, components, 0, visitFn); canDelete { t.root = nil } } @@ -60,7 +65,12 @@ func (t *BoundedTree) ensureVisited(n *Node, currentPath util.FullPath, componen } else { // fmt.Printf("ensure %v\n", currentPath) - children, err := visitFn(currentPath) + filerPath := currentPath + if t.baseDir != "/" { + filerPath = t.baseDir + filerPath + } + + children, err := visitFn(filerPath) if err != nil { glog.V(0).Infof("failed to visit %s: %v", currentPath, err) return -- cgit v1.2.3