Skip to content

Commit

Permalink
Merge pull request #8230 from kobergj/FixSearchPanic
Browse files Browse the repository at this point in the history
Cleanup `search.go`
  • Loading branch information
kobergj authored Jan 17, 2024
2 parents 903097e + b8b0d0b commit f56cf08
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/cleanup-search-searchgo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Cleanup `search/pkg/search/search.go`

Now uses proto getters to avoid panics.

https://github.com/owncloud/ocis/pull/8230
40 changes: 20 additions & 20 deletions services/search/pkg/search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func ResolveReference(ctx context.Context, ref *provider.Reference, ri *provider
}

gpRes, err := gatewayClient.GetPath(ctx, &provider.GetPathRequest{
ResourceId: ri.Id,
ResourceId: ri.GetId(),
})
if err != nil || gpRes.Status.Code != rpc.Code_CODE_OK {
if err != nil || gpRes.GetStatus().GetCode() != rpc.Code_CODE_OK {
return nil, err
}
return &provider.Reference{
Expand All @@ -43,7 +43,7 @@ func ResolveReference(ctx context.Context, ref *provider.Reference, ri *provider
SpaceId: ref.GetResourceId().GetSpaceId(),
OpaqueId: ref.GetResourceId().GetSpaceId(),
},
Path: utils.MakeRelativePath(gpRes.Path),
Path: utils.MakeRelativePath(gpRes.GetPath()),
}, nil
}

Expand All @@ -56,7 +56,7 @@ func (ma matchArray) Swap(i, j int) {
ma[i], ma[j] = ma[j], ma[i]
}
func (ma matchArray) Less(i, j int) bool {
return ma[i].Score > ma[j].Score
return ma[i].GetScore() > ma[j].GetScore()
}

func logDocCount(engine engine.Engine, logger log.Logger) {
Expand Down Expand Up @@ -88,7 +88,7 @@ func statResource(ctx context.Context, ref *provider.Reference, gatewaySelector
logger.Error().Err(err).Msg("failed to stat the moved resource")
return nil, err
}
switch res.Status.Code {
switch res.GetStatus().GetCode() {
case rpc.Code_CODE_OK:
return res, nil
case rpc.Code_CODE_NOT_FOUND:
Expand All @@ -111,34 +111,34 @@ func convertToWebDAVPermissions(isShared, isMountpoint, isDir bool, p *provider.
if isShared {
fmt.Fprintf(&b, "S")
}
if p.ListContainer &&
p.ListFileVersions &&
p.ListRecycle &&
p.Stat &&
p.GetPath &&
p.GetQuota &&
p.InitiateFileDownload {
if p.GetListContainer() &&
p.GetListFileVersions() &&
p.GetListRecycle() &&
p.GetStat() &&
p.GetGetPath() &&
p.GetGetQuota() &&
p.GetInitiateFileDownload() {
fmt.Fprintf(&b, "R")
}
if isMountpoint {
fmt.Fprintf(&b, "M")
}
if p.Delete {
if p.GetDelete() {
fmt.Fprintf(&b, "D")
}
if p.InitiateFileUpload &&
p.RestoreFileVersion &&
p.RestoreRecycleItem {
if p.GetInitiateFileUpload() &&
p.GetRestoreFileVersion() &&
p.GetRestoreRecycleItem() {
fmt.Fprintf(&b, "NV")
if !isDir {
fmt.Fprintf(&b, "W")
}
}
if isDir &&
p.ListContainer &&
p.Stat &&
p.CreateContainer &&
p.InitiateFileUpload {
p.GetListContainer() &&
p.GetStat() &&
p.GetCreateContainer() &&
p.GetInitiateFileUpload() {
fmt.Fprintf(&b, "CK")
}
return b.String()
Expand Down

0 comments on commit f56cf08

Please sign in to comment.