Skip to content

Commit

Permalink
write blob based on session id
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Apr 5, 2024
1 parent ef59ba2 commit 8b53e0d
Show file tree
Hide file tree
Showing 18 changed files with 229 additions and 211 deletions.
24 changes: 13 additions & 11 deletions pkg/storage/fs/ocis/blobstore/blobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ 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 @@ -49,8 +48,8 @@ func New(root string) (*Blobstore, error) {
}

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

// Download retrieves a blob from the blobstore for reading
func (bs *Blobstore) Download(node *node.Node) (io.ReadCloser, error) {
dest, err := bs.path(node)
func (bs *Blobstore) Download(spaceID, blobID string) (io.ReadCloser, error) {
dest, err := bs.path(spaceID, blobID)
if err != nil {
return nil, err
}
Expand All @@ -98,8 +97,8 @@ func (bs *Blobstore) Download(node *node.Node) (io.ReadCloser, error) {
}

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

func (bs *Blobstore) path(node *node.Node) (string, error) {
if node.BlobID == "" {
return "", fmt.Errorf("blobstore: BlobID is empty")
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")
}
return filepath.Join(
bs.root,
filepath.Clean(filepath.Join(
"/", "spaces", lookup.Pathify(node.SpaceID, 1, 2), "blobs", lookup.Pathify(node.BlobID, 4, 2)),
"/", "spaces", lookup.Pathify(spaceID, 1, 2), "blobs", lookup.Pathify(blobID, 4, 2)),
),
), nil
}
18 changes: 8 additions & 10 deletions pkg/storage/fs/ocis/blobstore/blobstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ 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 @@ -34,7 +33,8 @@ import (
var _ = Describe("Blobstore", func() {
var (
tmpRoot string
blobNode *node.Node
spaceID string
blobID string
blobPath string
blobSrcFile string
data []byte
Expand All @@ -48,10 +48,8 @@ var _ = Describe("Blobstore", func() {
Expect(err).ToNot(HaveOccurred())

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

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

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

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

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

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

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

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

_, err = os.Stat(blobPath)
Expand Down
24 changes: 13 additions & 11 deletions pkg/storage/fs/posix/blobstore/blobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ 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 @@ -49,8 +48,8 @@ func New(root string) (*Blobstore, error) {
}

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

// Download retrieves a blob from the blobstore for reading
func (bs *Blobstore) Download(node *node.Node) (io.ReadCloser, error) {
dest, err := bs.path(node)
func (bs *Blobstore) Download(spaceID, blobID string) (io.ReadCloser, error) {
dest, err := bs.path(spaceID, blobID)
if err != nil {
return nil, err
}
Expand All @@ -98,8 +97,8 @@ func (bs *Blobstore) Download(node *node.Node) (io.ReadCloser, error) {
}

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

func (bs *Blobstore) path(node *node.Node) (string, error) {
if node.BlobID == "" {
return "", fmt.Errorf("blobstore: BlobID is empty")
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")
}
return filepath.Join(
bs.root,
filepath.Clean(filepath.Join(
"/", "spaces", lookup.Pathify(node.SpaceID, 1, 2), "blobs", lookup.Pathify(node.BlobID, 4, 2)),
"/", "spaces", lookup.Pathify(spaceID, 1, 2), "blobs", lookup.Pathify(blobID, 4, 2)),
),
), nil
}
18 changes: 8 additions & 10 deletions pkg/storage/fs/posix/blobstore/blobstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ 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 @@ -34,7 +33,8 @@ import (
var _ = Describe("Blobstore", func() {
var (
tmpRoot string
blobNode *node.Node
spaceID string
blobID string
blobPath string
blobSrcFile string
data []byte
Expand All @@ -48,10 +48,8 @@ var _ = Describe("Blobstore", func() {
Expect(err).ToNot(HaveOccurred())

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

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

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

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

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

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

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

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

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

0 comments on commit 8b53e0d

Please sign in to comment.