Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix public file shares #1666

Merged
merged 2 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/fix-public-file-shares.md
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
},
},
})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -687,19 +691,33 @@ 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{
ResourceId: publicShareResponse.GetShare().GetResourceId(),
})
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
}
3 changes: 0 additions & 3 deletions internal/http/services/owncloud/ocdav/publicfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down