diff --git a/internal/grpc/services/storageprovider/storageprovider.go b/internal/grpc/services/storageprovider/storageprovider.go index d4e6ccf2112..34cfc791e5b 100644 --- a/internal/grpc/services/storageprovider/storageprovider.go +++ b/internal/grpc/services/storageprovider/storageprovider.go @@ -940,6 +940,11 @@ func (s *service) ListContainer(ctx context.Context, req *provider.ListContainer }, nil } + // Hack to enable search + if req.Opaque.Map["search"] != nil { + s.storage.ListFolder(ctx, newRef, []string{"search"}) + } + mds, err := s.storage.ListFolder(ctx, newRef, req.ArbitraryMetadataKeys) if err != nil { var st *rpc.Status diff --git a/internal/http/services/owncloud/ocdav/report.go b/internal/http/services/owncloud/ocdav/report.go index 6b6cd9c4e47..e1040f398e8 100644 --- a/internal/http/services/owncloud/ocdav/report.go +++ b/internal/http/services/owncloud/ocdav/report.go @@ -20,6 +20,7 @@ package ocdav import ( "encoding/xml" + "fmt" "io" "io/ioutil" "net/http" @@ -28,6 +29,7 @@ import ( rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" providerv1beta1 "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" "github.com/cs3org/reva/pkg/appctx" ctxpkg "github.com/cs3org/reva/pkg/ctx" ) @@ -71,25 +73,38 @@ func (s *svc) doSearchFiles(w http.ResponseWriter, r *http.Request, sf *reportSe log.Info().Msgf("hugo: search is: %+v", sf) - /* - _, err := bleve.Open("/var/tmp/search.db") - if err != nil { - log.Error().Err(err).Msg("hugo: error opening bleve db") - w.WriteHeader(http.StatusInternalServerError) - return - } + client, err := s.getClient() + if err != nil { + log.Error().Err(err).Msg("search: error getting grpc client") + w.WriteHeader(http.StatusInternalServerError) + return + } - query := bleve.NewWildcardQuery(sf.Search.Pattern) - req := bleve.NewSearchRequest(query) - res, err := index.Search(req) - if err != nil { - log.Error().Err(err).Msg("hugo: error searching") - w.WriteHeader(http.StatusInternalServerError) - return - } - */ + opaqueMap := map[string]*typespb.OpaqueEntry{ + "search": { + Decoder: "plain", + Value: []byte("search"), + }, + } + + ref := &provider.Reference{Path: "/eos/project/c/cernbox"} + + req := &provider.ListContainerRequest{Opaque: &typespb.Opaque{ + Map: opaqueMap, + }, Ref: ref} + + res, err := client.ListContainer(ctx, req) + + if err != nil { + log.Error().Err(err).Msg("search: error listing container") + w.WriteHeader(http.StatusInternalServerError) + return + } + + for _, v := range res.Infos { + fmt.Println(v) + } - //log.Info().Msgf("hugo: bleve result: %+v", res) data := ` diff --git a/pkg/storage/utils/eosfs/eosfs.go b/pkg/storage/utils/eosfs/eosfs.go index f9cf55113eb..6055355b4f4 100644 --- a/pkg/storage/utils/eosfs/eosfs.go +++ b/pkg/storage/utils/eosfs/eosfs.go @@ -63,6 +63,7 @@ import ( const ( refTargetAttrKey = "reva.target" + lwShareAttrKey = "reva.lwshare" ) const ( @@ -1279,6 +1280,47 @@ func (fs *eosfs) ListFolder(ctx context.Context, ref *provider.Reference, mdKeys return nil, errors.Wrap(err, "eosfs: error resolving reference") } + u, err := getUser(ctx) + if err != nil { + return nil, errors.Wrap(err, "eosfs: no user in ctx") + } + // lightweight accounts don't have share folders, so we're passing an empty string as path + auth, err := fs.getUserAuth(ctx, u, "") + if err != nil { + return nil, err + } + + searchString := "" + finfos := []*provider.ResourceInfo{} + + for i, key := range mdKeys { + if key == "search" { + // Check that searchString not empty + searchString = mdKeys[i] + + eosFileInfos, err := fs.c.SearchDir(ctx, auth, searchString, p) + if err != nil { + return nil, errors.Wrap(err, "eosfs: error searching") + } + + for _, eosFileInfo := range eosFileInfos { + // filter out sys files + if !fs.conf.ShowHiddenSysFiles { + base := path.Base(eosFileInfo.File) + if hiddenReg.MatchString(base) { + continue + } + } + + if finfo, err := fs.convertToFileReference(ctx, eosFileInfo); err == nil { + finfos = append(finfos, finfo) + } + } + + return finfos, nil + } + } + if fs.conf.EnableHome { return fs.listWithHome(ctx, p) } @@ -1372,45 +1414,6 @@ func (fs *eosfs) listShareFolderRoot(ctx context.Context, p string) (finfos []*p return finfos, nil } -func (fs *eosfs) findFilesOnTree(ctx context.Context, ss string, p string) (finfos []*provider.ResourceInfo, err error) { - fn := fs.wrapShadow(ctx, p) - - u, err := getUser(ctx) - - if err != nil { - return nil, errors.Wrap(err, "eosfs: search: no user in ctx") - } - // lightweight accounts don't have share folders, so we're passing an empty string as path - auth, err := fs.getUserAuth(ctx, u, "") - if err != nil { - return nil, err - } - - log := appctx.GetLogger(ctx) - log.Info().Msgf("eosfs: search: user=%s path=%s searchString=%s", u, fn, ss) - - eosFileInfos, err := fs.c.SearchDir(ctx, auth, ss, fn) - if err != nil { - return nil, errors.Wrap(err, "eosfs: search: error listing") - } - - for _, eosFileInfo := range eosFileInfos { - // filter out sys files - if !fs.conf.ShowHiddenSysFiles { - base := path.Base(eosFileInfo.File) - if hiddenReg.MatchString(base) { - continue - } - } - - if finfo, err := fs.convertToFileReference(ctx, eosFileInfo); err == nil { - finfos = append(finfos, finfo) - } - } - - return finfos, nil -} - // CreateStorageSpace creates a storage space func (fs *eosfs) CreateStorageSpace(ctx context.Context, req *provider.CreateStorageSpaceRequest) (*provider.CreateStorageSpaceResponse, error) { return nil, fmt.Errorf("unimplemented: CreateStorageSpace")