Skip to content

Commit

Permalink
fix: chunked upload of existing file creates new version
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas committed Jul 19, 2021
1 parent 7df477f commit 36f3efa
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/chunked-upload-versions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Fix chunked uploads for new versions

Chunked uploads didn't create a new version, when the file to upload already existed.

https://github.com/cs3org/reva/pull/1899
35 changes: 30 additions & 5 deletions pkg/storage/utils/decomposedfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,14 @@ func (fs *Decomposedfs) InitiateUpload(ctx context.Context, ref *provider.Refere

log := appctx.GetLogger(ctx)

var relative string // the internal path of the file node

n, err := fs.lu.NodeFromResource(ctx, ref)
n, err := fs.lookupNode(ctx, ref.Path)
if err != nil {
return nil, err
}

// permissions are checked in NewUpload below

relative, err = fs.lu.Path(ctx, n)
relative, err := fs.lu.Path(ctx, n)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -207,7 +205,7 @@ func (fs *Decomposedfs) NewUpload(ctx context.Context, info tusd.FileInfo) (uplo
}
info.MetaData["dir"] = filepath.Clean(info.MetaData["dir"])

n, err := fs.lu.NodeFromPath(ctx, filepath.Join(info.MetaData["dir"], info.MetaData["filename"]))
n, err := fs.lookupNode(ctx, filepath.Join(info.MetaData["dir"], info.MetaData["filename"]))
if err != nil {
return nil, errors.Wrap(err, "Decomposedfs: error wrapping filename")
}
Expand Down Expand Up @@ -360,6 +358,33 @@ func (fs *Decomposedfs) GetUpload(ctx context.Context, id string) (tusd.Upload,
}, nil
}

// lookupNode looks up nodes by path.
// This method can also handle lookups for paths which contain chunking information.
func (fs *Decomposedfs) lookupNode(ctx context.Context, path string) (*node.Node, error) {
p := path
isChunked, err := chunking.IsChunked(path)
if err != nil {
return nil, err
}
if isChunked {
chunkInfo, err := chunking.GetChunkBLOBInfo(path)
if err != nil {
return nil, err
}
p = chunkInfo.Path
}

n, err := fs.lu.NodeFromPath(ctx, p)
if err != nil {
return nil, err
}

if isChunked {
n.Name = filepath.Base(path)
}
return n, nil
}

type fileUpload struct {
// info stores the current information about the upload
info tusd.FileInfo
Expand Down
3 changes: 0 additions & 3 deletions tests/acceptance/expected-failures-on-OCIS-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ Basic file management like up and download, move, copy, properties, quota, trash
- [apiWebdavUpload1/uploadFile.feature:112](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUpload1/uploadFile.feature#L112)
- [apiWebdavUpload1/uploadFile.feature:113](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUpload1/uploadFile.feature#L113)

#### [uploading with old-chunking does not work](https://github.com/owncloud/ocis/issues/1343)
- [apiWebdavUpload2/uploadFileUsingOldChunking.feature:43](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUpload2/uploadFileUsingOldChunking.feature#L43)

#### [invalid file-names should not be created using the TUS protocol](https://github.com/owncloud/ocis/issues/1001)
- [apiWebdavUploadTUS/uploadFile.feature:143](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L143)
- [apiWebdavUploadTUS/uploadFile.feature:144](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L144)
Expand Down
3 changes: 0 additions & 3 deletions tests/acceptance/expected-failures-on-S3NG-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ Basic file management like up and download, move, copy, properties, quota, trash
- [apiWebdavUpload1/uploadFile.feature:112](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUpload1/uploadFile.feature#L112)
- [apiWebdavUpload1/uploadFile.feature:113](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUpload1/uploadFile.feature#L113)

#### [uploading with old-chunking does not work](https://github.com/owncloud/ocis/issues/1343)
- [apiWebdavUpload2/uploadFileUsingOldChunking.feature:43](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUpload2/uploadFileUsingOldChunking.feature#L43)

#### [invalid file-names should not be created using the TUS protocol](https://github.com/owncloud/ocis/issues/1001)
- [apiWebdavUploadTUS/uploadFile.feature:143](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L135)
- [apiWebdavUploadTUS/uploadFile.feature:144](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavUploadTUS/uploadFile.feature#L136)
Expand Down

0 comments on commit 36f3efa

Please sign in to comment.