Skip to content

Commit 2698dc1

Browse files
committed
start using correct node path
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
1 parent 2401678 commit 2698dc1

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

Diff for: pkg/storage/utils/decomposedfs/lookup.go

+16-18
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ package decomposedfs
2121
import (
2222
"context"
2323
"fmt"
24-
"os"
2524
"path/filepath"
2625
"strings"
2726

@@ -93,24 +92,23 @@ func (lu *Lookup) NodeFromID(ctx context.Context, id *provider.ResourceId) (n *n
9392
return n, n.FindStorageSpaceRoot()
9493
}
9594

96-
// NodeFromSpaceID converts a resource id without an opaque id into a Node
97-
func (lu *Lookup) NodeFromSpaceID(ctx context.Context, id *provider.ResourceId) (n *node.Node, err error) {
98-
d := filepath.Join(lu.Options.Root, "spaces", spaceTypeAny, id.StorageId)
99-
matches, err := filepath.Glob(d)
100-
if err != nil {
101-
return nil, err
102-
}
103-
104-
if len(matches) != 1 {
105-
return nil, fmt.Errorf("can't determine node from spaceID: found %d matching spaces. Path: %s", len(matches), d)
106-
}
107-
108-
target, err := os.Readlink(matches[0])
109-
if err != nil {
110-
appctx.GetLogger(ctx).Error().Err(err).Str("match", matches[0]).Msg("could not read link, skipping")
95+
func Pathify(id string, depth, width int) string {
96+
b := strings.Builder{}
97+
i := 0
98+
for ; i < depth; i++ {
99+
if len(id) <= i*width+width {
100+
break
101+
}
102+
b.WriteString(id[i*width : i*width+width])
103+
b.WriteRune(filepath.Separator)
111104
}
105+
b.WriteString(id[i*width:])
106+
return b.String()
107+
}
112108

113-
node, err := node.ReadNode(ctx, lu, id.StorageId, filepath.Base(target))
109+
// NodeFromSpaceID converts a resource id without an opaque id into a Node
110+
func (lu *Lookup) NodeFromSpaceID(ctx context.Context, id *provider.ResourceId) (n *node.Node, err error) {
111+
node, err := node.ReadNode(ctx, lu, id.StorageId, id.StorageId)
114112
if err != nil {
115113
return nil, err
116114
}
@@ -192,7 +190,7 @@ func (lu *Lookup) InternalRoot() string {
192190

193191
// InternalPath returns the internal path for a given ID
194192
func (lu *Lookup) InternalPath(spaceID, nodeID string) string {
195-
return filepath.Join(lu.Options.Root, "nodes", spaceID, nodeID)
193+
return filepath.Join(lu.Options.Root, "spaces", Pathify(spaceID, 1, 2), "nodes", Pathify(nodeID, 4, 2))
196194
}
197195

198196
func (lu *Lookup) mustGetUserLayout(ctx context.Context) string {

Diff for: pkg/storage/utils/decomposedfs/tree/tree.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ func New(root string, tta bool, tsa bool, lu PathLookup, bs Blobstore) *Tree {
9696
func (t *Tree) Setup(owner *userpb.UserId, propagateToRoot bool) error {
9797
// create data paths for internal layout
9898
dataPaths := []string{
99-
filepath.Join(t.root, "nodes"),
99+
filepath.Join(t.root, "spaces"),
100+
//filepath.Join(t.root, "nodes"),
100101
// notes contain symlinks from nodes/<u-u-i-d>/uploads/<uploadid> to ../../uploads/<uploadid>
101102
// better to keep uploads on a fast / volatile storage before a workflow finally moves them to the nodes dir
102-
filepath.Join(t.root, "uploads"),
103-
filepath.Join(t.root, "trash"),
103+
//filepath.Join(t.root, "uploads"),
104+
//filepath.Join(t.root, "trash"),
104105
}
105106
for _, v := range dataPaths {
106107
err := os.MkdirAll(v, 0700)

0 commit comments

Comments
 (0)