diff --git a/block.go b/block.go index 9f0ad9c..b105b07 100644 --- a/block.go +++ b/block.go @@ -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 diff --git a/coreapi.go b/coreapi.go index bef3ce0..12cb166 100644 --- a/coreapi.go +++ b/coreapi.go @@ -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 diff --git a/object.go b/object.go index 3e4b7e0..86536d4 100644 --- a/object.go +++ b/object.go @@ -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 @@ -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) @@ -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. diff --git a/path.go b/path.go deleted file mode 100644 index 1986511..0000000 --- a/path.go +++ /dev/null @@ -1,4 +0,0 @@ -package iface - -//TODO: merge with ipfspath so we don't depend on it - diff --git a/path/path.go b/path/path.go index 414d454..01b1673 100644 --- a/path/path.go +++ b/path/path.go @@ -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. // @@ -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, @@ -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, @@ -139,8 +139,8 @@ 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() } @@ -148,10 +148,10 @@ func ParsePath(p string) Path { 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, diff --git a/pin.go b/pin.go index 736b2d6..7df2956 100644 --- a/pin.go +++ b/pin.go @@ -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 @@ -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 diff --git a/tests/block.go b/tests/block.go index 905da89..5f69aa9 100644 --- a/tests/block.go +++ b/tests/block.go @@ -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 { diff --git a/tests/dag.go b/tests/dag.go index f05a131..60bb0b7 100644 --- a/tests/dag.go +++ b/tests/dag.go @@ -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 { diff --git a/tests/name.go b/tests/name.go index 98ae685..efaf1d3 100644 --- a/tests/name.go +++ b/tests/name.go @@ -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) { diff --git a/tests/path.go b/tests/path.go index ef5cb7b..eb40c6a 100644 --- a/tests/path.go +++ b/tests/path.go @@ -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) } @@ -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) } @@ -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) } @@ -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) } @@ -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") diff --git a/tests/unixfs.go b/tests/unixfs.go index 6def555..a5b6242 100644 --- a/tests/unixfs.go +++ b/tests/unixfs.go @@ -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) @@ -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 { diff --git a/unixfs.go b/unixfs.go index 0b27519..686c402 100644 --- a/unixfs.go +++ b/unixfs.go @@ -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. @@ -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 //