Skip to content

Commit

Permalink
fix wrong node to set space name (#2178)
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar authored Oct 15, 2021
1 parent 5866f5e commit 2e9bc0c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion changelog/unreleased/get-quota-storage-space.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +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/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 @@ -221,7 +221,7 @@ func (fs *Decomposedfs) CreateHome(ctx context.Context) (err error) {
}
}

if err := n.SetMetadata(xattrs.SpaceNameAttr, u.DisplayName); err != nil {
if err := h.SetMetadata(xattrs.SpaceNameAttr, u.DisplayName); err != nil {
return err
}

Expand Down
4 changes: 1 addition & 3 deletions pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,13 @@ func (fs *Decomposedfs) ListStorageSpaces(ctx context.Context, filter []*provide
// do not list shares as spaces for the owner
continue
}
case "project":
default:
sname, err := xattr.Get(n.InternalPath(), xattrs.SpaceNameAttr)
if err != nil {
appctx.GetLogger(ctx).Error().Err(err).Interface("node", n).Msg("could not read space name, attribute not found")
continue
}
space.Name = string(sname)
default:
space.Name = "root"
}

// filter out spaces user cannot access (currently based on stat permission)
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 2e9bc0c

Please sign in to comment.