Skip to content

Commit

Permalink
unwrap path in getQuota
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar committed Oct 13, 2021
1 parent 7b573b4 commit 14b2d8b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
12 changes: 11 additions & 1 deletion internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,17 @@ func (s *service) CreateSymlink(ctx context.Context, req *provider.CreateSymlink
}

func (s *service) GetQuota(ctx context.Context, req *provider.GetQuotaRequest) (*provider.GetQuotaResponse, error) {
total, used, err := s.storage.GetQuota(ctx, req)
newRef, err := s.unwrap(ctx, req.Ref)
if err != nil {
return &provider.GetQuotaResponse{
Status: status.NewInternal(ctx, err, "error unwrapping path"),
}, nil
}
newReq := &provider.GetQuotaRequest{
Ref: newRef,
Opaque: req.Opaque,
}
total, used, err := s.storage.GetQuota(ctx, newReq)
if err != nil {
var st *rpc.Status
switch err.(type) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (fs *Decomposedfs) CreateHome(ctx context.Context) (err error) {
return
}

if fs.o.TreeTimeAccounting {
if fs.o.TreeTimeAccounting || fs.o.TreeSizeAccounting {
homePath := h.InternalPath()
// mark the home node as the end of propagation
if err = xattr.Set(homePath, xattrs.PropagationAttr, []byte("1")); err != nil {
Expand Down
22 changes: 14 additions & 8 deletions pkg/storage/utils/decomposedfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (fs *Decomposedfs) InitiateUpload(ctx context.Context, ref *provider.Refere

log.Debug().Interface("info", info).Interface("node", n).Interface("metadata", metadata).Msg("Decomposedfs: resolved filename")

_, err = checkQuota(ctx, fs, uint64(info.Size))
_, err = checkQuota(ctx, fs, n.SpaceRoot, uint64(info.Size))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -462,11 +462,6 @@ func (upload *fileUpload) FinishUpload(ctx context.Context) (err error) {
return
}

_, err = checkQuota(upload.ctx, upload.fs, uint64(fi.Size()))
if err != nil {
return err
}

n := node.New(
upload.info.Storage["NodeId"],
upload.info.Storage["NodeParentId"],
Expand All @@ -479,6 +474,11 @@ func (upload *fileUpload) FinishUpload(ctx context.Context) (err error) {
n.SpaceRoot = &node.Node{
ID: upload.info.Storage["SpaceRoot"],
}
_, err = checkQuota(upload.ctx, upload.fs, n.SpaceRoot, uint64(fi.Size()))
if err != nil {
return err
}

if n.ID == "" {
n.ID = uuid.New().String()
}
Expand Down Expand Up @@ -738,8 +738,14 @@ func (upload *fileUpload) ConcatUploads(ctx context.Context, uploads []tusd.Uplo
return
}

func checkQuota(ctx context.Context, fs *Decomposedfs, fileSize uint64) (quotaSufficient bool, err error) {
req := &provider.GetQuotaRequest{}
func checkQuota(ctx context.Context, fs *Decomposedfs, spaceRoot *node.Node, fileSize uint64) (quotaSufficient bool, err error) {
req := &provider.GetQuotaRequest{
Ref: &provider.Reference{
ResourceId: &provider.ResourceId{
OpaqueId: spaceRoot.ID,
},
},
}
total, inUse, err := fs.GetQuota(ctx, req)
if err != nil {
switch err.(type) {
Expand Down

0 comments on commit 14b2d8b

Please sign in to comment.