Skip to content

Commit

Permalink
new IsAbsolutePathReference check
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic committed Jul 8, 2021
1 parent ce7845b commit 7058dd1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,7 @@ func (s *svc) getPath(ctx context.Context, ref *provider.Reference, keys ...stri
return res.Info.Path, res.Status
}

if ref.ResourceId == nil && strings.HasPrefix(ref.Path, "/") {
if utils.IsAbsolutePathReference(ref) {
return ref.Path, &rpc.Status{Code: rpc.Code_CODE_OK}
}
return "", &rpc.Status{Code: rpc.Code_CODE_INTERNAL}
Expand Down
1 change: 0 additions & 1 deletion internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ func (s *service) InitiateFileDownload(ctx context.Context, req *provider.Initia
// For example, https://data-server.example.org/home/docs/myfile.txt
// or ownclouds://data-server.example.org/home/docs/myfile.txt
log := appctx.GetLogger(ctx)

u := *s.dataServerURL
log.Info().Str("data-server", u.String()).Interface("ref", req.Ref).Msg("file download")

Expand Down
6 changes: 6 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ func IsAbsoluteReference(ref *provider.Reference) bool {
return (ref.ResourceId != nil && ref.Path == "") || (ref.ResourceId == nil) && strings.HasPrefix(ref.Path, "/")
}

// IsAbsolutePathReference returns true if the given reference qualifies as a global path
// when only the path is set and starts with /
func IsAbsolutePathReference(ref *provider.Reference) bool {
return ref.ResourceId == nil && strings.HasPrefix(ref.Path, "/")
}

// MakeRelativePath prefixes the path with a . to use it in a relative reference
func MakeRelativePath(p string) string {
p = path.Join("/", p)
Expand Down

0 comments on commit 7058dd1

Please sign in to comment.