diff --git a/changelog/unreleased/gateway-filter-invalid-references.md b/changelog/unreleased/gateway-filter-invalid-references.md new file mode 100644 index 00000000000..cd4ce50451b --- /dev/null +++ b/changelog/unreleased/gateway-filter-invalid-references.md @@ -0,0 +1,5 @@ +Bugfix: let the gateway filter invalid references + +We now filter deleted and unshared entries from the response when listing the shares folder of a user. + +https://github.com/cs3org/reva/pull/1274 \ No newline at end of file diff --git a/internal/grpc/services/gateway/storageprovider.go b/internal/grpc/services/gateway/storageprovider.go index c3ce9261993..aa44ba6f409 100644 --- a/internal/grpc/services/gateway/storageprovider.go +++ b/internal/grpc/services/gateway/storageprovider.go @@ -1623,29 +1623,33 @@ func (s *svc) listSharesFolder(ctx context.Context) (*provider.ListContainerResp Status: status.NewInternal(ctx, err, "gateway: error listing shared folder"), }, nil } - - for i, ref := range lcr.Infos { - info, protocol, err := s.checkRef(ctx, ref) + checkedInfos := make([]*provider.ResourceInfo, 0) + for i := range lcr.Infos { + info, protocol, err := s.checkRef(ctx, lcr.Infos[i]) if _, ok := err.(errtypes.IsNotFound); ok { // this might arise when the shared resource has been moved to the recycle bin continue + } else if _, ok := err.(errtypes.PermissionDenied); ok { + // this might arise when the resource was unshared, but the share reference was not removed + continue } else if err != nil { return &provider.ListContainerResponse{ - Status: status.NewInternal(ctx, err, "gateway: error resolving reference:"+ref.Path), + Status: status.NewInternal(ctx, err, "gateway: error resolving reference:"+lcr.Infos[i].Path), }, nil } if protocol == "webdav" { - info, err = s.webdavRefStat(ctx, ref.Target) + info, err = s.webdavRefStat(ctx, lcr.Infos[i].Target) if err != nil { // Might be the case that the webdav token has expired continue } } - info.Path = ref.GetPath() - lcr.Infos[i] = info + info.Path = lcr.Infos[i].GetPath() + checkedInfos = append(checkedInfos, info) } + lcr.Infos = checkedInfos return lcr, nil }