Skip to content

Commit 759fd1a

Browse files
authored
Merge pull request #5026 from kobergj/DeleteBlobsOnSpaceDelete
Delete Blobs on Space Delete
2 parents 7d37996 + d1b4ab9 commit 759fd1a

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-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

+49-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,58 @@ 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+
// remove .mpk file so subsequent attempts will not try to delete the blob again
783+
return os.Remove(path)
784+
}
785+
786+
// This is deletes all blobs of the space
787+
// NOTE: This isn't needed when no s3 is used, but we can't differentiate that here...
788+
if err := filepath.Walk(root, walkfn); err != nil {
789+
return err
790+
}
791+
747792
// remove space metadata
748-
if err := os.RemoveAll(fs.getSpaceRoot(spaceID)); err != nil {
793+
if err := os.RemoveAll(root); err != nil {
749794
return err
750795
}
751796

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

754801
return nil
755802
}

0 commit comments

Comments
 (0)