@@ -460,10 +460,10 @@ func (ds *Shard) walkTrie(ctx context.Context, cb func(*Shard) error) error {
460460
461461// setValue sets the link `value` in the given key, either creating the entry
462462// if it didn't exist or overwriting the old one. It returns the old entry (if any).
463- func (ds * Shard ) setValue (ctx context.Context , hv * hashBits , key string , value * ipld.Link ) (oldValue * ipld.Link , err error ) {
463+ func (ds * Shard ) setValue (ctx context.Context , hv * hashBits , key string , value * ipld.Link ) (* ipld.Link , error ) {
464464 idx , err := hv .Next (ds .tableSizeLg2 )
465465 if err != nil {
466- return
466+ return nil , err
467467 }
468468
469469 if ! ds .childer .has (idx ) {
@@ -474,22 +474,22 @@ func (ds *Shard) setValue(ctx context.Context, hv *hashBits, key string, value *
474474 i := ds .childer .sliceIndex (idx )
475475 child , err := ds .childer .get (ctx , i )
476476 if err != nil {
477- return
477+ return nil , err
478478 }
479479
480480 if child .isValueNode () {
481481 // Leaf node. This is the base case of this recursive function.
482482 if child .key == key {
483483 // We are in the correct shard (tree level) so we modify this child
484484 // and return.
485- oldValue = child .val
485+ oldValue : = child .val
486486
487487 if value == nil { // Remove old entry.
488488 return oldValue , ds .childer .rm (idx )
489489 }
490490
491491 child .val = value // Overwrite entry.
492- return
492+ return oldValue , nil
493493 }
494494
495495 if value == nil {
@@ -519,11 +519,11 @@ func (ds *Shard) setValue(ctx context.Context, hv *hashBits, key string, value *
519519 // will create new ones until we find different slots for both.)
520520 _ , err = child .setValue (ctx , hv , key , value )
521521 if err != nil {
522- return
522+ return nil , err
523523 }
524524 _ , err = child .setValue (ctx , chhv , grandChild .key , grandChild .val )
525525 if err != nil {
526- return
526+ return nil , err
527527 }
528528
529529 // Replace this leaf node with the new Shard node.
@@ -532,9 +532,9 @@ func (ds *Shard) setValue(ctx context.Context, hv *hashBits, key string, value *
532532 } else {
533533 // We are in a Shard (internal node). We will recursively call this
534534 // function until finding the leaf (the logic of the `if` case above).
535- oldValue , err = child .setValue (ctx , hv , key , value )
535+ oldValue , err : = child .setValue (ctx , hv , key , value )
536536 if err != nil {
537- return
537+ return nil , err
538538 }
539539
540540 if value == nil {
@@ -558,25 +558,25 @@ func (ds *Shard) setValue(ctx context.Context, hv *hashBits, key string, value *
558558 if schild .isValueNode () {
559559 ds .childer .set (schild , i )
560560 }
561- return
561+ return oldValue , nil
562562 }
563563
564564 // Otherwise, work with the link.
565565 slnk := child .childer .link (0 )
566566 var lnkType linkType
567567 lnkType , err = child .childer .sd .childLinkType (slnk )
568568 if err != nil {
569- return
569+ return nil , err
570570 }
571571 if lnkType == shardValueLink {
572572 // sub-shard with a single value element, collapse it
573573 ds .childer .setLink (slnk , i )
574574 }
575- return
575+ return oldValue , nil
576576 }
577577 }
578578
579- return
579+ return oldValue , nil
580580 }
581581}
582582
0 commit comments