Skip to content

Commit

Permalink
Merge pull request #62 from Lombiq/issue/NEST-442
Browse files Browse the repository at this point in the history
NEST-442: Always return non-negative number for storage space limit
  • Loading branch information
DemeSzabolcs authored May 24, 2023
2 parents f187a79 + 693953e commit fcc3c3c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Lombiq.Hosting.Tenants.MediaStorageManagement.Service;
public interface IMediaStorageQuotaService
{
/// <summary>
/// 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.
/// </summary>
Task<long> GetRemainingMediaSpaceQuotaLeftAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public async Task<long> 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;
Expand Down

0 comments on commit fcc3c3c

Please sign in to comment.