From 80f4581f7204cbafcac80cd9e685e5d8814f7082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20N=C3=A9meth?= Date: Mon, 22 May 2023 23:01:04 +0200 Subject: [PATCH] Always return non-negative number --- .../Service/IMediaStorageQuotaService.cs | 2 +- .../Service/MediaStorageQuotaService.cs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs index 3ce70fa7..2579af71 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/IMediaStorageQuotaService.cs @@ -8,7 +8,7 @@ namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Service; public interface IMediaStorageQuotaService { /// - /// Returns remaining quota space left in bytes. + /// Returns remaining quota space left in bytes. It is always a non-negative number, meaning the minimum value is 0. /// Task GetRemainingMediaSpaceQuotaLeftAsync(); diff --git a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs index b519044a..53127025 100644 --- a/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs +++ b/Lombiq.Hosting.Tenants.MediaStorageManagement/Service/MediaStorageQuotaService.cs @@ -25,7 +25,9 @@ public async Task GetRemainingMediaSpaceQuotaLeftAsync() var listed = await directoryContent.ToListAsync(); var sumSize = listed.Where(item => item.Length > 0).Sum(item => item.Length); - return MaxSpaceForTenantInBytes() - sumSize; + var remainingSpace = MaxSpaceForTenantInBytes() - sumSize; + + return remainingSpace < 0 ? 0 : remainingSpace; } public long MaxSpaceForTenantInBytes() => _mediaStorageManagementOptions.MaximumStorageQuota;