From fc9a2807d2a57ec97d0e1440e3f6b2bfc788ddb7 Mon Sep 17 00:00:00 2001 From: Hugo Gonzalez Labrador Date: Tue, 8 Nov 2022 15:24:10 +0100 Subject: [PATCH] Update stuff --- .../http/services/owncloud/ocdav/report.go | 138 ++++++++++-------- pkg/eosclient/eosbinary/eosbinary.go | 11 ++ 2 files changed, 91 insertions(+), 58 deletions(-) diff --git a/internal/http/services/owncloud/ocdav/report.go b/internal/http/services/owncloud/ocdav/report.go index 80ed804401c..4efd22b5571 100644 --- a/internal/http/services/owncloud/ocdav/report.go +++ b/internal/http/services/owncloud/ocdav/report.go @@ -21,6 +21,7 @@ package ocdav import ( "encoding/xml" "io" + "io/ioutil" "net/http" "strings" @@ -29,8 +30,6 @@ import ( providerv1beta1 "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" "github.com/cs3org/reva/pkg/appctx" ctxpkg "github.com/cs3org/reva/pkg/ctx" - - "github.com/blevesearch/bleve/v2" ) const ( @@ -43,26 +42,6 @@ func (s *svc) handleReport(w http.ResponseWriter, r *http.Request, ns string) { log := appctx.GetLogger(ctx) log.Info().Msgf("hugo: searching in path: %s", r.URL.Path) - index, 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 - } - - query := bleve.NewQueryStringQuery("mydoc") - 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 - } - - log.Info().Msgf("hugo: bleve result: %+v", res) - - // fn := path.Join(ns, r.URL.Path) - rep, status, err := readReport(r.Body) if err != nil { log.Error().Err(err).Msg("error reading report") @@ -87,13 +66,74 @@ func (s *svc) handleReport(w http.ResponseWriter, r *http.Request, ns string) { func (s *svc) doSearchFiles(w http.ResponseWriter, r *http.Request, sf *reportSearchFiles) { ctx := r.Context() log := appctx.GetLogger(ctx) - _, err := s.getClient() - if err != nil { - log.Error().Err(err).Msg("error getting grpc client") - w.WriteHeader(http.StatusInternalServerError) - return - } - w.WriteHeader(http.StatusNotImplemented) + + 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 + } + + 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 + } + */ + + //log.Info().Msgf("hugo: bleve result: %+v", res) + data := ` + + + + /remote.php/dav/spaces/1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51/asd.txt + + + 1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!d5613880-307c-4e3e-b56d-97839fcf6d03 + 1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!4c510ada-c86b-4815-8820-42cdf82c3d51 + asd.txt + 2022-11-08T10:45:16Z + text/plain + RDNVW + + + 0 + 0.4809828996658325 + + HTTP/1.1 200 OK + + + + /remote.php/dav/spaces/1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51/asdddddd + + + 1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!fa3c7a85-5fc4-46d3-a0b1-293a282da1b7 + 1284d238-aa92-42ce-bdc4-0b0000009157$4c510ada-c86b-4815-8820-42cdf82c3d51!4c510ada-c86b-4815-8820-42cdf82c3d51 + asdddddd + 2022-11-08T10:45:32Z + httpd/unix-directory + RDNVCK + + + + + 0 + 0.4809828996658325 + + HTTP/1.1 200 OK + + + +` + w.Write([]byte(data)) + w.WriteHeader(207) + return } func (s *svc) doFilterFiles(w http.ResponseWriter, r *http.Request, ff *reportFilterFiles, namespace string) { @@ -171,7 +211,7 @@ type reportSearchFiles struct { Search reportSearchFilesSearch `xml:"search"` } type reportSearchFilesSearch struct { - Pattern string `xml:"search"` + Pattern string `xml:"pattern"` Limit int `xml:"limit"` Offset int `xml:"offset"` } @@ -189,34 +229,16 @@ type reportFilterFilesRules struct { } func readReport(r io.Reader) (rep *report, status int, err error) { - decoder := xml.NewDecoder(r) - rep = &report{} - for { - t, err := decoder.Token() - if err == io.EOF { - // io.EOF is a successful end - return rep, 0, nil - } - if err != nil { - return nil, http.StatusBadRequest, err - } + content, err := ioutil.ReadAll(r) + if err != nil { + return nil, 0, err + } - if v, ok := t.(xml.StartElement); ok { - if v.Name.Local == elementNameSearchFiles { - var repSF reportSearchFiles - err = decoder.DecodeElement(&repSF, &v) - if err != nil { - return nil, http.StatusBadRequest, err - } - rep.SearchFiles = &repSF - } else if v.Name.Local == elementNameFilterFiles { - var repFF reportFilterFiles - err = decoder.DecodeElement(&repFF, &v) - if err != nil { - return nil, http.StatusBadRequest, err - } - rep.FilterFiles = &repFF - } - } + s := &reportSearchFiles{Search: reportSearchFilesSearch{}} + err = xml.Unmarshal(content, s) + if err != nil { + return nil, 0, err } + + return &report{SearchFiles: s}, 0, err } diff --git a/pkg/eosclient/eosbinary/eosbinary.go b/pkg/eosclient/eosbinary/eosbinary.go index 0f80ec55c66..a689e9869cf 100644 --- a/pkg/eosclient/eosbinary/eosbinary.go +++ b/pkg/eosclient/eosbinary/eosbinary.go @@ -742,6 +742,17 @@ func (c *Client) List(ctx context.Context, auth eosclient.Authorization, path st return c.parseFind(ctx, auth, path, stdout) } +// List the contents of the directory given by path infinity +// Use with care +func (c *Client) ListInfinity(ctx context.Context, auth eosclient.Authorization, path string) ([]*eosclient.FileInfo, error) { + args := []string{"find", "--fileinfo", path} + stdout, _, err := c.executeEOS(ctx, args, auth) + if err != nil { + return nil, errors.Wrapf(err, "eosclient: error listing fn=%s", path) + } + return c.parseFind(ctx, auth, path, stdout) +} + // Read reads a file from the mgm func (c *Client) Read(ctx context.Context, auth eosclient.Authorization, path string) (io.ReadCloser, error) { rand := "eosread-" + uuid.New().String()