@@ -50,6 +50,7 @@ import (
50
50
"github.com/cs3org/reva/v2/pkg/storagespace"
51
51
"github.com/cs3org/reva/v2/pkg/utils"
52
52
"github.com/pkg/errors"
53
+ "github.com/shamaton/msgpack/v2"
53
54
"golang.org/x/sync/errgroup"
54
55
)
55
56
@@ -744,12 +745,58 @@ func (fs *Decomposedfs) DeleteStorageSpace(ctx context.Context, req *provider.De
744
745
return err
745
746
}
746
747
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
+
747
792
// remove space metadata
748
- if err := os .RemoveAll (fs . getSpaceRoot ( spaceID ) ); err != nil {
793
+ if err := os .RemoveAll (root ); err != nil {
749
794
return err
750
795
}
751
796
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 ))
753
800
754
801
return nil
755
802
}
0 commit comments