Skip to content

Commit

Permalink
revert blobstore signature changes
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic committed Apr 10, 2024
1 parent f6f30f2 commit 753dae0
Show file tree
Hide file tree
Showing 18 changed files with 243 additions and 269 deletions.
31 changes: 11 additions & 20 deletions pkg/storage/fs/ocis/blobstore/blobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"path/filepath"

"github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/lookup"
"github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/node"
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/pkg/errors"
)
Expand All @@ -48,8 +49,8 @@ func New(root string) (*Blobstore, error) {
}

// Upload stores some data in the blobstore under the given key
func (bs *Blobstore) Upload(spaceID, blobID string, blobSize int64, source string) error {
dest, err := bs.path(spaceID, blobID)
func (bs *Blobstore) Upload(node *node.Node, source string) error {
dest, err := bs.path(node)
if err != nil {
return err
}
Expand Down Expand Up @@ -84,28 +85,21 @@ func (bs *Blobstore) Upload(spaceID, blobID string, blobSize int64, source strin
}

// Download retrieves a blob from the blobstore for reading
func (bs *Blobstore) Download(spaceID, blobID string, blobSize int64) (io.ReadCloser, error) {
dest, err := bs.path(spaceID, blobID)
func (bs *Blobstore) Download(node *node.Node) (io.ReadCloser, error) {
dest, err := bs.path(node)
if err != nil {
return nil, err
}
file, err := os.Open(dest)
if err != nil {
return nil, errors.Wrapf(err, "could not read blob '%s'", dest)
}
fi, err := file.Stat()
if err != nil {
return nil, errors.Wrapf(err, "could not stat blob '%s'", dest)
}
if fi.Size() != blobSize {
return nil, fmt.Errorf("blob has unexpected size. %d bytes expected, got %d bytes", blobSize, fi.Size())
}
return file, nil
}

// Delete deletes a blob from the blobstore
func (bs *Blobstore) Delete(spaceID, blobID string) error {
dest, err := bs.path(spaceID, blobID)
func (bs *Blobstore) Delete(node *node.Node) error {
dest, err := bs.path(node)
if err != nil {
return err
}
Expand All @@ -115,17 +109,14 @@ func (bs *Blobstore) Delete(spaceID, blobID string) error {
return nil
}

func (bs *Blobstore) path(spaceID, blobID string) (string, error) {
if spaceID == "" {
return "", fmt.Errorf("blobstore: spaceID is empty")
}
if blobID == "" {
return "", fmt.Errorf("blobstore: blobID is empty")
func (bs *Blobstore) path(node *node.Node) (string, error) {
if node.BlobID == "" {
return "", fmt.Errorf("blobstore: BlobID is empty")
}
return filepath.Join(
bs.root,
filepath.Clean(filepath.Join(
"/", "spaces", lookup.Pathify(spaceID, 1, 2), "blobs", lookup.Pathify(blobID, 4, 2)),
"/", "spaces", lookup.Pathify(node.SpaceID, 1, 2), "blobs", lookup.Pathify(node.BlobID, 4, 2)),
),
), nil
}
18 changes: 10 additions & 8 deletions pkg/storage/fs/ocis/blobstore/blobstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"path"

"github.com/cs3org/reva/v2/pkg/storage/fs/ocis/blobstore"
"github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/node"
"github.com/cs3org/reva/v2/tests/helpers"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -33,8 +34,7 @@ import (
var _ = Describe("Blobstore", func() {
var (
tmpRoot string
spaceID string
blobID string
blobNode *node.Node
blobPath string
blobSrcFile string
data []byte
Expand All @@ -48,8 +48,10 @@ var _ = Describe("Blobstore", func() {
Expect(err).ToNot(HaveOccurred())

data = []byte("1234567890")
spaceID = "wonderfullspace"
blobID = "huuuuugeblob"
blobNode = &node.Node{
SpaceID: "wonderfullspace",
BlobID: "huuuuugeblob",
}
blobPath = path.Join(tmpRoot, "spaces", "wo", "nderfullspace", "blobs", "hu", "uu", "uu", "ge", "blob")

blobSrcFile = path.Join(tmpRoot, "blobsrc")
Expand All @@ -75,7 +77,7 @@ var _ = Describe("Blobstore", func() {
Expect(os.WriteFile(blobSrcFile, data, 0700)).To(Succeed())
})
It("writes the blob", func() {
err := bs.Upload(spaceID, blobID, int64(len(data)), blobSrcFile)
err := bs.Upload(blobNode, blobSrcFile)
Expect(err).ToNot(HaveOccurred())

writtenBytes, err := os.ReadFile(blobPath)
Expand All @@ -93,7 +95,7 @@ var _ = Describe("Blobstore", func() {

Describe("Download", func() {
It("cleans the key", func() {
reader, err := bs.Download(spaceID, blobID, int64(len(data)))
reader, err := bs.Download(blobNode)
Expect(err).ToNot(HaveOccurred())

readData, err := io.ReadAll(reader)
Expand All @@ -102,7 +104,7 @@ var _ = Describe("Blobstore", func() {
})

It("returns a reader to the blob", func() {
reader, err := bs.Download(spaceID, blobID, int64(len(data)))
reader, err := bs.Download(blobNode)
Expect(err).ToNot(HaveOccurred())

readData, err := io.ReadAll(reader)
Expand All @@ -116,7 +118,7 @@ var _ = Describe("Blobstore", func() {
_, err := os.Stat(blobPath)
Expect(err).ToNot(HaveOccurred())

err = bs.Delete(spaceID, blobID)
err = bs.Delete(blobNode)
Expect(err).ToNot(HaveOccurred())

_, err = os.Stat(blobPath)
Expand Down
32 changes: 11 additions & 21 deletions pkg/storage/fs/posix/blobstore/blobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"path/filepath"

"github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/lookup"
"github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/node"
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/pkg/errors"
)
Expand All @@ -48,8 +49,8 @@ func New(root string) (*Blobstore, error) {
}

// Upload stores some data in the blobstore under the given key
func (bs *Blobstore) Upload(spaceID, blobID string, blobSize int64, source string) error {
dest, err := bs.path(spaceID, blobID)
func (bs *Blobstore) Upload(node *node.Node, source string) error {
dest, err := bs.path(node)
if err != nil {
return err
}
Expand Down Expand Up @@ -84,29 +85,21 @@ func (bs *Blobstore) Upload(spaceID, blobID string, blobSize int64, source strin
}

// Download retrieves a blob from the blobstore for reading
func (bs *Blobstore) Download(spaceID, blobID string, blobSize int64) (io.ReadCloser, error) {
dest, err := bs.path(spaceID, blobID)
func (bs *Blobstore) Download(node *node.Node) (io.ReadCloser, error) {
dest, err := bs.path(node)
if err != nil {
return nil, err
}
file, err := os.Open(dest)
if err != nil {
return nil, errors.Wrapf(err, "could not read blob '%s'", dest)
}
fi, err := file.Stat()
if err != nil {
return nil, errors.Wrapf(err, "could not stat blob '%s'", dest)
}
if fi.Size() != blobSize {
return nil, fmt.Errorf("blob has unexpected size. %d bytes expected, got %d bytes", blobSize, fi.Size())
}

return file, nil
}

// Delete deletes a blob from the blobstore
func (bs *Blobstore) Delete(spaceID, blobID string) error {
dest, err := bs.path(spaceID, blobID)
func (bs *Blobstore) Delete(node *node.Node) error {
dest, err := bs.path(node)
if err != nil {
return err
}
Expand All @@ -116,17 +109,14 @@ func (bs *Blobstore) Delete(spaceID, blobID string) error {
return nil
}

func (bs *Blobstore) path(spaceID, blobID string) (string, error) {
if spaceID == "" {
return "", fmt.Errorf("blobstore: spaceID is empty")
}
if blobID == "" {
return "", fmt.Errorf("blobstore: blobID is empty")
func (bs *Blobstore) path(node *node.Node) (string, error) {
if node.BlobID == "" {
return "", fmt.Errorf("blobstore: BlobID is empty")
}
return filepath.Join(
bs.root,
filepath.Clean(filepath.Join(
"/", "spaces", lookup.Pathify(spaceID, 1, 2), "blobs", lookup.Pathify(blobID, 4, 2)),
"/", "spaces", lookup.Pathify(node.SpaceID, 1, 2), "blobs", lookup.Pathify(node.BlobID, 4, 2)),
),
), nil
}
18 changes: 10 additions & 8 deletions pkg/storage/fs/posix/blobstore/blobstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"path"

"github.com/cs3org/reva/v2/pkg/storage/fs/ocis/blobstore"
"github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/node"
"github.com/cs3org/reva/v2/tests/helpers"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -33,8 +34,7 @@ import (
var _ = Describe("Blobstore", func() {
var (
tmpRoot string
spaceID string
blobID string
blobNode *node.Node
blobPath string
blobSrcFile string
data []byte
Expand All @@ -48,8 +48,10 @@ var _ = Describe("Blobstore", func() {
Expect(err).ToNot(HaveOccurred())

data = []byte("1234567890")
spaceID = "wonderfullspace"
blobID = "huuuuugeblob"
blobNode = &node.Node{
SpaceID: "wonderfullspace",
BlobID: "huuuuugeblob",
}
blobPath = path.Join(tmpRoot, "spaces", "wo", "nderfullspace", "blobs", "hu", "uu", "uu", "ge", "blob")

blobSrcFile = path.Join(tmpRoot, "blobsrc")
Expand All @@ -75,7 +77,7 @@ var _ = Describe("Blobstore", func() {
Expect(os.WriteFile(blobSrcFile, data, 0700)).To(Succeed())
})
It("writes the blob", func() {
err := bs.Upload(spaceID, blobID, int64(len(data)), blobSrcFile)
err := bs.Upload(blobNode, blobSrcFile)
Expect(err).ToNot(HaveOccurred())

writtenBytes, err := os.ReadFile(blobPath)
Expand All @@ -93,7 +95,7 @@ var _ = Describe("Blobstore", func() {

Describe("Download", func() {
It("cleans the key", func() {
reader, err := bs.Download(spaceID, blobID, int64(len(data)))
reader, err := bs.Download(blobNode)
Expect(err).ToNot(HaveOccurred())

readData, err := io.ReadAll(reader)
Expand All @@ -102,7 +104,7 @@ var _ = Describe("Blobstore", func() {
})

It("returns a reader to the blob", func() {
reader, err := bs.Download(spaceID, blobID, int64(len(data)))
reader, err := bs.Download(blobNode)
Expect(err).ToNot(HaveOccurred())

readData, err := io.ReadAll(reader)
Expand All @@ -116,7 +118,7 @@ var _ = Describe("Blobstore", func() {
_, err := os.Stat(blobPath)
Expect(err).ToNot(HaveOccurred())

err = bs.Delete(spaceID, blobID)
err = bs.Delete(blobNode)
Expect(err).ToNot(HaveOccurred())

_, err = os.Stat(blobPath)
Expand Down
Loading

0 comments on commit 753dae0

Please sign in to comment.