From 1d9182025dfd45bfbf34acd53f7de0ee4bbb1ecd Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Wed, 25 Sep 2024 10:36:31 +0200 Subject: [PATCH] fix(graph): handle unknown remaining size in quota In certain setups the storage is not able to report the remaining size of a space. E.g. when no quota is set and the space is using the S3 blob storage drive. In this case the graph API response will now not include the `remaining` properyt in the quota. Fixes: #9245 --- services/graph/pkg/service/v0/drives.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/services/graph/pkg/service/v0/drives.go b/services/graph/pkg/service/v0/drives.go index c494612484..39370c96d0 100644 --- a/services/graph/pkg/service/v0/drives.go +++ b/services/graph/pkg/service/v0/drives.go @@ -850,11 +850,13 @@ func (g Graph) getDriveQuota(ctx context.Context, space *storageprovider.Storage logger := g.logger.SubloggerWithRequestID(ctx) noQuotaInOpaque := true + remainingUnknown := true var remaining, used, total int64 if space.Opaque != nil { m := space.Opaque.Map if e, ok := m["quota.remaining"]; ok { noQuotaInOpaque = false + remainingUnknown = false remaining, _ = strconv.ParseInt(string(e.Value), 10, 64) } if e, ok := m["quota.used"]; ok { @@ -899,6 +901,7 @@ func (g Graph) getDriveQuota(ctx context.Context, space *storageprovider.Storage if res.Opaque != nil { m := res.Opaque.Map if e, ok := m["remaining"]; ok { + remainingUnknown = false remaining, _ = strconv.ParseInt(string(e.Value), 10, 64) } } @@ -908,15 +911,21 @@ func (g Graph) getDriveQuota(ctx context.Context, space *storageprovider.Storage } qta := libregraph.Quota{ - Remaining: &remaining, - Used: &used, - Total: &total, + Used: &used, + Total: &total, + } + + if !remainingUnknown { + qta.Remaining = &remaining } var t int64 - if total != 0 { + switch { + case total != 0: t = total - } else { + case remainingUnknown: + t = math.MaxInt64 + default: // Quota was not set // Use remaining bytes to calculate state t = remaining