path: rename ParsePath and ResolvedPath
This commit was moved from ipfs/interface-go-ipfs-core@21a72398d98125cae4fcef33cc80ed4a1f3be22c This commit was moved from ipfs/boxo@fbc9ab8769cbaac70a6459c33973c0d894e85126
Łukasz Magiera committed
Mar 26, 2019 at 15:09 UTC
3669a774ffa2b3c545baf3f80f77c6d792295e34
12 files changed
+33
-37
core/coreiface/block.go
+1
-1
@@ -14,7 +14,7 @@ type BlockStat interface {
14
Size() int
15
16
// Path returns path to the block
17
- Path() path.ResolvedPath
17
+ Path() path.Resolved
18
}
19
20
// BlockAPI specifies the interface to the block layer
core/coreiface/coreapi.go
+1
-1
@@ -44,7 +44,7 @@ type CoreAPI interface {
44
PubSub() PubSubAPI
45
46
// ResolvePath resolves the path using Unixfs resolver
47
- ResolvePath(context.Context, path.Path) (path.ResolvedPath, error)
47
+ ResolvePath(context.Context, path.Path) (path.Resolved, error)
48
49
// ResolveNode resolves the path (if not resolved already) using Unixfs
50
// resolver, gets and returns the resolved Node
core/coreiface/object.go
+7
-7
@@ -59,11 +59,11 @@ type ObjectChange struct {
59
60
// Before holds the link path before the change. Note that when a link is
61
// added, this will be nil.
62
- Before path.ResolvedPath
62
+ Before path.Resolved
63
64
// After holds the link path after the change. Note that when a link is
65
// removed, this will be nil.
66
- After path.ResolvedPath
66
+ After path.Resolved
67
}
68
69
// ObjectAPI specifies the interface to MerkleDAG and contains useful utilities
@@ -73,7 +73,7 @@ type ObjectAPI interface {
73
New(context.Context, ...options.ObjectNewOption) (ipld.Node, error)
74
75
// Put imports the data into merkledag
76
- Put(context.Context, io.Reader, ...options.ObjectPutOption) (path.ResolvedPath, error)
76
+ Put(context.Context, io.Reader, ...options.ObjectPutOption) (path.Resolved, error)
77
78
// Get returns the node for the path
79
Get(context.Context, path.Path) (ipld.Node, error)
@@ -90,16 +90,16 @@ type ObjectAPI interface {
90
// AddLink adds a link under the specified path. child path can point to a
91
// subdirectory within the patent which must be present (can be overridden
92
// with WithCreate option).
93
- AddLink(ctx context.Context, base path.Path, name string, child path.Path, opts ...options.ObjectAddLinkOption) (path.ResolvedPath, error)
93
+ AddLink(ctx context.Context, base path.Path, name string, child path.Path, opts ...options.ObjectAddLinkOption) (path.Resolved, error)
94
95
// RmLink removes a link from the node
96
- RmLink(ctx context.Context, base path.Path, link string) (path.ResolvedPath, error)
96
+ RmLink(ctx context.Context, base path.Path, link string) (path.Resolved, error)
97
98
// AppendData appends data to the node
99
- AppendData(context.Context, path.Path, io.Reader) (path.ResolvedPath, error)
99
+ AppendData(context.Context, path.Path, io.Reader) (path.Resolved, error)
100
101
// SetData sets the data contained in the node
102
- SetData(context.Context, path.Path, io.Reader) (path.ResolvedPath, error)
102
+ SetData(context.Context, path.Path, io.Reader) (path.Resolved, error)
103
104
// Diff returns a set of changes needed to transform the first object into the
105
// second.
core/coreiface/path.go
deleted
-4
@@ -1,4 +0,0 @@
1
-package iface
2
-
3
-//TODO: merge with ipfspath so we don't depend on it
4
-
core/coreiface/path/path.go
+8
-8
@@ -39,9 +39,9 @@ type Path interface {
39
IsValid() error
40
}
41
42
-// ResolvedPath is a path which was resolved to the last resolvable node.
42
+// Resolved is a path which was resolved to the last resolvable node.
43
// ResolvedPaths are guaranteed to return nil from `IsValid`
44
-type ResolvedPath interface {
44
+type Resolved interface {
45
// Cid returns the CID of the node referenced by the path. Remainder of the
46
// path is guaranteed to be within the node.
47
//
@@ -120,7 +120,7 @@ func Join(base Path, a ...string) Path {
120
}
121
122
// IpfsPath creates new /ipfs path from the provided CID
123
-func IpfsPath(c cid.Cid) ResolvedPath {
123
+func IpfsPath(c cid.Cid) Resolved {
124
return &resolvedPath{
125
path: path{"/ipfs/" + c.String()},
126
cid: c,
@@ -130,7 +130,7 @@ func IpfsPath(c cid.Cid) ResolvedPath {
130
}
131
132
// IpldPath creates new /ipld path from the provided CID
133
-func IpldPath(c cid.Cid) ResolvedPath {
133
+func IpldPath(c cid.Cid) Resolved {
134
return &resolvedPath{
135
path: path{"/ipld/" + c.String()},
136
cid: c,
@@ -139,8 +139,8 @@ func IpldPath(c cid.Cid) ResolvedPath {
139
}
140
}
141
142
-// ParsePath parses string path to a Path
143
-func ParsePath(p string) Path {
142
+// New parses string path to a Path
143
+func New(p string) Path {
144
if pp, err := ipfspath.ParsePath(p); err == nil {
145
p = pp.String()
146
}
@@ -148,10 +148,10 @@ func ParsePath(p string) Path {
148
return &path{path: p}
149
}
150
151
-// NewResolvedPath creates new ResolvedPath. This function performs no checks
151
+// NewResolvedPath creates new Resolved path. This function performs no checks
152
// and is intended to be used by resolver implementations. Incorrect inputs may
153
// cause panics. Handle with care.
154
-func NewResolvedPath(ipath ipfspath.Path, c cid.Cid, root cid.Cid, remainder string) ResolvedPath {
154
+func NewResolvedPath(ipath ipfspath.Path, c cid.Cid, root cid.Cid, remainder string) Resolved {
155
return &resolvedPath{
156
path: path{ipath.String()},
157
cid: c,
core/coreiface/pin.go
+2
-2
@@ -10,7 +10,7 @@ import (
10
// Pin holds information about pinned resource
11
type Pin interface {
12
// Path to the pinned object
13
- Path() path.ResolvedPath
13
+ Path() path.Resolved
14
15
// Type of the pin
16
Type() string
@@ -28,7 +28,7 @@ type PinStatus interface {
28
// BadPinNode is a node that has been marked as bad by Pin.Verify
29
type BadPinNode interface {
30
// Path is the path of the node
31
- Path() path.ResolvedPath
31
+ Path() path.Resolved
32
33
// Err is the reason why the node has been marked as bad
34
Err() error
core/coreiface/tests/block.go
+1
-1
@@ -111,7 +111,7 @@ func (tp *provider) TestBlockGet(t *testing.T) {
111
t.Error("didn't get correct data back")
112
}
113
114
- p := path.ParsePath("/ipfs/" + res.Path().Cid().String())
114
+ p := path.New("/ipfs/" + res.Path().Cid().String())
115
116
rp, err := api.ResolvePath(ctx, p)
117
if err != nil {
core/coreiface/tests/dag.go
+1
-1
@@ -114,7 +114,7 @@ func (tp *provider) TestDagPath(t *testing.T) {
114
t.Fatal(err)
115
}
116
117
- p := path.ParsePath(gopath.Join(nd.Cid().String(), "lnk"))
117
+ p := path.New(gopath.Join(nd.Cid().String(), "lnk"))
118
119
rp, err := api.ResolvePath(ctx, p)
120
if err != nil {
core/coreiface/tests/name.go
+1
-1
@@ -36,7 +36,7 @@ func addTestObject(ctx context.Context, api coreiface.CoreAPI) (path.Path, error
36
}
37
38
func appendPath(p path.Path, sub string) path.Path {
39
- return path.ParsePath(gopath.Join(p.String(), sub))
39
+ return path.New(gopath.Join(p.String(), sub))
40
}
41
42
func (tp *provider) TestPublishResolve(t *testing.T) {
core/coreiface/tests/path.go
+5
-5
@@ -75,7 +75,7 @@ func (tp *provider) TestPathRemainder(t *testing.T) {
75
t.Fatal(err)
76
}
77
78
- rp1, err := api.ResolvePath(ctx, path.ParsePath(nd.String()+"/foo/bar"))
78
+ rp1, err := api.ResolvePath(ctx, path.New(nd.String()+"/foo/bar"))
79
if err != nil {
80
t.Fatal(err)
81
}
@@ -106,7 +106,7 @@ func (tp *provider) TestEmptyPathRemainder(t *testing.T) {
106
t.Fatal(err)
107
}
108
109
- rp1, err := api.ResolvePath(ctx, path.ParsePath(nd.Cid().String()))
109
+ rp1, err := api.ResolvePath(ctx, path.New(nd.Cid().String()))
110
if err != nil {
111
t.Fatal(err)
112
}
@@ -137,7 +137,7 @@ func (tp *provider) TestInvalidPathRemainder(t *testing.T) {
137
t.Fatal(err)
138
}
139
140
- _, err = api.ResolvePath(ctx, path.ParsePath("/ipld/"+nd.Cid().String()+"/bar/baz"))
140
+ _, err = api.ResolvePath(ctx, path.New("/ipld/"+nd.Cid().String()+"/bar/baz"))
141
if err == nil || !strings.Contains(err.Error(), "no such link found") {
142
t.Fatalf("unexpected error: %s", err)
143
}
@@ -173,7 +173,7 @@ func (tp *provider) TestPathRoot(t *testing.T) {
173
t.Fatal(err)
174
}
175
176
- rp, err := api.ResolvePath(ctx, path.ParsePath("/ipld/"+nd.Cid().String()+"/foo"))
176
+ rp, err := api.ResolvePath(ctx, path.New("/ipld/"+nd.Cid().String()+"/foo"))
177
if err != nil {
178
t.Fatal(err)
179
}
@@ -188,7 +188,7 @@ func (tp *provider) TestPathRoot(t *testing.T) {
188
}
189
190
func (tp *provider) TestPathJoin(t *testing.T) {
191
- p1 := path.ParsePath("/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz")
191
+ p1 := path.New("/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz")
192
193
if path.Join(p1, "foo").String() != "/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz/foo" {
194
t.Error("unexpected path")
core/coreiface/tests/unixfs.go
+2
-2
@@ -102,7 +102,7 @@ func (tp *provider) TestAdd(t *testing.T) {
102
t.Fatal(err)
103
}
104
105
- p := func(h string) path.ResolvedPath {
105
+ p := func(h string) path.Resolved {
106
c, err := cid.Parse(h)
107
if err != nil {
108
t.Fatal(err)
@@ -593,7 +593,7 @@ func (tp *provider) TestGetEmptyFile(t *testing.T) {
593
t.Fatal(err)
594
}
595
596
- emptyFilePath := path.ParsePath(emptyFile)
596
+ emptyFilePath := path.New(emptyFile)
597
598
r, err := api.Unixfs().Get(ctx, emptyFilePath)
599
if err != nil {
core/coreiface/unixfs.go
+4
-4
@@ -11,9 +11,9 @@ import (
11
12
type AddEvent struct {
13
Name string
14
- Path path.ResolvedPath `json:",omitempty"`
15
- Bytes int64 `json:",omitempty"`
16
- Size string `json:",omitempty"`
14
+ Path path.Resolved `json:",omitempty"`
15
+ Bytes int64 `json:",omitempty"`
16
+ Size string `json:",omitempty"`
17
}
18
19
// FileType is an enum of possible UnixFS file types.
@@ -65,7 +65,7 @@ type UnixfsAPI interface {
65
// Add imports the data from the reader into merkledag file
66
//
67
// TODO: a long useful comment on how to use this for many different scenarios
68
- Add(context.Context, files.Node, ...options.UnixfsAddOption) (path.ResolvedPath, error)
68
+ Add(context.Context, files.Node, ...options.UnixfsAddOption) (path.Resolved, error)
69
70
// Get returns a read-only handle to a file tree referenced by a path
71
//