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

Commit

Permalink
search: log stderr from 'eos find' and replace mock response
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuAlfageme committed Feb 8, 2023
1 parent d8a4e55 commit 79bfa5d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
14 changes: 7 additions & 7 deletions internal/http/services/owncloud/ocdav/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
ctxpkg "github.com/cs3org/reva/pkg/ctx"
)
Expand All @@ -49,7 +49,7 @@ func (s *svc) handleReport(w http.ResponseWriter, r *http.Request, ns string) {
return
}

log.Info().Msgf("hugo: searching in path: %s with pattern: %s", r.URL.Path, rep.SearchFiles.Search.Pattern)
log.Info().Msgf("searching in path: %s with pattern: %s", r.URL.Path, rep.SearchFiles.Search.Pattern)

if rep.SearchFiles != nil {
s.doSearchFiles(w, r, rep.SearchFiles)
Expand All @@ -68,7 +68,7 @@ func (s *svc) doSearchFiles(w http.ResponseWriter, r *http.Request, sf *reportSe
ctx := r.Context()
log := appctx.GetLogger(ctx)

log.Info().Msgf("hugo: search is: %+v", sf)
log.Info().Msgf("search is: %+v", sf)

client, err := s.getClient()
if err != nil {
Expand All @@ -77,7 +77,7 @@ func (s *svc) doSearchFiles(w http.ResponseWriter, r *http.Request, sf *reportSe
return
}

opaqueMap := map[string]*typespb.OpaqueEntry{
opaqueMap := map[string]*types.OpaqueEntry{
"search": {
Decoder: "plain",
Value: []byte("search"),
Expand All @@ -88,10 +88,10 @@ func (s *svc) doSearchFiles(w http.ResponseWriter, r *http.Request, sf *reportSe
},
}

// TODO(salfagem): hardcoded path for the time being:
ref := &provider.Reference{Path: "/eos/project/t/test"}
// TODO(salfagem): hardcoded path for the time being, enable a list:
ref := &provider.Reference{Path: "/eos/project/a/awesomeproject"}

req := &provider.ListContainerRequest{Opaque: &typespb.Opaque{
req := &provider.ListContainerRequest{Opaque: &types.Opaque{
Map: opaqueMap,
}, Ref: ref}

Expand Down
15 changes: 8 additions & 7 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,11 +720,11 @@ 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) {
// TODO(salfagem): path is truncated - i.e. /c/cernbox (not absolute)
args := []string{"newfind", "--fileinfo", "--name", searchString, path}
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/t/test") {
if !strings.HasPrefix(path, "/eos/project/a/awesomeproject") {
log.Debug().Msgf("eosbinary - prefix doesn't match")
return nil, errors.Errorf("eosclient: search path out of bounds fn=%s", path)
}
Expand All @@ -735,18 +735,19 @@ func (c *Client) SearchDir(ctx context.Context, auth eosclient.Authorization, se
return nil, errors.Errorf("eosclient: ilegal search string: %s", searchString)
}
// TODO: set a timeout for the find in case it goes out of hand
stdout, _, err := c.executeEOS(ctx, args, auth)
stdout, stderr, err := c.executeEOS(ctx, args, auth)
if err != nil {
switch err.(type) {
case errtypes.NotFound, errtypes.PermissionDenied:
// Errcode 7: "TOOBIG"
case errtypes.IsNotFound, errtypes.IsPermissionDenied:
log.Debug().Msgf("eosbinary - user had insufficient permissions to search part of the directory")
default:
log.Error().Msgf("ERRROR LISTING= %s", stdout)
// There will be errors:
//return nil, errors.Wrapf(err, "eosclient: error listing fn=%s", path)
// There will be errors; we cannot ignore them:
return nil, errors.Wrapf(err, "eosclient: error listing fn=%s", path)
}
}
log.Debug().Msgf("eos find stdout= %s", stdout)
log.Debug().Msgf("=========== eos find stderr =========== %s", stderr)
return c.parseFind(ctx, auth, path, stdout)
}

Expand Down

0 comments on commit 79bfa5d

Please sign in to comment.