Skip to content

Commit

Permalink
Fix wrong space root during upload
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar committed Oct 13, 2021
1 parent ab7054c commit ea14bfa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
17 changes: 10 additions & 7 deletions pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,16 +611,19 @@ func (n *Node) AsResourceInfo(ctx context.Context, rp *provider.ResourcePermissi
// quota
if _, ok := mdKeysMap[QuotaKey]; (nodeType == provider.ResourceType_RESOURCE_TYPE_CONTAINER) && returnAllKeys || ok {
var quotaPath string
if n.SpaceRoot != nil {
quotaPath = n.SpaceRoot.InternalPath()
} else {
if n.SpaceRoot == nil {
root, err := n.lu.HomeOrRootNode(ctx)
if err != nil {
sublog.Error().Err(err).Msg("error determining the space root node for quota")
if err == nil {
quotaPath = root.InternalPath()
} else {
sublog.Debug().Err(err).Msg("error determining the space root node for quota")
}
quotaPath = root.InternalPath()
} else {
quotaPath = n.SpaceRoot.InternalPath()
}
if quotaPath != "" {
readQuotaIntoOpaque(ctx, quotaPath, ri)
}
readQuotaIntoOpaque(ctx, quotaPath, ri)
}

// only read the requested metadata attributes
Expand Down
19 changes: 14 additions & 5 deletions pkg/storage/utils/decomposedfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func (fs *Decomposedfs) InitiateUpload(ctx context.Context, ref *provider.Refere
"dir": filepath.Dir(relative),
},
Size: uploadLength,
Storage: map[string]string{
"SpaceRoot": n.SpaceRoot.ID,
},
}

if metadata != nil {
Expand Down Expand Up @@ -250,16 +253,23 @@ func (fs *Decomposedfs) NewUpload(ctx context.Context, info tusd.FileInfo) (uplo
if err != nil {
return nil, errors.Wrap(err, "Decomposedfs: error determining owner")
}
var spaceRoot string
if info.Storage != nil {
if spaceRoot, ok = info.Storage["SpaceRoot"]; !ok {
spaceRoot = n.SpaceRoot.ID
}
} else {
spaceRoot = n.SpaceRoot.ID
}

info.Storage = map[string]string{
// Todo: add storage space root
"Type": "OCISStore",
"BinPath": binPath,

"NodeId": n.ID,
"NodeParentId": n.ParentID,
"NodeName": n.Name,
"SpaceRoot": n.SpaceRoot.ID,
"SpaceRoot": spaceRoot,

"Idp": usr.Id.Idp,
"UserId": usr.Id.OpaqueId,
Expand Down Expand Up @@ -739,14 +749,13 @@ 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) {
req := &provider.GetQuotaRequest{
total, inUse, err := fs.GetQuota(ctx, &provider.GetQuotaRequest{
Ref: &provider.Reference{
ResourceId: &provider.ResourceId{
OpaqueId: spaceRoot.ID,
},
},
}
total, inUse, err := fs.GetQuota(ctx, req)
})
if err != nil {
switch err.(type) {
case errtypes.NotFound:
Expand Down

0 comments on commit ea14bfa

Please sign in to comment.