Commit 21a72398 authored by Łukasz Magiera's avatar Łukasz Magiera

path: rename ParsePath and ResolvedPath

parent 5a836515
...@@ -14,7 +14,7 @@ type BlockStat interface { ...@@ -14,7 +14,7 @@ type BlockStat interface {
Size() int Size() int
// Path returns path to the block // Path returns path to the block
Path() path.ResolvedPath Path() path.Resolved
} }
// BlockAPI specifies the interface to the block layer // BlockAPI specifies the interface to the block layer
......
...@@ -44,7 +44,7 @@ type CoreAPI interface { ...@@ -44,7 +44,7 @@ type CoreAPI interface {
PubSub() PubSubAPI PubSub() PubSubAPI
// ResolvePath resolves the path using Unixfs resolver // 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 // ResolveNode resolves the path (if not resolved already) using Unixfs
// resolver, gets and returns the resolved Node // resolver, gets and returns the resolved Node
......
...@@ -59,11 +59,11 @@ type ObjectChange struct { ...@@ -59,11 +59,11 @@ type ObjectChange struct {
// Before holds the link path before the change. Note that when a link is // Before holds the link path before the change. Note that when a link is
// added, this will be nil. // 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 // After holds the link path after the change. Note that when a link is
// removed, this will be nil. // removed, this will be nil.
After path.ResolvedPath After path.Resolved
} }
// ObjectAPI specifies the interface to MerkleDAG and contains useful utilities // ObjectAPI specifies the interface to MerkleDAG and contains useful utilities
...@@ -73,7 +73,7 @@ type ObjectAPI interface { ...@@ -73,7 +73,7 @@ type ObjectAPI interface {
New(context.Context, ...options.ObjectNewOption) (ipld.Node, error) New(context.Context, ...options.ObjectNewOption) (ipld.Node, error)
// Put imports the data into merkledag // 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 returns the node for the path
Get(context.Context, path.Path) (ipld.Node, error) Get(context.Context, path.Path) (ipld.Node, error)
...@@ -90,16 +90,16 @@ type ObjectAPI interface { ...@@ -90,16 +90,16 @@ type ObjectAPI interface {
// AddLink adds a link under the specified path. child path can point to a // 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 // subdirectory within the patent which must be present (can be overridden
// with WithCreate option). // 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 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 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 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 // Diff returns a set of changes needed to transform the first object into the
// second. // second.
......
package iface
//TODO: merge with ipfspath so we don't depend on it
...@@ -39,9 +39,9 @@ type Path interface { ...@@ -39,9 +39,9 @@ type Path interface {
IsValid() error 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` // 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 // Cid returns the CID of the node referenced by the path. Remainder of the
// path is guaranteed to be within the node. // path is guaranteed to be within the node.
// //
...@@ -120,7 +120,7 @@ func Join(base Path, a ...string) Path { ...@@ -120,7 +120,7 @@ func Join(base Path, a ...string) Path {
} }
// IpfsPath creates new /ipfs path from the provided CID // IpfsPath creates new /ipfs path from the provided CID
func IpfsPath(c cid.Cid) ResolvedPath { func IpfsPath(c cid.Cid) Resolved {
return &resolvedPath{ return &resolvedPath{
path: path{"/ipfs/" + c.String()}, path: path{"/ipfs/" + c.String()},
cid: c, cid: c,
...@@ -130,7 +130,7 @@ func IpfsPath(c cid.Cid) ResolvedPath { ...@@ -130,7 +130,7 @@ func IpfsPath(c cid.Cid) ResolvedPath {
} }
// IpldPath creates new /ipld path from the provided CID // IpldPath creates new /ipld path from the provided CID
func IpldPath(c cid.Cid) ResolvedPath { func IpldPath(c cid.Cid) Resolved {
return &resolvedPath{ return &resolvedPath{
path: path{"/ipld/" + c.String()}, path: path{"/ipld/" + c.String()},
cid: c, cid: c,
...@@ -139,8 +139,8 @@ func IpldPath(c cid.Cid) ResolvedPath { ...@@ -139,8 +139,8 @@ func IpldPath(c cid.Cid) ResolvedPath {
} }
} }
// ParsePath parses string path to a Path // New parses string path to a Path
func ParsePath(p string) Path { func New(p string) Path {
if pp, err := ipfspath.ParsePath(p); err == nil { if pp, err := ipfspath.ParsePath(p); err == nil {
p = pp.String() p = pp.String()
} }
...@@ -148,10 +148,10 @@ func ParsePath(p string) Path { ...@@ -148,10 +148,10 @@ func ParsePath(p string) Path {
return &path{path: p} 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 // and is intended to be used by resolver implementations. Incorrect inputs may
// cause panics. Handle with care. // 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{ return &resolvedPath{
path: path{ipath.String()}, path: path{ipath.String()},
cid: c, cid: c,
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
// Pin holds information about pinned resource // Pin holds information about pinned resource
type Pin interface { type Pin interface {
// Path to the pinned object // Path to the pinned object
Path() path.ResolvedPath Path() path.Resolved
// Type of the pin // Type of the pin
Type() string Type() string
...@@ -28,7 +28,7 @@ type PinStatus interface { ...@@ -28,7 +28,7 @@ type PinStatus interface {
// BadPinNode is a node that has been marked as bad by Pin.Verify // BadPinNode is a node that has been marked as bad by Pin.Verify
type BadPinNode interface { type BadPinNode interface {
// Path is the path of the node // 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 is the reason why the node has been marked as bad
Err() error Err() error
......
...@@ -111,7 +111,7 @@ func (tp *provider) TestBlockGet(t *testing.T) { ...@@ -111,7 +111,7 @@ func (tp *provider) TestBlockGet(t *testing.T) {
t.Error("didn't get correct data back") 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) rp, err := api.ResolvePath(ctx, p)
if err != nil { if err != nil {
......
...@@ -114,7 +114,7 @@ func (tp *provider) TestDagPath(t *testing.T) { ...@@ -114,7 +114,7 @@ func (tp *provider) TestDagPath(t *testing.T) {
t.Fatal(err) 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) rp, err := api.ResolvePath(ctx, p)
if err != nil { if err != nil {
......
...@@ -36,7 +36,7 @@ func addTestObject(ctx context.Context, api coreiface.CoreAPI) (path.Path, error ...@@ -36,7 +36,7 @@ func addTestObject(ctx context.Context, api coreiface.CoreAPI) (path.Path, error
} }
func appendPath(p path.Path, sub string) path.Path { 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) { func (tp *provider) TestPublishResolve(t *testing.T) {
......
...@@ -75,7 +75,7 @@ func (tp *provider) TestPathRemainder(t *testing.T) { ...@@ -75,7 +75,7 @@ func (tp *provider) TestPathRemainder(t *testing.T) {
t.Fatal(err) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -106,7 +106,7 @@ func (tp *provider) TestEmptyPathRemainder(t *testing.T) { ...@@ -106,7 +106,7 @@ func (tp *provider) TestEmptyPathRemainder(t *testing.T) {
t.Fatal(err) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -137,7 +137,7 @@ func (tp *provider) TestInvalidPathRemainder(t *testing.T) { ...@@ -137,7 +137,7 @@ func (tp *provider) TestInvalidPathRemainder(t *testing.T) {
t.Fatal(err) 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") { if err == nil || !strings.Contains(err.Error(), "no such link found") {
t.Fatalf("unexpected error: %s", err) t.Fatalf("unexpected error: %s", err)
} }
...@@ -173,7 +173,7 @@ func (tp *provider) TestPathRoot(t *testing.T) { ...@@ -173,7 +173,7 @@ func (tp *provider) TestPathRoot(t *testing.T) {
t.Fatal(err) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -188,7 +188,7 @@ func (tp *provider) TestPathRoot(t *testing.T) { ...@@ -188,7 +188,7 @@ func (tp *provider) TestPathRoot(t *testing.T) {
} }
func (tp *provider) TestPathJoin(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" { if path.Join(p1, "foo").String() != "/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz/foo" {
t.Error("unexpected path") t.Error("unexpected path")
......
...@@ -102,7 +102,7 @@ func (tp *provider) TestAdd(t *testing.T) { ...@@ -102,7 +102,7 @@ func (tp *provider) TestAdd(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
p := func(h string) path.ResolvedPath { p := func(h string) path.Resolved {
c, err := cid.Parse(h) c, err := cid.Parse(h)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
...@@ -593,7 +593,7 @@ func (tp *provider) TestGetEmptyFile(t *testing.T) { ...@@ -593,7 +593,7 @@ func (tp *provider) TestGetEmptyFile(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
emptyFilePath := path.ParsePath(emptyFile) emptyFilePath := path.New(emptyFile)
r, err := api.Unixfs().Get(ctx, emptyFilePath) r, err := api.Unixfs().Get(ctx, emptyFilePath)
if err != nil { if err != nil {
......
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
type AddEvent struct { type AddEvent struct {
Name string Name string
Path path.ResolvedPath `json:",omitempty"` Path path.Resolved `json:",omitempty"`
Bytes int64 `json:",omitempty"` Bytes int64 `json:",omitempty"`
Size string `json:",omitempty"` Size string `json:",omitempty"`
} }
...@@ -65,7 +65,7 @@ type UnixfsAPI interface { ...@@ -65,7 +65,7 @@ type UnixfsAPI interface {
// Add imports the data from the reader into merkledag file // Add imports the data from the reader into merkledag file
// //
// TODO: a long useful comment on how to use this for many different scenarios // 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 // Get returns a read-only handle to a file tree referenced by a path
// //
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment