From 2b0d9aa9b0d854b66b6c3d1a9d275ddb64774cf7 Mon Sep 17 00:00:00 2001 From: David Christofas Date: Mon, 28 Mar 2022 13:00:54 +0200 Subject: [PATCH] improve quota handling in the graph API --- graph/pkg/service/v0/drives.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/graph/pkg/service/v0/drives.go b/graph/pkg/service/v0/drives.go index a82f28422..63e7e4721 100644 --- a/graph/pkg/service/v0/drives.go +++ b/graph/pkg/service/v0/drives.go @@ -584,16 +584,32 @@ func (g Graph) getDriveQuota(ctx context.Context, space *storageprovider.Storage return nil, err } - total := int64(res.TotalBytes) + var remaining int64 + if res.Opaque != nil { + m := res.Opaque.Map + if e, ok := m["remaining"]; ok { + remaining, _ = strconv.ParseInt(string(e.Value), 10, 64) + } + } used := int64(res.UsedBytes) - remaining := total - used qta := libregraph.Quota{ Remaining: &remaining, - Total: &total, Used: &used, } - state := calculateQuotaState(total, used) + + var t int64 + if total := int64(res.TotalBytes); total != 0 { + + // A quota was set + qta.Total = &total + t = total + } else { + // Quota was not set + // Use remaining bytes to calculate state + t = remaining + } + state := calculateQuotaState(t, used) qta.State = &state return &qta, nil