Skip to content

Commit

Permalink
start using correct node path
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 15, 2022
1 parent 2401678 commit 2698dc1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
34 changes: 16 additions & 18 deletions pkg/storage/utils/decomposedfs/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package decomposedfs
import (
"context"
"fmt"
"os"
"path/filepath"
"strings"

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

// NodeFromSpaceID converts a resource id without an opaque id into a Node
func (lu *Lookup) NodeFromSpaceID(ctx context.Context, id *provider.ResourceId) (n *node.Node, err error) {
d := filepath.Join(lu.Options.Root, "spaces", spaceTypeAny, id.StorageId)
matches, err := filepath.Glob(d)
if err != nil {
return nil, err
}

if len(matches) != 1 {
return nil, fmt.Errorf("can't determine node from spaceID: found %d matching spaces. Path: %s", len(matches), d)
}

target, err := os.Readlink(matches[0])
if err != nil {
appctx.GetLogger(ctx).Error().Err(err).Str("match", matches[0]).Msg("could not read link, skipping")
func Pathify(id string, depth, width int) string {
b := strings.Builder{}
i := 0
for ; i < depth; i++ {
if len(id) <= i*width+width {
break
}
b.WriteString(id[i*width : i*width+width])
b.WriteRune(filepath.Separator)
}
b.WriteString(id[i*width:])
return b.String()
}

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

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

func (lu *Lookup) mustGetUserLayout(ctx context.Context) string {
Expand Down
7 changes: 4 additions & 3 deletions pkg/storage/utils/decomposedfs/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ func New(root string, tta bool, tsa bool, lu PathLookup, bs Blobstore) *Tree {
func (t *Tree) Setup(owner *userpb.UserId, propagateToRoot bool) error {
// create data paths for internal layout
dataPaths := []string{
filepath.Join(t.root, "nodes"),
filepath.Join(t.root, "spaces"),
//filepath.Join(t.root, "nodes"),
// notes contain symlinks from nodes/<u-u-i-d>/uploads/<uploadid> to ../../uploads/<uploadid>
// better to keep uploads on a fast / volatile storage before a workflow finally moves them to the nodes dir
filepath.Join(t.root, "uploads"),
filepath.Join(t.root, "trash"),
//filepath.Join(t.root, "uploads"),
//filepath.Join(t.root, "trash"),
}
for _, v := range dataPaths {
err := os.MkdirAll(v, 0700)
Expand Down

0 comments on commit 2698dc1

Please sign in to comment.