Skip to content

Commit 3e0cbcd

Browse files
committed
fix(dcfs): delete blobs when space is deleted
Signed-off-by: jkoberg <[email protected]>
1 parent 014a603 commit 3e0cbcd

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Bugfix: Delete Blobs when Space is deleted
2+
3+
Delete all blobs of a space when the space is deleted.
4+
5+
https://github.com/cs3org/reva/pull/5026

pkg/storage/utils/decomposedfs/spaces.go

+48-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import (
5050
"github.com/cs3org/reva/v2/pkg/storagespace"
5151
"github.com/cs3org/reva/v2/pkg/utils"
5252
"github.com/pkg/errors"
53+
"github.com/shamaton/msgpack/v2"
5354
"golang.org/x/sync/errgroup"
5455
)
5556

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

748+
root := fs.getSpaceRoot(spaceID)
749+
750+
// walkfn will delete the blob if the node has one
751+
walkfn := func(path string, info os.FileInfo, err error) error {
752+
if err != nil {
753+
return err
754+
}
755+
756+
if filepath.Ext(path) != ".mpk" {
757+
return nil
758+
}
759+
760+
b, err := os.ReadFile(path)
761+
if err != nil {
762+
return err
763+
}
764+
765+
m := map[string][]byte{}
766+
if err := msgpack.Unmarshal(b, &m); err != nil {
767+
return err
768+
}
769+
770+
bid := m["user.ocis.blobid"]
771+
if string(bid) == "" {
772+
return nil
773+
}
774+
775+
if err := fs.tp.DeleteBlob(&node.Node{
776+
BlobID: string(bid),
777+
SpaceID: spaceID,
778+
}); err != nil {
779+
return err
780+
}
781+
782+
return nil
783+
}
784+
785+
// This is deletes all blobs of the space
786+
// NOTE: This isn't needed when no s3 is used, but we can't differentiate that here...
787+
if err := filepath.Walk(root, walkfn); err != nil {
788+
return err
789+
}
790+
747791
// remove space metadata
748-
if err := os.RemoveAll(fs.getSpaceRoot(spaceID)); err != nil {
792+
if err := os.RemoveAll(root); err != nil {
749793
return err
750794
}
751795

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

754800
return nil
755801
}

0 commit comments

Comments
 (0)