Skip to content

Commit

Permalink
feat(blobstore): allow listing
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <jkoberg@owncloud.com>
Co-authored-by: dragonchaser <crichter@owncloud.com>
Signed-off-by: jkoberg <jkoberg@owncloud.com>
  • Loading branch information
kobergj and dragonchaser committed May 23, 2024
1 parent fae5c10 commit 5c0bfa1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/add-list-method-to-blobsstore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Add List method to ocis and s3ng blobstore

Allow listing blobstores for maintenance

https://github.com/cs3org/reva/pull/4696
25 changes: 25 additions & 0 deletions pkg/storage/fs/ocis/blobstore/blobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"io"
"os"
"path/filepath"
"strings"

"github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/lookup"
"github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/node"
Expand Down Expand Up @@ -109,6 +110,30 @@ func (bs *Blobstore) Delete(node *node.Node) error {
return nil
}

// List lists all blobs in the Blobstore
func (bs *Blobstore) List() ([]string, error) {
dirs, err := filepath.Glob(filepath.Join(bs.root, "spaces", "*", "*", "blobs", "*", "*", "*", "*", "*"))
if err != nil {
return nil, err
}
blobids := make([]string, 0, len(dirs))
for _, d := range dirs {
seps := strings.Split(d, "/")
var b string
var now bool
for _, s := range seps {
if now {
b += s
}
if s == "blobs" {
now = true
}
}
blobids = append(blobids, b)
}
return blobids, nil
}

func (bs *Blobstore) path(node *node.Node) (string, error) {
if node.BlobID == "" {
return "", fmt.Errorf("blobstore: BlobID is empty")
Expand Down
16 changes: 16 additions & 0 deletions pkg/storage/fs/s3ng/blobstore/blobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ func (bs *Blobstore) Delete(node *node.Node) error {
return nil
}

// List lists all blobs in the Blobstore
func (bs *Blobstore) List() ([]string, error) {
ch := bs.client.ListObjects(context.Background(), bs.bucket, minio.ListObjectsOptions{})

var err error
ids := make([]string, 0)
for oi := range ch {
if oi.Err != nil {
err = oi.Err
continue
}
ids = append(ids, oi.Key)
}
return ids, err
}

func (bs *Blobstore) path(node *node.Node) string {
// https://aws.amazon.com/de/premiumsupport/knowledge-center/s3-prefix-nested-folders-difference/
// Prefixes are used to partion a bucket. A prefix is everything except the filename.
Expand Down

0 comments on commit 5c0bfa1

Please sign in to comment.