Skip to content

Commit

Permalink
Merge pull request #1 from TRON-US/btfs-upgrade
Browse files Browse the repository at this point in the history
merge ipfs v0.7.0
  • Loading branch information
Eric Chen authored Dec 7, 2020
2 parents 3b488a5 + 0b2d7c8 commit 8559471
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ os:
language: go

go:
- 1.11.x
- 1.14.x
- 1.15.x

env:
global:
- GOTFLAGS="-race"
matrix:
- BUILD_DEPTYPE=gx
- BUILD_DEPTYPE=gomod


Expand All @@ -24,7 +24,6 @@ script:

cache:
directories:
- $GOPATH/src/gx
- $GOPATH/pkg/mod
- $HOME/.cache/go-build

Expand Down
4 changes: 4 additions & 0 deletions resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (cid.
return cid.Cid{}, nil, err
}

if len(rest) == 0 {
return lnk.Cid, nil, nil
}

next, err := lnk.GetNode(ctx, r.DAG)
if err != nil {
return cid.Cid{}, nil, err
Expand Down
40 changes: 40 additions & 0 deletions resolver/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,43 @@ func TestRecurivePathResolution(t *testing.T) {
p.String(), rCid.String(), cKey.String()))
}
}

func TestResolveToLastNode_NoUnnecessaryFetching(t *testing.T) {
ctx := context.Background()
dagService := dagmock.Mock()

a := randNode()
b := randNode()

err := a.AddNodeLink("child", b)
if err != nil {
t.Fatal(err)
}

err = dagService.Add(ctx, a)
if err != nil {
t.Fatal(err)
}

aKey := a.Cid()

segments := []string{aKey.String(), "child"}
p, err := path.FromSegments("/btfs/", segments...)
if err != nil {
t.Fatal(err)
}

resolver := resolver.NewBasicResolver(dagService)
resolvedCID, remainingPath, err := resolver.ResolveToLastNode(ctx, p)
if err != nil {
t.Fatal(err)
}

if len(remainingPath) > 0 {
t.Fatal("cannot have remaining path")
}

if !resolvedCID.Equals(b.Cid()) {
t.Fatal("resolved to the wrong CID")
}
}

0 comments on commit 8559471

Please sign in to comment.