@@ -21,7 +21,6 @@ package decomposedfs
21
21
import (
22
22
"context"
23
23
"fmt"
24
- "os"
25
24
"path/filepath"
26
25
"strings"
27
26
@@ -93,24 +92,23 @@ func (lu *Lookup) NodeFromID(ctx context.Context, id *provider.ResourceId) (n *n
93
92
return n , n .FindStorageSpaceRoot ()
94
93
}
95
94
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 )
111
104
}
105
+ b .WriteString (id [i * width :])
106
+ return b .String ()
107
+ }
112
108
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 )
114
112
if err != nil {
115
113
return nil , err
116
114
}
@@ -192,7 +190,7 @@ func (lu *Lookup) InternalRoot() string {
192
190
193
191
// InternalPath returns the internal path for a given ID
194
192
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 ) )
196
194
}
197
195
198
196
func (lu * Lookup ) mustGetUserLayout (ctx context.Context ) string {
0 commit comments