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 70e6132
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 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
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 70e6132

Please sign in to comment.