Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
search: add searchString from opaque to the mdKeys on ListFolder()
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuAlfageme committed Nov 24, 2022
1 parent 97afb61 commit 327ab51
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,9 +940,9 @@ func (s *service) ListContainer(ctx context.Context, req *provider.ListContainer
}, nil
}

// Hack to enable search
// Ugly hack to enable search
if req.Opaque.Map["search"] != nil {
s.storage.ListFolder(ctx, newRef, []string{"search"})
s.storage.ListFolder(ctx, newRef, []string{"search", string(req.Opaque.Map["searchString"].GetValue())})
}

mds, err := s.storage.ListFolder(ctx, newRef, req.ArbitraryMetadataKeys)
Expand Down
8 changes: 6 additions & 2 deletions internal/http/services/owncloud/ocdav/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (s *svc) handleReport(w http.ResponseWriter, r *http.Request, ns string) {
ctx := r.Context()
log := appctx.GetLogger(ctx)

// TODO(salfagem): catch empty request body
rep, status, err := readReport(r.Body)
if err != nil {
log.Error().Err(err).Msg("error reading report")
Expand All @@ -62,8 +63,6 @@ func (s *svc) handleReport(w http.ResponseWriter, r *http.Request, ns string) {
return
}

// TODO(jfd): implement report

w.WriteHeader(http.StatusNotImplemented)
}

Expand All @@ -85,8 +84,13 @@ func (s *svc) doSearchFiles(w http.ResponseWriter, r *http.Request, sf *reportSe
Decoder: "plain",
Value: []byte("search"),
},
"searchString": {
Decoder: "plain",
Value: []byte(sf.Search.Pattern),
},
}

// TODO(salfagem): hardcoded path for the time being:
ref := &provider.Reference{Path: "/eos/project/c/cernbox"}

req := &provider.ListContainerRequest{Opaque: &typespb.Opaque{
Expand Down
7 changes: 6 additions & 1 deletion pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,14 +745,19 @@ func (c *Client) List(ctx context.Context, auth eosclient.Authorization, path st

// List the contents of the directory given by path with depth infinity
func (c *Client) SearchDir(ctx context.Context, auth eosclient.Authorization, searchString string, path string) ([]*eosclient.FileInfo, error) {
args := []string{"find", "--fileinfo", "--name", searchString, path}
// TODO(salfagem): path is truncated - i.e. /c/cernbox (not absolute)
args := []string{"find", "--fileinfo", "-name", searchString, path}
log := appctx.GetLogger(ctx)
log.Debug().Msgf("eosbinary search with args: %s", args)
// Safeguard #2 to prevent the search to go to undesired places:
if !strings.HasPrefix(path, "/eos/project/c/cernbox") {
log.Debug().Msgf("eosbinary - prefix doesn't match")
return nil, errors.Errorf("eosclient: search path out of bounds fn=%s", path)
}
// For the moment, just file names are supported, no paths (and no parentheses, braquets...)
searchStringMatch, _ := regexp.MatchString(`^[\w\d\s\*\-\.]+$`, searchString)
if !searchStringMatch {
log.Debug().Msgf("eosbinary - searchstring is not valid")
return nil, errors.Errorf("eosclient: ilegal search string: %s", searchString)
}
// TODO: set a timeout for the find in case it goes out of hand
Expand Down
13 changes: 10 additions & 3 deletions pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ import (

const (
refTargetAttrKey = "reva.target"
lwShareAttrKey = "reva.lwshare"
)

const (
Expand Down Expand Up @@ -1275,11 +1274,16 @@ func (fs *eosfs) getMDShareFolder(ctx context.Context, p string, mdKeys []string
}

func (fs *eosfs) ListFolder(ctx context.Context, ref *provider.Reference, mdKeys []string) ([]*provider.ResourceInfo, error) {
log := appctx.GetLogger(ctx)

p, err := fs.resolve(ctx, ref)

if err != nil {
return nil, errors.Wrap(err, "eosfs: error resolving reference")
}

p = fs.wrap(ctx, p)

u, err := getUser(ctx)
if err != nil {
return nil, errors.Wrap(err, "eosfs: no user in ctx")
Expand All @@ -1295,8 +1299,11 @@ func (fs *eosfs) ListFolder(ctx context.Context, ref *provider.Reference, mdKeys

for i, key := range mdKeys {
if key == "search" {
// Check that searchString not empty
searchString = mdKeys[i]
// TODO(salfagem): Ugly hack due to mdKeys being an array.
// - also check that searchString not empty:
searchString = mdKeys[i+1]

log.Info().Msgf("eosfs: running search: path=%s searchString=%s", p, searchString)

eosFileInfos, err := fs.c.SearchDir(ctx, auth, searchString, p)
if err != nil {
Expand Down

0 comments on commit 327ab51

Please sign in to comment.