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

Delete Blobs on Space Delete #5026

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/proper-space-delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Delete Blobs when Space is deleted

Delete all blobs of a space when the space is deleted.

https://github.com/cs3org/reva/pull/5026
50 changes: 48 additions & 2 deletions pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
"github.com/cs3org/reva/v2/pkg/storagespace"
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/pkg/errors"
"github.com/shamaton/msgpack/v2"
"golang.org/x/sync/errgroup"
)

Expand Down Expand Up @@ -744,12 +745,57 @@ func (fs *Decomposedfs) DeleteStorageSpace(ctx context.Context, req *provider.De
return err
}

root := fs.getSpaceRoot(spaceID)

// walkfn will delete the blob if the node has one
walkfn := func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

if filepath.Ext(path) != ".mpk" {
return nil
}

b, err := os.ReadFile(path)
if err != nil {
return err
}

m := map[string][]byte{}
if err := msgpack.Unmarshal(b, &m); err != nil {
return err
}

bid := m["user.ocis.blobid"]
if string(bid) == "" {
return nil
}

if err := fs.tp.DeleteBlob(&node.Node{
BlobID: string(bid),
SpaceID: spaceID,
}); err != nil {
return err
}

return nil
}

// This is deletes all blobs of the space
// NOTE: This isn't needed when no s3 is used, but we can't differentiate that here...
if err := filepath.Walk(root, walkfn); err != nil {
return err
}

// remove space metadata
if err := os.RemoveAll(fs.getSpaceRoot(spaceID)); err != nil {
if err := os.RemoveAll(root); err != nil {
return err
}

// TODO remove space blobs with s3 backend by adding a purge method to the Blobstore interface
// try removing the space root node
// Note that this will fail when there are other spaceids starting with the same two digits.
_ = os.Remove(filepath.Dir(root))

return nil
}
Expand Down
Loading