From 1c11eedcd57705b9e3aaf42fd6c1e8246c310606 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Mon, 28 Oct 2024 09:51:17 +0100 Subject: [PATCH] fix(decomposedfs): fix quota calculation Signed-off-by: jkoberg --- changelog/unreleased/fix-quota-calculation.md | 5 +++++ pkg/storage/utils/decomposedfs/decomposedfs.go | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/fix-quota-calculation.md diff --git a/changelog/unreleased/fix-quota-calculation.md b/changelog/unreleased/fix-quota-calculation.md new file mode 100644 index 0000000000..a4abe3a082 --- /dev/null +++ b/changelog/unreleased/fix-quota-calculation.md @@ -0,0 +1,5 @@ +Bugfix: Fix quota calculation + +Quota would show "exceeded" when remaining quota was 0 because total was 0. + +https://github.com/cs3org/reva/pull/4902 diff --git a/pkg/storage/utils/decomposedfs/decomposedfs.go b/pkg/storage/utils/decomposedfs/decomposedfs.go index 7411b9ed95..22ccb4ba71 100644 --- a/pkg/storage/utils/decomposedfs/decomposedfs.go +++ b/pkg/storage/utils/decomposedfs/decomposedfs.go @@ -22,6 +22,7 @@ import ( "context" "fmt" "io" + "math" "net/url" "path" "path/filepath" @@ -603,7 +604,9 @@ func (fs *Decomposedfs) GetQuota(ctx context.Context, ref *provider.Reference) ( func (fs *Decomposedfs) calculateTotalUsedRemaining(quotaStr string, inUse uint64) (uint64, uint64, uint64, error) { var err error - var total, remaining uint64 + var total uint64 + + remaining := uint64(math.MaxUint64) switch quotaStr { case node.QuotaUncalculated, node.QuotaUnknown: // best we can do is return current total @@ -616,8 +619,11 @@ func (fs *Decomposedfs) calculateTotalUsedRemaining(quotaStr string, inUse uint6 return 0, 0, 0, err } - if total > inUse { + switch { + case total > inUse: remaining = total - inUse + case total <= inUse: + remaining = 0 } }