Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: chunked upload of existing file creates new version #1899

Merged
merged 1 commit into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add a reason how this function differs from the one in the lookup interface? Do you think other implementations of the decomposedfs need the same handling / detection of chunked paths? should fs.lu.NodeFromPath maybe get a parameter to handle chunked paths? why not add a fs.lu.NodeFromChunkedPath and refactor the two functions to share more code?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, now I see that you are calling fs.lu.NodeFromPath in lookupNode ... nevermind my comment ;-)

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