From 69bd21f2cc97433365e2285a09a953c7fa62b352 Mon Sep 17 00:00:00 2001 From: David Christofas Date: Fri, 30 Apr 2021 17:44:04 +0200 Subject: [PATCH] Fix public file shares (#1666) --- .../unreleased/fix-public-file-shares.md | 6 +++ .../publicstorageprovider.go | 40 ++++++++++++++----- .../services/owncloud/ocdav/publicfile.go | 3 -- 3 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 changelog/unreleased/fix-public-file-shares.md diff --git a/changelog/unreleased/fix-public-file-shares.md b/changelog/unreleased/fix-public-file-shares.md new file mode 100644 index 0000000000..8bd7924ead --- /dev/null +++ b/changelog/unreleased/fix-public-file-shares.md @@ -0,0 +1,6 @@ +Bugfix: Fix public file shares + +Fixed stat requests and propfind responses for publicly shared files. + +https://github.com/cs3org/reva/pull/1666 + diff --git a/internal/grpc/services/publicstorageprovider/publicstorageprovider.go b/internal/grpc/services/publicstorageprovider/publicstorageprovider.go index 66c3678027..b2a1e45b02 100644 --- a/internal/grpc/services/publicstorageprovider/publicstorageprovider.go +++ b/internal/grpc/services/publicstorageprovider/publicstorageprovider.go @@ -139,7 +139,7 @@ func (s *service) translatePublicRefToCS3Ref(ctx context.Context, ref *provider. return nil, "", nil, nil, err } - originalPath, ls, st, err := s.resolveToken(ctx, tkn) + originalPath, ls, _, st, err := s.resolveToken(ctx, tkn) switch { case err != nil: return nil, "", nil, nil, err @@ -452,7 +452,7 @@ func (s *service) Stat(ctx context.Context, req *provider.StatRequest) (*provide return nil, err } - originalPath, ls, st, err := s.resolveToken(ctx, tkn) + originalPath, ls, ri, st, err := s.resolveToken(ctx, tkn) switch { case err != nil: return nil, err @@ -466,12 +466,16 @@ func (s *service) Stat(ctx context.Context, req *provider.StatRequest) (*provide }, nil } + p := originalPath + if ri.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER { + p = path.Join("/", p, relativePath) + } var statResponse *provider.StatResponse // the call has to be made to the gateway instead of the storage. statResponse, err = s.gateway.Stat(ctx, &provider.StatRequest{ Ref: &provider.Reference{ Spec: &provider.Reference_Path{ - Path: path.Join("/", originalPath, relativePath), + Path: p, }, }, }) @@ -518,7 +522,7 @@ func (s *service) ListContainer(ctx context.Context, req *provider.ListContainer return nil, err } - pathFromToken, ls, st, err := s.resolveToken(ctx, tkn) + pathFromToken, ls, _, st, err := s.resolveToken(ctx, tkn) switch { case err != nil: return nil, err @@ -668,10 +672,10 @@ func (s *service) trimMountPrefix(fn string) (string, error) { } // resolveToken returns the path and share for the publicly shared resource. -func (s *service) resolveToken(ctx context.Context, token string) (string, *link.PublicShare, *rpc.Status, error) { +func (s *service) resolveToken(ctx context.Context, token string) (string, *link.PublicShare, *provider.ResourceInfo, *rpc.Status, error) { driver, err := pool.GetGatewayServiceClient(s.conf.GatewayAddr) if err != nil { - return "", nil, nil, err + return "", nil, nil, nil, err } publicShareResponse, err := driver.GetPublicShare( @@ -687,9 +691,9 @@ func (s *service) resolveToken(ctx context.Context, token string) (string, *link ) switch { case err != nil: - return "", nil, nil, err + return "", nil, nil, nil, err case publicShareResponse.Status.Code != rpc.Code_CODE_OK: - return "", nil, publicShareResponse.Status, nil + return "", nil, nil, publicShareResponse.Status, nil } pathRes, err := s.gateway.GetPath(ctx, &provider.GetPathRequest{ @@ -697,9 +701,23 @@ func (s *service) resolveToken(ctx context.Context, token string) (string, *link }) switch { case err != nil: - return "", nil, nil, err + return "", nil, nil, nil, err case pathRes.Status.Code != rpc.Code_CODE_OK: - return "", nil, pathRes.Status, nil + return "", nil, nil, pathRes.Status, nil + } + + sRes, err := s.gateway.Stat(ctx, &provider.StatRequest{ + Ref: &provider.Reference{ + Spec: &provider.Reference_Id{ + Id: publicShareResponse.GetShare().GetResourceId(), + }, + }, + }) + switch { + case err != nil: + return "", nil, nil, nil, err + case sRes.Status.Code != rpc.Code_CODE_OK: + return "", nil, nil, sRes.Status, nil } - return pathRes.Path, publicShareResponse.GetShare(), nil, nil + return pathRes.Path, publicShareResponse.GetShare(), sRes.Info, nil, nil } diff --git a/internal/http/services/owncloud/ocdav/publicfile.go b/internal/http/services/owncloud/ocdav/publicfile.go index a87e84c8da..c5670014f0 100644 --- a/internal/http/services/owncloud/ocdav/publicfile.go +++ b/internal/http/services/owncloud/ocdav/publicfile.go @@ -231,9 +231,6 @@ func (s *svc) getPublicFileInfos(onContainer, onlyRoot bool, i *provider.Resourc } } - // link share only appears on root collection - delete(i.Opaque.Map, "link-share") - // add the file info infos = append(infos, i)