Skip to content

Commit ea14bfa

Browse files
committed
Fix wrong space root during upload
1 parent ab7054c commit ea14bfa

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

pkg/storage/utils/decomposedfs/node/node.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -611,16 +611,19 @@ func (n *Node) AsResourceInfo(ctx context.Context, rp *provider.ResourcePermissi
611611
// quota
612612
if _, ok := mdKeysMap[QuotaKey]; (nodeType == provider.ResourceType_RESOURCE_TYPE_CONTAINER) && returnAllKeys || ok {
613613
var quotaPath string
614-
if n.SpaceRoot != nil {
615-
quotaPath = n.SpaceRoot.InternalPath()
616-
} else {
614+
if n.SpaceRoot == nil {
617615
root, err := n.lu.HomeOrRootNode(ctx)
618-
if err != nil {
619-
sublog.Error().Err(err).Msg("error determining the space root node for quota")
616+
if err == nil {
617+
quotaPath = root.InternalPath()
618+
} else {
619+
sublog.Debug().Err(err).Msg("error determining the space root node for quota")
620620
}
621-
quotaPath = root.InternalPath()
621+
} else {
622+
quotaPath = n.SpaceRoot.InternalPath()
623+
}
624+
if quotaPath != "" {
625+
readQuotaIntoOpaque(ctx, quotaPath, ri)
622626
}
623-
readQuotaIntoOpaque(ctx, quotaPath, ri)
624627
}
625628

626629
// only read the requested metadata attributes

pkg/storage/utils/decomposedfs/upload.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ func (fs *Decomposedfs) InitiateUpload(ctx context.Context, ref *provider.Refere
132132
"dir": filepath.Dir(relative),
133133
},
134134
Size: uploadLength,
135+
Storage: map[string]string{
136+
"SpaceRoot": n.SpaceRoot.ID,
137+
},
135138
}
136139

137140
if metadata != nil {
@@ -250,16 +253,23 @@ func (fs *Decomposedfs) NewUpload(ctx context.Context, info tusd.FileInfo) (uplo
250253
if err != nil {
251254
return nil, errors.Wrap(err, "Decomposedfs: error determining owner")
252255
}
256+
var spaceRoot string
257+
if info.Storage != nil {
258+
if spaceRoot, ok = info.Storage["SpaceRoot"]; !ok {
259+
spaceRoot = n.SpaceRoot.ID
260+
}
261+
} else {
262+
spaceRoot = n.SpaceRoot.ID
263+
}
253264

254265
info.Storage = map[string]string{
255-
// Todo: add storage space root
256266
"Type": "OCISStore",
257267
"BinPath": binPath,
258268

259269
"NodeId": n.ID,
260270
"NodeParentId": n.ParentID,
261271
"NodeName": n.Name,
262-
"SpaceRoot": n.SpaceRoot.ID,
272+
"SpaceRoot": spaceRoot,
263273

264274
"Idp": usr.Id.Idp,
265275
"UserId": usr.Id.OpaqueId,
@@ -739,14 +749,13 @@ func (upload *fileUpload) ConcatUploads(ctx context.Context, uploads []tusd.Uplo
739749
}
740750

741751
func checkQuota(ctx context.Context, fs *Decomposedfs, spaceRoot *node.Node, fileSize uint64) (quotaSufficient bool, err error) {
742-
req := &provider.GetQuotaRequest{
752+
total, inUse, err := fs.GetQuota(ctx, &provider.GetQuotaRequest{
743753
Ref: &provider.Reference{
744754
ResourceId: &provider.ResourceId{
745755
OpaqueId: spaceRoot.ID,
746756
},
747757
},
748-
}
749-
total, inUse, err := fs.GetQuota(ctx, req)
758+
})
750759
if err != nil {
751760
switch err.(type) {
752761
case errtypes.NotFound:

0 commit comments

Comments
 (0)