From 0f61578a0b98365268c03bbf504dedc0c1b9fbd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 7 Jan 2022 14:30:32 +0000 Subject: [PATCH] handle space does not exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- .../edge-handle-spaces-does-not-exist-case.md | 5 +++++ internal/http/services/owncloud/ocdav/spaces.go | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 changelog/unreleased/edge-handle-spaces-does-not-exist-case.md diff --git a/changelog/unreleased/edge-handle-spaces-does-not-exist-case.md b/changelog/unreleased/edge-handle-spaces-does-not-exist-case.md new file mode 100644 index 0000000000..8b185f4774 --- /dev/null +++ b/changelog/unreleased/edge-handle-spaces-does-not-exist-case.md @@ -0,0 +1,5 @@ +Bugfix: handle non existing spaces correctly + +When looking up a space by id we returned the wrong status code. + +https://github.com/cs3org/reva/pull/2422 \ No newline at end of file diff --git a/internal/http/services/owncloud/ocdav/spaces.go b/internal/http/services/owncloud/ocdav/spaces.go index 7695cf33b3..2f6276bcfb 100644 --- a/internal/http/services/owncloud/ocdav/spaces.go +++ b/internal/http/services/owncloud/ocdav/spaces.go @@ -202,15 +202,18 @@ func (s *svc) lookUpStorageSpaceByID(ctx context.Context, spaceID string) (*stor return nil, lSSRes.Status, err } - if len(lSSRes.StorageSpaces) != 1 { + switch len(lSSRes.StorageSpaces) { + case 0: + return nil, &rpc.Status{Code: rpc.Code_CODE_NOT_FOUND}, nil // since the caller only expects a single space return not found status + case 1: + return lSSRes.StorageSpaces[0], lSSRes.Status, nil + default: return nil, nil, fmt.Errorf("unexpected number of spaces %d", len(lSSRes.StorageSpaces)) } - return lSSRes.StorageSpaces[0], lSSRes.Status, nil - } func (s *svc) lookUpStorageSpaceReference(ctx context.Context, spaceID string, relativePath string, spacesDavRequest bool) (*storageProvider.Reference, *rpc.Status, error) { space, status, err := s.lookUpStorageSpaceByID(ctx, spaceID) - if err != nil { + if space == nil { return nil, status, err } return makeRelativeReference(space, relativePath, spacesDavRequest), status, err