Skip to content

Commit

Permalink
Remove virtual view filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Jun 9, 2021
1 parent ff786a7 commit 9f349e1
Showing 1 changed file with 19 additions and 32 deletions.
51 changes: 19 additions & 32 deletions pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"net/url"
"os"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"
Expand All @@ -42,7 +41,6 @@ import (
"github.com/cs3org/reva/pkg/eosclient/eosbinary"
"github.com/cs3org/reva/pkg/eosclient/eosgrpc"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/logger"
"github.com/cs3org/reva/pkg/mime"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
"github.com/cs3org/reva/pkg/sharedconf"
Expand Down Expand Up @@ -198,29 +196,22 @@ func NewEOSFS(c *Config) (storage.FS, error) {

func (fs *eosfs) userIDcacheWarmup() {
if !fs.conf.EnableHome {
log := logger.New().With().Int("pid", os.Getpid()).Logger()
log.Debug().Msg("Starting userIDcacheWarmup")

count := 0
ctx := context.Background()
paths := []string{fs.wrap(ctx, "/")}
uid, gid, _ := fs.getRootUIDAndGID(ctx)

for i := 0; i < fs.conf.UserIDCacheWarmupDepth; i++ {
var newPaths []string
for _, fn := range paths {
if eosFileInfos, err := fs.c.List(ctx, uid, gid, fn); err != nil {
if eosFileInfos, err := fs.c.List(ctx, uid, gid, fn); err == nil {
for _, f := range eosFileInfos {
if _, err := fs.getUserIDGateway(ctx, strconv.FormatUint(f.UID, 10)); err != nil {
count++
}
_, _ = fs.getUserIDGateway(ctx, strconv.FormatUint(f.UID, 10))
newPaths = append(newPaths, f.File)
}
}
}
paths = newPaths
}
log.Debug().Msgf("userIDcacheWarmup complete, added %d users", count)
}
}

Expand Down Expand Up @@ -618,7 +609,7 @@ func (fs *eosfs) GetMD(ctx context.Context, ref *provider.Reference, mdKeys []st
return nil, err
}

return fs.convertToResourceInfo(ctx, eosFileInfo, false)
return fs.convertToResourceInfo(ctx, eosFileInfo)
}

func (fs *eosfs) getMDShareFolder(ctx context.Context, p string, mdKeys []string) (*provider.ResourceInfo, error) {
Expand All @@ -641,7 +632,7 @@ func (fs *eosfs) getMDShareFolder(ctx context.Context, p string, mdKeys []string
// TODO(labkode): diff between root (dir) and children (ref)

if fs.isShareFolderRoot(ctx, p) {
return fs.convertToResourceInfo(ctx, eosFileInfo, false)
return fs.convertToResourceInfo(ctx, eosFileInfo)
}
return fs.convertToFileReference(ctx, eosFileInfo)
}
Expand Down Expand Up @@ -683,10 +674,6 @@ func (fs *eosfs) listWithNominalHome(ctx context.Context, p string) (finfos []*p
}

fn := fs.wrap(ctx, p)
virtualView := false
if !fs.conf.EnableHome && filepath.Dir(fn) == filepath.Clean(fs.conf.Namespace) {
virtualView = true
}

eosFileInfos, err := fs.c.List(ctx, uid, gid, fn)
if err != nil {
Expand All @@ -704,7 +691,7 @@ func (fs *eosfs) listWithNominalHome(ctx context.Context, p string) (finfos []*p
}

// Remove the hidden folders in the topmost directory
if finfo, err := fs.convertToResourceInfo(ctx, eosFileInfo, virtualView); err == nil && finfo.Path != "/" && !strings.HasPrefix(finfo.Path, "/.") {
if finfo, err := fs.convertToResourceInfo(ctx, eosFileInfo); err == nil && finfo.Path != "/" && !strings.HasPrefix(finfo.Path, "/.") {
finfos = append(finfos, finfo)
}
}
Expand Down Expand Up @@ -758,7 +745,7 @@ func (fs *eosfs) listHome(ctx context.Context, home string) ([]*provider.Resourc
}
}

if finfo, err := fs.convertToResourceInfo(ctx, eosFileInfo, false); err == nil && finfo.Path != "/" && !strings.HasPrefix(finfo.Path, "/.") {
if finfo, err := fs.convertToResourceInfo(ctx, eosFileInfo); err == nil && finfo.Path != "/" && !strings.HasPrefix(finfo.Path, "/.") {
finfos = append(finfos, finfo)
}
}
Expand Down Expand Up @@ -1363,7 +1350,7 @@ func (fs *eosfs) convertToRecycleItem(ctx context.Context, eosDeletedItem *eoscl
}

func (fs *eosfs) convertToRevision(ctx context.Context, eosFileInfo *eosclient.FileInfo) (*provider.FileVersion, error) {
md, err := fs.convertToResourceInfo(ctx, eosFileInfo, false)
md, err := fs.convertToResourceInfo(ctx, eosFileInfo)
if err != nil {
return nil, err
}
Expand All @@ -1376,12 +1363,12 @@ func (fs *eosfs) convertToRevision(ctx context.Context, eosFileInfo *eosclient.F
return revision, nil
}

func (fs *eosfs) convertToResourceInfo(ctx context.Context, eosFileInfo *eosclient.FileInfo, virtualView bool) (*provider.ResourceInfo, error) {
return fs.convert(ctx, eosFileInfo, virtualView)
func (fs *eosfs) convertToResourceInfo(ctx context.Context, eosFileInfo *eosclient.FileInfo) (*provider.ResourceInfo, error) {
return fs.convert(ctx, eosFileInfo)
}

func (fs *eosfs) convertToFileReference(ctx context.Context, eosFileInfo *eosclient.FileInfo) (*provider.ResourceInfo, error) {
info, err := fs.convert(ctx, eosFileInfo, false)
info, err := fs.convert(ctx, eosFileInfo)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1471,7 +1458,7 @@ func mergePermissions(l *provider.ResourcePermissions, r *provider.ResourcePermi
l.UpdateGrant = l.UpdateGrant || r.UpdateGrant
}

func (fs *eosfs) convert(ctx context.Context, eosFileInfo *eosclient.FileInfo, virtualView bool) (*provider.ResourceInfo, error) {
func (fs *eosfs) convert(ctx context.Context, eosFileInfo *eosclient.FileInfo) (*provider.ResourceInfo, error) {
path, err := fs.unwrap(ctx, eosFileInfo.File)
if err != nil {
return nil, err
Expand All @@ -1482,13 +1469,10 @@ func (fs *eosfs) convert(ctx context.Context, eosFileInfo *eosclient.FileInfo, v
size = eosFileInfo.TreeSize
}

owner := &userpb.UserId{}
if !virtualView {
owner, err = fs.getUserIDGateway(ctx, strconv.FormatUint(eosFileInfo.UID, 10))
if err != nil {
sublog := appctx.GetLogger(ctx).With().Logger()
sublog.Warn().Uint64("uid", eosFileInfo.UID).Msg("could not lookup userid, leaving empty")
}
owner, err := fs.getUserIDGateway(ctx, strconv.FormatUint(eosFileInfo.UID, 10))
if err != nil {
sublog := appctx.GetLogger(ctx).With().Logger()
sublog.Warn().Uint64("uid", eosFileInfo.UID).Msg("could not lookup userid, leaving empty")
}

var xs provider.ResourceChecksum
Expand Down Expand Up @@ -1581,9 +1565,12 @@ func (fs *eosfs) getUIDGateway(ctx context.Context, u *userpb.UserId) (string, s
}

func (fs *eosfs) getUserIDGateway(ctx context.Context, uid string) (*userpb.UserId, error) {
if userIDInterface, err := fs.userIDCache.Get(uid); err != nil {
log := appctx.GetLogger(ctx)
if userIDInterface, err := fs.userIDCache.Get(uid); err == nil {
log.Debug().Msg("eosfs: found cached uid " + uid)
return userIDInterface.(*userpb.UserId), nil
}
log.Debug().Msg("eosfs: retrieving user from gateway for uid " + uid)
client, err := pool.GetGatewayServiceClient(fs.conf.GatewaySvc)
if err != nil {
return nil, errors.Wrap(err, "eos: error getting gateway grpc client")
Expand Down

0 comments on commit 9f349e1

Please sign in to comment.