Skip to content

Commit

Permalink
Use string as the space index values again
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Jun 20, 2023
1 parent 9a6ff63 commit fa0381c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions pkg/storage/utils/decomposedfs/spaceidindex/spaceidindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
type Index struct {
root string
name string
cache mtimesyncedcache.Cache[string, map[string][]byte]
cache mtimesyncedcache.Cache[string, map[string]string]
}

type readWriteCloseSeekTruncater interface {
Expand All @@ -36,7 +36,7 @@ func (i *Index) Init() error {
return os.MkdirAll(filepath.Join(i.root, i.name), 0700)
}

func (i *Index) Load(index string) (map[string][]byte, error) {
func (i *Index) Load(index string) (map[string]string, error) {
indexPath := filepath.Join(i.root, i.name, index+".mpk")
fi, err := os.Stat(indexPath)
if err != nil {
Expand All @@ -47,15 +47,15 @@ func (i *Index) Load(index string) (map[string][]byte, error) {

// func (i *Index) RemoveFromIndex(key, entry string) os.LinkError {

func (i *Index) Add(index, key string, value []byte) error {
return i.UpdateIndex(index, map[string][]byte{key: value}, []string{})
func (i *Index) Add(index, key string, value string) error {
return i.UpdateIndex(index, map[string]string{key: value}, []string{})
}

func (i *Index) Remove(index, key string) error {
return i.UpdateIndex(index, map[string][]byte{}, []string{key})
return i.UpdateIndex(index, map[string]string{}, []string{key})
}

func (i *Index) UpdateIndex(index string, addLinks map[string][]byte, removeLinks []string) error {
func (i *Index) UpdateIndex(index string, addLinks map[string]string, removeLinks []string) error {
indexPath := filepath.Join(i.root, i.name, index+".mpk")

var err error
Expand All @@ -79,7 +79,7 @@ func (i *Index) UpdateIndex(index string, addLinks map[string][]byte, removeLink
if err != nil {
return err
}
links := map[string][]byte{}
links := map[string]string{}
if len(msgBytes) > 0 {
err = msgpack.Unmarshal(msgBytes, &links)
if err != nil {
Expand Down Expand Up @@ -116,8 +116,8 @@ func (i *Index) UpdateIndex(index string, addLinks map[string][]byte, removeLink
return nil
}

func (i *Index) readSpaceIndex(indexPath, cacheKey string, mtime time.Time) (map[string][]byte, error) {
return i.cache.LoadOrStore(cacheKey, mtime, func() (map[string][]byte, error) {
func (i *Index) readSpaceIndex(indexPath, cacheKey string, mtime time.Time) (map[string]string, error) {
return i.cache.LoadOrStore(cacheKey, mtime, func() (map[string]string, error) {
// Acquire a read log on the index file
f, err := lockedfile.Open(indexPath)
if err != nil {
Expand All @@ -137,7 +137,7 @@ func (i *Index) readSpaceIndex(indexPath, cacheKey string, mtime time.Time) (map
if err != nil {
return nil, errors.Wrap(err, "unable to read index")
}
links := map[string][]byte{}
links := map[string]string{}
if len(msgBytes) > 0 {
err = msgpack.Unmarshal(msgBytes, &links)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (fs *Decomposedfs) ListStorageSpaces(ctx context.Context, filter []*provide
}

matches := map[string]struct{}{}
var allMatches map[string][]byte
var allMatches map[string]string
var err error

if requestedUserID != nil {
Expand Down Expand Up @@ -771,17 +771,17 @@ func (fs *Decomposedfs) updateIndexes(ctx context.Context, grantee *provider.Gra
}

func (fs *Decomposedfs) linkSpaceByUser(ctx context.Context, userID, spaceID string) error {
target := []byte("../../../spaces/" + lookup.Pathify(spaceID, 1, 2) + "/nodes/" + lookup.Pathify(spaceID, 4, 2))
target := "../../../spaces/" + lookup.Pathify(spaceID, 1, 2) + "/nodes/" + lookup.Pathify(spaceID, 4, 2)
return fs.userSpaceIndex.Add(userID, spaceID, target)
}

func (fs *Decomposedfs) linkSpaceByGroup(ctx context.Context, groupID, spaceID string) error {
target := []byte("../../../spaces/" + lookup.Pathify(spaceID, 1, 2) + "/nodes/" + lookup.Pathify(spaceID, 4, 2))
target := "../../../spaces/" + lookup.Pathify(spaceID, 1, 2) + "/nodes/" + lookup.Pathify(spaceID, 4, 2)
return fs.groupSpaceIndex.Add(groupID, spaceID, target)
}

func (fs *Decomposedfs) linkStorageSpaceType(ctx context.Context, spaceType string, spaceID string) error {
target := []byte("../../../spaces/" + lookup.Pathify(spaceID, 1, 2) + "/nodes/" + lookup.Pathify(spaceID, 4, 2))
target := "../../../spaces/" + lookup.Pathify(spaceID, 1, 2) + "/nodes/" + lookup.Pathify(spaceID, 4, 2)
return fs.spaceTypeIndex.Add(spaceType, spaceID, target)
}

Expand Down

0 comments on commit fa0381c

Please sign in to comment.