@@ -538,14 +538,15 @@ func walkGatewaySimpleSelector(ctx context.Context, p path.ImmutablePath, params
538
538
}
539
539
540
540
func (bb * BlocksBackend ) getNode (ctx context.Context , path path.ImmutablePath ) (ContentPathMetadata , format.Node , error ) {
541
- roots , lastSeg , err := bb .getPathRoots (ctx , path )
541
+ roots , lastSeg , remainder , err := bb .getPathRoots (ctx , path )
542
542
if err != nil {
543
543
return ContentPathMetadata {}, nil , err
544
544
}
545
545
546
546
md := ContentPathMetadata {
547
- PathSegmentRoots : roots ,
548
- LastSegment : lastSeg ,
547
+ PathSegmentRoots : roots ,
548
+ LastSegment : lastSeg ,
549
+ LastSegmentRemainder : remainder ,
549
550
}
550
551
551
552
lastRoot := lastSeg .Cid ()
@@ -558,7 +559,7 @@ func (bb *BlocksBackend) getNode(ctx context.Context, path path.ImmutablePath) (
558
559
return md , nd , err
559
560
}
560
561
561
- func (bb * BlocksBackend ) getPathRoots (ctx context.Context , contentPath path.ImmutablePath ) ([]cid.Cid , path.ImmutablePath , error ) {
562
+ func (bb * BlocksBackend ) getPathRoots (ctx context.Context , contentPath path.ImmutablePath ) ([]cid.Cid , path.ImmutablePath , [] string , error ) {
562
563
/*
563
564
These are logical roots where each CID represent one path segment
564
565
and resolves to either a directory or the root block of a file.
@@ -582,7 +583,10 @@ func (bb *BlocksBackend) getPathRoots(ctx context.Context, contentPath path.Immu
582
583
contentPathStr := contentPath .String ()
583
584
pathSegments := strings .Split (contentPathStr [6 :], "/" )
584
585
sp .WriteString (contentPathStr [:5 ]) // /ipfs or /ipns
585
- var lastPath path.ImmutablePath
586
+ var (
587
+ lastPath path.ImmutablePath
588
+ remainder []string
589
+ )
586
590
for _ , root := range pathSegments {
587
591
if root == "" {
588
592
continue
@@ -591,23 +595,24 @@ func (bb *BlocksBackend) getPathRoots(ctx context.Context, contentPath path.Immu
591
595
sp .WriteString (root )
592
596
p , err := path .NewPath (sp .String ())
593
597
if err != nil {
594
- return nil , nil , err
598
+ return nil , nil , nil , err
595
599
}
596
- resolvedSubPath , err := bb .resolvePath (ctx , p )
600
+ resolvedSubPath , remainderSubPath , err := bb .resolvePath (ctx , p )
597
601
if err != nil {
598
602
// TODO: should we be more explicit here and is this part of the IPFSBackend contract?
599
603
// The issue here was that we returned datamodel.ErrWrongKind instead of this resolver error
600
604
if isErrNotFound (err ) {
601
- return nil , nil , & resolver.ErrNoLink {Name : root , Node : lastPath .Cid ()}
605
+ return nil , nil , nil , & resolver.ErrNoLink {Name : root , Node : lastPath .Cid ()}
602
606
}
603
- return nil , nil , err
607
+ return nil , nil , nil , err
604
608
}
605
609
lastPath = resolvedSubPath
610
+ remainder = remainderSubPath
606
611
pathRoots = append (pathRoots , lastPath .Cid ())
607
612
}
608
613
609
614
pathRoots = pathRoots [:len (pathRoots )- 1 ]
610
- return pathRoots , lastPath , nil
615
+ return pathRoots , lastPath , remainder , nil
611
616
}
612
617
613
618
func (bb * BlocksBackend ) ResolveMutable (ctx context.Context , p path.Path ) (path.ImmutablePath , error ) {
@@ -658,7 +663,7 @@ func (bb *BlocksBackend) GetDNSLinkRecord(ctx context.Context, hostname string)
658
663
}
659
664
660
665
func (bb * BlocksBackend ) IsCached (ctx context.Context , p path.Path ) bool {
661
- rp , err := bb .resolvePath (ctx , p )
666
+ rp , _ , err := bb .resolvePath (ctx , p )
662
667
if err != nil {
663
668
return false
664
669
}
@@ -668,46 +673,52 @@ func (bb *BlocksBackend) IsCached(ctx context.Context, p path.Path) bool {
668
673
}
669
674
670
675
func (bb * BlocksBackend ) ResolvePath (ctx context.Context , path path.ImmutablePath ) (ContentPathMetadata , error ) {
671
- roots , lastSeg , err := bb .getPathRoots (ctx , path )
676
+ roots , lastSeg , remainder , err := bb .getPathRoots (ctx , path )
672
677
if err != nil {
673
678
return ContentPathMetadata {}, err
674
679
}
675
680
md := ContentPathMetadata {
676
- PathSegmentRoots : roots ,
677
- LastSegment : lastSeg ,
681
+ PathSegmentRoots : roots ,
682
+ LastSegment : lastSeg ,
683
+ LastSegmentRemainder : remainder ,
678
684
}
679
685
return md , nil
680
686
}
681
687
682
- func (bb * BlocksBackend ) resolvePath (ctx context.Context , p path.Path ) (path.ImmutablePath , error ) {
688
+ func (bb * BlocksBackend ) resolvePath (ctx context.Context , p path.Path ) (path.ImmutablePath , [] string , error ) {
683
689
var err error
684
690
if p .Namespace () == path .IPNSNamespace {
685
691
p , err = resolve .ResolveIPNS (ctx , bb .namesys , p )
686
692
if err != nil {
687
- return nil , err
693
+ return nil , nil , err
688
694
}
689
695
}
690
696
691
697
if p .Namespace () != path .IPFSNamespace {
692
- return nil , fmt .Errorf ("unsupported path namespace: %s" , p .Namespace ())
698
+ return nil , nil , fmt .Errorf ("unsupported path namespace: %s" , p .Namespace ())
693
699
}
694
700
695
701
imPath , err := path .NewImmutablePath (p )
696
702
if err != nil {
697
- return nil , err
703
+ return nil , nil , err
698
704
}
699
705
700
- node , rest , err := bb .resolver .ResolveToLastNode (ctx , imPath )
706
+ node , remainder , err := bb .resolver .ResolveToLastNode (ctx , imPath )
701
707
if err != nil {
702
- return nil , err
708
+ return nil , nil , err
703
709
}
704
710
705
- p , err = path .Join (path .NewIPFSPath (node ), rest ... )
711
+ p , err = path .Join (path .NewIPFSPath (node ), remainder ... )
706
712
if err != nil {
707
- return nil , err
713
+ return nil , nil , err
714
+ }
715
+
716
+ imPath , err = path .NewImmutablePath (p )
717
+ if err != nil {
718
+ return nil , nil , err
708
719
}
709
720
710
- return path . NewImmutablePath ( p )
721
+ return imPath , remainder , nil
711
722
}
712
723
713
724
type nodeGetterToCarExporer struct {
0 commit comments