@@ -485,14 +485,15 @@ func walkGatewaySimpleSelector(ctx context.Context, p path.ImmutablePath, params
485
485
}
486
486
487
487
func (bb * BlocksBackend ) getNode (ctx context.Context , path path.ImmutablePath ) (ContentPathMetadata , format.Node , error ) {
488
- roots , lastSeg , err := bb .getPathRoots (ctx , path )
488
+ roots , lastSeg , remainder , err := bb .getPathRoots (ctx , path )
489
489
if err != nil {
490
490
return ContentPathMetadata {}, nil , err
491
491
}
492
492
493
493
md := ContentPathMetadata {
494
- PathSegmentRoots : roots ,
495
- LastSegment : lastSeg ,
494
+ PathSegmentRoots : roots ,
495
+ LastSegment : lastSeg ,
496
+ LastSegmentRemainder : remainder ,
496
497
}
497
498
498
499
lastRoot := lastSeg .Cid ()
@@ -505,7 +506,7 @@ func (bb *BlocksBackend) getNode(ctx context.Context, path path.ImmutablePath) (
505
506
return md , nd , err
506
507
}
507
508
508
- func (bb * BlocksBackend ) getPathRoots (ctx context.Context , contentPath path.ImmutablePath ) ([]cid.Cid , path.ImmutablePath , error ) {
509
+ func (bb * BlocksBackend ) getPathRoots (ctx context.Context , contentPath path.ImmutablePath ) ([]cid.Cid , path.ImmutablePath , [] string , error ) {
509
510
/*
510
511
These are logical roots where each CID represent one path segment
511
512
and resolves to either a directory or the root block of a file.
@@ -529,7 +530,10 @@ func (bb *BlocksBackend) getPathRoots(ctx context.Context, contentPath path.Immu
529
530
contentPathStr := contentPath .String ()
530
531
pathSegments := strings .Split (contentPathStr [6 :], "/" )
531
532
sp .WriteString (contentPathStr [:5 ]) // /ipfs or /ipns
532
- var lastPath path.ImmutablePath
533
+ var (
534
+ lastPath path.ImmutablePath
535
+ remainder []string
536
+ )
533
537
for _ , root := range pathSegments {
534
538
if root == "" {
535
539
continue
@@ -538,23 +542,24 @@ func (bb *BlocksBackend) getPathRoots(ctx context.Context, contentPath path.Immu
538
542
sp .WriteString (root )
539
543
p , err := path .NewPath (sp .String ())
540
544
if err != nil {
541
- return nil , nil , err
545
+ return nil , nil , nil , err
542
546
}
543
- resolvedSubPath , err := bb .resolvePath (ctx , p )
547
+ resolvedSubPath , remainderSubPath , err := bb .resolvePath (ctx , p )
544
548
if err != nil {
545
549
// TODO: should we be more explicit here and is this part of the IPFSBackend contract?
546
550
// The issue here was that we returned datamodel.ErrWrongKind instead of this resolver error
547
551
if isErrNotFound (err ) {
548
- return nil , nil , & resolver.ErrNoLink {Name : root , Node : lastPath .Cid ()}
552
+ return nil , nil , nil , & resolver.ErrNoLink {Name : root , Node : lastPath .Cid ()}
549
553
}
550
- return nil , nil , err
554
+ return nil , nil , nil , err
551
555
}
552
556
lastPath = resolvedSubPath
557
+ remainder = remainderSubPath
553
558
pathRoots = append (pathRoots , lastPath .Cid ())
554
559
}
555
560
556
561
pathRoots = pathRoots [:len (pathRoots )- 1 ]
557
- return pathRoots , lastPath , nil
562
+ return pathRoots , lastPath , remainder , nil
558
563
}
559
564
560
565
func (bb * BlocksBackend ) ResolveMutable (ctx context.Context , p path.Path ) (path.ImmutablePath , error ) {
@@ -605,7 +610,7 @@ func (bb *BlocksBackend) GetDNSLinkRecord(ctx context.Context, hostname string)
605
610
}
606
611
607
612
func (bb * BlocksBackend ) IsCached (ctx context.Context , p path.Path ) bool {
608
- rp , err := bb .resolvePath (ctx , p )
613
+ rp , _ , err := bb .resolvePath (ctx , p )
609
614
if err != nil {
610
615
return false
611
616
}
@@ -615,46 +620,52 @@ func (bb *BlocksBackend) IsCached(ctx context.Context, p path.Path) bool {
615
620
}
616
621
617
622
func (bb * BlocksBackend ) ResolvePath (ctx context.Context , path path.ImmutablePath ) (ContentPathMetadata , error ) {
618
- roots , lastSeg , err := bb .getPathRoots (ctx , path )
623
+ roots , lastSeg , remainder , err := bb .getPathRoots (ctx , path )
619
624
if err != nil {
620
625
return ContentPathMetadata {}, err
621
626
}
622
627
md := ContentPathMetadata {
623
- PathSegmentRoots : roots ,
624
- LastSegment : lastSeg ,
628
+ PathSegmentRoots : roots ,
629
+ LastSegment : lastSeg ,
630
+ LastSegmentRemainder : remainder ,
625
631
}
626
632
return md , nil
627
633
}
628
634
629
- func (bb * BlocksBackend ) resolvePath (ctx context.Context , p path.Path ) (path.ImmutablePath , error ) {
635
+ func (bb * BlocksBackend ) resolvePath (ctx context.Context , p path.Path ) (path.ImmutablePath , [] string , error ) {
630
636
var err error
631
637
if p .Namespace () == path .IPNSNamespace {
632
638
p , err = resolve .ResolveIPNS (ctx , bb .namesys , p )
633
639
if err != nil {
634
- return nil , err
640
+ return nil , nil , err
635
641
}
636
642
}
637
643
638
644
if p .Namespace () != path .IPFSNamespace {
639
- return nil , fmt .Errorf ("unsupported path namespace: %s" , p .Namespace ())
645
+ return nil , nil , fmt .Errorf ("unsupported path namespace: %s" , p .Namespace ())
640
646
}
641
647
642
648
imPath , err := path .NewImmutablePath (p )
643
649
if err != nil {
644
- return nil , err
650
+ return nil , nil , err
645
651
}
646
652
647
- node , rest , err := bb .resolver .ResolveToLastNode (ctx , imPath )
653
+ node , remainder , err := bb .resolver .ResolveToLastNode (ctx , imPath )
648
654
if err != nil {
649
- return nil , err
655
+ return nil , nil , err
650
656
}
651
657
652
- p , err = path .Join (path .NewIPFSPath (node ), rest ... )
658
+ p , err = path .Join (path .NewIPFSPath (node ), remainder ... )
653
659
if err != nil {
654
- return nil , err
660
+ return nil , nil , err
661
+ }
662
+
663
+ imPath , err = path .NewImmutablePath (p )
664
+ if err != nil {
665
+ return nil , nil , err
655
666
}
656
667
657
- return path . NewImmutablePath ( p )
668
+ return imPath , remainder , nil
658
669
}
659
670
660
671
type nodeGetterToCarExporer struct {
0 commit comments