This repository was archived by the owner on Jun 27, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +34
-9
lines changed Expand file tree Collapse file tree 1 file changed +34
-9
lines changed Original file line number Diff line number Diff line change @@ -214,7 +214,9 @@ func (d *BasicDirectory) needsToSwitchToHAMTDir(name string, nodeToAdd ipld.Node
214
214
}
215
215
operationSizeChange -= estimatedLinkSize (name , entryToRemove .Cid )
216
216
}
217
- operationSizeChange += estimatedLinkSize (name , nodeToAdd .Cid ())
217
+ if nodeToAdd != nil {
218
+ operationSizeChange += estimatedLinkSize (name , nodeToAdd .Cid ())
219
+ }
218
220
219
221
return d .estimatedSize + operationSizeChange >= HAMTShardingSize , nil
220
222
}
@@ -613,15 +615,38 @@ func (d *UpgradeableDirectory) RemoveChild(ctx context.Context, name string) err
613
615
if err != nil {
614
616
return err
615
617
}
616
-
617
- if switchToBasic {
618
- basicDir , err := hamtDir .switchToBasic (ctx )
619
- if err != nil {
620
- return err
621
- }
622
- d .Directory = basicDir
618
+ if ! switchToBasic {
619
+ return hamtDir .RemoveChild (ctx , name )
620
+ }
621
+ basicDir , err := hamtDir .switchToBasic (ctx )
622
+ if err != nil {
623
+ return err
623
624
}
625
+ err = basicDir .RemoveChild (ctx , name )
626
+ if err != nil {
627
+ return err
628
+ }
629
+ d .Directory = basicDir
630
+ return nil
624
631
}
625
632
626
- return d .Directory .RemoveChild (ctx , name )
633
+ // BasicDirectory
634
+ basicDir := d .Directory .(* BasicDirectory )
635
+ switchToHAMT , err := basicDir .needsToSwitchToHAMTDir (name , nil )
636
+ if err != nil {
637
+ return err
638
+ }
639
+ if ! switchToHAMT {
640
+ return basicDir .RemoveChild (ctx , name )
641
+ }
642
+ hamtDir , err = basicDir .SwitchToSharding (ctx )
643
+ if err != nil {
644
+ return err
645
+ }
646
+ hamtDir .RemoveChild (ctx , name )
647
+ if err != nil {
648
+ return err
649
+ }
650
+ d .Directory = hamtDir
651
+ return nil
627
652
}
You can’t perform that action at this time.
0 commit comments