Skip to content

Commit

Permalink
treat 0 byte uploads as size deferred
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Sep 19, 2023
1 parent cfec3a6 commit 76662f5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/storage/utils/decomposedfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var _idRegexp = regexp.MustCompile(".*/([^/]+).info")
// It creates a node for new files to persist the fileid for the new child.
// TODO read optional content for small files in this request
// TODO InitiateUpload (and Upload) needs a way to receive the expected checksum. Maybe in metadata as 'checksum' => 'sha1 aeosvp45w5xaeoe' = lowercase, space separated?
// TODO needs a way to handle unknown filesize, currently uses the context
// FIXME metadata is actually used to carry all kinds of headers
func (fs *Decomposedfs) InitiateUpload(ctx context.Context, ref *provider.Reference, uploadLength int64, headers map[string]string) (map[string]string, error) {
log := appctx.GetLogger(ctx)
Expand Down Expand Up @@ -156,9 +157,16 @@ func (fs *Decomposedfs) InitiateUpload(ctx context.Context, ref *provider.Refere

usr := ctxpkg.ContextMustGetUser(ctx)

// treat 0 length uploads as deferred
sizeIsDeferred := false
if uploadLength == 0 {
sizeIsDeferred = true
}

info := tusd.FileInfo{
MetaData: tusMetadata,
Size: uploadLength,
MetaData: tusMetadata,
Size: uploadLength,
SizeIsDeferred: sizeIsDeferred,
}
if lockID, ok := ctxpkg.ContextGetLockID(ctx); ok {
info.MetaData[tus.CS3Prefix+"lockid"] = lockID
Expand Down Expand Up @@ -460,7 +468,7 @@ func (fs *Decomposedfs) Upload(ctx context.Context, ref *provider.Reference, r i
return provider.ResourceInfo{}, errors.Wrap(err, "Decomposedfs: error writing to binary file")
}

if chunked {
if chunked || uploadInfo.SizeIsDeferred {
// update the size
uploadInfo.Size = bytesWritten
}
Expand Down

0 comments on commit 76662f5

Please sign in to comment.