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 15, 2021
1 parent 0e06ee2 commit adc095b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions changelog/unreleased/get-quota-storage-space.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ Implementation of [cs3org/cs3apis#147](https://github.com/cs3org/cs3apis/pull/14

Make the cs3apis accept a Reference in the getQuota Request to limit the call to a specific storage space.

https://github.com/cs3org/reva/issues/2152
https://github.com/cs3org/reva/issues/2178
https://github.com/cs3org/reva/pull/2152
https://github.com/cs3org/reva/pull/2178
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
13 changes: 9 additions & 4 deletions pkg/storage/utils/decomposedfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,15 +752,20 @@ 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)

enoughDiskSpace := enoughDiskSpace(fs, spaceRoot.InternalPath(), fileSize)
if !enoughDiskSpace {
return false, errtypes.InsufficientStorage("disk full")
}
quotaB, _ := xattr.Get(spaceRoot.InternalPath(), xattrs.QuotaAttr)
var total uint64
if quotaB != nil {
total, _ = strconv.ParseUint(string(quotaB), 10, 64)
} else {
// if quota is not set, it means unlimited
return true, nil
}

if (fileSize > total-used || total < used) && !enoughDiskSpace {
if fileSize > total-used || total < used {
return false, errtypes.InsufficientStorage("quota exceeded")
}
return true, nil
Expand Down

0 comments on commit adc095b

Please sign in to comment.