Skip to content

Commit

Permalink
drop lookup RootNode()
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Feb 16, 2022
1 parent afdafb1 commit 3208d8f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 47 deletions.
14 changes: 6 additions & 8 deletions pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,12 @@ func (fs *Decomposedfs) Shutdown(ctx context.Context) error {
// TODO Document in the cs3 should we return quota or free space?
func (fs *Decomposedfs) GetQuota(ctx context.Context, ref *provider.Reference) (total uint64, inUse uint64, err error) {
var n *node.Node
if ref != nil {
if n, err = fs.lu.NodeFromResource(ctx, ref); err != nil {
return 0, 0, err
}
} else {
if n, err = fs.lu.RootNode(ctx); err != nil {
return 0, 0, err
}
if ref == nil {
err = errtypes.BadRequest("no space given")
return 0, 0, err
}
if n, err = fs.lu.NodeFromResource(ctx, ref); err != nil {
return 0, 0, err
}

if !n.Exists {
Expand Down
7 changes: 0 additions & 7 deletions pkg/storage/utils/decomposedfs/lookup/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,6 @@ func (lu *Lookup) Path(ctx context.Context, n *node.Node) (p string, err error)
return
}

// RootNode returns the root node of the storage
func (lu *Lookup) RootNode(ctx context.Context) (*node.Node, error) {
n := node.New(node.NoSpaceID, node.RootID, "", "", 0, "", nil, lu)
n.Exists = true
return n, nil
}

// WalkPath calls n.Child(segment) on every path segment in p starting at the node r.
// If a function f is given it will be executed for every segment node, but not the root node r.
// If followReferences is given the current visited reference node is replaced by the referenced node.
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/utils/decomposedfs/node/locks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ var _ = Describe("Node locks", func() {
User: env.Owner.Id,
LockId: uuid.New().String(),
}
n = node.New("tobelockedid", "", "tobelocked", 10, "", env.Owner.Id, env.Lookup)
n2 = node.New("neverlockedid", "", "neverlocked", 10, "", env.Owner.Id, env.Lookup)
n = node.New("spaceid", "tobelockedid", "", "tobelocked", 10, "", env.Owner.Id, env.Lookup)
n2 = node.New("spaceid", "neverlockedid", "", "neverlocked", 10, "", env.Owner.Id, env.Lookup)
})

AfterEach(func() {
Expand Down
17 changes: 2 additions & 15 deletions pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ type Node struct {

// PathLookup defines the interface for the lookup component
type PathLookup interface {
RootNode(ctx context.Context) (node *Node, err error)

InternalRoot() string
InternalPath(spaceID, nodeID string) string
Path(ctx context.Context, n *Node) (path string, err error)
Expand Down Expand Up @@ -660,19 +658,8 @@ func (n *Node) AsResourceInfo(ctx context.Context, rp *provider.ResourcePermissi
}
// quota
if _, ok := mdKeysMap[QuotaKey]; (nodeType == provider.ResourceType_RESOURCE_TYPE_CONTAINER) && returnAllKeys || ok {
var quotaPath string
if n.SpaceRoot == nil {
root, err := n.lu.RootNode(ctx)
if err == nil {
quotaPath = root.InternalPath()
} else {
sublog.Debug().Err(err).Msg("error determining the space root node for quota")
}
} else {
quotaPath = n.SpaceRoot.InternalPath()
}
if quotaPath != "" {
readQuotaIntoOpaque(ctx, quotaPath, ri)
if n.SpaceRoot != nil && n.SpaceRoot.InternalPath() != "" {
readQuotaIntoOpaque(ctx, n.SpaceRoot.InternalPath(), ri)
}
}

Expand Down
6 changes: 2 additions & 4 deletions pkg/storage/utils/decomposedfs/node/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,8 @@ func (p *Permissions) AssemblePermissions(ctx context.Context, n *Node) (ap prov
return OwnerPermissions(), nil
}
// determine root
var rn *Node
if rn, err = p.lu.RootNode(ctx); err != nil {
return NoPermissions(), err
}

rn := n.SpaceRoot

cn := n

Expand Down
10 changes: 1 addition & 9 deletions pkg/storage/utils/decomposedfs/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ type Blobstore interface {
type PathLookup interface {
NodeFromResource(ctx context.Context, ref *provider.Reference) (*node.Node, error)
NodeFromID(ctx context.Context, id *provider.ResourceId) (n *node.Node, err error)
RootNode(ctx context.Context) (node *node.Node, err error)

InternalRoot() string
InternalPath(spaceID, nodeID string) string
Expand Down Expand Up @@ -609,14 +608,7 @@ func (t *Tree) Propagate(ctx context.Context, n *node.Node) (err error) {

// is propagation enabled for the parent node?

var root *node.Node
if n.SpaceRoot == nil {
if root, err = t.lookup.RootNode(ctx); err != nil {
return
}
} else {
root = n.SpaceRoot
}
root := n.SpaceRoot

// use a sync time and don't rely on the mtime of the current node, as the stat might not change when a rename happened too quickly
sTime := time.Now().UTC()
Expand Down
5 changes: 3 additions & 2 deletions pkg/storage/utils/decomposedfs/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/storage"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/lookup"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/mocks"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/node"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/options"
Expand All @@ -56,7 +57,7 @@ var _ = Describe("File uploads", func() {
spaceID string

o *options.Options
lookup *decomposedfs.Lookup
lookup *lookup.Lookup
permissions *mocks.PermissionsChecker
bs *treemocks.Blobstore
)
Expand Down Expand Up @@ -94,7 +95,7 @@ var _ = Describe("File uploads", func() {
"root": tmpRoot,
})
Expect(err).ToNot(HaveOccurred())
lookup = &decomposedfs.Lookup{Options: o}
lookup = &lookup.Lookup{Options: o}
permissions = &mocks.PermissionsChecker{}
bs = &treemocks.Blobstore{}
})
Expand Down

0 comments on commit 3208d8f

Please sign in to comment.