Skip to content

Commit

Permalink
Fix listing all spaces of all types. Do not choke on errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Jun 19, 2023
1 parent f3b4dc1 commit 51e1763
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,27 +299,27 @@ func (fs *Decomposedfs) ListStorageSpaces(ctx context.Context, filter []*provide
matches := map[string]struct{}{}

if requestedUserID != nil {
allMatches := map[string]string{}
indexPath := filepath.Join(fs.o.Root, "indexes", "by-user-id", requestedUserID.GetOpaqueId())
fi, err := os.Stat(indexPath)
if err != nil {
return nil, err
}
allMatches, err := fs.spaceIDCache.LoadOrStore("by-user-id:"+requestedUserID.GetOpaqueId(), fi.ModTime(), func() (map[string]string, error) {
path := filepath.Join(fs.o.Root, "indexes", "by-user-id", requestedUserID.GetOpaqueId(), "*")
m, err := filepath.Glob(path)
if err != nil {
return nil, err
}
matches := map[string]string{}
for _, match := range m {
link, err := os.Readlink(match)
if err == nil {
allMatches, err = fs.spaceIDCache.LoadOrStore("by-user-id:"+requestedUserID.GetOpaqueId(), fi.ModTime(), func() (map[string]string, error) {
path := filepath.Join(fs.o.Root, "indexes", "by-user-id", requestedUserID.GetOpaqueId(), "*")
m, err := filepath.Glob(path)
if err != nil {
continue
return nil, err
}
matches[match] = link
}
return matches, nil
})
matches := map[string]string{}
for _, match := range m {
link, err := os.Readlink(match)
if err != nil {
continue
}
matches[match] = link
}
return matches, nil
})
}
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -381,10 +381,13 @@ func (fs *Decomposedfs) ListStorageSpaces(ctx context.Context, filter []*provide

if requestedUserID == nil {
for spaceType := range spaceTypes {
indexPath := filepath.Join(fs.o.Root, "indexes", "by-type", spaceType)
indexPath := filepath.Join(fs.o.Root, "indexes", "by-type")
if spaceType != spaceTypeAny {
indexPath = filepath.Join(indexPath, spaceType)
}
fi, err := os.Stat(indexPath)
if err != nil {
return nil, err
continue
}
allMatches, err := fs.spaceIDCache.LoadOrStore("by-type:"+spaceType, fi.ModTime(), func() (map[string]string, error) {
path := filepath.Join(fs.o.Root, "indexes", "by-type", spaceType, "*")
Expand Down

0 comments on commit 51e1763

Please sign in to comment.