From 36f3efa9f3b90e81b7c5261bf900cc06c87c4dc8 Mon Sep 17 00:00:00 2001 From: David Christofas Date: Mon, 19 Jul 2021 14:08:20 +0200 Subject: [PATCH] fix: chunked upload of existing file creates new version --- .../unreleased/chunked-upload-versions.md | 5 +++ pkg/storage/utils/decomposedfs/upload.go | 35 ++++++++++++++++--- .../expected-failures-on-OCIS-storage.md | 3 -- .../expected-failures-on-S3NG-storage.md | 3 -- 4 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 changelog/unreleased/chunked-upload-versions.md diff --git a/changelog/unreleased/chunked-upload-versions.md b/changelog/unreleased/chunked-upload-versions.md new file mode 100644 index 0000000000..c5114e9827 --- /dev/null +++ b/changelog/unreleased/chunked-upload-versions.md @@ -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 diff --git a/pkg/storage/utils/decomposedfs/upload.go b/pkg/storage/utils/decomposedfs/upload.go index 63d2e71838..689928721e 100644 --- a/pkg/storage/utils/decomposedfs/upload.go +++ b/pkg/storage/utils/decomposedfs/upload.go @@ -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 } @@ -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") } @@ -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 diff --git a/tests/acceptance/expected-failures-on-OCIS-storage.md b/tests/acceptance/expected-failures-on-OCIS-storage.md index d83949df4b..a47390e80f 100644 --- a/tests/acceptance/expected-failures-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-on-OCIS-storage.md @@ -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) diff --git a/tests/acceptance/expected-failures-on-S3NG-storage.md b/tests/acceptance/expected-failures-on-S3NG-storage.md index b04dea5dea..24379de835 100644 --- a/tests/acceptance/expected-failures-on-S3NG-storage.md +++ b/tests/acceptance/expected-failures-on-S3NG-storage.md @@ -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)