Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
gx update and fix code to use new Cid type
Browse files Browse the repository at this point in the history
  • Loading branch information
kevina committed Sep 12, 2018
1 parent c9cfadd commit f330c63
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
"gxDependencies": [
{
"author": "why",
"hash": "QmNr4E8z9bGTztvHJktp7uQaMdx9p3r9Asrq6eYk7iCh4a",
"hash": "Qmc68D3Dta37BCB9yMbsWRCUdytjHiv8kRsyStSkthQzo3",
"name": "go-merkledag",
"version": "1.0.14"
"version": "1.1.0"
},
{
"author": "whyrusleeping",
"hash": "QmX5CsuHyVZeTLxgRSYkgLSDQKb9UjE8xnhQzCEJWWWFsC",
"hash": "QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL",
"name": "go-ipld-format",
"version": "0.5.8"
"version": "0.6.0"
},
{
"author": "whyrusleeping",
"hash": "QmZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb",
"hash": "QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7",
"name": "go-cid",
"version": "0.8.0"
"version": "0.9.0"
},
{
"hash": "QmRREK2CAZ5Re2Bd9zZFG6FeYDppUWt5cMgsoUEp3ktgSr",
Expand All @@ -36,6 +36,6 @@
"license": "",
"name": "go-path",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "1.0.14"
"version": "1.0.13"
}

8 changes: 4 additions & 4 deletions path.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func FromString(s string) Path {
}

// FromCid safely converts a cid.Cid type to a Path type.
func FromCid(c *cid.Cid) Path {
func FromCid(c cid.Cid) Path {
return Path("/ipfs/" + c.String())
}

Expand Down Expand Up @@ -160,21 +160,21 @@ func SplitList(pth string) []string {

// SplitAbsPath clean up and split fpath. It extracts the first component (which
// must be a Multihash) and return it separately.
func SplitAbsPath(fpath Path) (*cid.Cid, []string, error) {
func SplitAbsPath(fpath Path) (cid.Cid, []string, error) {
parts := fpath.Segments()
if parts[0] == "ipfs" || parts[0] == "ipld" {
parts = parts[1:]
}

// if nothing, bail.
if len(parts) == 0 {
return nil, nil, ErrNoComponents
return cid.Cid{}, nil, ErrNoComponents
}

c, err := cid.Decode(parts[0])
// first element in the path is a cid
if err != nil {
return nil, nil, err
return cid.Cid{}, nil, err
}

return c, parts[1:], nil
Expand Down
18 changes: 9 additions & 9 deletions resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var ErrNoComponents = errors.New(
// ErrNoLink is returned when a link is not found in a path
type ErrNoLink struct {
Name string
Node *cid.Cid
Node cid.Cid
}

// Error implements the Error interface for ErrNoLink with a useful
Expand Down Expand Up @@ -57,10 +57,10 @@ func NewBasicResolver(ds ipld.DAGService) *Resolver {

// ResolveToLastNode walks the given path and returns the cid of the last node
// referenced by the path
func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (*cid.Cid, []string, error) {
func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (cid.Cid, []string, error) {
c, p, err := path.SplitAbsPath(fpath)
if err != nil {
return nil, nil, err
return cid.Cid{}, nil, err
}

if len(p) == 0 {
Expand All @@ -69,7 +69,7 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (*cid

nd, err := r.DAG.Get(ctx, c)
if err != nil {
return nil, nil, err
return cid.Cid{}, nil, err
}

for len(p) > 0 {
Expand All @@ -83,12 +83,12 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (*cid
}

if err != nil {
return nil, nil, err
return cid.Cid{}, nil, err
}

next, err := lnk.GetNode(ctx, r.DAG)
if err != nil {
return nil, nil, err
return cid.Cid{}, nil, err
}
nd = next
p = rest
Expand All @@ -101,15 +101,15 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (*cid
// Confirm the path exists within the object
val, rest, err := nd.Resolve(p)
if err != nil {
return nil, nil, err
return cid.Cid{}, nil, err
}

if len(rest) > 0 {
return nil, nil, errors.New("path failed to resolve fully")
return cid.Cid{}, nil, errors.New("path failed to resolve fully")
}
switch val.(type) {
case *ipld.Link:
return nil, nil, errors.New("inconsistent ResolveOnce / nd.Resolve")
return cid.Cid{}, nil, errors.New("inconsistent ResolveOnce / nd.Resolve")
default:
return nd.Cid(), p, nil
}
Expand Down

0 comments on commit f330c63

Please sign in to comment.