Skip to content

Commit

Permalink
Merge pull request #5026 from kobergj/DeleteBlobsOnSpaceDelete
Browse files Browse the repository at this point in the history
Delete Blobs on Space Delete
  • Loading branch information
kobergj authored Jan 7, 2025
2 parents 7d37996 + d1b4ab9 commit 759fd1a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
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
51 changes: 49 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,58 @@ 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
}

// remove .mpk file so subsequent attempts will not try to delete the blob again
return os.Remove(path)
}

// 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

0 comments on commit 759fd1a

Please sign in to comment.