diff --git a/changelog/unreleased/change-references.md b/changelog/unreleased/change-references.md
new file mode 100644
index 0000000000..8013fad047
--- /dev/null
+++ b/changelog/unreleased/change-references.md
@@ -0,0 +1,8 @@
+Change: absolute and relative references
+
+We unified the `Reference_Id` end `Reference_Path` types to a combined `Reference` that contains both:
+- a `resource_id` property that can identify a node using a `storage_id` and an `opaque_id`
+- a `path` property that can be used to represent absolute paths as well as paths relative to the id based properties.
+While this is a breaking change it allows passing both: absolute as well as relative references.
+
+https://github.com/cs3org/reva/pull/1721
\ No newline at end of file
diff --git a/cmd/reva/app-tokens-create.go b/cmd/reva/app-tokens-create.go
index f23295f5e7..9b5a0d46f7 100644
--- a/cmd/reva/app-tokens-create.go
+++ b/cmd/reva/app-tokens-create.go
@@ -213,13 +213,7 @@ func getPathScope(ctx context.Context, client gateway.GatewayAPIClient, path, pe
return nil, err
}
- statResponse, err := client.Stat(ctx, &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: path,
- },
- },
- })
+ statResponse, err := client.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{Path: path}})
if err != nil {
return nil, err
diff --git a/cmd/reva/download.go b/cmd/reva/download.go
index 53b38a098b..7dcb383a2c 100644
--- a/cmd/reva/download.go
+++ b/cmd/reva/download.go
@@ -55,9 +55,7 @@ func downloadCommand() *command {
return err
}
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{Path: remote},
- }
+ ref := &provider.Reference{Path: remote}
req1 := &provider.StatRequest{Ref: ref}
ctx := getAuthContext()
res1, err := client.Stat(ctx, req1)
@@ -71,11 +69,7 @@ func downloadCommand() *command {
info := res1.Info
req2 := &provider.InitiateFileDownloadRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: remote,
- },
- },
+ Ref: &provider.Reference{Path: remote},
}
res, err := client.InitiateFileDownload(ctx, req2)
if err != nil {
diff --git a/cmd/reva/ls.go b/cmd/reva/ls.go
index fa93fd9517..d2201058ae 100644
--- a/cmd/reva/ls.go
+++ b/cmd/reva/ls.go
@@ -51,9 +51,7 @@ func lsCommand() *command {
return err
}
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{Path: fn},
- }
+ ref := &provider.Reference{Path: fn}
req := &provider.ListContainerRequest{Ref: ref}
ctx := getAuthContext()
diff --git a/cmd/reva/mkdir.go b/cmd/reva/mkdir.go
index d98b474319..c81e7560d6 100644
--- a/cmd/reva/mkdir.go
+++ b/cmd/reva/mkdir.go
@@ -43,9 +43,7 @@ func mkdirCommand() *command {
return err
}
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{Path: fn},
- }
+ ref := &provider.Reference{Path: fn}
req := &provider.CreateContainerRequest{Ref: ref}
res, err := client.CreateContainer(ctx, req)
if err != nil {
diff --git a/cmd/reva/mv.go b/cmd/reva/mv.go
index bacb13aeb6..72a9bd09ef 100644
--- a/cmd/reva/mv.go
+++ b/cmd/reva/mv.go
@@ -44,12 +44,8 @@ func moveCommand() *command {
return err
}
- sourceRef := &provider.Reference{
- Spec: &provider.Reference_Path{Path: src},
- }
- targetRef := &provider.Reference{
- Spec: &provider.Reference_Path{Path: dst},
- }
+ sourceRef := &provider.Reference{Path: src}
+ targetRef := &provider.Reference{Path: dst}
req := &provider.MoveRequest{Source: sourceRef, Destination: targetRef}
res, err := client.Move(ctx, req)
if err != nil {
diff --git a/cmd/reva/ocm-share-create.go b/cmd/reva/ocm-share-create.go
index aa83d57857..3ec838fef8 100644
--- a/cmd/reva/ocm-share-create.go
+++ b/cmd/reva/ocm-share-create.go
@@ -87,9 +87,7 @@ func ocmShareCreateCommand() *command {
return formatError(remoteUserRes.Status)
}
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{Path: fn},
- }
+ ref := &provider.Reference{Path: fn}
req := &provider.StatRequest{Ref: ref}
res, err := client.Stat(ctx, req)
if err != nil {
diff --git a/cmd/reva/open-file-in-app-provider.go b/cmd/reva/open-file-in-app-provider.go
index 7be45c9dcf..aee37ea492 100644
--- a/cmd/reva/open-file-in-app-provider.go
+++ b/cmd/reva/open-file-in-app-provider.go
@@ -59,9 +59,7 @@ func openFileInAppProviderCommand() *command {
return err
}
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{Path: path},
- }
+ ref := &provider.Reference{Path: path}
opaqueObj := &typespb.Opaque{
Map: map[string]*typespb.OpaqueEntry{},
diff --git a/cmd/reva/open-in-app.go b/cmd/reva/open-in-app.go
index 46451bc20d..7a6712dd39 100644
--- a/cmd/reva/open-in-app.go
+++ b/cmd/reva/open-in-app.go
@@ -62,7 +62,7 @@ func openInAppCommand() *command {
}
ref := &provider.Reference{
- Spec: &provider.Reference_Path{Path: path},
+ Path: path,
}
opaqueObj := &typespb.Opaque{
diff --git a/cmd/reva/public-share-create.go b/cmd/reva/public-share-create.go
index b50af172a5..f22eac189b 100644
--- a/cmd/reva/public-share-create.go
+++ b/cmd/reva/public-share-create.go
@@ -53,9 +53,7 @@ func publicShareCreateCommand() *command {
return err
}
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{Path: fn},
- }
+ ref := &provider.Reference{Path: fn}
req := &provider.StatRequest{Ref: ref}
res, err := client.Stat(ctx, req)
diff --git a/cmd/reva/recycle-list.go b/cmd/reva/recycle-list.go
index 649ae48dc2..6fd9f256f5 100644
--- a/cmd/reva/recycle-list.go
+++ b/cmd/reva/recycle-list.go
@@ -47,9 +47,7 @@ func recycleListCommand() *command {
req := &gateway.ListRecycleRequest{
Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: getHomeRes.Path,
- },
+ Path: getHomeRes.Path,
},
}
res, err := client.ListRecycle(ctx, req)
diff --git a/cmd/reva/recycle-purge.go b/cmd/reva/recycle-purge.go
index d33e43553f..88e9585294 100644
--- a/cmd/reva/recycle-purge.go
+++ b/cmd/reva/recycle-purge.go
@@ -46,9 +46,7 @@ func recyclePurgeCommand() *command {
req := &gateway.PurgeRecycleRequest{
Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: getHomeRes.Path,
- },
+ Path: getHomeRes.Path,
},
}
diff --git a/cmd/reva/recycle-restore.go b/cmd/reva/recycle-restore.go
index 5915b21387..a081251053 100644
--- a/cmd/reva/recycle-restore.go
+++ b/cmd/reva/recycle-restore.go
@@ -52,9 +52,7 @@ func recycleRestoreCommand() *command {
req := &provider.RestoreRecycleItemRequest{
Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: getHomeRes.Path,
- },
+ Path: getHomeRes.Path,
},
Key: key,
}
diff --git a/cmd/reva/rm.go b/cmd/reva/rm.go
index b596e745d0..d992564528 100644
--- a/cmd/reva/rm.go
+++ b/cmd/reva/rm.go
@@ -42,9 +42,7 @@ func rmCommand() *command {
return err
}
- ref := &storageproviderv1beta1pb.Reference{
- Spec: &storageproviderv1beta1pb.Reference_Path{Path: fn},
- }
+ ref := &storageproviderv1beta1pb.Reference{Path: fn}
req := &storageproviderv1beta1pb.DeleteRequest{Ref: ref}
res, err := client.Delete(ctx, req)
if err != nil {
diff --git a/cmd/reva/share-create.go b/cmd/reva/share-create.go
index 77194f07ab..1513569cef 100644
--- a/cmd/reva/share-create.go
+++ b/cmd/reva/share-create.go
@@ -63,10 +63,7 @@ func shareCreateCommand() *command {
return err
}
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{Path: fn},
- }
-
+ ref := &provider.Reference{Path: fn}
req := &provider.StatRequest{Ref: ref}
res, err := client.Stat(ctx, req)
if err != nil {
diff --git a/cmd/reva/stat.go b/cmd/reva/stat.go
index 29147038cd..c84cba9a0f 100644
--- a/cmd/reva/stat.go
+++ b/cmd/reva/stat.go
@@ -44,9 +44,7 @@ func statCommand() *command {
return err
}
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{Path: fn},
- }
+ ref := &provider.Reference{Path: fn}
req := &provider.StatRequest{Ref: ref}
res, err := client.Stat(ctx, req)
if err != nil {
diff --git a/cmd/reva/transfer-create.go b/cmd/reva/transfer-create.go
index 308c1b5438..f72d49c336 100644
--- a/cmd/reva/transfer-create.go
+++ b/cmd/reva/transfer-create.go
@@ -78,11 +78,7 @@ func transferCreateCommand() *command {
// verify resource stats
statReq := &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: fn,
- },
- },
+ Ref: &provider.Reference{Path: fn},
}
statRes, err := client.Stat(ctx, statReq)
if err != nil {
diff --git a/cmd/reva/upload.go b/cmd/reva/upload.go
index 56ca5d8db4..f9c969aba6 100644
--- a/cmd/reva/upload.go
+++ b/cmd/reva/upload.go
@@ -92,11 +92,7 @@ func uploadCommand() *command {
}
req := &provider.InitiateFileUploadRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: target,
- },
- },
+ Ref: &provider.Reference{Path: target},
Opaque: &typespb.Opaque{
Map: map[string]*typespb.OpaqueEntry{
"Upload-Length": {
@@ -212,11 +208,7 @@ func uploadCommand() *command {
}
req2 := &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: target,
- },
- },
+ Ref: &provider.Reference{Path: target},
}
res2, err := gwc.Stat(ctx, req2)
if err != nil {
diff --git a/go.mod b/go.mod
index 47f2d2983b..aaccd4d28c 100644
--- a/go.mod
+++ b/go.mod
@@ -15,7 +15,7 @@ require (
github.com/cheggaaa/pb v1.0.29
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e
- github.com/cs3org/go-cs3apis v0.0.0-20210527092509-2b828e94ed4c
+ github.com/cs3org/go-cs3apis v0.0.0-20210614143420-5ee2eb1e7887
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/eventials/go-tus v0.0.0-20200718001131-45c7ec8f5d59
github.com/gdexlab/go-render v1.0.1
diff --git a/go.sum b/go.sum
index 5392d0bbcf..3dc551b4a9 100644
--- a/go.sum
+++ b/go.sum
@@ -151,8 +151,8 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e h1:tqSPWQeueWTKnJVMJffz4pz0o1WuQxJ28+5x5JgaHD8=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
-github.com/cs3org/go-cs3apis v0.0.0-20210527092509-2b828e94ed4c h1:EaKDtDswzfWUr70xoN63sPLZyvdinkmXrjqc5AFhVZE=
-github.com/cs3org/go-cs3apis v0.0.0-20210527092509-2b828e94ed4c/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
+github.com/cs3org/go-cs3apis v0.0.0-20210614143420-5ee2eb1e7887 h1:X5Se3M/kbh9w6LZQvyLS7djAGKcWGzmaY6IOa7Talpk=
+github.com/cs3org/go-cs3apis v0.0.0-20210614143420-5ee2eb1e7887/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cucumber/godog v0.8.1/go.mod h1:vSh3r/lM+psC1BPXvdkSEuNjmXfpVqrMGYAElF6hxnA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
diff --git a/internal/grpc/interceptors/auth/auth.go b/internal/grpc/interceptors/auth/auth.go
index a611023c56..b7618b4686 100644
--- a/internal/grpc/interceptors/auth/auth.go
+++ b/internal/grpc/interceptors/auth/auth.go
@@ -263,7 +263,7 @@ func dismantleToken(ctx context.Context, tkn string, req interface{}, mgr token.
// has access to it.
statReq := &provider.StatRequest{
Ref: &provider.Reference{
- Spec: &provider.Reference_Id{Id: share.ResourceId},
+ ResourceId: share.ResourceId,
},
}
@@ -280,7 +280,7 @@ func dismantleToken(ctx context.Context, tkn string, req interface{}, mgr token.
}
}
- return nil, err
+ return nil, errtypes.PermissionDenied("access token has invalid scope")
}
func extractRef(req interface{}) (*provider.Reference, bool) {
diff --git a/internal/grpc/services/gateway/appprovider.go b/internal/grpc/services/gateway/appprovider.go
index 74297b4b9c..f7921c9520 100644
--- a/internal/grpc/services/gateway/appprovider.go
+++ b/internal/grpc/services/gateway/appprovider.go
@@ -67,11 +67,7 @@ func (s *svc) OpenInApp(ctx context.Context, req *gateway.OpenInAppRequest) (*pr
}
statRes, err := s.stat(ctx, &storageprovider.StatRequest{
- Ref: &storageprovider.Reference{
- Spec: &storageprovider.Reference_Path{
- Path: resName,
- },
- },
+ Ref: &storageprovider.Reference{Path: resName},
})
if err != nil {
return &providerpb.OpenInAppResponse{
@@ -136,11 +132,7 @@ func (s *svc) openFederatedShares(ctx context.Context, targetURL string, vm gate
return nil, err
}
- ref := &storageprovider.Reference{
- Spec: &storageprovider.Reference_Path{
- Path: ep.filePath,
- },
- }
+ ref := &storageprovider.Reference{Path: ep.filePath}
appProviderReq := &gateway.OpenInAppRequest{
Ref: ref,
ViewMode: vm,
diff --git a/internal/grpc/services/gateway/ocmshareprovider.go b/internal/grpc/services/gateway/ocmshareprovider.go
index 872009d9c1..d1d686a846 100644
--- a/internal/grpc/services/gateway/ocmshareprovider.go
+++ b/internal/grpc/services/gateway/ocmshareprovider.go
@@ -318,9 +318,7 @@ func (s *svc) createOCMReference(ctx context.Context, share *ocm.Share) (*rpc.St
if share.ShareType == ocm.Share_SHARE_TYPE_TRANSFER {
createTransferDir, err := s.CreateContainer(ctx, &provider.CreateContainerRequest{
Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: path.Join(homeRes.Path, s.c.DataTransfersFolder),
- },
+ Path: path.Join(homeRes.Path, s.c.DataTransfersFolder),
},
})
if err != nil {
@@ -345,7 +343,7 @@ func (s *svc) createOCMReference(ctx context.Context, share *ocm.Share) (*rpc.St
log.Info().Msg("mount path will be:" + refPath)
createRefReq := &provider.CreateReferenceRequest{
- Path: refPath,
+ Ref: &provider.Reference{Path: refPath},
TargetUri: targetURI,
}
diff --git a/internal/grpc/services/gateway/storageprovider.go b/internal/grpc/services/gateway/storageprovider.go
index 90a5a04272..466bb7f303 100644
--- a/internal/grpc/services/gateway/storageprovider.go
+++ b/internal/grpc/services/gateway/storageprovider.go
@@ -122,9 +122,16 @@ func (s *svc) ListStorageSpaces(ctx context.Context, req *provider.ListStorageSp
id = f.GetId()
}
}
- c, err := s.findByID(ctx, &provider.ResourceId{
- OpaqueId: id.OpaqueId,
- })
+ parts := strings.SplitN(id.OpaqueId, "!", 2)
+ if len(parts) != 2 {
+ return &provider.ListStorageSpacesResponse{
+ Status: status.NewInvalidArg(ctx, "space id must be separated by !"),
+ }, nil
+ }
+ c, err := s.find(ctx, &provider.Reference{ResourceId: &provider.ResourceId{
+ StorageId: parts[0], // FIXME REFERENCE the StorageSpaceId is a storageid + a opaqueid
+ OpaqueId: parts[1],
+ }})
if err != nil {
return &provider.ListStorageSpacesResponse{
Status: status.NewStatusFromErrType(ctx, "error finding path", err),
@@ -144,7 +151,7 @@ func (s *svc) ListStorageSpaces(ctx context.Context, req *provider.ListStorageSp
func (s *svc) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) {
log := appctx.GetLogger(ctx)
// TODO: needs to be fixed
- c, err := s.findByID(ctx, req.StorageSpace.Root)
+ c, err := s.find(ctx, &provider.Reference{ResourceId: req.StorageSpace.Root})
if err != nil {
return &provider.UpdateStorageSpaceResponse{
Status: status.NewStatusFromErrType(ctx, "error finding ID", err),
@@ -164,9 +171,16 @@ func (s *svc) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorag
func (s *svc) DeleteStorageSpace(ctx context.Context, req *provider.DeleteStorageSpaceRequest) (*provider.DeleteStorageSpaceResponse, error) {
log := appctx.GetLogger(ctx)
// TODO: needs to be fixed
- c, err := s.findByID(ctx, &provider.ResourceId{
- OpaqueId: req.Id.OpaqueId,
- })
+ parts := strings.SplitN(req.Id.OpaqueId, "!", 2)
+ if len(parts) != 2 {
+ return &provider.DeleteStorageSpaceResponse{
+ Status: status.NewInvalidArg(ctx, "space id must be separated by !"),
+ }, nil
+ }
+ c, err := s.find(ctx, &provider.Reference{ResourceId: &provider.ResourceId{
+ StorageId: parts[0], // FIXME REFERENCE the StorageSpaceId is a storageid + a opaqueid
+ OpaqueId: parts[1],
+ }})
if err != nil {
return &provider.DeleteStorageSpaceResponse{
Status: status.NewStatusFromErrType(ctx, "error finding path", err),
@@ -282,12 +296,8 @@ func (s *svc) InitiateFileDownload(ctx context.Context, req *provider.InitiateFi
// if it is a file allow download
if ri.Type == provider.ResourceType_RESOURCE_TYPE_FILE {
log.Debug().Str("path", p).Interface("ri", ri).Msg("path points to share name file")
- req.Ref = &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: ri.Path,
- },
- }
- log.Debug().Msg("download path: " + ri.Path)
+ req.Ref.Path = ri.Path
+ log.Debug().Str("path", ri.Path).Msg("download")
return s.initiateFileDownload(ctx, req)
}
@@ -304,11 +314,7 @@ func (s *svc) InitiateFileDownload(ctx context.Context, req *provider.InitiateFi
shareName, shareChild := s.splitShare(ctx, p)
statReq := &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: shareName,
- },
- },
+ Ref: &provider.Reference{Path: shareName},
}
statRes, err := s.stat(ctx, statReq)
if err != nil {
@@ -352,13 +358,8 @@ func (s *svc) InitiateFileDownload(ctx context.Context, req *provider.InitiateFi
}
// append child to target
- target := path.Join(ri.Path, shareChild)
- req.Ref = &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: target,
- },
- }
- log.Debug().Msg("download path: " + target)
+ req.Ref.Path = path.Join(ri.Path, shareChild)
+ log.Debug().Str("path", req.Ref.Path).Msg("download")
return s.initiateFileDownload(ctx, req)
}
@@ -494,12 +495,8 @@ func (s *svc) InitiateFileUpload(ctx context.Context, req *provider.InitiateFile
// if it is a file allow upload
if ri.Type == provider.ResourceType_RESOURCE_TYPE_FILE {
log.Debug().Str("path", p).Interface("ri", ri).Msg("path points to share name file")
- req.Ref = &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: ri.Path,
- },
- }
- log.Debug().Msg("upload path: " + ri.Path)
+ req.Ref.Path = ri.Path
+ log.Debug().Str("path", ri.Path).Msg("upload")
return s.initiateFileUpload(ctx, req)
}
@@ -515,13 +512,7 @@ func (s *svc) InitiateFileUpload(ctx context.Context, req *provider.InitiateFile
log.Debug().Msgf("shared child: %s", p)
shareName, shareChild := s.splitShare(ctx, p)
- statReq := &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: shareName,
- },
- },
- }
+ statReq := &provider.StatRequest{Ref: &provider.Reference{Path: shareName}}
statRes, err := s.stat(ctx, statReq)
if err != nil {
return &gateway.InitiateFileUploadResponse{
@@ -564,12 +555,7 @@ func (s *svc) InitiateFileUpload(ctx context.Context, req *provider.InitiateFile
}
// append child to target
- target := path.Join(ri.Path, shareChild)
- req.Ref = &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: target,
- },
- }
+ req.Ref.Path = path.Join(ri.Path, shareChild)
return s.initiateFileUpload(ctx, req)
}
@@ -635,13 +621,7 @@ func (s *svc) initiateFileUpload(ctx context.Context, req *provider.InitiateFile
}
func (s *svc) GetPath(ctx context.Context, req *provider.GetPathRequest) (*provider.GetPathResponse, error) {
- statReq := &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Id{
- Id: req.ResourceId,
- },
- },
- }
+ statReq := &provider.StatRequest{Ref: &provider.Reference{ResourceId: req.ResourceId}}
statRes, err := s.stat(ctx, statReq)
if err != nil {
err = errors.Wrap(err, "gateway: error stating ref:"+statReq.Ref.String())
@@ -687,13 +667,7 @@ func (s *svc) CreateContainer(ctx context.Context, req *provider.CreateContainer
log.Debug().Msgf("shared child: %s", p)
shareName, shareChild := s.splitShare(ctx, p)
- statReq := &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: shareName,
- },
- },
- }
+ statReq := &provider.StatRequest{Ref: &provider.Reference{Path: shareName}}
statRes, err := s.stat(ctx, statReq)
if err != nil {
return &provider.CreateContainerResponse{
@@ -727,12 +701,7 @@ func (s *svc) CreateContainer(ctx context.Context, req *provider.CreateContainer
}
// append child to target
- target := path.Join(ri.Path, shareChild)
- req.Ref = &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: target,
- },
- }
+ req.Ref.Path = path.Join(ri.Path, shareChild)
return s.createContainer(ctx, req)
}
@@ -788,11 +757,7 @@ func (s *svc) Delete(ctx context.Context, req *provider.DeleteRequest) (*provide
if s.isShareName(ctx, p) {
log.Debug().Msgf("path:%s points to share name", p)
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: p,
- },
- }
+ ref := &provider.Reference{Path: p}
req.Ref = ref
return s.delete(ctx, req)
@@ -802,11 +767,7 @@ func (s *svc) Delete(ctx context.Context, req *provider.DeleteRequest) (*provide
shareName, shareChild := s.splitShare(ctx, p)
log.Debug().Msgf("path:%s sharename:%s sharechild: %s", p, shareName, shareChild)
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: shareName,
- },
- }
+ ref := &provider.Reference{Path: shareName}
statReq := &provider.StatRequest{Ref: ref}
statRes, err := s.stat(ctx, statReq)
@@ -842,14 +803,7 @@ func (s *svc) Delete(ctx context.Context, req *provider.DeleteRequest) (*provide
}
// append child to target
- target := path.Join(ri.Path, shareChild)
- ref = &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: target,
- },
- }
-
- req.Ref = ref
+ req.Ref.Path = path.Join(ri.Path, shareChild)
return s.delete(ctx, req)
}
@@ -913,13 +867,7 @@ func (s *svc) Move(ctx context.Context, req *provider.MoveRequest) (*provider.Mo
}
- statReq := &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: shareName,
- },
- },
- }
+ statReq := &provider.StatRequest{Ref: &provider.Reference{Path: shareName}}
statRes, err := s.stat(ctx, statReq)
if err != nil {
return &provider.MoveResponse{
@@ -953,14 +901,10 @@ func (s *svc) Move(ctx context.Context, req *provider.MoveRequest) (*provider.Mo
}
src := &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: path.Join(ri.Path, shareChild),
- },
+ Path: path.Join(ri.Path, shareChild),
}
dst := &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: path.Join(ri.Path, dshareChild),
- },
+ Path: path.Join(ri.Path, dshareChild),
}
req.Source = src
@@ -1043,13 +987,7 @@ func (s *svc) UnsetArbitraryMetadata(ctx context.Context, req *provider.UnsetArb
}
func (s *svc) statHome(ctx context.Context) (*provider.StatResponse, error) {
- statRes, err := s.stat(ctx, &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: s.getHome(ctx),
- },
- },
- })
+ statRes, err := s.stat(ctx, &provider.StatRequest{Ref: &provider.Reference{Path: s.getHome(ctx)}})
if err != nil {
return &provider.StatResponse{
Status: status.NewInternal(ctx, err, "gateway: error stating home"),
@@ -1097,13 +1035,7 @@ func (s *svc) statHome(ctx context.Context) (*provider.StatResponse, error) {
}
func (s *svc) statSharesFolder(ctx context.Context) (*provider.StatResponse, error) {
- statRes, err := s.stat(ctx, &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: s.getSharedFolder(ctx),
- },
- },
- })
+ statRes, err := s.stat(ctx, &provider.StatRequest{Ref: &provider.Reference{Path: s.getSharedFolder(ctx)}})
if err != nil {
return &provider.StatResponse{
Status: status.NewInternal(ctx, err, "gateway: error stating shares folder"),
@@ -1214,13 +1146,7 @@ func (s *svc) statOnProvider(ctx context.Context, req *provider.StatRequest, res
if resPath != "" && !strings.HasPrefix(resPath, p.ProviderPath) {
newPath = p.ProviderPath
}
- r, err := c.Stat(ctx, &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: newPath,
- },
- },
- })
+ r, err := c.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{Path: newPath}})
if err != nil {
*e = errors.Wrap(err, "gateway: error calling ListContainer")
return
@@ -1296,13 +1222,7 @@ func (s *svc) Stat(ctx context.Context, req *provider.StatRequest) (*provider.St
if s.isShareChild(ctx, p) {
shareName, shareChild := s.splitShare(ctx, p)
- statReq := &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: shareName,
- },
- },
- }
+ statReq := &provider.StatRequest{Ref: &provider.Reference{Path: shareName}}
statRes, err := s.stat(ctx, statReq)
if err != nil {
return &provider.StatResponse{
@@ -1338,11 +1258,7 @@ func (s *svc) Stat(ctx context.Context, req *provider.StatRequest) (*provider.St
}
// append child to target
- req.Ref = &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: path.Join(ri.Path, shareChild),
- },
- }
+ req.Ref.Path = path.Join(ri.Path, shareChild)
res, err := s.stat(ctx, req)
if err != nil {
return &provider.StatResponse{
@@ -1405,11 +1321,9 @@ func (s *svc) handleCS3Ref(ctx context.Context, opaque string) (*provider.Resour
req := &provider.StatRequest{
Ref: &provider.Reference{
- Spec: &provider.Reference_Id{
- Id: &provider.ResourceId{
- StorageId: parts[0],
- OpaqueId: parts[1],
- },
+ ResourceId: &provider.ResourceId{
+ StorageId: parts[0],
+ OpaqueId: parts[1],
},
},
}
@@ -1447,11 +1361,7 @@ func (s *svc) ListContainerStream(_ *provider.ListContainerStreamRequest, _ gate
func (s *svc) listHome(ctx context.Context, req *provider.ListContainerRequest) (*provider.ListContainerResponse, error) {
lcr, err := s.listContainer(ctx, &provider.ListContainerRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: s.getHome(ctx),
- },
- },
+ Ref: &provider.Reference{Path: s.getHome(ctx)},
ArbitraryMetadataKeys: req.ArbitraryMetadataKeys,
})
if err != nil {
@@ -1466,7 +1376,7 @@ func (s *svc) listHome(ctx context.Context, req *provider.ListContainerRequest)
}
for i := range lcr.Infos {
- if s.isSharedFolder(ctx, lcr.Infos[i].Path) {
+ if s.isSharedFolder(ctx, lcr.Infos[i].GetPath()) {
statSharedFolder, err := s.statSharesFolder(ctx)
if err != nil {
return &provider.ListContainerResponse{
@@ -1487,13 +1397,7 @@ func (s *svc) listHome(ctx context.Context, req *provider.ListContainerRequest)
}
func (s *svc) listSharesFolder(ctx context.Context) (*provider.ListContainerResponse, error) {
- lcr, err := s.listContainer(ctx, &provider.ListContainerRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: s.getSharedFolder(ctx),
- },
- },
- })
+ lcr, err := s.listContainer(ctx, &provider.ListContainerRequest{Ref: &provider.Reference{Path: s.getSharedFolder(ctx)}})
if err != nil {
return &provider.ListContainerResponse{
Status: status.NewInternal(ctx, err, "gateway: error listing shared folder"),
@@ -1524,7 +1428,7 @@ func (s *svc) listSharesFolder(ctx context.Context) (*provider.ListContainerResp
}
}
- info.Path = lcr.Infos[i].GetPath()
+ info.Path = lcr.Infos[i].Path
checkedInfos = append(checkedInfos, info)
}
lcr.Infos = checkedInfos
@@ -1603,13 +1507,7 @@ func (s *svc) listContainerOnProvider(ctx context.Context, req *provider.ListCon
if resPath != "" && !strings.HasPrefix(resPath, p.ProviderPath) {
newPath = p.ProviderPath
}
- r, err := c.ListContainer(ctx, &provider.ListContainerRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: newPath,
- },
- },
- })
+ r, err := c.ListContainer(ctx, &provider.ListContainerRequest{Ref: &provider.Reference{Path: newPath}})
if err != nil {
*e = errors.Wrap(err, "gateway: error calling ListContainer")
return
@@ -1640,13 +1538,7 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ
// we need to provide the info of the target, not the reference.
if s.isShareName(ctx, p) {
- statReq := &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: p,
- },
- },
- }
+ statReq := &provider.StatRequest{Ref: &provider.Reference{Path: p}}
statRes, err := s.stat(ctx, statReq)
if err != nil {
return &provider.ListContainerResponse{
@@ -1694,11 +1586,7 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ
}
newReq := &provider.ListContainerRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: ri.Path,
- },
- },
+ Ref: &provider.Reference{Path: ri.Path},
ArbitraryMetadataKeys: req.ArbitraryMetadataKeys,
}
newRes, err := s.listContainer(ctx, newReq)
@@ -1727,13 +1615,7 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ
if s.isShareChild(ctx, p) {
shareName, shareChild := s.splitShare(ctx, p)
- statReq := &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: shareName,
- },
- },
- }
+ statReq := &provider.StatRequest{Ref: &provider.Reference{Path: shareName}}
statRes, err := s.stat(ctx, statReq)
if err != nil {
return &provider.ListContainerResponse{
@@ -1781,11 +1663,7 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ
}
newReq := &provider.ListContainerRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: path.Join(ri.Path, shareChild),
- },
- },
+ Ref: &provider.Reference{Path: path.Join(ri.Path, shareChild)},
ArbitraryMetadataKeys: req.ArbitraryMetadataKeys,
}
newRes, err := s.listContainer(ctx, newReq)
@@ -1815,11 +1693,9 @@ func (s *svc) ListContainer(ctx context.Context, req *provider.ListContainerRequ
}
func (s *svc) getPath(ctx context.Context, ref *provider.Reference, keys ...string) (string, *rpc.Status) {
- if ref.GetPath() != "" {
- return ref.GetPath(), &rpc.Status{Code: rpc.Code_CODE_OK}
- }
- if ref.GetId() != nil && ref.GetId().GetOpaqueId() != "" {
+ // check if it is an id based or combined reference first
+ if ref.ResourceId != nil {
req := &provider.StatRequest{Ref: ref, ArbitraryMetadataKeys: keys}
res, err := s.stat(ctx, req)
if (res != nil && res.Status.Code != rpc.Code_CODE_OK) || err != nil {
@@ -1829,6 +1705,9 @@ func (s *svc) getPath(ctx context.Context, ref *provider.Reference, keys ...stri
return res.Info.Path, res.Status
}
+ if ref.Path != "" {
+ return ref.Path, &rpc.Status{Code: rpc.Code_CODE_OK}
+ }
return "", &rpc.Status{Code: rpc.Code_CODE_INTERNAL}
}
@@ -2017,21 +1896,8 @@ func (s *svc) GetQuota(ctx context.Context, req *gateway.GetQuotaRequest) (*prov
return res, nil
}
-func (s *svc) findByID(ctx context.Context, id *provider.ResourceId) (provider.ProviderAPIClient, error) {
- ref := &provider.Reference{
- Spec: &provider.Reference_Id{
- Id: id,
- },
- }
- return s.find(ctx, ref)
-}
-
func (s *svc) findByPath(ctx context.Context, path string) (provider.ProviderAPIClient, error) {
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: path,
- },
- }
+ ref := &provider.Reference{Path: path}
return s.find(ctx, ref)
}
diff --git a/internal/grpc/services/gateway/usershareprovider.go b/internal/grpc/services/gateway/usershareprovider.go
index 175258765f..2e9536619a 100644
--- a/internal/grpc/services/gateway/usershareprovider.go
+++ b/internal/grpc/services/gateway/usershareprovider.go
@@ -321,11 +321,13 @@ func (s *svc) UpdateReceivedShare(ctx context.Context, req *collaboration.Update
}
func (s *svc) createReference(ctx context.Context, resourceID *provider.ResourceId) *rpc.Status {
-
+ ref := &provider.Reference{
+ ResourceId: resourceID,
+ }
log := appctx.GetLogger(ctx)
// get the metadata about the share
- c, err := s.findByID(ctx, resourceID)
+ c, err := s.find(ctx, ref)
if err != nil {
if _, ok := err.(errtypes.IsNotFound); ok {
return status.NewNotFound(ctx, "storage provider not found")
@@ -334,11 +336,7 @@ func (s *svc) createReference(ctx context.Context, resourceID *provider.Resource
}
statReq := &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Id{
- Id: resourceID,
- },
- },
+ Ref: ref,
}
statRes, err := c.Stat(ctx, statReq)
@@ -372,7 +370,7 @@ func (s *svc) createReference(ctx context.Context, resourceID *provider.Resource
log.Info().Msg("mount path will be:" + refPath)
createRefReq := &provider.CreateReferenceRequest{
- Path: refPath,
+ Ref: &provider.Reference{Path: refPath},
// cs3 is the Scheme and %s/%s is the Opaque parts of a net.URL.
TargetUri: fmt.Sprintf("cs3:%s/%s", resourceID.GetStorageId(), resourceID.GetOpaqueId()),
}
@@ -402,20 +400,19 @@ func (s *svc) createReference(ctx context.Context, resourceID *provider.Resource
}
func (s *svc) addGrant(ctx context.Context, id *provider.ResourceId, g *provider.Grantee, p *provider.ResourcePermissions) (*rpc.Status, error) {
+ ref := &provider.Reference{
+ ResourceId: id,
+ }
grantReq := &provider.AddGrantRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Id{
- Id: id,
- },
- },
+ Ref: ref,
Grant: &provider.Grant{
Grantee: g,
Permissions: p,
},
}
- c, err := s.findByID(ctx, id)
+ c, err := s.find(ctx, ref)
if err != nil {
if _, ok := err.(errtypes.IsNotFound); ok {
return status.NewNotFound(ctx, "storage provider not found"), nil
@@ -436,20 +433,18 @@ func (s *svc) addGrant(ctx context.Context, id *provider.ResourceId, g *provider
}
func (s *svc) updateGrant(ctx context.Context, id *provider.ResourceId, g *provider.Grantee, p *provider.ResourcePermissions) (*rpc.Status, error) {
-
+ ref := &provider.Reference{
+ ResourceId: id,
+ }
grantReq := &provider.UpdateGrantRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Id{
- Id: id,
- },
- },
+ Ref: ref,
Grant: &provider.Grant{
Grantee: g,
Permissions: p,
},
}
- c, err := s.findByID(ctx, id)
+ c, err := s.find(ctx, ref)
if err != nil {
if _, ok := err.(errtypes.IsNotFound); ok {
return status.NewNotFound(ctx, "storage provider not found"), nil
@@ -470,20 +465,19 @@ func (s *svc) updateGrant(ctx context.Context, id *provider.ResourceId, g *provi
}
func (s *svc) removeGrant(ctx context.Context, id *provider.ResourceId, g *provider.Grantee, p *provider.ResourcePermissions) (*rpc.Status, error) {
+ ref := &provider.Reference{
+ ResourceId: id,
+ }
grantReq := &provider.RemoveGrantRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Id{
- Id: id,
- },
- },
+ Ref: ref,
Grant: &provider.Grant{
Grantee: g,
Permissions: p,
},
}
- c, err := s.findByID(ctx, id)
+ c, err := s.find(ctx, ref)
if err != nil {
if _, ok := err.(errtypes.IsNotFound); ok {
return status.NewNotFound(ctx, "storage provider not found"), nil
diff --git a/internal/grpc/services/publicstorageprovider/publicstorageprovider.go b/internal/grpc/services/publicstorageprovider/publicstorageprovider.go
index b941b9b110..b53f5adf07 100644
--- a/internal/grpc/services/publicstorageprovider/publicstorageprovider.go
+++ b/internal/grpc/services/publicstorageprovider/publicstorageprovider.go
@@ -148,9 +148,7 @@ func (s *service) translatePublicRefToCS3Ref(ctx context.Context, ref *provider.
return nil, "", nil, st, nil
}
- cs3Ref := &provider.Reference{
- Spec: &provider.Reference_Path{Path: path.Join("/", originalPath, relativePath)},
- }
+ cs3Ref := &provider.Reference{Path: path.Join("/", originalPath, relativePath)}
log.Debug().
Interface("sourceRef", ref).
Interface("cs3Ref", cs3Ref).
@@ -473,13 +471,7 @@ func (s *service) Stat(ctx context.Context, req *provider.StatRequest) (*provide
}
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: p,
- },
- },
- })
+ statResponse, err = s.gateway.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{Path: p}})
if err != nil {
return &provider.StatResponse{
Status: status.NewInternal(ctx, err, "gateway: error calling Stat for ref:"+req.Ref.String()),
@@ -540,13 +532,7 @@ func (s *service) ListContainer(ctx context.Context, req *provider.ListContainer
listContainerR, err := s.gateway.ListContainer(
ctx,
- &provider.ListContainerRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: path.Join("/", pathFromToken, relativePath),
- },
- },
- },
+ &provider.ListContainerRequest{Ref: &provider.Reference{Path: path.Join("/", pathFromToken, relativePath)}},
)
if err != nil {
return &provider.ListContainerResponse{
@@ -587,8 +573,8 @@ func filterPermissions(l *provider.ResourcePermissions, r *provider.ResourcePerm
}
func (s *service) unwrap(ctx context.Context, ref *provider.Reference) (token string, relativePath string, err error) {
- if ref.GetId() != nil {
- return "", "", errtypes.BadRequest("need path based ref: got " + ref.String())
+ if ref.ResourceId != nil {
+ return "", "", errtypes.BadRequest("need absolute path ref: got " + ref.String())
}
if ref.GetPath() == "" {
@@ -709,9 +695,7 @@ func (s *service) resolveToken(ctx context.Context, token string) (string, *link
sRes, err := s.gateway.Stat(ctx, &provider.StatRequest{
Ref: &provider.Reference{
- Spec: &provider.Reference_Id{
- Id: publicShareResponse.GetShare().GetResourceId(),
- },
+ ResourceId: publicShareResponse.GetShare().GetResourceId(),
},
})
switch {
diff --git a/internal/grpc/services/storageprovider/storageprovider.go b/internal/grpc/services/storageprovider/storageprovider.go
index 7785771fcb..cc2f296c55 100644
--- a/internal/grpc/services/storageprovider/storageprovider.go
+++ b/internal/grpc/services/storageprovider/storageprovider.go
@@ -816,7 +816,7 @@ func (s *service) ListRecycle(ctx context.Context, req *provider.ListRecycleRequ
func (s *service) RestoreRecycleItem(ctx context.Context, req *provider.RestoreRecycleItemRequest) (*provider.RestoreRecycleItemResponse, error) {
// TODO(labkode): CRITICAL: fill recycle info with storage provider.
- if err := s.storage.RestoreRecycleItem(ctx, req.Key, req.RestorePath); err != nil {
+ if err := s.storage.RestoreRecycleItem(ctx, req.Key, req.RestoreRef); err != nil {
var st *rpc.Status
switch err.(type) {
case errtypes.IsNotFound:
@@ -838,9 +838,9 @@ func (s *service) RestoreRecycleItem(ctx context.Context, req *provider.RestoreR
}
func (s *service) PurgeRecycle(ctx context.Context, req *provider.PurgeRecycleRequest) (*provider.PurgeRecycleResponse, error) {
- // if a key was sent as opacque id purge only that item
- if req.GetRef().GetId() != nil && req.GetRef().GetId().GetOpaqueId() != "" {
- if err := s.storage.PurgeRecycleItem(ctx, req.GetRef().GetId().GetOpaqueId()); err != nil {
+ // if a key was sent as opaque id purge only that item
+ if req.GetRef().GetResourceId() != nil && req.GetRef().GetResourceId().OpaqueId != "" {
+ if err := s.storage.PurgeRecycleItem(ctx, req.GetRef().GetResourceId().OpaqueId); err != nil {
var st *rpc.Status
switch err.(type) {
case errtypes.IsNotFound:
@@ -1028,13 +1028,7 @@ func (s *service) CreateReference(ctx context.Context, req *provider.CreateRefer
}, nil
}
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: req.Path,
- },
- }
-
- newRef, err := s.unwrap(ctx, ref)
+ newRef, err := s.unwrap(ctx, req.Ref)
if err != nil {
return &provider.CreateReferenceResponse{
Status: status.NewInternal(ctx, err, "error unwrapping path"),
@@ -1101,17 +1095,8 @@ func getFS(c *config) (storage.FS, error) {
}
func (s *service) unwrap(ctx context.Context, ref *provider.Reference) (*provider.Reference, error) {
- if ref.GetId() != nil {
- idRef := &provider.Reference{
- Spec: &provider.Reference_Id{
- Id: &provider.ResourceId{
- StorageId: "", // we are unwrapping on purpose, bottom layers only need OpaqueId.
- OpaqueId: ref.GetId().OpaqueId,
- },
- },
- }
-
- return idRef, nil
+ if ref.GetResourceId() != nil {
+ return ref, nil
}
if ref.GetPath() == "" {
@@ -1125,11 +1110,7 @@ func (s *service) unwrap(ctx context.Context, ref *provider.Reference) (*provide
return nil, err
}
- pathRef := &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: fsfn,
- },
- }
+ pathRef := &provider.Reference{Path: fsfn}
return pathRef, nil
}
diff --git a/internal/http/services/owncloud/ocdav/copy.go b/internal/http/services/owncloud/ocdav/copy.go
index 1a7e29a704..a3cbee49ec 100644
--- a/internal/http/services/owncloud/ocdav/copy.go
+++ b/internal/http/services/owncloud/ocdav/copy.go
@@ -81,9 +81,7 @@ func (s *svc) handleCopy(w http.ResponseWriter, r *http.Request, ns string) {
}
// check src exists
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{Path: src},
- }
+ ref := &provider.Reference{Path: src}
srcStatReq := &provider.StatRequest{Ref: ref}
srcStatRes, err := client.Stat(ctx, srcStatReq)
if err != nil {
@@ -98,9 +96,7 @@ func (s *svc) handleCopy(w http.ResponseWriter, r *http.Request, ns string) {
}
// check dst exists
- ref = &provider.Reference{
- Spec: &provider.Reference_Path{Path: dst},
- }
+ ref = &provider.Reference{Path: dst}
dstStatReq := &provider.StatRequest{Ref: ref}
dstStatRes, err := client.Stat(ctx, dstStatReq)
if err != nil {
@@ -126,9 +122,7 @@ func (s *svc) handleCopy(w http.ResponseWriter, r *http.Request, ns string) {
} else {
// check if an intermediate path / the parent exists
intermediateDir := path.Dir(dst)
- ref = &provider.Reference{
- Spec: &provider.Reference_Path{Path: intermediateDir},
- }
+ ref = &provider.Reference{Path: intermediateDir}
intStatReq := &provider.StatRequest{Ref: ref}
intStatRes, err := client.Stat(ctx, intStatReq)
if err != nil {
@@ -164,9 +158,7 @@ func (s *svc) descend(ctx context.Context, client gateway.GatewayAPIClient, src
if src.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER {
// create dir
createReq := &provider.CreateContainerRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{Path: dst},
- },
+ Ref: &provider.Reference{Path: dst},
}
createRes, err := client.CreateContainer(ctx, createReq)
if err != nil || createRes.Status.Code != rpc.Code_CODE_OK {
@@ -181,9 +173,7 @@ func (s *svc) descend(ctx context.Context, client gateway.GatewayAPIClient, src
// descend for children
listReq := &provider.ListContainerRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{Path: src.Path},
- },
+ Ref: &provider.Reference{Path: src.Path},
}
res, err := client.ListContainer(ctx, listReq)
if err != nil {
@@ -207,9 +197,7 @@ func (s *svc) descend(ctx context.Context, client gateway.GatewayAPIClient, src
// 1. get download url
dReq := &provider.InitiateFileDownloadRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{Path: src.Path},
- },
+ Ref: &provider.Reference{Path: src.Path},
}
dRes, err := client.InitiateFileDownload(ctx, dReq)
@@ -231,9 +219,7 @@ func (s *svc) descend(ctx context.Context, client gateway.GatewayAPIClient, src
// 2. get upload url
uReq := &provider.InitiateFileUploadRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{Path: dst},
- },
+ Ref: &provider.Reference{Path: dst},
Opaque: &typespb.Opaque{
Map: map[string]*typespb.OpaqueEntry{
"Upload-Length": {
diff --git a/internal/http/services/owncloud/ocdav/dav.go b/internal/http/services/owncloud/ocdav/dav.go
index ca5abc1884..a1681fe29d 100644
--- a/internal/http/services/owncloud/ocdav/dav.go
+++ b/internal/http/services/owncloud/ocdav/dav.go
@@ -249,9 +249,7 @@ func (h *DavHandler) Handler(s *svc) http.Handler {
}
func getTokenStatInfo(ctx context.Context, client gatewayv1beta1.GatewayAPIClient, token string) (*provider.StatResponse, error) {
- return client.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{
- Spec: &provider.Reference_Path{Path: path.Join("/public", token)},
- }})
+ return client.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{Path: path.Join("/public", token)}})
}
func handleBasicAuth(ctx context.Context, c gatewayv1beta1.GatewayAPIClient, token, pw string) (*gatewayv1beta1.AuthenticateResponse, error) {
diff --git a/internal/http/services/owncloud/ocdav/delete.go b/internal/http/services/owncloud/ocdav/delete.go
index 0bdf55561a..8898a95d1a 100644
--- a/internal/http/services/owncloud/ocdav/delete.go
+++ b/internal/http/services/owncloud/ocdav/delete.go
@@ -44,9 +44,7 @@ func (s *svc) handleDelete(w http.ResponseWriter, r *http.Request, ns string) {
return
}
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{Path: fn},
- }
+ ref := &provider.Reference{Path: fn}
req := &provider.DeleteRequest{Ref: ref}
res, err := client.Delete(ctx, req)
if err != nil {
diff --git a/internal/http/services/owncloud/ocdav/get.go b/internal/http/services/owncloud/ocdav/get.go
index d6ab7d6c89..d462d8fa1c 100644
--- a/internal/http/services/owncloud/ocdav/get.go
+++ b/internal/http/services/owncloud/ocdav/get.go
@@ -55,9 +55,7 @@ func (s *svc) handleGet(w http.ResponseWriter, r *http.Request, ns string) {
}
sReq := &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{Path: fn},
- },
+ Ref: &provider.Reference{Path: fn},
}
sRes, err := client.Stat(ctx, sReq)
if err != nil {
@@ -79,9 +77,7 @@ func (s *svc) handleGet(w http.ResponseWriter, r *http.Request, ns string) {
}
dReq := &provider.InitiateFileDownloadRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{Path: fn},
- },
+ Ref: &provider.Reference{Path: fn},
}
dRes, err := client.InitiateFileDownload(ctx, dReq)
diff --git a/internal/http/services/owncloud/ocdav/head.go b/internal/http/services/owncloud/ocdav/head.go
index 250da299bb..f70d4b95d8 100644
--- a/internal/http/services/owncloud/ocdav/head.go
+++ b/internal/http/services/owncloud/ocdav/head.go
@@ -50,9 +50,7 @@ func (s *svc) handleHead(w http.ResponseWriter, r *http.Request, ns string) {
return
}
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{Path: fn},
- }
+ ref := &provider.Reference{Path: fn}
req := &provider.StatRequest{Ref: ref}
res, err := client.Stat(ctx, req)
if err != nil {
diff --git a/internal/http/services/owncloud/ocdav/mkcol.go b/internal/http/services/owncloud/ocdav/mkcol.go
index c93a8f9f67..889598a43b 100644
--- a/internal/http/services/owncloud/ocdav/mkcol.go
+++ b/internal/http/services/owncloud/ocdav/mkcol.go
@@ -54,9 +54,7 @@ func (s *svc) handleMkcol(w http.ResponseWriter, r *http.Request, ns string) {
}
// check fn exists
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{Path: fn},
- }
+ ref := &provider.Reference{Path: fn}
statReq := &provider.StatRequest{Ref: ref}
statRes, err := client.Stat(ctx, statReq)
if err != nil {
diff --git a/internal/http/services/owncloud/ocdav/move.go b/internal/http/services/owncloud/ocdav/move.go
index 77debda500..e92bc1bede 100644
--- a/internal/http/services/owncloud/ocdav/move.go
+++ b/internal/http/services/owncloud/ocdav/move.go
@@ -67,9 +67,7 @@ func (s *svc) handleMove(w http.ResponseWriter, r *http.Request, ns string) {
// check src exists
srcStatReq := &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{Path: src},
- },
+ Ref: &provider.Reference{Path: src},
}
srcStatRes, err := client.Stat(ctx, srcStatReq)
if err != nil {
@@ -83,9 +81,7 @@ func (s *svc) handleMove(w http.ResponseWriter, r *http.Request, ns string) {
}
// check dst exists
- dstStatRef := &provider.Reference{
- Spec: &provider.Reference_Path{Path: dst},
- }
+ dstStatRef := &provider.Reference{Path: dst}
dstStatReq := &provider.StatRequest{Ref: dstStatRef}
dstStatRes, err := client.Stat(ctx, dstStatReq)
if err != nil {
@@ -124,9 +120,7 @@ func (s *svc) handleMove(w http.ResponseWriter, r *http.Request, ns string) {
} else {
// check if an intermediate path / the parent exists
intermediateDir := path.Dir(dst)
- ref2 := &provider.Reference{
- Spec: &provider.Reference_Path{Path: intermediateDir},
- }
+ ref2 := &provider.Reference{Path: intermediateDir}
intStatReq := &provider.StatRequest{Ref: ref2}
intStatRes, err := client.Stat(ctx, intStatReq)
if err != nil {
@@ -147,12 +141,8 @@ func (s *svc) handleMove(w http.ResponseWriter, r *http.Request, ns string) {
// TODO what if intermediate is a file?
}
- sourceRef := &provider.Reference{
- Spec: &provider.Reference_Path{Path: src},
- }
- dstRef := &provider.Reference{
- Spec: &provider.Reference_Path{Path: dst},
- }
+ sourceRef := &provider.Reference{Path: src}
+ dstRef := &provider.Reference{Path: dst}
mReq := &provider.MoveRequest{Source: sourceRef, Destination: dstRef}
mRes, err := client.Move(ctx, mReq)
if err != nil {
diff --git a/internal/http/services/owncloud/ocdav/propfind.go b/internal/http/services/owncloud/ocdav/propfind.go
index 71eb313918..9e71d6b036 100644
--- a/internal/http/services/owncloud/ocdav/propfind.go
+++ b/internal/http/services/owncloud/ocdav/propfind.go
@@ -110,9 +110,7 @@ func (s *svc) handlePropfind(w http.ResponseWriter, r *http.Request, ns string)
}
}
}
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{Path: fn},
- }
+ ref := &provider.Reference{Path: fn}
req := &provider.StatRequest{
Ref: ref,
ArbitraryMetadataKeys: metadataKeys,
@@ -155,9 +153,7 @@ func (s *svc) handlePropfind(w http.ResponseWriter, r *http.Request, ns string)
for len(stack) > 0 {
// retrieve path on top of stack
path := stack[len(stack)-1]
- ref = &provider.Reference{
- Spec: &provider.Reference_Path{Path: path},
- }
+ ref = &provider.Reference{Path: path}
req := &provider.ListContainerRequest{
Ref: ref,
ArbitraryMetadataKeys: metadataKeys,
diff --git a/internal/http/services/owncloud/ocdav/proppatch.go b/internal/http/services/owncloud/ocdav/proppatch.go
index a8fe5933a0..f7dd927743 100644
--- a/internal/http/services/owncloud/ocdav/proppatch.go
+++ b/internal/http/services/owncloud/ocdav/proppatch.go
@@ -63,9 +63,7 @@ func (s *svc) handleProppatch(w http.ResponseWriter, r *http.Request, ns string)
// check if resource exists
statReq := &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{Path: fn},
- },
+ Ref: &provider.Reference{Path: fn},
}
statRes, err := c.Stat(ctx, statReq)
if err != nil {
@@ -80,15 +78,11 @@ func (s *svc) handleProppatch(w http.ResponseWriter, r *http.Request, ns string)
}
rreq := &provider.UnsetArbitraryMetadataRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{Path: fn},
- },
+ Ref: &provider.Reference{Path: fn},
ArbitraryMetadataKeys: []string{""},
}
sreq := &provider.SetArbitraryMetadataRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{Path: fn},
- },
+ Ref: &provider.Reference{Path: fn},
ArbitraryMetadata: &provider.ArbitraryMetadata{
Metadata: map[string]string{},
},
diff --git a/internal/http/services/owncloud/ocdav/put.go b/internal/http/services/owncloud/ocdav/put.go
index 71a8c1b7b3..7a9ad49963 100644
--- a/internal/http/services/owncloud/ocdav/put.go
+++ b/internal/http/services/owncloud/ocdav/put.go
@@ -156,9 +156,7 @@ func (s *svc) handlePutHelper(w http.ResponseWriter, r *http.Request, content io
return
}
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{Path: fn},
- }
+ ref := &provider.Reference{Path: fn}
sReq := &provider.StatRequest{Ref: ref}
sRes, err := client.Stat(ctx, sReq)
if err != nil {
@@ -315,13 +313,7 @@ func (s *svc) handlePutHelper(w http.ResponseWriter, r *http.Request, content io
w.WriteHeader(http.StatusInternalServerError)
return
}
- sReq = &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: chunk.Path,
- },
- },
- }
+ sReq = &provider.StatRequest{Ref: &provider.Reference{Path: chunk.Path}}
}
// stat again to check the new file's metadata
diff --git a/internal/http/services/owncloud/ocdav/trashbin.go b/internal/http/services/owncloud/ocdav/trashbin.go
index c97353c76f..cbc992f922 100644
--- a/internal/http/services/owncloud/ocdav/trashbin.go
+++ b/internal/http/services/owncloud/ocdav/trashbin.go
@@ -179,13 +179,7 @@ func (h *TrashbinHandler) listTrashbin(w http.ResponseWriter, r *http.Request, s
// ask gateway for recycle items
// TODO(labkode): add Reference to ListRecycleRequest
- getRecycleRes, err := gc.ListRecycle(ctx, &gateway.ListRecycleRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: getHomeRes.Path,
- },
- },
- })
+ getRecycleRes, err := gc.ListRecycle(ctx, &gateway.ListRecycleRequest{Ref: &provider.Reference{Path: getHomeRes.Path}})
if err != nil {
sublog.Error().Err(err).Msg("error calling ListRecycle")
@@ -285,8 +279,8 @@ func (h *TrashbinHandler) itemToPropResponse(ctx context.Context, s *svc, u *use
Prop: []*propertyXML{},
})
// yes this is redundant, can be derived from oc:trashbin-original-location which contains the full path, clients should not fetch it
- response.Propstat[0].Prop = append(response.Propstat[0].Prop, s.newProp("oc:trashbin-original-filename", filepath.Base(item.Path)))
- response.Propstat[0].Prop = append(response.Propstat[0].Prop, s.newProp("oc:trashbin-original-location", strings.TrimPrefix(item.Path, "/")))
+ response.Propstat[0].Prop = append(response.Propstat[0].Prop, s.newProp("oc:trashbin-original-filename", filepath.Base(item.Ref.Path)))
+ response.Propstat[0].Prop = append(response.Propstat[0].Prop, s.newProp("oc:trashbin-original-location", strings.TrimPrefix(item.Ref.Path, "/")))
response.Propstat[0].Prop = append(response.Propstat[0].Prop, s.newProp("oc:trashbin-delete-timestamp", strconv.FormatUint(item.DeletionTime.Seconds, 10)))
response.Propstat[0].Prop = append(response.Propstat[0].Prop, s.newProp("oc:trashbin-delete-datetime", dTime))
if item.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER {
@@ -322,10 +316,10 @@ func (h *TrashbinHandler) itemToPropResponse(ctx context.Context, s *svc, u *use
}
case "trashbin-original-filename":
// yes this is redundant, can be derived from oc:trashbin-original-location which contains the full path, clients should not fetch it
- propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:trashbin-original-filename", filepath.Base(item.Path)))
+ propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:trashbin-original-filename", filepath.Base(item.Ref.Path)))
case "trashbin-original-location":
// TODO (jfd) double check and clarify the cs3 spec what the Key is about and if Path is only the folder that contains the file or if it includes the filename
- propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:trashbin-original-location", strings.TrimPrefix(item.Path, "/")))
+ propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:trashbin-original-location", strings.TrimPrefix(item.Ref.Path, "/")))
case "trashbin-delete-datetime":
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:trashbin-delete-datetime", dTime))
case "trashbin-delete-timestamp":
@@ -400,12 +394,10 @@ func (h *TrashbinHandler) restore(w http.ResponseWriter, r *http.Request, s *svc
// use the key which is prefixed with the StoragePath to lookup the correct storage ...
// TODO currently limited to the home storage
Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: getHomeRes.Path,
- },
+ Path: getHomeRes.Path,
},
- Key: key,
- RestorePath: dst,
+ Key: key,
+ RestoreRef: &provider.Reference{Path: dst},
}
res, err := client.RestoreRecycleItem(ctx, req)
@@ -447,13 +439,7 @@ func (h *TrashbinHandler) delete(w http.ResponseWriter, r *http.Request, s *svc,
HandleErrorStatus(&sublog, w, getHomeRes.Status)
return
}
- sRes, err := client.Stat(ctx, &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: getHomeRes.Path,
- },
- },
- })
+ sRes, err := client.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{Path: getHomeRes.Path}})
if err != nil {
sublog.Error().Err(err).Msg("error calling Stat")
w.WriteHeader(http.StatusInternalServerError)
@@ -469,11 +455,9 @@ func (h *TrashbinHandler) delete(w http.ResponseWriter, r *http.Request, s *svc,
req := &gateway.PurgeRecycleRequest{
Ref: &provider.Reference{
- Spec: &provider.Reference_Id{
- Id: &provider.ResourceId{
- OpaqueId: key,
- StorageId: sRes.Info.Id.StorageId,
- },
+ ResourceId: &provider.ResourceId{
+ StorageId: sRes.Info.Id.StorageId,
+ OpaqueId: key,
},
},
}
diff --git a/internal/http/services/owncloud/ocdav/tus.go b/internal/http/services/owncloud/ocdav/tus.go
index fec279f494..8fb4c7a1a1 100644
--- a/internal/http/services/owncloud/ocdav/tus.go
+++ b/internal/http/services/owncloud/ocdav/tus.go
@@ -84,9 +84,7 @@ func (s *svc) handleTusPost(w http.ResponseWriter, r *http.Request, ns string) {
}
sReq := &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{Path: fn},
- },
+ Ref: &provider.Reference{Path: fn},
}
sRes, err := client.Stat(ctx, sReq)
if err != nil {
@@ -136,9 +134,7 @@ func (s *svc) handleTusPost(w http.ResponseWriter, r *http.Request, ns string) {
// initiateUpload
uReq := &provider.InitiateFileUploadRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{Path: fn},
- },
+ Ref: &provider.Reference{Path: fn},
Opaque: &typespb.Opaque{
Map: opaqueMap,
},
diff --git a/internal/http/services/owncloud/ocdav/versions.go b/internal/http/services/owncloud/ocdav/versions.go
index bd261594ae..af3644cbdf 100644
--- a/internal/http/services/owncloud/ocdav/versions.go
+++ b/internal/http/services/owncloud/ocdav/versions.go
@@ -46,7 +46,7 @@ func (h *VersionsHandler) Handler(s *svc, rid *provider.ResourceId) http.Handler
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
- if rid == (*provider.ResourceId)(nil) {
+ if rid == nil {
http.Error(w, "404 Not Found", http.StatusNotFound)
return
}
@@ -99,11 +99,8 @@ func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request,
return
}
- ref := &provider.Reference{
- Spec: &provider.Reference_Id{Id: rid},
- }
- req := &provider.StatRequest{Ref: ref}
- res, err := client.Stat(ctx, req)
+ ref := &provider.Reference{ResourceId: rid}
+ res, err := client.Stat(ctx, &provider.StatRequest{Ref: ref})
if err != nil {
sublog.Error().Err(err).Msg("error sending a grpc stat request")
w.WriteHeader(http.StatusInternalServerError)
@@ -116,10 +113,7 @@ func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request,
info := res.Info
- lvReq := &provider.ListFileVersionsRequest{
- Ref: ref,
- }
- lvRes, err := client.ListFileVersions(ctx, lvReq)
+ lvRes, err := client.ListFileVersions(ctx, &provider.ListFileVersionsRequest{Ref: ref})
if err != nil {
sublog.Error().Err(err).Msg("error sending list container grpc request")
w.WriteHeader(http.StatusInternalServerError)
@@ -143,7 +137,7 @@ func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request,
// Opaque
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
Id: &provider.ResourceId{
- StorageId: "versions", // this is a virtual storage
+ StorageId: "versions",
OpaqueId: info.Id.OpaqueId + "@" + versions[i].GetKey(),
},
// Checksum
@@ -193,9 +187,7 @@ func (h *VersionsHandler) doRestore(w http.ResponseWriter, r *http.Request, s *s
}
req := &provider.RestoreFileVersionRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Id{Id: rid},
- },
+ Ref: &provider.Reference{ResourceId: rid},
Key: key,
}
diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go
index 5c8029f4a1..5e5115e23e 100644
--- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go
+++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go
@@ -377,13 +377,7 @@ func (h *Handler) updatePublicShare(w http.ResponseWriter, r *http.Request, shar
return
}
- statReq := provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Id{
- Id: before.Share.ResourceId,
- },
- },
- }
+ statReq := provider.StatRequest{Ref: &provider.Reference{ResourceId: before.Share.ResourceId}}
statRes, err := gwC.Stat(r.Context(), &statReq)
if err != nil {
diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go
index fefe0acad2..624df6bcf9 100644
--- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go
+++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go
@@ -52,6 +52,7 @@ import (
"github.com/cs3org/reva/pkg/rhttp/router"
"github.com/cs3org/reva/pkg/share/cache"
"github.com/cs3org/reva/pkg/share/cache/registry"
+ "github.com/cs3org/reva/pkg/utils"
"github.com/pkg/errors"
)
@@ -217,11 +218,7 @@ func (h *Handler) createShare(w http.ResponseWriter, r *http.Request) {
fn := path.Join(h.homeNamespace, r.FormValue("path"))
statReq := provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: fn,
- },
- },
+ Ref: &provider.Reference{Path: fn},
}
sublog := appctx.GetLogger(ctx).With().Str("path", fn).Logger()
@@ -509,13 +506,9 @@ func (h *Handler) updateShare(w http.ResponseWriter, r *http.Request, shareID st
return
}
- statReq := provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Id{
- Id: uRes.Share.ResourceId,
- },
- },
- }
+ statReq := provider.StatRequest{Ref: &provider.Reference{
+ ResourceId: uRes.Share.ResourceId,
+ }}
statRes, err := client.Stat(r.Context(), &statReq)
if err != nil {
@@ -625,8 +618,7 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) {
var info *provider.ResourceInfo
if pinfo != nil {
// check if the shared resource matches the path resource
- if rs.Share.ResourceId.StorageId != pinfo.GetId().StorageId ||
- rs.Share.ResourceId.OpaqueId != pinfo.GetId().OpaqueId {
+ if !utils.ResourceIDEqual(rs.Share.ResourceId, pinfo.Id) {
// try next share
continue
}
@@ -795,7 +787,7 @@ func (h *Handler) addFileInfo(ctx context.Context, s *conversions.ShareData, inf
}
s.MimeType = parsedMt
// TODO STime: &types.Timestamp{Seconds: info.Mtime.Seconds, Nanos: info.Mtime.Nanos},
- s.StorageID = info.Id.StorageId
+ s.StorageID = info.Id.StorageId + "!" + info.Id.OpaqueId
// TODO Storage: int
s.ItemSource = wrapResourceID(info.Id)
s.FileSource = s.ItemSource
@@ -943,18 +935,12 @@ func (h *Handler) getAdditionalInfoAttribute(ctx context.Context, u *userIdentif
func (h *Handler) getResourceInfoByPath(ctx context.Context, client gateway.GatewayAPIClient, path string) (*provider.ResourceInfo, *rpc.Status, error) {
return h.getResourceInfo(ctx, client, path, &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: path,
- },
+ Path: path,
})
}
func (h *Handler) getResourceInfoByID(ctx context.Context, client gateway.GatewayAPIClient, id *provider.ResourceId) (*provider.ResourceInfo, *rpc.Status, error) {
- return h.getResourceInfo(ctx, client, wrapResourceID(id), &provider.Reference{
- Spec: &provider.Reference_Id{
- Id: id,
- },
- })
+ return h.getResourceInfo(ctx, client, wrapResourceID(id), &provider.Reference{ResourceId: id})
}
// getResourceInfo retrieves the resource info to a target.
diff --git a/internal/http/services/owncloud/ocs/handlers/cloud/users/users.go b/internal/http/services/owncloud/ocs/handlers/cloud/users/users.go
index 89538d075e..37f6232784 100644
--- a/internal/http/services/owncloud/ocs/handlers/cloud/users/users.go
+++ b/internal/http/services/owncloud/ocs/handlers/cloud/users/users.go
@@ -126,13 +126,7 @@ func (h *Handler) handleUsers(w http.ResponseWriter, r *http.Request, u *userpb.
return
}
- getQuotaRes, err := gc.GetQuota(ctx, &gateway.GetQuotaRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: getHomeRes.Path,
- },
- },
- })
+ getQuotaRes, err := gc.GetQuota(ctx, &gateway.GetQuotaRequest{Ref: &provider.Reference{Path: getHomeRes.Path}})
if err != nil {
sublog.Error().Err(err).Msg("error calling GetQuota")
w.WriteHeader(http.StatusInternalServerError)
diff --git a/pkg/app/app.go b/pkg/app/app.go
index 4adb0904dd..1534094f2d 100644
--- a/pkg/app/app.go
+++ b/pkg/app/app.go
@@ -40,5 +40,5 @@ type ProviderInfo struct {
// Provider is the interface that application providers implement
// for providing the iframe location to a iframe UI Provider
type Provider interface {
- GetIFrame(ctx context.Context, resID *provider.ResourceId, token string) (string, error)
+ GetIFrame(ctx context.Context, resID *provider.Reference, token string) (string, error)
}
diff --git a/pkg/app/provider/demo/demo.go b/pkg/app/provider/demo/demo.go
index 928c602b1b..28134083e5 100644
--- a/pkg/app/provider/demo/demo.go
+++ b/pkg/app/provider/demo/demo.go
@@ -32,8 +32,8 @@ type provider struct {
iframeUIProvider string
}
-func (p *provider) GetIFrame(ctx context.Context, resID *providerpb.ResourceId, token string) (string, error) {
- msg := fmt.Sprintf("", p.iframeUIProvider, resID.StorageId+":"+resID.OpaqueId, token)
+func (p *provider) GetIFrame(ctx context.Context, resID *providerpb.Reference, token string) (string, error) {
+ msg := fmt.Sprintf("", p.iframeUIProvider, resID.ResourceId.StorageId+":"+resID.ResourceId.OpaqueId, token)
return msg, nil
}
diff --git a/pkg/auth/scope/publicshare.go b/pkg/auth/scope/publicshare.go
index 1b7b686631..7a2e9ed8b7 100644
--- a/pkg/auth/scope/publicshare.go
+++ b/pkg/auth/scope/publicshare.go
@@ -71,11 +71,12 @@ func publicshareScope(scope *authpb.Scope, resource interface{}) (bool, error) {
}
func checkStorageRef(s *link.PublicShare, r *provider.Reference) bool {
- // ref: >
- if r.GetId() != nil {
- return s.ResourceId.StorageId == r.GetId().StorageId && s.ResourceId.OpaqueId == r.GetId().OpaqueId
+ // r: >
+ if r.ResourceId != nil && r.Path == "" { // path must be empty
+ return s.ResourceId.StorageId == r.ResourceId.StorageId && s.ResourceId.OpaqueId == r.ResourceId.OpaqueId
}
- // ref:
+
+ // r:
if strings.HasPrefix(r.GetPath(), "/public/"+s.Token) {
return true
}
diff --git a/pkg/auth/scope/resourceinfo.go b/pkg/auth/scope/resourceinfo.go
index 3d75938bce..3d90770df1 100644
--- a/pkg/auth/scope/resourceinfo.go
+++ b/pkg/auth/scope/resourceinfo.go
@@ -68,9 +68,10 @@ func resourceinfoScope(scope *authpb.Scope, resource interface{}) (bool, error)
}
func checkResourceInfo(inf *provider.ResourceInfo, ref *provider.Reference) bool {
- // ref: >
- if ref.GetId() != nil {
- return inf.Id.StorageId == ref.GetId().StorageId && inf.Id.OpaqueId == ref.GetId().OpaqueId
+ // ref: >
+ if ref.ResourceId != nil { // path can be empty or a relative path
+ // TODO what about the path?
+ return inf.Id.StorageId == ref.ResourceId.StorageId && inf.Id.OpaqueId == ref.ResourceId.OpaqueId
}
// ref:
if strings.HasPrefix(ref.GetPath(), inf.Path) {
diff --git a/pkg/auth/scope/user.go b/pkg/auth/scope/user.go
index 42ebf47728..82a700dfce 100644
--- a/pkg/auth/scope/user.go
+++ b/pkg/auth/scope/user.go
@@ -33,11 +33,7 @@ func userScope(scope *authpb.Scope, resource interface{}) (bool, error) {
// GetOwnerScope returns the default owner scope with access to all resources.
func GetOwnerScope() (map[string]*authpb.Scope, error) {
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: "/",
- },
- }
+ ref := &provider.Reference{Path: "/"}
val, err := utils.MarshalProtoV1ToJSON(ref)
if err != nil {
return nil, err
diff --git a/pkg/cbox/utils/conversions.go b/pkg/cbox/utils/conversions.go
index 2117282224..12a5510a89 100644
--- a/pkg/cbox/utils/conversions.go
+++ b/pkg/cbox/utils/conversions.go
@@ -187,7 +187,11 @@ func ConvertToCS3Share(s DBShare) *collaboration.Share {
Id: &collaboration.ShareId{
OpaqueId: s.ID,
},
- ResourceId: &provider.ResourceId{OpaqueId: s.ItemSource, StorageId: s.Prefix},
+ //ResourceId: &provider.Reference{StorageId: s.Prefix, NodeId: s.ItemSource},
+ ResourceId: &provider.ResourceId{
+ StorageId: s.Prefix,
+ OpaqueId: s.ItemSource,
+ },
Permissions: &collaboration.SharePermissions{Permissions: IntTosharePerm(s.Permissions)},
Grantee: ExtractGrantee(s.ShareType, s.ShareWith),
Owner: ExtractUserID(s.UIDOwner),
@@ -234,7 +238,10 @@ func ConvertToCS3PublicShare(s DBShare) *link.PublicShare {
Id: &link.PublicShareId{
OpaqueId: s.ID,
},
- ResourceId: &provider.ResourceId{OpaqueId: s.ItemSource, StorageId: s.Prefix},
+ ResourceId: &provider.ResourceId{
+ StorageId: s.Prefix,
+ OpaqueId: s.ItemSource,
+ },
Permissions: &link.PublicSharePermissions{Permissions: IntTosharePerm(s.Permissions)},
Owner: ExtractUserID(s.UIDOwner),
Creator: ExtractUserID(s.UIDInitiator),
diff --git a/pkg/ocm/share/manager/json/json.go b/pkg/ocm/share/manager/json/json.go
index 7a4e9d867a..3168f4951a 100644
--- a/pkg/ocm/share/manager/json/json.go
+++ b/pkg/ocm/share/manager/json/json.go
@@ -416,7 +416,7 @@ func (m *mgr) getByKey(ctx context.Context, key *ocm.ShareKey) (*ocm.Share, erro
continue
}
if (utils.UserEqual(key.Owner, share.Owner) || utils.UserEqual(key.Owner, share.Creator)) &&
- utils.ResourceEqual(key.ResourceId, share.ResourceId) && utils.GranteeEqual(key.Grantee, share.Grantee) {
+ utils.ResourceEqual(&provider.Reference{ResourceId: key.ResourceId}, &provider.Reference{ResourceId: share.ResourceId}) && utils.GranteeEqual(key.Grantee, share.Grantee) {
return &share, nil
}
}
@@ -492,7 +492,7 @@ func sharesEqual(ref *ocm.ShareReference, s *ocm.Share) bool {
}
} else if ref.GetKey() != nil {
if (utils.UserEqual(ref.GetKey().Owner, s.Owner) || utils.UserEqual(ref.GetKey().Owner, s.Creator)) &&
- utils.ResourceEqual(ref.GetKey().ResourceId, s.ResourceId) && utils.GranteeEqual(ref.GetKey().Grantee, s.Grantee) {
+ utils.ResourceEqual(&provider.Reference{ResourceId: ref.GetKey().ResourceId}, &provider.Reference{ResourceId: s.ResourceId}) && utils.GranteeEqual(ref.GetKey().Grantee, s.Grantee) {
return true
}
}
@@ -563,7 +563,7 @@ func (m *mgr) ListShares(ctx context.Context, filters []*ocm.ListOCMSharesReques
// TODO(labkode): add the rest of filters.
for _, f := range filters {
if f.Type == ocm.ListOCMSharesRequest_Filter_TYPE_RESOURCE_ID {
- if share.ResourceId.StorageId == f.GetResourceId().StorageId && share.ResourceId.OpaqueId == f.GetResourceId().OpaqueId {
+ if utils.ResourceEqual(&provider.Reference{ResourceId: share.ResourceId}, &provider.Reference{ResourceId: f.GetResourceId()}) {
ss = append(ss, &share)
}
}
diff --git a/pkg/publicshare/manager/json/json.go b/pkg/publicshare/manager/json/json.go
index eb2e17aa4b..655f8b78a7 100644
--- a/pkg/publicshare/manager/json/json.go
+++ b/pkg/publicshare/manager/json/json.go
@@ -379,7 +379,7 @@ func (m *manager) ListPublicShares(ctx context.Context, u *user.User, filters []
} else {
for i := range filters {
if filters[i].Type == link.ListPublicSharesRequest_Filter_TYPE_RESOURCE_ID {
- if local.ResourceId.StorageId == filters[i].GetResourceId().StorageId && local.ResourceId.OpaqueId == filters[i].GetResourceId().OpaqueId {
+ if utils.ResourceEqual(&provider.Reference{ResourceId: local.ResourceId}, &provider.Reference{ResourceId: filters[i].GetResourceId()}) {
if notExpired(&local.PublicShare) {
shares = append(shares, &local.PublicShare)
} else if err := m.revokeExpiredPublicShare(ctx, &local.PublicShare, u); err != nil {
diff --git a/pkg/publicshare/manager/memory/memory.go b/pkg/publicshare/manager/memory/memory.go
index 7473ae3ad7..f06aa39358 100644
--- a/pkg/publicshare/manager/memory/memory.go
+++ b/pkg/publicshare/manager/memory/memory.go
@@ -35,6 +35,7 @@ import (
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/publicshare"
"github.com/cs3org/reva/pkg/publicshare/manager/registry"
+ "github.com/cs3org/reva/pkg/utils"
)
func init() {
@@ -179,7 +180,7 @@ func (m *manager) ListPublicShares(ctx context.Context, u *user.User, filters []
} else {
for _, f := range filters {
if f.Type == link.ListPublicSharesRequest_Filter_TYPE_RESOURCE_ID {
- if s.ResourceId.StorageId == f.GetResourceId().StorageId && s.ResourceId.OpaqueId == f.GetResourceId().OpaqueId {
+ if utils.ResourceEqual(&provider.Reference{ResourceId: s.ResourceId}, &provider.Reference{ResourceId: f.GetResourceId()}) {
shares = append(shares, s)
}
}
diff --git a/pkg/rhttp/datatx/manager/simple/simple.go b/pkg/rhttp/datatx/manager/simple/simple.go
index b09aa669ed..50445f1df6 100644
--- a/pkg/rhttp/datatx/manager/simple/simple.go
+++ b/pkg/rhttp/datatx/manager/simple/simple.go
@@ -73,7 +73,7 @@ func (m *manager) Handler(fs storage.FS) (http.Handler, error) {
fn := r.URL.Path
defer r.Body.Close()
- ref := &provider.Reference{Spec: &provider.Reference_Path{Path: fn}}
+ ref := &provider.Reference{Path: fn}
err := fs.Upload(ctx, ref, r.Body)
switch v := err.(type) {
diff --git a/pkg/rhttp/datatx/utils/download/download.go b/pkg/rhttp/datatx/utils/download/download.go
index f7de5fab9c..8cab207bff 100644
--- a/pkg/rhttp/datatx/utils/download/download.go
+++ b/pkg/rhttp/datatx/utils/download/download.go
@@ -46,7 +46,7 @@ func GetOrHeadFile(w http.ResponseWriter, r *http.Request, fs storage.FS) {
fn = files[0]
}
- ref := &provider.Reference{Spec: &provider.Reference_Path{Path: fn}}
+ ref := &provider.Reference{Path: fn}
// TODO check preconditions like If-Range, If-Match ...
diff --git a/pkg/sdk/action/download.go b/pkg/sdk/action/download.go
index 109f2a33b4..7f081a58fa 100644
--- a/pkg/sdk/action/download.go
+++ b/pkg/sdk/action/download.go
@@ -89,13 +89,7 @@ func (action *DownloadAction) Download(fileInfo *storage.ResourceInfo) ([]byte,
func (action *DownloadAction) initiateDownload(fileInfo *storage.ResourceInfo) (*gateway.InitiateFileDownloadResponse, error) {
// Initiating a download request gets us the download endpoint for the specified resource
- req := &provider.InitiateFileDownloadRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: fileInfo.Path,
- },
- },
- }
+ req := &provider.InitiateFileDownloadRequest{Ref: &provider.Reference{ResourceId: fileInfo.Id}}
res, err := action.session.Client().InitiateFileDownload(action.session.Context(), req)
if err := net.CheckRPCInvocation("initiating download", res, err); err != nil {
return nil, err
diff --git a/pkg/sdk/action/enumfiles.go b/pkg/sdk/action/enumfiles.go
index d98a5157c2..1cf55a96c9 100644
--- a/pkg/sdk/action/enumfiles.go
+++ b/pkg/sdk/action/enumfiles.go
@@ -34,9 +34,7 @@ type EnumFilesAction struct {
// ListAll retrieves all files and directories contained in the provided path.
func (action *EnumFilesAction) ListAll(path string, includeSubdirectories bool) ([]*storage.ResourceInfo, error) {
- ref := &storage.Reference{
- Spec: &storage.Reference_Path{Path: path},
- }
+ ref := &storage.Reference{Path: path}
req := &storage.ListContainerRequest{Ref: ref}
res, err := action.session.Client().ListContainer(action.session.Context(), req)
if err := net.CheckRPCInvocation("listing container", res, err); err != nil {
diff --git a/pkg/sdk/action/fileops.go b/pkg/sdk/action/fileops.go
index 3f02b3a282..06a3ad83a8 100644
--- a/pkg/sdk/action/fileops.go
+++ b/pkg/sdk/action/fileops.go
@@ -37,9 +37,7 @@ type FileOperationsAction struct {
// Stat queries the file information of the specified remote resource.
func (action *FileOperationsAction) Stat(path string) (*storage.ResourceInfo, error) {
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{Path: path},
- }
+ ref := &provider.Reference{Path: path}
req := &provider.StatRequest{Ref: ref}
res, err := action.session.Client().Stat(action.session.Context(), req)
if err := net.CheckRPCInvocation("querying resource information", res, err); err != nil {
@@ -85,9 +83,7 @@ func (action *FileOperationsAction) MakePath(path string) error {
fileInfo, err := action.Stat(curPath)
if err != nil { // Stating failed, so the path probably doesn't exist yet
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{Path: curPath},
- }
+ ref := &provider.Reference{Path: curPath}
req := &provider.CreateContainerRequest{Ref: ref}
res, err := action.session.Client().CreateContainer(action.session.Context(), req)
if err := net.CheckRPCInvocation("creating container", res, err); err != nil {
@@ -104,12 +100,8 @@ func (action *FileOperationsAction) MakePath(path string) error {
// Move moves the specified source to a new location. The caller must ensure that the target directory exists.
func (action *FileOperationsAction) Move(source string, target string) error {
- sourceRef := &provider.Reference{
- Spec: &provider.Reference_Path{Path: source},
- }
- targetRef := &provider.Reference{
- Spec: &provider.Reference_Path{Path: target},
- }
+ sourceRef := &provider.Reference{Path: source}
+ targetRef := &provider.Reference{Path: target}
req := &provider.MoveRequest{Source: sourceRef, Destination: targetRef}
res, err := action.session.Client().Move(action.session.Context(), req)
if err := net.CheckRPCInvocation("moving resource", res, err); err != nil {
@@ -131,9 +123,7 @@ func (action *FileOperationsAction) MoveTo(source string, path string) error {
// Remove deletes the specified resource.
func (action *FileOperationsAction) Remove(path string) error {
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{Path: path},
- }
+ ref := &provider.Reference{Path: path}
req := &provider.DeleteRequest{Ref: ref}
res, err := action.session.Client().Delete(action.session.Context(), req)
if err := net.CheckRPCInvocation("deleting resource", res, err); err != nil {
diff --git a/pkg/sdk/action/upload.go b/pkg/sdk/action/upload.go
index 10f1548714..263722d670 100644
--- a/pkg/sdk/action/upload.go
+++ b/pkg/sdk/action/upload.go
@@ -131,11 +131,7 @@ func (action *UploadAction) upload(data io.Reader, dataInfo os.FileInfo, target
func (action *UploadAction) initiateUpload(target string, size int64) (*gateway.InitiateFileUploadResponse, error) {
// Initiating an upload request gets us the upload endpoint for the specified target
req := &provider.InitiateFileUploadRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: target,
- },
- },
+ Ref: &provider.Reference{Path: target},
Opaque: &types.Opaque{
Map: map[string]*types.OpaqueEntry{
"Upload-Length": {
diff --git a/pkg/share/cache/cbox/cbox.go b/pkg/share/cache/cbox/cbox.go
index 925a553c2d..9404926ecf 100644
--- a/pkg/share/cache/cbox/cbox.go
+++ b/pkg/share/cache/cbox/cbox.go
@@ -92,8 +92,8 @@ func (m *manager) GetResourceInfos() ([]*provider.ResourceInfo, error) {
infos := []*provider.ResourceInfo{}
for rows.Next() {
- var storageID, opaqueID string
- if err := rows.Scan(&storageID, &opaqueID); err != nil {
+ var storageID, nodeID string
+ if err := rows.Scan(&storageID, &nodeID); err != nil {
continue
}
@@ -127,11 +127,9 @@ func (m *manager) GetResourceInfos() ([]*provider.ResourceInfo, error) {
})
inf, err := eos.GetMD(ctx, &provider.Reference{
- Spec: &provider.Reference_Id{
- Id: &provider.ResourceId{
- StorageId: storageID,
- OpaqueId: opaqueID,
- },
+ ResourceId: &provider.ResourceId{
+ StorageId: storageID,
+ OpaqueId: nodeID,
},
}, []string{})
if err != nil {
diff --git a/pkg/share/manager/json/json.go b/pkg/share/manager/json/json.go
index 586978933b..354ce47880 100644
--- a/pkg/share/manager/json/json.go
+++ b/pkg/share/manager/json/json.go
@@ -245,7 +245,7 @@ func (m *mgr) getByKey(ctx context.Context, key *collaboration.ShareKey) (*colla
defer m.Unlock()
for _, s := range m.model.Shares {
if (utils.UserEqual(key.Owner, s.Owner) || utils.UserEqual(key.Owner, s.Creator)) &&
- utils.ResourceEqual(key.ResourceId, s.ResourceId) && utils.GranteeEqual(key.Grantee, s.Grantee) {
+ utils.ResourceIDEqual(key.ResourceId, s.ResourceId) && utils.GranteeEqual(key.Grantee, s.Grantee) {
return s, nil
}
}
@@ -323,7 +323,7 @@ func sharesEqual(ref *collaboration.ShareReference, s *collaboration.Share) bool
}
} else if ref.GetKey() != nil {
if (utils.UserEqual(ref.GetKey().Owner, s.Owner) || utils.UserEqual(ref.GetKey().Owner, s.Creator)) &&
- utils.ResourceEqual(ref.GetKey().ResourceId, s.ResourceId) && utils.GranteeEqual(ref.GetKey().Grantee, s.Grantee) {
+ utils.ResourceIDEqual(ref.GetKey().ResourceId, s.ResourceId) && utils.GranteeEqual(ref.GetKey().Grantee, s.Grantee) {
return true
}
}
@@ -369,7 +369,7 @@ func (m *mgr) ListShares(ctx context.Context, filters []*collaboration.ListShare
// TODO(labkode): add the rest of filters.
for _, f := range filters {
if f.Type == collaboration.ListSharesRequest_Filter_TYPE_RESOURCE_ID {
- if utils.ResourceEqual(s.ResourceId, f.GetResourceId()) {
+ if utils.ResourceIDEqual(s.ResourceId, f.GetResourceId()) {
ss = append(ss, s)
}
}
diff --git a/pkg/share/manager/memory/memory.go b/pkg/share/manager/memory/memory.go
index e3d6cda8bb..6b6c3e5b4c 100644
--- a/pkg/share/manager/memory/memory.go
+++ b/pkg/share/manager/memory/memory.go
@@ -125,7 +125,7 @@ func (m *manager) getByKey(ctx context.Context, key *collaboration.ShareKey) (*c
defer m.lock.Unlock()
for _, s := range m.shares {
if (utils.UserEqual(key.Owner, s.Owner) || utils.UserEqual(key.Owner, s.Creator)) &&
- utils.ResourceEqual(key.ResourceId, s.ResourceId) && utils.GranteeEqual(key.Grantee, s.Grantee) {
+ utils.ResourceIDEqual(key.ResourceId, s.ResourceId) && utils.GranteeEqual(key.Grantee, s.Grantee) {
return s, nil
}
}
@@ -188,7 +188,7 @@ func sharesEqual(ref *collaboration.ShareReference, s *collaboration.Share) bool
}
} else if ref.GetKey() != nil {
if (utils.UserEqual(ref.GetKey().Owner, s.Owner) || utils.UserEqual(ref.GetKey().Owner, s.Creator)) &&
- utils.ResourceEqual(ref.GetKey().ResourceId, s.ResourceId) && utils.GranteeEqual(ref.GetKey().Grantee, s.Grantee) {
+ utils.ResourceIDEqual(ref.GetKey().ResourceId, s.ResourceId) && utils.GranteeEqual(ref.GetKey().Grantee, s.Grantee) {
return true
}
}
@@ -230,7 +230,7 @@ func (m *manager) ListShares(ctx context.Context, filters []*collaboration.ListS
// TODO(labkode): add the rest of filters.
for _, f := range filters {
if f.Type == collaboration.ListSharesRequest_Filter_TYPE_RESOURCE_ID {
- if utils.ResourceEqual(s.ResourceId, f.GetResourceId()) {
+ if utils.ResourceIDEqual(s.ResourceId, f.GetResourceId()) {
ss = append(ss, s)
}
}
diff --git a/pkg/storage/fs/owncloud/owncloud.go b/pkg/storage/fs/owncloud/owncloud.go
index 41fdf42d5d..bc4fcf0058 100644
--- a/pkg/storage/fs/owncloud/owncloud.go
+++ b/pkg/storage/fs/owncloud/owncloud.go
@@ -263,7 +263,9 @@ func (fs *ocfs) toInternalPath(ctx context.Context, sp string) (ip string) {
if fs.c.EnableHome {
u := user.ContextMustGetUser(ctx)
layout := templates.WithUser(u, fs.c.UserLayout)
- ip = filepath.Join(fs.c.DataDirectory, layout, "files", sp)
+ // The inner filepath.Join prevents the path from breaking out of
+ // //files/
+ ip = filepath.Join(fs.c.DataDirectory, layout, "files", filepath.Join("/", sp))
} else {
// trim all /
sp = strings.Trim(sp, "/")
@@ -290,7 +292,7 @@ func (fs *ocfs) toInternalPath(ctx context.Context, sp string) (ip string) {
ip = filepath.Join(fs.c.DataDirectory, layout, "files")
} else {
// parts = "", "foo/bar.txt"
- ip = filepath.Join(fs.c.DataDirectory, layout, "files", segments[1])
+ ip = filepath.Join(fs.c.DataDirectory, layout, "files", filepath.Join(segments[1]))
}
}
@@ -362,7 +364,7 @@ func (fs *ocfs) getVersionsPath(ctx context.Context, ip string) string {
return filepath.Join(fs.c.DataDirectory, layout, "files_versions")
case 4:
// parts = "", "", "foo/bar.txt"
- return filepath.Join(fs.c.DataDirectory, layout, "files_versions", parts[3])
+ return filepath.Join(fs.c.DataDirectory, layout, "files_versions", filepath.Join("/", parts[3]))
default:
return "" // TODO Must not happen?
}
@@ -792,20 +794,19 @@ func (fs *ocfs) GetPathByID(ctx context.Context, id *provider.ResourceId) (strin
// resolve takes in a request path or request id and converts it to an internal path.
func (fs *ocfs) resolve(ctx context.Context, ref *provider.Reference) (string, error) {
- if ref.GetPath() != "" {
- return fs.toInternalPath(ctx, ref.GetPath()), nil
- }
- if ref.GetId() != nil {
- ip, err := fs.getPath(ctx, ref.GetId())
+ // if storage id is set look up that
+ if ref.ResourceId != nil {
+ ip, err := fs.getPath(ctx, ref.ResourceId)
if err != nil {
return "", err
}
- return ip, nil
+ return filepath.Join("/", ip, filepath.Join("/", ref.Path)), nil
}
- // reference is invalid
- return "", fmt.Errorf("invalid reference %+v", ref)
+ // use a path
+ return fs.toInternalPath(ctx, ref.Path), nil
+
}
func (fs *ocfs) AddGrant(ctx context.Context, ref *provider.Reference, g *provider.Grant) error {
@@ -2137,7 +2138,9 @@ func (fs *ocfs) convertToRecycleItem(ctx context.Context, rp string, md os.FileI
Type: getResourceType(md.IsDir()),
Key: md.Name(),
// TODO do we need to prefix the path? it should be relative to this storage root, right?
- Path: originalPath,
+ Ref: &provider.Reference{
+ Path: originalPath,
+ },
Size: uint64(md.Size()),
DeletionTime: &types.Timestamp{
Seconds: uint64(ttime),
@@ -2173,7 +2176,7 @@ func (fs *ocfs) ListRecycle(ctx context.Context) ([]*provider.RecycleItem, error
return items, nil
}
-func (fs *ocfs) RestoreRecycleItem(ctx context.Context, key, restorePath string) error {
+func (fs *ocfs) RestoreRecycleItem(ctx context.Context, key string, restoreRef *provider.Reference) error {
// TODO check permission? on what? user must be the owner?
log := appctx.GetLogger(ctx)
rp, err := fs.getRecyclePath(ctx)
@@ -2188,17 +2191,20 @@ func (fs *ocfs) RestoreRecycleItem(ctx context.Context, key, restorePath string)
return nil
}
- if restorePath == "" {
+ if restoreRef == nil {
+ restoreRef = &provider.Reference{}
+ }
+ if restoreRef.Path == "" {
v, err := xattr.Get(src, trashOriginPrefix)
if err != nil {
log.Error().Err(err).Str("key", key).Str("path", src).Msg("could not read origin")
}
- restorePath = filepath.Join("/", filepath.Clean(string(v)), strings.TrimSuffix(filepath.Base(src), suffix))
+ restoreRef.Path = filepath.Join("/", filepath.Clean(string(v)), strings.TrimSuffix(filepath.Base(src), suffix))
}
- tgt := fs.toInternalPath(ctx, restorePath)
+ tgt := fs.toInternalPath(ctx, restoreRef.Path)
// move back to original location
if err := os.Rename(src, tgt); err != nil {
- log.Error().Err(err).Str("key", key).Str("restorePath", restorePath).Str("src", src).Str("tgt", tgt).Msg("could not restore item")
+ log.Error().Err(err).Str("key", key).Str("restorePath", restoreRef.Path).Str("src", src).Str("tgt", tgt).Msg("could not restore item")
return errors.Wrap(err, "ocfs: could not restore item")
}
// unset trash origin location in metadata
diff --git a/pkg/storage/fs/owncloud/upload.go b/pkg/storage/fs/owncloud/upload.go
index e48f1c7494..181f86e643 100644
--- a/pkg/storage/fs/owncloud/upload.go
+++ b/pkg/storage/fs/owncloud/upload.go
@@ -263,7 +263,7 @@ func (fs *ocfs) getUploadPath(ctx context.Context, uploadID string) (string, err
// GetUpload returns the Upload for the given upload id
func (fs *ocfs) GetUpload(ctx context.Context, id string) (tusd.Upload, error) {
- infoPath := filepath.Join(fs.c.UploadInfoDir, id+".info")
+ infoPath := filepath.Join(fs.c.UploadInfoDir, filepath.Join("/", id+".info"))
info := tusd.FileInfo{}
data, err := ioutil.ReadFile(infoPath)
diff --git a/pkg/storage/fs/owncloudsql/owncloudsql.go b/pkg/storage/fs/owncloudsql/owncloudsql.go
index 2b7b871398..030d079ce5 100644
--- a/pkg/storage/fs/owncloudsql/owncloudsql.go
+++ b/pkg/storage/fs/owncloudsql/owncloudsql.go
@@ -651,12 +651,9 @@ func (fs *ocfs) GetPathByID(ctx context.Context, id *provider.ResourceId) (strin
// resolve takes in a request path or request id and converts it to an internal path.
func (fs *ocfs) resolve(ctx context.Context, ref *provider.Reference) (string, error) {
- if ref.GetPath() != "" {
- return fs.toInternalPath(ctx, ref.GetPath()), nil
- }
- if ref.GetId() != nil {
- p, err := fs.filecache.Path(ref.GetId().OpaqueId)
+ if ref.GetResourceId() != nil {
+ p, err := fs.filecache.Path(ref.GetResourceId().OpaqueId)
if err != nil {
return "", err
}
@@ -672,6 +669,10 @@ func (fs *ocfs) resolve(ctx context.Context, ref *provider.Reference) (string, e
return fs.toInternalPath(ctx, p), nil
}
+ if ref.GetPath() != "" {
+ return fs.toInternalPath(ctx, ref.GetPath()), nil
+ }
+
// reference is invalid
return "", fmt.Errorf("invalid reference %+v", ref)
}
@@ -1990,7 +1991,7 @@ func (fs *ocfs) convertToRecycleItem(ctx context.Context, md os.FileInfo) *provi
Type: getResourceType(md.IsDir()),
Key: md.Name(),
// TODO do we need to prefix the path? it should be relative to this storage root, right?
- Path: originalPath,
+ Ref: &provider.Reference{Path: originalPath},
Size: uint64(md.Size()),
DeletionTime: &types.Timestamp{
Seconds: uint64(ttime),
@@ -2026,7 +2027,7 @@ func (fs *ocfs) ListRecycle(ctx context.Context) ([]*provider.RecycleItem, error
return items, nil
}
-func (fs *ocfs) RestoreRecycleItem(ctx context.Context, key, restorePath string) error {
+func (fs *ocfs) RestoreRecycleItem(ctx context.Context, key string, restoreRef *provider.Reference) error {
// TODO check permission? on what? user must be the owner?
log := appctx.GetLogger(ctx)
rp, err := fs.getRecyclePath(ctx)
@@ -2041,17 +2042,17 @@ func (fs *ocfs) RestoreRecycleItem(ctx context.Context, key, restorePath string)
return nil
}
- if restorePath == "" {
+ if restoreRef.Path == "" {
v, err := xattr.Get(src, trashOriginPrefix)
if err != nil {
log.Error().Err(err).Str("key", key).Str("path", src).Msg("could not read origin")
}
- restorePath = filepath.Join("/", filepath.Clean(string(v)), strings.TrimSuffix(filepath.Base(src), suffix))
+ restoreRef.Path = filepath.Join("/", filepath.Clean(string(v)), strings.TrimSuffix(filepath.Base(src), suffix))
}
- tgt := fs.toInternalPath(ctx, restorePath)
+ tgt := fs.toInternalPath(ctx, restoreRef.Path)
// move back to original location
if err := os.Rename(src, tgt); err != nil {
- log.Error().Err(err).Str("key", key).Str("restorePath", restorePath).Str("src", src).Str("tgt", tgt).Msg("could not restore item")
+ log.Error().Err(err).Str("key", key).Str("restorePath", restoreRef.Path).Str("src", src).Str("tgt", tgt).Msg("could not restore item")
return errors.Wrap(err, "ocfs: could not restore item")
}
diff --git a/pkg/storage/fs/s3/s3.go b/pkg/storage/fs/s3/s3.go
index d7cfc4a493..83c1fe1db8 100644
--- a/pkg/storage/fs/s3/s3.go
+++ b/pkg/storage/fs/s3/s3.go
@@ -115,12 +115,12 @@ func (fs *s3FS) addRoot(p string) string {
}
func (fs *s3FS) resolve(ctx context.Context, ref *provider.Reference) (string, error) {
- if ref.GetPath() != "" {
+ if ref.Path != "" {
return fs.addRoot(ref.GetPath()), nil
}
- if ref.GetId() != nil {
- fn := path.Join("/", strings.TrimPrefix(ref.GetId().OpaqueId, "fileid-"))
+ if ref.ResourceId != nil {
+ fn := path.Join("/", strings.TrimPrefix(ref.ResourceId.OpaqueId, "fileid-"))
fn = fs.addRoot(fn)
return fn, nil
}
@@ -172,7 +172,9 @@ func (fs *s3FS) normalizeObject(ctx context.Context, o *s3.Object, fn string) *p
fn = fs.removeRoot(path.Join("/", fn))
isDir := strings.HasSuffix(*o.Key, "/")
md := &provider.ResourceInfo{
- Id: &provider.ResourceId{OpaqueId: "fileid-" + strings.TrimPrefix(fn, "/")},
+ Id: &provider.ResourceId{
+ OpaqueId: "fileid-" + strings.TrimPrefix(fn, "/"),
+ },
Path: fn,
Type: getResourceType(isDir),
Etag: *o.ETag,
@@ -656,6 +658,6 @@ func (fs *s3FS) ListRecycle(ctx context.Context) ([]*provider.RecycleItem, error
return nil, errtypes.NotSupported("list recycle")
}
-func (fs *s3FS) RestoreRecycleItem(ctx context.Context, restoreKey, restorePath string) error {
+func (fs *s3FS) RestoreRecycleItem(ctx context.Context, key string, restoreRef *provider.Reference) error {
return errtypes.NotSupported("restore recycle")
}
diff --git a/pkg/storage/migrate/metadata.go b/pkg/storage/migrate/metadata.go
index b9aae4b3ab..fe56b438ef 100644
--- a/pkg/storage/migrate/metadata.go
+++ b/pkg/storage/migrate/metadata.go
@@ -73,9 +73,7 @@ func ImportMetadata(ctx context.Context, client gateway.GatewayAPIClient, export
if len(m) > 0 {
resourcePath := path.Join(ns, path.Base(exportPath), strings.TrimPrefix(fileData.Path, "/files/"))
samReq := &storageprovider.SetArbitraryMetadataRequest{
- Ref: &storageprovider.Reference{
- Spec: &storageprovider.Reference_Path{Path: resourcePath},
- },
+ Ref: &storageprovider.Reference{Path: resourcePath},
ArbitraryMetadata: &storageprovider.ArbitraryMetadata{
Metadata: m,
},
diff --git a/pkg/storage/migrate/shares.go b/pkg/storage/migrate/shares.go
index 4fc746d084..74207059bd 100644
--- a/pkg/storage/migrate/shares.go
+++ b/pkg/storage/migrate/shares.go
@@ -67,11 +67,7 @@ func ImportShares(ctx context.Context, client gateway.GatewayAPIClient, exportPa
// Stat file, skip share creation if it does not exist on the target system
resourcePath := path.Join(ns, path.Base(exportPath), shareData.Path)
- statReq := &provider.StatRequest{
- Ref: &provider.Reference{
- Spec: &provider.Reference_Path{Path: resourcePath},
- },
- }
+ statReq := &provider.StatRequest{Ref: &provider.Reference{Path: resourcePath}}
statResp, err := client.Stat(ctx, statReq)
if err != nil {
diff --git a/pkg/storage/registry/static/static.go b/pkg/storage/registry/static/static.go
index 0242011ecf..3074dd467e 100644
--- a/pkg/storage/registry/static/static.go
+++ b/pkg/storage/registry/static/static.go
@@ -143,7 +143,26 @@ func (b *reg) FindProviders(ctx context.Context, ref *provider.Reference) ([]*re
var match *registrypb.ProviderInfo
var shardedMatches []*registrypb.ProviderInfo
- // Try to find by path first as most storage operations will be done using the path.
+ // If the reference has a resource id set, use it to route
+ if ref.ResourceId != nil {
+ for prefix, rule := range b.c.Rules {
+ addr := getProviderAddr(ctx, rule)
+ r, err := regexp.Compile("^" + prefix + "$")
+ if err != nil {
+ continue
+ }
+ // TODO(labkode): fill path info based on provider id, if path and storage id points to same id, take that.
+ if m := r.FindString(ref.ResourceId.StorageId); m != "" {
+ return []*registrypb.ProviderInfo{{
+ ProviderId: ref.ResourceId.StorageId,
+ Address: addr,
+ }}, nil
+ }
+ }
+ }
+
+ // Try to find by path as most storage operations will be done using the path.
+ // TODO this needs to be reevaluated once all clients query the storage registry for a list of storage providers
fn := path.Clean(ref.GetPath())
if fn != "" {
for prefix, rule := range b.c.Rules {
@@ -179,27 +198,6 @@ func (b *reg) FindProviders(ctx context.Context, ref *provider.Reference) ([]*re
return shardedMatches, nil
}
- // Try with id
- id := ref.GetId()
- if id == nil {
- return nil, errtypes.NotFound("storage provider not found for ref " + ref.String())
- }
-
- for prefix, rule := range b.c.Rules {
- addr := getProviderAddr(ctx, rule)
- r, err := regexp.Compile("^" + prefix + "$")
- if err != nil {
- continue
- }
- // TODO(labkode): fill path info based on provider id, if path and storage id points to same id, take that.
- if m := r.FindString(id.StorageId); m != "" {
- return []*registrypb.ProviderInfo{®istrypb.ProviderInfo{
- ProviderId: id.StorageId,
- Address: addr,
- }}, nil
- }
- }
-
return nil, errtypes.NotFound("storage provider not found for ref " + ref.String())
}
diff --git a/pkg/storage/registry/static/static_test.go b/pkg/storage/registry/static/static_test.go
index ff0aee14cc..1872ba8aab 100644
--- a/pkg/storage/registry/static/static_test.go
+++ b/pkg/storage/registry/static/static_test.go
@@ -125,11 +125,7 @@ var _ = Describe("Static", func() {
})
Describe("FindProviders for home reference", func() {
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: "/home/abcd",
- },
- }
+ ref := &provider.Reference{Path: "/home/abcd"}
It("finds all providers for user alice for a home ref", func() {
providers, err := handler.FindProviders(ctxAlice, ref)
@@ -153,11 +149,7 @@ var _ = Describe("Static", func() {
})
Describe("FindProviders for eos reference", func() {
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: "/eos/user/b/bob/xyz",
- },
- }
+ ref := &provider.Reference{Path: "/eos/user/b/bob/xyz"}
It("finds all providers for user alice for an eos ref", func() {
providers, err := handler.FindProviders(ctxAlice, ref)
@@ -181,11 +173,7 @@ var _ = Describe("Static", func() {
})
Describe("FindProviders for project reference", func() {
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: "/eos/project/pqr",
- },
- }
+ ref := &provider.Reference{Path: "/eos/project/pqr"}
It("finds all providers for user alice for a project ref", func() {
providers, err := handler.FindProviders(ctxAlice, ref)
@@ -209,16 +197,8 @@ var _ = Describe("Static", func() {
})
Describe("FindProviders for virtual references", func() {
- ref1 := &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: "/eos",
- },
- }
- ref2 := &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: "/",
- },
- }
+ ref1 := &provider.Reference{Path: "/eos"}
+ ref2 := &provider.Reference{Path: "/"}
It("finds all providers for user alice for a virtual eos ref", func() {
providers, err := handler.FindProviders(ctxAlice, ref1)
@@ -247,10 +227,8 @@ var _ = Describe("Static", func() {
Describe("FindProviders for reference containing ID", func() {
ref := &provider.Reference{
- Spec: &provider.Reference_Id{
- Id: &provider.ResourceId{
- StorageId: "123e4567-e89b-12d3-a456-426655440000",
- },
+ ResourceId: &provider.ResourceId{
+ StorageId: "123e4567-e89b-12d3-a456-426655440000",
},
}
diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go
index 53e718886c..8481c45a98 100644
--- a/pkg/storage/storage.go
+++ b/pkg/storage/storage.go
@@ -43,7 +43,7 @@ type FS interface {
DownloadRevision(ctx context.Context, ref *provider.Reference, key string) (io.ReadCloser, error)
RestoreRevision(ctx context.Context, ref *provider.Reference, key string) error
ListRecycle(ctx context.Context) ([]*provider.RecycleItem, error)
- RestoreRecycleItem(ctx context.Context, key, restorePath string) error
+ RestoreRecycleItem(ctx context.Context, key string, restoreRef *provider.Reference) error
PurgeRecycleItem(ctx context.Context, key string) error
EmptyRecycle(ctx context.Context) error
GetPathByID(ctx context.Context, id *provider.ResourceId) (string, error)
diff --git a/pkg/storage/utils/chunking/chunking.go b/pkg/storage/utils/chunking/chunking.go
index 5130d88772..656ec14fe9 100644
--- a/pkg/storage/utils/chunking/chunking.go
+++ b/pkg/storage/utils/chunking/chunking.go
@@ -96,7 +96,7 @@ func (c *ChunkHandler) createChunkTempFile() (string, *os.File, error) {
}
func (c *ChunkHandler) getChunkFolderName(i *ChunkBLOBInfo) (string, error) {
- path := "/" + c.ChunkFolder + filepath.Clean("/"+i.uploadID())
+ path := filepath.Join("/", c.ChunkFolder, filepath.Join("/", i.uploadID()))
if err := os.MkdirAll(path, 0755); err != nil {
return "", err
}
@@ -132,7 +132,7 @@ func (c *ChunkHandler) saveChunk(path string, r io.ReadCloser) (bool, string, er
}
// c.logger.Info().Log("chunkfolder", chunksFolderName)
- chunkTarget := chunksFolderName + "/" + fmt.Sprintf("%d", chunkInfo.CurrentChunk)
+ chunkTarget := filepath.Join(chunksFolderName, strconv.Itoa(chunkInfo.CurrentChunk))
if err = os.Rename(chunkTempFilename, chunkTarget); err != nil {
return false, "", err
}
@@ -171,7 +171,7 @@ func (c *ChunkHandler) saveChunk(path string, r io.ReadCloser) (bool, string, er
// walk all chunks and append to assembled file
for i := range chunks {
- target := chunksFolderName + "/" + fmt.Sprintf("%d", i)
+ target := filepath.Join(chunksFolderName, strconv.Itoa(i))
chunk, err := os.Open(target)
if err != nil {
diff --git a/pkg/storage/utils/decomposedfs/decomposedfs.go b/pkg/storage/utils/decomposedfs/decomposedfs.go
index cfef24de56..3d55a99a19 100644
--- a/pkg/storage/utils/decomposedfs/decomposedfs.go
+++ b/pkg/storage/utils/decomposedfs/decomposedfs.go
@@ -63,7 +63,7 @@ type Tree interface {
// CreateReference(ctx context.Context, node *node.Node, targetURI *url.URL) error
Move(ctx context.Context, oldNode *node.Node, newNode *node.Node) (err error)
Delete(ctx context.Context, node *node.Node) (err error)
- RestoreRecycleItemFunc(ctx context.Context, key, restorePath string) (*node.Node, func() error, error)
+ RestoreRecycleItemFunc(ctx context.Context, key, restorePath string) (*node.Node, func() error, error) // FIXME REFERENCE use ref instead of path
PurgeRecycleItemFunc(ctx context.Context, key string) (*node.Node, func() error, error)
WriteBlob(key string, reader io.Reader) error
diff --git a/pkg/storage/utils/decomposedfs/decomposedfs_concurrency_test.go b/pkg/storage/utils/decomposedfs/decomposedfs_concurrency_test.go
index 2db853e810..fd3c2e3281 100644
--- a/pkg/storage/utils/decomposedfs/decomposedfs_concurrency_test.go
+++ b/pkg/storage/utils/decomposedfs/decomposedfs_concurrency_test.go
@@ -108,17 +108,13 @@ var _ = Describe("Decomposed", func() {
// upload file with contents: "test"
go func(wg *sync.WaitGroup) {
- _ = fs.Upload(ctx, &provider.Reference{
- Spec: &provider.Reference_Path{Path: "uploaded.txt"},
- }, f)
+ _ = fs.Upload(ctx, &provider.Reference{Path: "uploaded.txt"}, f)
wg.Done()
}(wg)
// upload file with contents: "another run"
go func(wg *sync.WaitGroup) {
- _ = fs.Upload(ctx, &provider.Reference{
- Spec: &provider.Reference_Path{Path: "uploaded.txt"},
- }, f1)
+ _ = fs.Upload(ctx, &provider.Reference{Path: "uploaded.txt"}, f1)
wg.Done()
}(wg)
@@ -129,9 +125,7 @@ var _ = Describe("Decomposed", func() {
// same for 2 uploads.
wg.Wait()
- revisions, err := fs.ListRevisions(ctx, &provider.Reference{
- Spec: &provider.Reference_Path{Path: "uploaded.txt"},
- })
+ revisions, err := fs.ListRevisions(ctx, &provider.Reference{Path: "uploaded.txt"})
Expect(err).ToNot(HaveOccurred())
Expect(len(revisions)).To(Equal(1))
@@ -146,9 +140,7 @@ var _ = Describe("Decomposed", func() {
go func() {
err := fs.CreateDir(ctx, "fightforit")
if err != nil {
- rinfo, err := fs.GetMD(ctx, &provider.Reference{
- Spec: &provider.Reference_Path{Path: "fightforit"},
- }, nil)
+ rinfo, err := fs.GetMD(ctx, &provider.Reference{Path: "fightforit"}, nil)
Expect(err).ToNot(HaveOccurred())
Expect(rinfo).ToNot(BeNil())
}
diff --git a/pkg/storage/utils/decomposedfs/decomposedfs_test.go b/pkg/storage/utils/decomposedfs/decomposedfs_test.go
index 118bb1f87a..0fa7d535c3 100644
--- a/pkg/storage/utils/decomposedfs/decomposedfs_test.go
+++ b/pkg/storage/utils/decomposedfs/decomposedfs_test.go
@@ -38,11 +38,7 @@ var _ = Describe("Decomposed", func() {
)
BeforeEach(func() {
- ref = &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: "/dir1",
- },
- }
+ ref = &provider.Reference{Path: "/dir1"}
})
JustBeforeEach(func() {
diff --git a/pkg/storage/utils/decomposedfs/grants_test.go b/pkg/storage/utils/decomposedfs/grants_test.go
index e8f93cbe89..5224d2fb66 100644
--- a/pkg/storage/utils/decomposedfs/grants_test.go
+++ b/pkg/storage/utils/decomposedfs/grants_test.go
@@ -41,11 +41,7 @@ var _ = Describe("Grants", func() {
)
BeforeEach(func() {
- ref = &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: "/dir1",
- },
- }
+ ref = &provider.Reference{Path: "/dir1"}
grant = &provider.Grant{
Grantee: &provider.Grantee{
diff --git a/pkg/storage/utils/decomposedfs/lookup.go b/pkg/storage/utils/decomposedfs/lookup.go
index 0de4106b73..fe1fc315bc 100644
--- a/pkg/storage/utils/decomposedfs/lookup.go
+++ b/pkg/storage/utils/decomposedfs/lookup.go
@@ -40,16 +40,16 @@ type Lookup struct {
// NodeFromResource takes in a request path or request id and converts it to a Node
func (lu *Lookup) NodeFromResource(ctx context.Context, ref *provider.Reference) (*node.Node, error) {
- if ref.GetPath() != "" {
- return lu.NodeFromPath(ctx, ref.GetPath())
+ if ref.ResourceId != nil {
+ return lu.NodeFromID(ctx, ref.ResourceId)
}
- if ref.GetId() != nil {
- return lu.NodeFromID(ctx, ref.GetId())
+ if ref.Path != "" {
+ return lu.NodeFromPath(ctx, ref.GetPath())
}
// reference is invalid
- return nil, fmt.Errorf("invalid reference %+v", ref)
+ return nil, fmt.Errorf("invalid reference %+v. at least resource_id or path must be set", ref)
}
// NodeFromPath converts a filename into a Node
diff --git a/pkg/storage/utils/decomposedfs/mocks/Tree.go b/pkg/storage/utils/decomposedfs/mocks/Tree.go
index 0874e2bbc9..8fe655b985 100644
--- a/pkg/storage/utils/decomposedfs/mocks/Tree.go
+++ b/pkg/storage/utils/decomposedfs/mocks/Tree.go
@@ -104,18 +104,18 @@ func (_m *Tree) GetMD(ctx context.Context, _a1 *node.Node) (os.FileInfo, error)
}
// GetPathByID provides a mock function with given fields: ctx, id
-func (_m *Tree) GetPathByID(ctx context.Context, id *providerv1beta1.ResourceId) (string, error) {
+func (_m *Tree) GetPathByID(ctx context.Context, id *providerv1beta1.Reference) (string, error) {
ret := _m.Called(ctx, id)
var r0 string
- if rf, ok := ret.Get(0).(func(context.Context, *providerv1beta1.ResourceId) string); ok {
+ if rf, ok := ret.Get(0).(func(context.Context, *providerv1beta1.Reference) string); ok {
r0 = rf(ctx, id)
} else {
r0 = ret.Get(0).(string)
}
var r1 error
- if rf, ok := ret.Get(1).(func(context.Context, *providerv1beta1.ResourceId) error); ok {
+ if rf, ok := ret.Get(1).(func(context.Context, *providerv1beta1.Reference) error); ok {
r1 = rf(ctx, id)
} else {
r1 = ret.Error(1)
diff --git a/pkg/storage/utils/decomposedfs/node/node.go b/pkg/storage/utils/decomposedfs/node/node.go
index 55af74eb5c..660165ef32 100644
--- a/pkg/storage/utils/decomposedfs/node/node.go
+++ b/pkg/storage/utils/decomposedfs/node/node.go
@@ -200,7 +200,7 @@ func isNotDir(err error) bool {
// Child returns the child node with the given name
func (n *Node) Child(ctx context.Context, name string) (*Node, error) {
- link, err := os.Readlink(filepath.Join(n.InternalPath(), name))
+ link, err := os.Readlink(filepath.Join(n.InternalPath(), filepath.Join("/", name)))
if err != nil {
if os.IsNotExist(err) || isNotDir(err) {
c := &Node{
diff --git a/pkg/storage/utils/decomposedfs/recycle.go b/pkg/storage/utils/decomposedfs/recycle.go
index 1282f9a0f6..c30b16dd3c 100644
--- a/pkg/storage/utils/decomposedfs/recycle.go
+++ b/pkg/storage/utils/decomposedfs/recycle.go
@@ -117,7 +117,7 @@ func (fs *Decomposedfs) ListRecycle(ctx context.Context) (items []*provider.Recy
// lookup origin path in extended attributes
var attrBytes []byte
if attrBytes, err = xattr.Get(nodePath, xattrs.TrashOriginAttr); err == nil {
- item.Path = string(attrBytes)
+ item.Ref = &provider.Reference{Path: string(attrBytes)}
} else {
log.Error().Err(err).Str("trashRoot", trashRoot).Str("name", names[i]).Str("link", trashnode).Msg("could not read origin path, skipping")
continue
@@ -146,8 +146,11 @@ func (fs *Decomposedfs) ListRecycle(ctx context.Context) (items []*provider.Recy
}
// RestoreRecycleItem restores the specified item
-func (fs *Decomposedfs) RestoreRecycleItem(ctx context.Context, key, restorePath string) error {
- rn, restoreFunc, err := fs.tp.RestoreRecycleItemFunc(ctx, key, restorePath)
+func (fs *Decomposedfs) RestoreRecycleItem(ctx context.Context, key string, restoreRef *provider.Reference) error {
+ if restoreRef == nil {
+ restoreRef = &provider.Reference{}
+ }
+ rn, restoreFunc, err := fs.tp.RestoreRecycleItemFunc(ctx, key, restoreRef.Path)
if err != nil {
return err
}
diff --git a/pkg/storage/utils/decomposedfs/upload_test.go b/pkg/storage/utils/decomposedfs/upload_test.go
index ebe2791428..903f93bb2d 100644
--- a/pkg/storage/utils/decomposedfs/upload_test.go
+++ b/pkg/storage/utils/decomposedfs/upload_test.go
@@ -56,11 +56,7 @@ var _ = Describe("File uploads", func() {
)
BeforeEach(func() {
- ref = &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: "/foo",
- },
- }
+ ref = &provider.Reference{Path: "/foo"}
user = &userpb.User{
Id: &userpb.UserId{
Idp: "idp",
diff --git a/pkg/storage/utils/eosfs/eosfs.go b/pkg/storage/utils/eosfs/eosfs.go
index 4976a04c30..6ac5882b53 100644
--- a/pkg/storage/utils/eosfs/eosfs.go
+++ b/pkg/storage/utils/eosfs/eosfs.go
@@ -330,21 +330,20 @@ func (fs *eosfs) unwrapInternal(ctx context.Context, ns, np, layout string) (str
// resolve takes in a request path or request id and returns the unwrappedNominal path.
func (fs *eosfs) resolve(ctx context.Context, u *userpb.User, ref *provider.Reference) (string, error) {
- if ref.GetPath() != "" {
- return ref.GetPath(), nil
- }
-
- if ref.GetId() != nil {
- p, err := fs.getPath(ctx, u, ref.GetId())
+ if ref.ResourceId != nil {
+ p, err := fs.getPath(ctx, u, ref.ResourceId)
if err != nil {
return "", err
}
-
+ p = path.Join(p, ref.Path)
return p, nil
}
+ if ref.Path != "" {
+ return ref.Path, nil
+ }
// reference is invalid
- return "", fmt.Errorf("invalid reference %+v. id and path are missing", ref)
+ return "", fmt.Errorf("invalid reference %+v. at least resource_id or path must be set", ref)
}
func (fs *eosfs) getPath(ctx context.Context, u *userpb.User, id *provider.ResourceId) (string, error) {
@@ -387,6 +386,7 @@ func (fs *eosfs) GetPathByID(ctx context.Context, id *provider.ResourceId) (stri
}
// parts[0] = 868317, parts[1] = photos, ...
+ // FIXME REFERENCE ... umm ... 868317/photos? @ishank011 might be a leftover
parts := strings.Split(id.OpaqueId, "/")
fileID, err := strconv.ParseUint(parts[0], 10, 64)
if err != nil {
@@ -1338,7 +1338,7 @@ func (fs *eosfs) ListRecycle(ctx context.Context) ([]*provider.RecycleItem, erro
return recycleEntries, nil
}
-func (fs *eosfs) RestoreRecycleItem(ctx context.Context, key, restorePath string) error {
+func (fs *eosfs) RestoreRecycleItem(ctx context.Context, key string, restoreRef *provider.Reference) error {
u, err := getUser(ctx)
if err != nil {
return errors.Wrap(err, "eos: no user in ctx")
@@ -1358,7 +1358,7 @@ func (fs *eosfs) convertToRecycleItem(ctx context.Context, eosDeletedItem *eoscl
return nil, err
}
recycleItem := &provider.RecycleItem{
- Path: path,
+ Ref: &provider.Reference{Path: path},
Key: eosDeletedItem.RestoreKey,
Size: eosDeletedItem.Size,
DeletionTime: &types.Timestamp{Seconds: eosDeletedItem.DeletionMTime},
@@ -1676,7 +1676,7 @@ func (fs *eosfs) getEosMetadata(finfo *eosclient.FileInfo) []byte {
No RestoreRecycleItem(ctx context.Context, key string) error
No PurgeRecycleItem(ctx context.Context, key string) error
No EmptyRecycle(ctx context.Context) error
- ? GetPathByID(ctx context.Context, id *provider.ResourceId) (string, error)
+ ? GetPathByID(ctx context.Context, id *provider.Reference) (string, error)
No AddGrant(ctx context.Context, ref *provider.Reference, g *provider.Grant) error
No RemoveGrant(ctx context.Context, ref *provider.Reference, g *provider.Grant) error
No UpdateGrant(ctx context.Context, ref *provider.Reference, g *provider.Grant) error
@@ -1707,7 +1707,7 @@ func (fs *eosfs) getEosMetadata(finfo *eosclient.FileInfo) []byte {
No RestoreRecycleItem(ctx context.Context, key string) error
No PurgeRecycleItem(ctx context.Context, key string) error
No EmptyRecycle(ctx context.Context) error
- ? GetPathByID(ctx context.Context, id *provider.ResourceId) (string, error)
+ ? GetPathByID(ctx context.Context, id *provider.Reference) (string, error)
No AddGrant(ctx context.Context, ref *provider.Reference, g *provider.Grant) error
No RemoveGrant(ctx context.Context, ref *provider.Reference, g *provider.Grant) error
No UpdateGrant(ctx context.Context, ref *provider.Reference, g *provider.Grant) error
@@ -1738,7 +1738,7 @@ func (fs *eosfs) getEosMetadata(finfo *eosclient.FileInfo) []byte {
No RestoreRecycleItem(ctx context.Context, key string) error
No PurgeRecycleItem(ctx context.Context, key string) error
No EmptyRecycle(ctx context.Context) error
- ? GetPathByID(ctx context.Context, id *provider.ResourceId) (string, error)
+ ? GetPathByID(ctx context.Context, id *provider.Reference) (string, error)
No AddGrant(ctx context.Context, ref *provider.Reference, g *provider.Grant) error
No RemoveGrant(ctx context.Context, ref *provider.Reference, g *provider.Grant) error
No UpdateGrant(ctx context.Context, ref *provider.Reference, g *provider.Grant) error
diff --git a/pkg/storage/utils/localfs/localfs.go b/pkg/storage/utils/localfs/localfs.go
index 3ed3873aba..d9c7e13870 100644
--- a/pkg/storage/utils/localfs/localfs.go
+++ b/pkg/storage/utils/localfs/localfs.go
@@ -135,17 +135,20 @@ func (fs *localfs) Shutdown(ctx context.Context) error {
return nil
}
-func (fs *localfs) resolve(ctx context.Context, ref *provider.Reference) (string, error) {
- if ref.GetPath() != "" {
- return ref.GetPath(), nil
+func (fs *localfs) resolve(ctx context.Context, ref *provider.Reference) (p string, err error) {
+ if ref.ResourceId != nil {
+ if p, err = fs.GetPathByID(ctx, ref.ResourceId); err != nil {
+ return "", err
+ }
+ return path.Join(p, path.Join("/", ref.Path)), nil
}
- if ref.GetId() != nil {
- return fs.GetPathByID(ctx, ref.GetId())
+ if ref.Path != "" {
+ return path.Join("/", ref.Path), nil
}
// reference is invalid
- return "", fmt.Errorf("local: invalid reference %+v", ref)
+ return "", fmt.Errorf("invalid reference %+v. at least resource_id or path must be set", ref)
}
func getUser(ctx context.Context) (*userpb.User, error) {
@@ -158,6 +161,9 @@ func getUser(ctx context.Context) (*userpb.User, error) {
}
func (fs *localfs) wrap(ctx context.Context, p string) string {
+ // This is to prevent path traversal.
+ // With this p can't break out of its parent folder
+ p = path.Join("/", p)
var internal string
if !fs.conf.DisableHome {
layout, err := fs.GetHome(ctx)
@@ -200,6 +206,7 @@ func (fs *localfs) wrapRecycleBin(ctx context.Context, p string) string {
}
func (fs *localfs) wrapVersions(ctx context.Context, p string) string {
+ p = path.Join("/", p)
var internal string
if !fs.conf.DisableHome {
layout, err := fs.GetHome(ctx)
@@ -415,7 +422,7 @@ func (fs *localfs) retrieveArbitraryMetadata(ctx context.Context, fn string, mdK
// GetPathByID returns the path pointed by the file id
// In this implementation the file id is in the form `fileid-url_encoded_path`
-func (fs *localfs) GetPathByID(ctx context.Context, id *provider.ResourceId) (string, error) {
+func (fs *localfs) GetPathByID(ctx context.Context, ref *provider.ResourceId) (string, error) {
var layout string
if !fs.conf.DisableHome {
var err error
@@ -424,7 +431,7 @@ func (fs *localfs) GetPathByID(ctx context.Context, id *provider.ResourceId) (st
return "", err
}
}
- return url.QueryUnescape(strings.TrimPrefix(id.OpaqueId, "fileid-"+layout))
+ return url.QueryUnescape(strings.TrimPrefix(ref.OpaqueId, "fileid-"+layout))
}
func (fs *localfs) AddGrant(ctx context.Context, ref *provider.Reference, g *provider.Grant) error {
@@ -1166,7 +1173,7 @@ func (fs *localfs) convertToRecycleItem(ctx context.Context, rp string, md os.Fi
return &provider.RecycleItem{
Type: getResourceType(md.IsDir()),
Key: md.Name(),
- Path: filePath,
+ Ref: &provider.Reference{Path: filePath},
Size: uint64(md.Size()),
DeletionTime: &types.Timestamp{
Seconds: uint64(ttime),
@@ -1192,7 +1199,7 @@ func (fs *localfs) ListRecycle(ctx context.Context) ([]*provider.RecycleItem, er
return items, nil
}
-func (fs *localfs) RestoreRecycleItem(ctx context.Context, restoreKey, restorePath string) error {
+func (fs *localfs) RestoreRecycleItem(ctx context.Context, restoreKey string, restoreRef *provider.Reference) error {
suffix := path.Ext(restoreKey)
if len(suffix) == 0 || !strings.HasPrefix(suffix, ".d") {
@@ -1206,8 +1213,8 @@ func (fs *localfs) RestoreRecycleItem(ctx context.Context, restoreKey, restorePa
var localRestorePath string
switch {
- case restorePath != "":
- localRestorePath = fs.wrap(ctx, restorePath)
+ case restoreRef != nil && restoreRef.Path != "":
+ localRestorePath = fs.wrap(ctx, restoreRef.Path)
case fs.isShareFolder(ctx, filePath):
localRestorePath = fs.wrapReferences(ctx, filePath)
default:
diff --git a/pkg/token/manager/demo/demo_test.go b/pkg/token/manager/demo/demo_test.go
index 964b49fe47..84680b2989 100644
--- a/pkg/token/manager/demo/demo_test.go
+++ b/pkg/token/manager/demo/demo_test.go
@@ -37,11 +37,7 @@ func TestEncodeDecode(t *testing.T) {
Username: "marie",
}
- ref := &provider.Reference{
- Spec: &provider.Reference_Path{
- Path: "/",
- },
- }
+ ref := &provider.Reference{Path: "/"}
val, err := json.Marshal(ref)
if err != nil {
t.Fatal(err)
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go
index fc6d1007e9..4e44d6181a 100644
--- a/pkg/utils/utils.go
+++ b/pkg/utils/utils.go
@@ -23,6 +23,7 @@ import (
"net"
"net/http"
"os/user"
+ "path"
"path/filepath"
"regexp"
"strings"
@@ -152,11 +153,16 @@ func GroupEqual(u, v *grouppb.GroupId) bool {
return u != nil && v != nil && u.Idp == v.Idp && u.OpaqueId == v.OpaqueId
}
-// ResourceEqual returns whether two resources have the same field values.
-func ResourceEqual(u, v *provider.ResourceId) bool {
+// ResourceIDEqual returns whether two resources have the same field values.
+func ResourceIDEqual(u, v *provider.ResourceId) bool {
return u != nil && v != nil && u.StorageId == v.StorageId && u.OpaqueId == v.OpaqueId
}
+// ResourceEqual returns whether two resources have the same field values.
+func ResourceEqual(u, v *provider.Reference) bool {
+ return u != nil && v != nil && u.Path == v.Path && ((u.ResourceId == nil && v.ResourceId == nil) || (ResourceIDEqual(u.ResourceId, v.ResourceId)))
+}
+
// GranteeEqual returns whether two grantees have the same field values.
func GranteeEqual(u, v *provider.Grantee) bool {
if u == nil || v == nil {
@@ -191,3 +197,33 @@ func UnmarshalJSONToProtoV1(b []byte, m proto.Message) error {
}
return nil
}
+
+// IsRelativeReference returns true if the given reference qualifies as relative
+// when the resource id is set and the path starts with a .
+//
+// TODO(corby): Currently if the path begins with a dot, the ResourceId is set but has empty storageId and OpaqueId
+// then the reference is still being viewed as relative. We need to check if we want that because in some
+// places we might not want to set both StorageId and OpaqueId so we can't do a hard check if they are set.
+func IsRelativeReference(ref *provider.Reference) bool {
+ return ref.ResourceId != nil && strings.HasPrefix(ref.Path, ".")
+}
+
+// IsAbsoluteReference returns true if the given reference qualifies as absolute
+// when either only the resource id is set or only the path is set and starts with /
+//
+// TODO(corby): Currently if the path is empty, the ResourceId is set but has empty storageId and OpaqueId
+// then the reference is still being viewed as absolute. We need to check if we want that because in some
+// places we might not want to set both StorageId and OpaqueId so we can't do a hard check if they are set.
+func IsAbsoluteReference(ref *provider.Reference) bool {
+ return (ref.ResourceId != nil && ref.Path == "") || (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)
+
+ if p == "/" {
+ return "."
+ }
+ return "." + p
+}
diff --git a/pkg/utils/utils_test.go b/pkg/utils/utils_test.go
index 176272a523..6d5a7ff335 100644
--- a/pkg/utils/utils_test.go
+++ b/pkg/utils/utils_test.go
@@ -18,7 +18,11 @@
package utils
-import "testing"
+import (
+ "testing"
+
+ provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
+)
var skipTests = []struct {
name string
@@ -42,3 +46,129 @@ func TestSkip(t *testing.T) {
})
}
}
+func TestIsRelativeReference(t *testing.T) {
+ tests := []struct {
+ ref *provider.Reference
+ expected bool
+ }{
+ {
+ &provider.Reference{},
+ false,
+ },
+ {
+ &provider.Reference{
+ Path: ".",
+ },
+ false,
+ },
+ {
+ &provider.Reference{
+ ResourceId: &provider.ResourceId{
+ StorageId: "storageId",
+ OpaqueId: "opaqueId",
+ },
+ Path: "/folder",
+ },
+ false,
+ },
+ {
+ &provider.Reference{
+ ResourceId: &provider.ResourceId{
+ StorageId: "storageId",
+ OpaqueId: "opaqueId",
+ },
+ Path: "./folder",
+ },
+ true,
+ },
+ {
+ &provider.Reference{
+ ResourceId: &provider.ResourceId{},
+ Path: "./folder",
+ },
+ true,
+ },
+ }
+
+ for _, tt := range tests {
+ result := IsRelativeReference(tt.ref)
+ if result != tt.expected {
+ t.Errorf("IsRelativeReference: ref %v expected %t got %t", tt.ref, tt.expected, result)
+ }
+ }
+}
+func TestIsAbsolutReference(t *testing.T) {
+ tests := []struct {
+ ref *provider.Reference
+ expected bool
+ }{
+ {
+ &provider.Reference{},
+ false,
+ },
+ {
+ &provider.Reference{
+ Path: ".",
+ },
+ false,
+ },
+ {
+ &provider.Reference{
+ ResourceId: &provider.ResourceId{
+ StorageId: "storageId",
+ OpaqueId: "opaqueId",
+ },
+ Path: "/folder",
+ },
+ false,
+ },
+ {
+ &provider.Reference{
+ Path: "/folder",
+ },
+ true,
+ },
+ {
+ &provider.Reference{
+ ResourceId: &provider.ResourceId{},
+ },
+ true,
+ },
+ {
+ &provider.Reference{
+ ResourceId: &provider.ResourceId{
+ StorageId: "storageId",
+ OpaqueId: "opaqueId",
+ },
+ },
+ true,
+ },
+ }
+
+ for _, tt := range tests {
+ result := IsAbsoluteReference(tt.ref)
+ if result != tt.expected {
+ t.Errorf("IsAbsolutReference: ref %v expected %t got %t", tt.ref, tt.expected, result)
+ }
+ }
+}
+
+func TestMakeRelativePath(t *testing.T) {
+ tests := []struct {
+ path string
+ relPath string
+ }{
+ {"", "."},
+ {"/", "."},
+ {"..", "."},
+ {"/folder", "./folder"},
+ {"/folder/../folder2", "./folder2"},
+ {"folder", "./folder"},
+ }
+ for _, tt := range tests {
+ rel := MakeRelativePath(tt.path)
+ if rel != tt.relPath {
+ t.Errorf("expected %s, got %s", tt.relPath, rel)
+ }
+ }
+}
diff --git a/tests/integration/grpc/storageprovider_test.go b/tests/integration/grpc/storageprovider_test.go
index 2dba78c7f9..d32a446004 100644
--- a/tests/integration/grpc/storageprovider_test.go
+++ b/tests/integration/grpc/storageprovider_test.go
@@ -63,25 +63,15 @@ var _ = Describe("storage providers", func() {
},
}
- homeRef = &storagep.Reference{
- Spec: &storagep.Reference_Path{Path: "/"},
- }
- filePath = "/file"
- fileRef = &storagep.Reference{
- Spec: &storagep.Reference_Path{Path: filePath},
- }
+ homeRef = &storagep.Reference{Path: "/"}
+ filePath = "/file"
+ fileRef = &storagep.Reference{Path: filePath}
versionedFilePath = "/versionedFile"
- versionedFileRef = &storagep.Reference{
- Spec: &storagep.Reference_Path{Path: versionedFilePath},
- }
- subdirPath = "/subdir"
- subdirRef = &storagep.Reference{
- Spec: &storagep.Reference_Path{Path: subdirPath},
- }
- sharesPath = "/Shares"
- sharesRef = &storagep.Reference{
- Spec: &storagep.Reference_Path{Path: sharesPath},
- }
+ versionedFileRef = &storagep.Reference{Path: versionedFilePath}
+ subdirPath = "/subdir"
+ subdirRef = &storagep.Reference{Path: subdirPath}
+ sharesPath = "/Shares"
+ sharesRef = &storagep.Reference{Path: sharesPath}
)
JustBeforeEach(func() {
@@ -133,9 +123,7 @@ var _ = Describe("storage providers", func() {
assertCreateContainer := func() {
It("creates a new directory", func() {
- newRef := &storagep.Reference{
- Spec: &storagep.Reference_Path{Path: "/newdir"},
- }
+ newRef := &storagep.Reference{Path: "/newdir"}
statRes, err := serviceClient.Stat(ctx, &storagep.StatRequest{Ref: newRef})
Expect(err).ToNot(HaveOccurred())
@@ -219,9 +207,7 @@ var _ = Describe("storage providers", func() {
Expect(err).ToNot(HaveOccurred())
Expect(statRes.Status.Code).To(Equal(rpcv1beta1.Code_CODE_OK))
- targetRef := &storagep.Reference{
- Spec: &storagep.Reference_Path{Path: "/new_subdir"},
- }
+ targetRef := &storagep.Reference{Path: "/new_subdir"}
res, err := serviceClient.Move(ctx, &storagep.MoveRequest{Source: subdirRef, Destination: targetRef})
Expect(res.Status.Code).To(Equal(rpcv1beta1.Code_CODE_OK))
Expect(err).ToNot(HaveOccurred())
@@ -342,7 +328,7 @@ var _ = Describe("storage providers", func() {
Expect(len(listRes.RecycleItems)).To(Equal(1))
item := listRes.RecycleItems[0]
- Expect(item.Path).To(Equal(subdirPath))
+ Expect(item.Ref.Path).To(Equal(subdirPath))
By("restoring a recycle item")
statRes, err := serviceClient.Stat(ctx, &storagep.StatRequest{Ref: subdirRef})
@@ -364,9 +350,7 @@ var _ = Describe("storage providers", func() {
})
It("restores resources to a different location", func() {
- restoreRef := &storagep.Reference{
- Spec: &storagep.Reference_Path{Path: "/subdirRestored"},
- }
+ restoreRef := &storagep.Reference{Path: "/subdirRestored"}
By("deleting an item")
res, err := serviceClient.Delete(ctx, &storagep.DeleteRequest{Ref: subdirRef})
Expect(err).ToNot(HaveOccurred())
@@ -379,7 +363,7 @@ var _ = Describe("storage providers", func() {
Expect(len(listRes.RecycleItems)).To(Equal(1))
item := listRes.RecycleItems[0]
- Expect(item.Path).To(Equal(subdirPath))
+ Expect(item.Ref.Path).To(Equal(subdirPath))
By("restoring the item to a different location")
statRes, err := serviceClient.Stat(ctx, &storagep.StatRequest{Ref: restoreRef})
@@ -388,9 +372,9 @@ var _ = Describe("storage providers", func() {
restoreRes, err := serviceClient.RestoreRecycleItem(ctx,
&storagep.RestoreRecycleItemRequest{
- Ref: subdirRef,
- Key: item.Key,
- RestorePath: "/subdirRestored",
+ Ref: subdirRef,
+ Key: item.Key,
+ RestoreRef: &storagep.Reference{Path: "/subdirRestored"},
},
)
Expect(err).ToNot(HaveOccurred())
@@ -432,7 +416,10 @@ var _ = Describe("storage providers", func() {
Expect(listRes.Status.Code).To(Equal(rpcv1beta1.Code_CODE_NOT_FOUND))
Expect(len(listRes.Infos)).To(Equal(0))
- res, err := serviceClient.CreateReference(ctx, &storagep.CreateReferenceRequest{Path: "/Shares/reference", TargetUri: "scheme://target"})
+ res, err := serviceClient.CreateReference(ctx, &storagep.CreateReferenceRequest{
+ Ref: &storagep.Reference{Path: "/Shares/reference"},
+ TargetUri: "scheme://target",
+ })
Expect(err).ToNot(HaveOccurred())
Expect(res.Status.Code).To(Equal(rpcv1beta1.Code_CODE_OK))