Skip to content

Commit

Permalink
fix quota logic
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar committed Oct 14, 2021
1 parent 0e06ee2 commit f72511d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (fs *Decomposedfs) GetQuota(ctx context.Context, ref *provider.Reference) (
switch {
case quotaStr == node.QuotaUncalculated, quotaStr == node.QuotaUnknown, quotaStr == node.QuotaUnlimited:
// best we can do is return current total
// TODO indicate unlimited total? -> in opaque data?
// TODO indicate unlimited total? -> in opaque data?, use ^uint64(0)?
default:
if quota, err := strconv.ParseUint(quotaStr, 10, 64); err == nil {
if total > quota {
Expand Down
11 changes: 9 additions & 2 deletions pkg/storage/utils/decomposedfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -753,14 +753,21 @@ func (upload *fileUpload) ConcatUploads(ctx context.Context, uploads []tusd.Uplo
func checkQuota(ctx context.Context, fs *Decomposedfs, spaceRoot *node.Node, fileSize uint64) (quotaSufficient bool, err error) {
used, _ := spaceRoot.GetTreeSize()
quotaB, _ := xattr.Get(spaceRoot.InternalPath(), xattrs.QuotaAttr)
total, _ := strconv.ParseUint(string(quotaB), 10, 64)
var total uint64
if quotaB != nil {
total, _ = strconv.ParseUint(string(quotaB), 10, 64)
} else {
// if quota is not set, it means unlimited
total = ^uint64(0)
}

enoughDiskSpace := enoughDiskSpace(fs, spaceRoot.InternalPath(), fileSize)
if !enoughDiskSpace {
return false, errtypes.InsufficientStorage("disk full")
}

if (fileSize > total-used || total < used) && !enoughDiskSpace {
// TODO: Decide how to represent unlimited quota
if (fileSize > total-used || total < used) && total != ^uint64(0) {
return false, errtypes.InsufficientStorage("quota exceeded")
}
return true, nil
Expand Down

0 comments on commit f72511d

Please sign in to comment.