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

Commit

Permalink
path: rename ParsePath and ResolvedPath
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Mar 26, 2019
1 parent fdee256 commit 9a0d495
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 37 deletions.
2 changes: 1 addition & 1 deletion block.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type BlockStat interface {
Size() int

// Path returns path to the block
Path() path.ResolvedPath
Path() path.Resolved
}

// BlockAPI specifies the interface to the block layer
Expand Down
2 changes: 1 addition & 1 deletion coreapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type CoreAPI interface {
PubSub() PubSubAPI

// ResolvePath resolves the path using Unixfs resolver
ResolvePath(context.Context, path.Path) (path.ResolvedPath, error)
ResolvePath(context.Context, path.Path) (path.Resolved, error)

// ResolveNode resolves the path (if not resolved already) using Unixfs
// resolver, gets and returns the resolved Node
Expand Down
14 changes: 7 additions & 7 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ type ObjectChange struct {

// Before holds the link path before the change. Note that when a link is
// added, this will be nil.
Before path.ResolvedPath
Before path.Resolved

// After holds the link path after the change. Note that when a link is
// removed, this will be nil.
After path.ResolvedPath
After path.Resolved
}

// ObjectAPI specifies the interface to MerkleDAG and contains useful utilities
Expand All @@ -73,7 +73,7 @@ type ObjectAPI interface {
New(context.Context, ...options.ObjectNewOption) (ipld.Node, error)

// Put imports the data into merkledag
Put(context.Context, io.Reader, ...options.ObjectPutOption) (path.ResolvedPath, error)
Put(context.Context, io.Reader, ...options.ObjectPutOption) (path.Resolved, error)

// Get returns the node for the path
Get(context.Context, path.Path) (ipld.Node, error)
Expand All @@ -90,16 +90,16 @@ type ObjectAPI interface {
// AddLink adds a link under the specified path. child path can point to a
// subdirectory within the patent which must be present (can be overridden
// with WithCreate option).
AddLink(ctx context.Context, base path.Path, name string, child path.Path, opts ...options.ObjectAddLinkOption) (path.ResolvedPath, error)
AddLink(ctx context.Context, base path.Path, name string, child path.Path, opts ...options.ObjectAddLinkOption) (path.Resolved, error)

// RmLink removes a link from the node
RmLink(ctx context.Context, base path.Path, link string) (path.ResolvedPath, error)
RmLink(ctx context.Context, base path.Path, link string) (path.Resolved, error)

// AppendData appends data to the node
AppendData(context.Context, path.Path, io.Reader) (path.ResolvedPath, error)
AppendData(context.Context, path.Path, io.Reader) (path.Resolved, error)

// SetData sets the data contained in the node
SetData(context.Context, path.Path, io.Reader) (path.ResolvedPath, error)
SetData(context.Context, path.Path, io.Reader) (path.Resolved, error)

// Diff returns a set of changes needed to transform the first object into the
// second.
Expand Down
4 changes: 0 additions & 4 deletions path.go

This file was deleted.

16 changes: 8 additions & 8 deletions path/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ type Path interface {
IsValid() error
}

// ResolvedPath is a path which was resolved to the last resolvable node.
// Resolved is a path which was resolved to the last resolvable node.
// ResolvedPaths are guaranteed to return nil from `IsValid`
type ResolvedPath interface {
type Resolved interface {
// Cid returns the CID of the node referenced by the path. Remainder of the
// path is guaranteed to be within the node.
//
Expand Down Expand Up @@ -120,7 +120,7 @@ func Join(base Path, a ...string) Path {
}

// IpfsPath creates new /ipfs path from the provided CID
func IpfsPath(c cid.Cid) ResolvedPath {
func IpfsPath(c cid.Cid) Resolved {
return &resolvedPath{
path: path{"/ipfs/" + c.String()},
cid: c,
Expand All @@ -130,7 +130,7 @@ func IpfsPath(c cid.Cid) ResolvedPath {
}

// IpldPath creates new /ipld path from the provided CID
func IpldPath(c cid.Cid) ResolvedPath {
func IpldPath(c cid.Cid) Resolved {
return &resolvedPath{
path: path{"/ipld/" + c.String()},
cid: c,
Expand All @@ -139,19 +139,19 @@ func IpldPath(c cid.Cid) ResolvedPath {
}
}

// ParsePath parses string path to a Path
func ParsePath(p string) Path {
// New parses string path to a Path
func New(p string) Path {
if pp, err := ipfspath.ParsePath(p); err == nil {
p = pp.String()
}

return &path{path: p}
}

// NewResolvedPath creates new ResolvedPath. This function performs no checks
// NewResolvedPath creates new Resolved path. This function performs no checks
// and is intended to be used by resolver implementations. Incorrect inputs may
// cause panics. Handle with care.
func NewResolvedPath(ipath ipfspath.Path, c cid.Cid, root cid.Cid, remainder string) ResolvedPath {
func NewResolvedPath(ipath ipfspath.Path, c cid.Cid, root cid.Cid, remainder string) Resolved {
return &resolvedPath{
path: path{ipath.String()},
cid: c,
Expand Down
4 changes: 2 additions & 2 deletions pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// Pin holds information about pinned resource
type Pin interface {
// Path to the pinned object
Path() path.ResolvedPath
Path() path.Resolved

// Type of the pin
Type() string
Expand All @@ -28,7 +28,7 @@ type PinStatus interface {
// BadPinNode is a node that has been marked as bad by Pin.Verify
type BadPinNode interface {
// Path is the path of the node
Path() path.ResolvedPath
Path() path.Resolved

// Err is the reason why the node has been marked as bad
Err() error
Expand Down
2 changes: 1 addition & 1 deletion tests/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (tp *provider) TestBlockGet(t *testing.T) {
t.Error("didn't get correct data back")
}

p := path.ParsePath("/ipfs/" + res.Path().Cid().String())
p := path.New("/ipfs/" + res.Path().Cid().String())

rp, err := api.ResolvePath(ctx, p)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion tests/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (tp *provider) TestDagPath(t *testing.T) {
t.Fatal(err)
}

p := path.ParsePath(gopath.Join(nd.Cid().String(), "lnk"))
p := path.New(gopath.Join(nd.Cid().String(), "lnk"))

rp, err := api.ResolvePath(ctx, p)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion tests/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func addTestObject(ctx context.Context, api coreiface.CoreAPI) (path.Path, error
}

func appendPath(p path.Path, sub string) path.Path {
return path.ParsePath(gopath.Join(p.String(), sub))
return path.New(gopath.Join(p.String(), sub))
}

func (tp *provider) TestPublishResolve(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions tests/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (tp *provider) TestPathRemainder(t *testing.T) {
t.Fatal(err)
}

rp1, err := api.ResolvePath(ctx, path.ParsePath(nd.String()+"/foo/bar"))
rp1, err := api.ResolvePath(ctx, path.New(nd.String()+"/foo/bar"))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -106,7 +106,7 @@ func (tp *provider) TestEmptyPathRemainder(t *testing.T) {
t.Fatal(err)
}

rp1, err := api.ResolvePath(ctx, path.ParsePath(nd.Cid().String()))
rp1, err := api.ResolvePath(ctx, path.New(nd.Cid().String()))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func (tp *provider) TestInvalidPathRemainder(t *testing.T) {
t.Fatal(err)
}

_, err = api.ResolvePath(ctx, path.ParsePath("/ipld/"+nd.Cid().String()+"/bar/baz"))
_, err = api.ResolvePath(ctx, path.New("/ipld/"+nd.Cid().String()+"/bar/baz"))
if err == nil || !strings.Contains(err.Error(), "no such link found") {
t.Fatalf("unexpected error: %s", err)
}
Expand Down Expand Up @@ -173,7 +173,7 @@ func (tp *provider) TestPathRoot(t *testing.T) {
t.Fatal(err)
}

rp, err := api.ResolvePath(ctx, path.ParsePath("/ipld/"+nd.Cid().String()+"/foo"))
rp, err := api.ResolvePath(ctx, path.New("/ipld/"+nd.Cid().String()+"/foo"))
if err != nil {
t.Fatal(err)
}
Expand All @@ -188,7 +188,7 @@ func (tp *provider) TestPathRoot(t *testing.T) {
}

func (tp *provider) TestPathJoin(t *testing.T) {
p1 := path.ParsePath("/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz")
p1 := path.New("/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz")

if path.Join(p1, "foo").String() != "/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz/foo" {
t.Error("unexpected path")
Expand Down
4 changes: 2 additions & 2 deletions tests/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (tp *provider) TestAdd(t *testing.T) {
t.Error(err)
}

p := func(h string) path.ResolvedPath {
p := func(h string) path.Resolved {
c, err := cid.Parse(h)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -624,7 +624,7 @@ func (tp *provider) TestGetEmptyFile(t *testing.T) {
t.Fatal(err)
}

emptyFilePath := path.ParsePath(emptyFile)
emptyFilePath := path.New(emptyFile)

r, err := api.Unixfs().Get(ctx, emptyFilePath)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (

type AddEvent struct {
Name string
Path path.ResolvedPath `json:",omitempty"`
Bytes int64 `json:",omitempty"`
Size string `json:",omitempty"`
Path path.Resolved `json:",omitempty"`
Bytes int64 `json:",omitempty"`
Size string `json:",omitempty"`
}

// FileType is an enum of possible UnixFS file types.
Expand Down Expand Up @@ -65,7 +65,7 @@ type UnixfsAPI interface {
// Add imports the data from the reader into merkledag file
//
// TODO: a long useful comment on how to use this for many different scenarios
Add(context.Context, files.Node, ...options.UnixfsAddOption) (path.ResolvedPath, error)
Add(context.Context, files.Node, ...options.UnixfsAddOption) (path.Resolved, error)

// Get returns a read-only handle to a file tree referenced by a path
//
Expand Down

0 comments on commit 9a0d495

Please sign in to comment.