From 1e8710d60654fe2489a2dd8c7ddb4a5cef53ae2c Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 7 Oct 2021 13:37:27 +0200 Subject: [PATCH 1/2] extend fs.FS interface with UpdateStorageSpace --- pkg/storage/fs/nextcloud/nextcloud.go | 7 +++++++ pkg/storage/fs/owncloud/owncloud.go | 4 ++++ pkg/storage/fs/owncloudsql/owncloudsql.go | 4 ++++ pkg/storage/fs/s3/s3.go | 4 ++++ pkg/storage/storage.go | 1 + pkg/storage/utils/decomposedfs/spaces.go | 6 ++++++ pkg/storage/utils/eosfs/eosfs.go | 4 ++++ pkg/storage/utils/localfs/localfs.go | 4 ++++ 8 files changed, 34 insertions(+) diff --git a/pkg/storage/fs/nextcloud/nextcloud.go b/pkg/storage/fs/nextcloud/nextcloud.go index e53a793a25..bfd12767ec 100644 --- a/pkg/storage/fs/nextcloud/nextcloud.go +++ b/pkg/storage/fs/nextcloud/nextcloud.go @@ -27,6 +27,9 @@ import ( "net/url" "strings" + "google.golang.org/grpc/codes" + gstatus "google.golang.org/grpc/status" + user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" "github.com/cs3org/reva/pkg/appctx" @@ -784,3 +787,7 @@ func (nc *StorageDriver) CreateStorageSpace(ctx context.Context, req *provider.C } return &respObj, nil } + +func (nc *StorageDriver) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) { + return nil, gstatus.Errorf(codes.Unimplemented, "method not implemented") +} diff --git a/pkg/storage/fs/owncloud/owncloud.go b/pkg/storage/fs/owncloud/owncloud.go index e2bcebdd17..9d19fd1f44 100644 --- a/pkg/storage/fs/owncloud/owncloud.go +++ b/pkg/storage/fs/owncloud/owncloud.go @@ -2234,6 +2234,10 @@ func (fs *ocfs) ListStorageSpaces(ctx context.Context, filter []*provider.ListSt return nil, errtypes.NotSupported("list storage spaces") } +func (fs *ocfs) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) { + return nil, errtypes.NotSupported("update storage space") +} + func (fs *ocfs) propagate(ctx context.Context, leafPath string) error { var root string if fs.c.EnableHome { diff --git a/pkg/storage/fs/owncloudsql/owncloudsql.go b/pkg/storage/fs/owncloudsql/owncloudsql.go index 4c776c34bf..aa3b15f446 100644 --- a/pkg/storage/fs/owncloudsql/owncloudsql.go +++ b/pkg/storage/fs/owncloudsql/owncloudsql.go @@ -1930,6 +1930,10 @@ func (fs *owncloudsqlfs) ListStorageSpaces(ctx context.Context, filter []*provid return nil, errtypes.NotSupported("list storage spaces") } +func (fs *owncloudsqlfs) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) { + return nil, errtypes.NotSupported("update storage space") +} + func readChecksumIntoResourceChecksum(ctx context.Context, checksums, algo string, ri *provider.ResourceInfo) { re := regexp.MustCompile(strings.ToUpper(algo) + `:(.*)`) matches := re.FindStringSubmatch(checksums) diff --git a/pkg/storage/fs/s3/s3.go b/pkg/storage/fs/s3/s3.go index f1522deb11..0e879447cb 100644 --- a/pkg/storage/fs/s3/s3.go +++ b/pkg/storage/fs/s3/s3.go @@ -680,3 +680,7 @@ func (fs *s3FS) RestoreRecycleItem(ctx context.Context, key, path string, restor func (fs *s3FS) ListStorageSpaces(ctx context.Context, filter []*provider.ListStorageSpacesRequest_Filter) ([]*provider.StorageSpace, error) { return nil, errtypes.NotSupported("list storage spaces") } + +func (fs *s3FS) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) { + return nil, errtypes.NotSupported("update storage space") +} diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index ff39b55b26..86d00b45b0 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -59,6 +59,7 @@ type FS interface { UnsetArbitraryMetadata(ctx context.Context, ref *provider.Reference, keys []string) error ListStorageSpaces(ctx context.Context, filter []*provider.ListStorageSpacesRequest_Filter) ([]*provider.StorageSpace, error) CreateStorageSpace(ctx context.Context, req *provider.CreateStorageSpaceRequest) (*provider.CreateStorageSpaceResponse, error) + UpdateStorageSpace(ctx context.Context, filter *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) } // Registry is the interface that storage registries implement diff --git a/pkg/storage/utils/decomposedfs/spaces.go b/pkg/storage/utils/decomposedfs/spaces.go index 7bc82296c6..90107b9691 100644 --- a/pkg/storage/utils/decomposedfs/spaces.go +++ b/pkg/storage/utils/decomposedfs/spaces.go @@ -27,6 +27,8 @@ import ( "strconv" "strings" + "github.com/cs3org/reva/pkg/errtypes" + userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" v1beta11 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" @@ -328,3 +330,7 @@ func (fs *Decomposedfs) createStorageSpace(ctx context.Context, spaceType, nodeI return nil } + +func (fs *Decomposedfs) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) { + return nil, errtypes.NotSupported("update storage space") +} diff --git a/pkg/storage/utils/eosfs/eosfs.go b/pkg/storage/utils/eosfs/eosfs.go index 909c0edbfb..c8b84b017f 100644 --- a/pkg/storage/utils/eosfs/eosfs.go +++ b/pkg/storage/utils/eosfs/eosfs.go @@ -1513,6 +1513,10 @@ func (fs *eosfs) ListStorageSpaces(ctx context.Context, filter []*provider.ListS return nil, errtypes.NotSupported("list storage spaces") } +func (fs *eosfs) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) { + return nil, errtypes.NotSupported("update storage space") +} + func (fs *eosfs) convertToRecycleItem(ctx context.Context, eosDeletedItem *eosclient.DeletedEntry) (*provider.RecycleItem, error) { path, err := fs.unwrap(ctx, eosDeletedItem.RestorePath) if err != nil { diff --git a/pkg/storage/utils/localfs/localfs.go b/pkg/storage/utils/localfs/localfs.go index e35d18601b..e25ebc66fd 100644 --- a/pkg/storage/utils/localfs/localfs.go +++ b/pkg/storage/utils/localfs/localfs.go @@ -1264,6 +1264,10 @@ func (fs *localfs) ListStorageSpaces(ctx context.Context, filter []*provider.Lis return nil, errtypes.NotSupported("list storage spaces") } +func (fs *localfs) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) { + return nil, errtypes.NotSupported("update storage space") +} + func (fs *localfs) propagate(ctx context.Context, leafPath string) error { var root string From fa9c3d44ce9d90c39a264ef2e0ff64f430c11db2 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 7 Oct 2021 16:19:57 +0200 Subject: [PATCH 2/2] draft implementation of updating a space name --- .../storageprovider/storageprovider.go | 4 +-- pkg/storage/utils/decomposedfs/spaces.go | 33 +++++++++++++++---- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/internal/grpc/services/storageprovider/storageprovider.go b/internal/grpc/services/storageprovider/storageprovider.go index c6e6d7f060..669c9d2a71 100644 --- a/internal/grpc/services/storageprovider/storageprovider.go +++ b/internal/grpc/services/storageprovider/storageprovider.go @@ -482,9 +482,7 @@ func (s *service) ListStorageSpaces(ctx context.Context, req *provider.ListStora } func (s *service) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) { - return &provider.UpdateStorageSpaceResponse{ - Status: status.NewUnimplemented(ctx, errtypes.NotSupported("UpdateStorageSpace not implemented"), "UpdateStorageSpace not implemented"), - }, nil + return s.storage.UpdateStorageSpace(ctx, req) } func (s *service) DeleteStorageSpace(ctx context.Context, req *provider.DeleteStorageSpaceRequest) (*provider.DeleteStorageSpaceResponse, error) { diff --git a/pkg/storage/utils/decomposedfs/spaces.go b/pkg/storage/utils/decomposedfs/spaces.go index 90107b9691..cc9c7162bd 100644 --- a/pkg/storage/utils/decomposedfs/spaces.go +++ b/pkg/storage/utils/decomposedfs/spaces.go @@ -27,8 +27,6 @@ import ( "strconv" "strings" - "github.com/cs3org/reva/pkg/errtypes" - userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" v1beta11 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" @@ -298,6 +296,33 @@ func (fs *Decomposedfs) ListStorageSpaces(ctx context.Context, filter []*provide } +func (fs *Decomposedfs) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) { + // TODO(refs) poor choice of API. Use an update mask to prevent unnecessary checks. + // MVP: update name attribute only. + /* + 1. look for the requested space + 2. iterate over the space properties and apply the changes + */ + + n, _ := fs.lu.NodeFromResource(ctx, &provider.Reference{ + ResourceId: req.StorageSpace.Root, + }) + + if !n.Exists { + panic("space does not exist") + } + + if err := n.SetMetadata(xattrs.SpaceNameAttr, req.StorageSpace.Name); err != nil { + return nil, err + } + + return &provider.UpdateStorageSpaceResponse{ + Status: &v1beta11.Status{ + Code: v1beta11.Code_CODE_OK, + }, + }, nil +} + // createHiddenSpaceFolder bootstraps a storage space root with a hidden ".space" folder used to store space related // metadata such as a description or an image. // Internally createHiddenSpaceFolder leverages the use of node.Child() to create a new node under the space root. @@ -330,7 +355,3 @@ func (fs *Decomposedfs) createStorageSpace(ctx context.Context, spaceType, nodeI return nil } - -func (fs *Decomposedfs) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorageSpaceRequest) (*provider.UpdateStorageSpaceResponse, error) { - return nil, errtypes.NotSupported("update storage space") -}