From 0e06ee2aa49b175a5086d70ff140fd1fce7ad70f Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Thu, 14 Oct 2021 21:23:00 +0200 Subject: [PATCH 1/2] fix wrong node to set space name --- changelog/unreleased/get-quota-storage-space.md | 3 ++- pkg/storage/utils/decomposedfs/decomposedfs.go | 2 +- pkg/storage/utils/decomposedfs/spaces.go | 4 +--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/changelog/unreleased/get-quota-storage-space.md b/changelog/unreleased/get-quota-storage-space.md index 9fd8208dd1..492c0ebfca 100644 --- a/changelog/unreleased/get-quota-storage-space.md +++ b/changelog/unreleased/get-quota-storage-space.md @@ -4,4 +4,5 @@ Implementation of [cs3org/cs3apis#147](https://github.com/cs3org/cs3apis/pull/14 Make the cs3apis accept a Reference in the getQuota Request to limit the call to a specific storage space. -https://github.com/cs3org/reva/issues/2152 \ No newline at end of file +https://github.com/cs3org/reva/issues/2152 +https://github.com/cs3org/reva/issues/2178 \ No newline at end of file diff --git a/pkg/storage/utils/decomposedfs/decomposedfs.go b/pkg/storage/utils/decomposedfs/decomposedfs.go index 59c6b7ecb4..873f136942 100644 --- a/pkg/storage/utils/decomposedfs/decomposedfs.go +++ b/pkg/storage/utils/decomposedfs/decomposedfs.go @@ -221,7 +221,7 @@ func (fs *Decomposedfs) CreateHome(ctx context.Context) (err error) { } } - if err := n.SetMetadata(xattrs.SpaceNameAttr, u.DisplayName); err != nil { + if err := h.SetMetadata(xattrs.SpaceNameAttr, u.DisplayName); err != nil { return err } diff --git a/pkg/storage/utils/decomposedfs/spaces.go b/pkg/storage/utils/decomposedfs/spaces.go index c57320878b..8a6d11e434 100644 --- a/pkg/storage/utils/decomposedfs/spaces.go +++ b/pkg/storage/utils/decomposedfs/spaces.go @@ -233,15 +233,13 @@ func (fs *Decomposedfs) ListStorageSpaces(ctx context.Context, filter []*provide // do not list shares as spaces for the owner continue } - case "project": + default: sname, err := xattr.Get(n.InternalPath(), xattrs.SpaceNameAttr) if err != nil { appctx.GetLogger(ctx).Error().Err(err).Interface("node", n).Msg("could not read space name, attribute not found") continue } space.Name = string(sname) - default: - space.Name = "root" } // filter out spaces user cannot access (currently based on stat permission) From 70e6132a0132cae870d09a1af51ce2c1e9dd35a9 Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Thu, 14 Oct 2021 21:43:30 +0200 Subject: [PATCH 2/2] fix quota logic --- changelog/unreleased/get-quota-storage-space.md | 4 ++-- pkg/storage/utils/decomposedfs/upload.go | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/changelog/unreleased/get-quota-storage-space.md b/changelog/unreleased/get-quota-storage-space.md index 492c0ebfca..fe2089d381 100644 --- a/changelog/unreleased/get-quota-storage-space.md +++ b/changelog/unreleased/get-quota-storage-space.md @@ -4,5 +4,5 @@ Implementation of [cs3org/cs3apis#147](https://github.com/cs3org/cs3apis/pull/14 Make the cs3apis accept a Reference in the getQuota Request to limit the call to a specific storage space. -https://github.com/cs3org/reva/issues/2152 -https://github.com/cs3org/reva/issues/2178 \ No newline at end of file +https://github.com/cs3org/reva/pull/2152 +https://github.com/cs3org/reva/pull/2178 diff --git a/pkg/storage/utils/decomposedfs/upload.go b/pkg/storage/utils/decomposedfs/upload.go index 5e69270d26..ff8b61b3ac 100644 --- a/pkg/storage/utils/decomposedfs/upload.go +++ b/pkg/storage/utils/decomposedfs/upload.go @@ -752,15 +752,20 @@ func (upload *fileUpload) ConcatUploads(ctx context.Context, uploads []tusd.Uplo func checkQuota(ctx context.Context, fs *Decomposedfs, spaceRoot *node.Node, fileSize uint64) (quotaSufficient bool, err error) { used, _ := spaceRoot.GetTreeSize() - quotaB, _ := xattr.Get(spaceRoot.InternalPath(), xattrs.QuotaAttr) - total, _ := strconv.ParseUint(string(quotaB), 10, 64) - enoughDiskSpace := enoughDiskSpace(fs, spaceRoot.InternalPath(), fileSize) if !enoughDiskSpace { return false, errtypes.InsufficientStorage("disk full") } + quotaB, _ := xattr.Get(spaceRoot.InternalPath(), xattrs.QuotaAttr) + var total uint64 + if quotaB != nil { + total, _ = strconv.ParseUint(string(quotaB), 10, 64) + } else { + // if quota is not set, it means unlimited + return true, nil + } - if (fileSize > total-used || total < used) && !enoughDiskSpace { + if fileSize > total-used || total < used { return false, errtypes.InsufficientStorage("quota exceeded") } return true, nil