Skip to content

Commit

Permalink
Revert "fix decomposedfs upload (#2330)"
Browse files Browse the repository at this point in the history
This reverts commit 7ac4043.
  • Loading branch information
butonic authored Dec 7, 2021
1 parent 7ac4043 commit cfac6c7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 51 deletions.
5 changes: 0 additions & 5 deletions changelog/unreleased/fix-decomposedfs-upload.md

This file was deleted.

6 changes: 5 additions & 1 deletion pkg/rhttp/datatx/manager/spaces/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package spaces

import (
"net/http"
"path"
"strings"

provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
Expand Down Expand Up @@ -76,8 +78,10 @@ func (m *manager) Handler(fs storage.FS) (http.Handler, error) {
case "GET", "HEAD":
download.GetOrHeadFile(w, r, fs, spaceID)
case "PUT":
fn := utils.MakeRelativePath(r.URL.Path)
// make a clean relative path
fn := path.Clean(strings.TrimLeft(r.URL.Path, "/"))
defer r.Body.Close()

// TODO refactor: pass Reference to Upload & GetOrHeadFile
// build a storage space reference
storageid, opaqeid := utils.SplitStorageSpaceID(spaceID)
Expand Down
14 changes: 1 addition & 13 deletions pkg/storage/utils/decomposedfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,7 @@ var defaultFilePerm = os.FileMode(0664)
func (fs *Decomposedfs) Upload(ctx context.Context, ref *provider.Reference, r io.ReadCloser) (err error) {
upload, err := fs.GetUpload(ctx, ref.GetPath())
if err != nil {
// Upload corresponding to this ID was not found.
// Assume that this corresponds to the resource path to which the file has to be uploaded.

// Set the length to 0 and set SizeIsDeferred to true
metadata := map[string]string{"sizedeferred": "true"}
uploadIDs, err := fs.InitiateUpload(ctx, ref, 0, metadata)
if err != nil {
return err
}
upload, err = fs.GetUpload(ctx, uploadIDs["simple"])
if err != nil {
return errors.Wrap(err, "Decomposedfs: error retrieving upload")
}
return errors.Wrap(err, "Decomposedfs: error retrieving upload")
}

uploadInfo := upload.(*fileUpload)
Expand Down
33 changes: 1 addition & 32 deletions pkg/storage/utils/decomposedfs/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ var _ = Describe("File uploads", func() {
Expect(err).ToNot(HaveOccurred())
Expect(resp.Status.Code).To(Equal(v1beta11.Code_CODE_OK))
spaceID = resp.StorageSpace.Id.OpaqueId
ref.ResourceId = &provider.ResourceId{StorageId: spaceID, OpaqueId: spaceID}
ref.ResourceId = &provider.ResourceId{StorageId: spaceID}
})

Context("the user's quota is exceeded", func() {
Expand Down Expand Up @@ -308,36 +308,5 @@ var _ = Describe("File uploads", func() {
})
})

When("the user directly uploads a file with a relative reference", func() {
It("succeeds", func() {
var (
fileContent = []byte("0123456789")
)

uploadRef := &provider.Reference{ResourceId: ref.ResourceId, Path: "./newfile.txt"}

bs.On("Upload", mock.AnythingOfType("string"), mock.AnythingOfType("*os.File")).
Return(nil).
Run(func(args mock.Arguments) {
reader := args.Get(1).(io.Reader)
data, err := ioutil.ReadAll(reader)

Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(fileContent))
})

err := fs.Upload(ctx, uploadRef, ioutil.NopCloser(bytes.NewReader(fileContent)))

Expect(err).ToNot(HaveOccurred())
bs.AssertCalled(GinkgoT(), "Upload", mock.Anything, mock.Anything)

relativeListRef := &provider.Reference{ResourceId: ref.ResourceId, Path: "."}
resources, err := fs.ListFolder(ctx, relativeListRef, []string{})
Expect(err).ToNot(HaveOccurred())
Expect(len(resources)).To(Equal(2)) // .space folder + newfile.txt
Expect(resources[0].Path).To(Or(Equal("newfile.txt"), Equal(".space")))
Expect(resources[1].Path).To(Or(Equal("newfile.txt"), Equal(".space")))
})
})
})
})

0 comments on commit cfac6c7

Please sign in to comment.