From 7453692491cca897b1538b72f622b884dce2f075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Thu, 19 May 2022 14:06:42 +0000 Subject: [PATCH] show mounted shares in virtual share jail root MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- .../sharesstorageprovider.go | 55 ++++++++++++++++++- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go b/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go index ec8f2f63b80..d2c13439e8b 100644 --- a/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go +++ b/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go @@ -382,8 +382,10 @@ func (s *service) ListStorageSpaces(ctx context.Context, req *provider.ListStora if spaceID == nil || utils.ResourceIDEqual(virtualRootID, spaceID) { earliestShare, atLeastOneAccepted := findEarliestShare(receivedShares, shareMd) var opaque *typesv1beta1.Opaque + var mtime *typesv1beta1.Timestamp if earliestShare != nil { if md, ok := shareMd[earliestShare.Id.OpaqueId]; ok { + mtime = md.Mtime opaque = utils.AppendPlainToOpaque(opaque, "etag", md.ETag) } } @@ -398,8 +400,9 @@ func (s *service) ListStorageSpaces(ctx context.Context, req *provider.ListStora SpaceType: "virtual", //Owner: &userv1beta1.User{Id: receivedShare.Share.Owner}, // FIXME actually, the mount point belongs to the recipient // the sharesstorageprovider keeps track of mount points - Root: virtualRootID, - Name: "Shares Jail", + Root: virtualRootID, + Name: "Shares Jail", + Mtime: mtime, } res.StorageSpaces = append(res.StorageSpaces, space) } @@ -761,9 +764,55 @@ func (s *service) ListContainer(ctx context.Context, req *provider.ListContainer if isVirtualRoot(req.Ref.ResourceId) { // The root is empty, it is filled by mountpoints + // but when accessing the root via /dav/spaces we need to list the content + + receivedShares, _, err := s.fetchShares(ctx) + if err != nil { + return nil, errors.Wrap(err, "sharesstorageprovider: error calling ListReceivedSharesRequest") + } + + infos := []*provider.ResourceInfo{} + for _, share := range receivedShares { + if share.GetState() != collaboration.ShareState_SHARE_STATE_ACCEPTED { + continue + } + + statRes, err := s.gateway.Stat(ctx, &provider.StatRequest{ + Opaque: req.Opaque, + Ref: &provider.Reference{ + ResourceId: share.Share.ResourceId, + // Path: "." TODO force a relative request? should not matter because we always only want the name + }, + ArbitraryMetadataKeys: req.ArbitraryMetadataKeys, + }) + switch { + case err != nil: + appctx.GetLogger(ctx).Error(). + Err(err). + Interface("share", share). + Msg("sharesstorageprovider: could make stat request when listing virtual root, skipping") + continue + case statRes.Status.Code != rpc.Code_CODE_OK: + appctx.GetLogger(ctx).Debug(). + Interface("share", share). + Interface("status", statRes.Status). + Msg("sharesstorageprovider: could not stat share when listing virtual root, skipping") + continue + } + + // override info + info := statRes.Info + info.Id = &provider.ResourceId{ + StorageId: utils.ShareStorageProviderID, + OpaqueId: share.Share.Id.OpaqueId, + } + info.Path = filepath.Base(share.MountPoint.Path) + + infos = append(infos, info) + } return &provider.ListContainerResponse{ Status: status.NewOK(ctx), - Infos: []*provider.ResourceInfo{}, + Infos: infos, }, nil } receivedShare, rpcStatus, err := s.resolveReference(ctx, req.Ref)