@cryptotaxi247 / kubo / commits / 51a937fff

path: WIP

This commit was moved from ipfs/interface-go-ipfs-core@5a836515396273412794edaaba72ef0cf3ead46d This commit was moved from ipfs/boxo@b8463e7c123e4ff15fd8fdd33a02a6414682ca9a

Łukasz Magiera committed Mar 25, 2019 at 19:37 UTC 51a937fffd45edbc0543fe4a2338b6034e5ea2a2
16 files changed +287 -273
core/coreiface/block.go
+6 -5
@@ -2,9 +2,10 @@ package iface
2
3 import (
4 "context"
5 + path "github.com/ipfs/interface-go-ipfs-core/path"
6 "io"
7
7 - options "github.com/ipfs/interface-go-ipfs-core/options"
8 + "github.com/ipfs/interface-go-ipfs-core/options"
9 )
10
11 // BlockStat contains information about a block
@@ -13,7 +14,7 @@ type BlockStat interface {
14 Size() int
15
16 // Path returns path to the block
16 - Path() ResolvedPath
17 + Path() path.ResolvedPath
18 }
19
20 // BlockAPI specifies the interface to the block layer
@@ -22,15 +23,15 @@ type BlockAPI interface {
23 Put(context.Context, io.Reader, ...options.BlockPutOption) (BlockStat, error)
24
25 // Get attempts to resolve the path and return a reader for data in the block
25 - Get(context.Context, Path) (io.Reader, error)
26 + Get(context.Context, path.Path) (io.Reader, error)
27
28 // Rm removes the block specified by the path from local blockstore.
29 // By default an error will be returned if the block can't be found locally.
30 //
31 // NOTE: If the specified block is pinned it won't be removed and no error
32 // will be returned
32 - Rm(context.Context, Path, ...options.BlockRmOption) error
33 + Rm(context.Context, path.Path, ...options.BlockRmOption) error
34
35 // Stat returns information on
35 - Stat(context.Context, Path) (BlockStat, error)
36 + Stat(context.Context, path.Path) (BlockStat, error)
37 }
core/coreiface/coreapi.go
+3 -2
@@ -4,6 +4,7 @@ package iface
4
5 import (
6 "context"
7 + path "github.com/ipfs/interface-go-ipfs-core/path"
8
9 "github.com/ipfs/interface-go-ipfs-core/options"
10
@@ -43,11 +44,11 @@ type CoreAPI interface {
44 PubSub() PubSubAPI
45
46 // ResolvePath resolves the path using Unixfs resolver
46 - ResolvePath(context.Context, Path) (ResolvedPath, error)
47 + ResolvePath(context.Context, path.Path) (path.ResolvedPath, error)
48
49 // ResolveNode resolves the path (if not resolved already) using Unixfs
50 // resolver, gets and returns the resolved Node
50 - ResolveNode(context.Context, Path) (ipld.Node, error)
51 + ResolveNode(context.Context, path.Path) (ipld.Node, error)
52
53 // WithOptions creates new instance of CoreAPI based on this instance with
54 // a set of options applied
core/coreiface/dht.go
+4 -3
@@ -2,10 +2,11 @@ package iface
2
3 import (
4 "context"
5 + path "github.com/ipfs/interface-go-ipfs-core/path"
6
7 "github.com/ipfs/interface-go-ipfs-core/options"
8
8 - peer "github.com/libp2p/go-libp2p-peer"
9 + "github.com/libp2p/go-libp2p-peer"
10 pstore "github.com/libp2p/go-libp2p-peerstore"
11 )
12
@@ -19,8 +20,8 @@ type DhtAPI interface {
20
21 // FindProviders finds peers in the DHT who can provide a specific value
22 // given a key.
22 - FindProviders(context.Context, Path, ...options.DhtFindProvidersOption) (<-chan pstore.PeerInfo, error)
23 + FindProviders(context.Context, path.Path, ...options.DhtFindProvidersOption) (<-chan pstore.PeerInfo, error)
24
25 // Provide announces to the network that you are providing given values
25 - Provide(context.Context, Path, ...options.DhtProvideOption) error
26 + Provide(context.Context, path.Path, ...options.DhtProvideOption) error
27 }
core/coreiface/key.go
+3 -2
@@ -2,8 +2,9 @@ package iface
2
3 import (
4 "context"
5 + path "github.com/ipfs/interface-go-ipfs-core/path"
6
6 - options "github.com/ipfs/interface-go-ipfs-core/options"
7 + "github.com/ipfs/interface-go-ipfs-core/options"
8
9 "github.com/libp2p/go-libp2p-peer"
10 )
@@ -14,7 +15,7 @@ type Key interface {
15 Name() string
16
17 // Path returns key path
17 - Path() Path
18 + Path() path.Path
19
20 // ID returns key PeerID
21 ID() peer.ID
core/coreiface/name.go
+6 -5
@@ -3,8 +3,9 @@ package iface
3 import (
4 "context"
5 "errors"
6 + path "github.com/ipfs/interface-go-ipfs-core/path"
7
7 - options "github.com/ipfs/interface-go-ipfs-core/options"
8 + "github.com/ipfs/interface-go-ipfs-core/options"
9 )
10
11 var ErrResolveFailed = errors.New("could not resolve name")
@@ -14,11 +15,11 @@ type IpnsEntry interface {
15 // Name returns IpnsEntry name
16 Name() string
17 // Value returns IpnsEntry value
17 - Value() Path
18 + Value() path.Path
19 }
20
21 type IpnsResult struct {
21 - Path
22 + path.Path
23 Err error
24 }
25
@@ -32,10 +33,10 @@ type IpnsResult struct {
33 // You can use .Key API to list and generate more names and their respective keys.
34 type NameAPI interface {
35 // Publish announces new IPNS name
35 - Publish(ctx context.Context, path Path, opts ...options.NamePublishOption) (IpnsEntry, error)
36 + Publish(ctx context.Context, path path.Path, opts ...options.NamePublishOption) (IpnsEntry, error)
37
38 // Resolve attempts to resolve the newest version of the specified name
38 - Resolve(ctx context.Context, name string, opts ...options.NameResolveOption) (Path, error)
39 + Resolve(ctx context.Context, name string, opts ...options.NameResolveOption) (path.Path, error)
40
41 // Search is a version of Resolve which outputs paths as they are discovered,
42 // reducing the time to first entry
core/coreiface/object.go
+15 -14
@@ -2,11 +2,12 @@ package iface
2
3 import (
4 "context"
5 + path "github.com/ipfs/interface-go-ipfs-core/path"
6 "io"
7
7 - options "github.com/ipfs/interface-go-ipfs-core/options"
8 + "github.com/ipfs/interface-go-ipfs-core/options"
9
9 - cid "github.com/ipfs/go-cid"
10 + "github.com/ipfs/go-cid"
11 ipld "github.com/ipfs/go-ipld-format"
12 )
13
@@ -58,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.
61 - Before ResolvedPath
62 + Before path.ResolvedPath
63
64 // After holds the link path after the change. Note that when a link is
65 // removed, this will be nil.
65 - After ResolvedPath
66 + After path.ResolvedPath
67 }
68
69 // ObjectAPI specifies the interface to MerkleDAG and contains useful utilities
@@ -72,35 +73,35 @@ type ObjectAPI interface {
73 New(context.Context, ...options.ObjectNewOption) (ipld.Node, error)
74
75 // Put imports the data into merkledag
75 - Put(context.Context, io.Reader, ...options.ObjectPutOption) (ResolvedPath, error)
76 + Put(context.Context, io.Reader, ...options.ObjectPutOption) (path.ResolvedPath, error)
77
78 // Get returns the node for the path
78 - Get(context.Context, Path) (ipld.Node, error)
79 + Get(context.Context, path.Path) (ipld.Node, error)
80
81 // Data returns reader for data of the node
81 - Data(context.Context, Path) (io.Reader, error)
82 + Data(context.Context, path.Path) (io.Reader, error)
83
84 // Links returns lint or links the node contains
84 - Links(context.Context, Path) ([]*ipld.Link, error)
85 + Links(context.Context, path.Path) ([]*ipld.Link, error)
86
87 // Stat returns information about the node
87 - Stat(context.Context, Path) (*ObjectStat, error)
88 + Stat(context.Context, path.Path) (*ObjectStat, error)
89
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).
92 - AddLink(ctx context.Context, base Path, name string, child Path, opts ...options.ObjectAddLinkOption) (ResolvedPath, error)
93 + AddLink(ctx context.Context, base path.Path, name string, child path.Path, opts ...options.ObjectAddLinkOption) (path.ResolvedPath, error)
94
95 // RmLink removes a link from the node
95 - RmLink(ctx context.Context, base Path, link string) (ResolvedPath, error)
96 + RmLink(ctx context.Context, base path.Path, link string) (path.ResolvedPath, error)
97
98 // AppendData appends data to the node
98 - AppendData(context.Context, Path, io.Reader) (ResolvedPath, error)
99 + AppendData(context.Context, path.Path, io.Reader) (path.ResolvedPath, error)
100
101 // SetData sets the data contained in the node
101 - SetData(context.Context, Path, io.Reader) (ResolvedPath, error)
102 + SetData(context.Context, path.Path, io.Reader) (path.ResolvedPath, error)
103
104 // Diff returns a set of changes needed to transform the first object into the
105 // second.
105 - Diff(context.Context, Path, Path) ([]ObjectChange, error)
106 + Diff(context.Context, path.Path, path.Path) ([]ObjectChange, error)
107 }
core/coreiface/path.go
-197
@@ -1,201 +1,4 @@
1 package iface
2
3 -import (
4 - "strings"
5 -
6 - cid "github.com/ipfs/go-cid"
7 - ipfspath "github.com/ipfs/go-path"
8 -)
9 -
3 //TODO: merge with ipfspath so we don't depend on it
4
12 -// Path is a generic wrapper for paths used in the API. A path can be resolved
13 -// to a CID using one of Resolve functions in the API.
14 -//
15 -// Paths must be prefixed with a valid prefix:
16 -//
17 -// * /ipfs - Immutable unixfs path (files)
18 -// * /ipld - Immutable ipld path (data)
19 -// * /ipns - Mutable names. Usually resolves to one of the immutable paths
20 -//TODO: /local (MFS)
21 -type Path interface {
22 - // String returns the path as a string.
23 - String() string
24 -
25 - // Namespace returns the first component of the path.
26 - //
27 - // For example path "/ipfs/QmHash", calling Namespace() will return "ipfs"
28 - //
29 - // Calling this method on invalid paths (IsValid() != nil) will result in
30 - // empty string
31 - Namespace() string
32 -
33 - // Mutable returns false if the data pointed to by this path in guaranteed
34 - // to not change.
35 - //
36 - // Note that resolved mutable path can be immutable.
37 - Mutable() bool
38 -
39 - // IsValid checks if this path is a valid ipfs Path, returning nil iff it is
40 - // valid
41 - IsValid() error
42 -}
43 -
44 -// ResolvedPath is a path which was resolved to the last resolvable node.
45 -// ResolvedPaths are guaranteed to return nil from `IsValid`
46 -type ResolvedPath interface {
47 - // Cid returns the CID of the node referenced by the path. Remainder of the
48 - // path is guaranteed to be within the node.
49 - //
50 - // Examples:
51 - // If you have 3 linked objects: QmRoot -> A -> B:
52 - //
53 - // cidB := {"foo": {"bar": 42 }}
54 - // cidA := {"B": {"/": cidB }}
55 - // cidRoot := {"A": {"/": cidA }}
56 - //
57 - // And resolve paths:
58 - //
59 - // * "/ipfs/${cidRoot}"
60 - // * Calling Cid() will return `cidRoot`
61 - // * Calling Root() will return `cidRoot`
62 - // * Calling Remainder() will return ``
63 - //
64 - // * "/ipfs/${cidRoot}/A"
65 - // * Calling Cid() will return `cidA`
66 - // * Calling Root() will return `cidRoot`
67 - // * Calling Remainder() will return ``
68 - //
69 - // * "/ipfs/${cidRoot}/A/B/foo"
70 - // * Calling Cid() will return `cidB`
71 - // * Calling Root() will return `cidRoot`
72 - // * Calling Remainder() will return `foo`
73 - //
74 - // * "/ipfs/${cidRoot}/A/B/foo/bar"
75 - // * Calling Cid() will return `cidB`
76 - // * Calling Root() will return `cidRoot`
77 - // * Calling Remainder() will return `foo/bar`
78 - Cid() cid.Cid
79 -
80 - // Root returns the CID of the root object of the path
81 - //
82 - // Example:
83 - // If you have 3 linked objects: QmRoot -> A -> B, and resolve path
84 - // "/ipfs/QmRoot/A/B", the Root method will return the CID of object QmRoot
85 - //
86 - // For more examples see the documentation of Cid() method
87 - Root() cid.Cid
88 -
89 - // Remainder returns unresolved part of the path
90 - //
91 - // Example:
92 - // If you have 2 linked objects: QmRoot -> A, where A is a CBOR node
93 - // containing the following data:
94 - //
95 - // {"foo": {"bar": 42 }}
96 - //
97 - // When resolving "/ipld/QmRoot/A/foo/bar", Remainder will return "foo/bar"
98 - //
99 - // For more examples see the documentation of Cid() method
100 - Remainder() string
101 -
102 - Path
103 -}
104 -
105 -// path implements coreiface.Path
106 -type path struct {
107 - path string
108 -}
109 -
110 -// resolvedPath implements coreiface.resolvedPath
111 -type resolvedPath struct {
112 - path
113 - cid cid.Cid
114 - root cid.Cid
115 - remainder string
116 -}
117 -
118 -// Join appends provided segments to the base path
119 -func Join(base Path, a ...string) Path {
120 - s := strings.Join(append([]string{base.String()}, a...), "/")
121 - return &path{path: s}
122 -}
123 -
124 -// IpfsPath creates new /ipfs path from the provided CID
125 -func IpfsPath(c cid.Cid) ResolvedPath {
126 - return &resolvedPath{
127 - path: path{"/ipfs/" + c.String()},
128 - cid: c,
129 - root: c,
130 - remainder: "",
131 - }
132 -}
133 -
134 -// IpldPath creates new /ipld path from the provided CID
135 -func IpldPath(c cid.Cid) ResolvedPath {
136 - return &resolvedPath{
137 - path: path{"/ipld/" + c.String()},
138 - cid: c,
139 - root: c,
140 - remainder: "",
141 - }
142 -}
143 -
144 -// ParsePath parses string path to a Path
145 -func ParsePath(p string) Path {
146 - if pp, err := ipfspath.ParsePath(p); err == nil {
147 - p = pp.String()
148 - }
149 -
150 - return &path{path: p}
151 -}
152 -
153 -// NewResolvedPath creates new ResolvedPath. This function performs no checks
154 -// and is intended to be used by resolver implementations. Incorrect inputs may
155 -// cause panics. Handle with care.
156 -func NewResolvedPath(ipath ipfspath.Path, c cid.Cid, root cid.Cid, remainder string) ResolvedPath {
157 - return &resolvedPath{
158 - path: path{ipath.String()},
159 - cid: c,
160 - root: root,
161 - remainder: remainder,
162 - }
163 -}
164 -
165 -func (p *path) String() string {
166 - return p.path
167 -}
168 -
169 -func (p *path) Namespace() string {
170 - ip, err := ipfspath.ParsePath(p.path)
171 - if err != nil {
172 - return ""
173 - }
174 -
175 - if len(ip.Segments()) < 1 {
176 - panic("path without namespace") //this shouldn't happen under any scenario
177 - }
178 - return ip.Segments()[0]
179 -}
180 -
181 -func (p *path) Mutable() bool {
182 - //TODO: MFS: check for /local
183 - return p.Namespace() == "ipns"
184 -}
185 -
186 -func (p *path) IsValid() error {
187 - _, err := ipfspath.ParsePath(p.path)
188 - return err
189 -}
190 -
191 -func (p *resolvedPath) Cid() cid.Cid {
192 - return p.cid
193 -}
194 -
195 -func (p *resolvedPath) Root() cid.Cid {
196 - return p.root
197 -}
198 -
199 -func (p *resolvedPath) Remainder() string {
200 - return p.remainder
201 -}
core/coreiface/path/path.go new
+199
@@ -0,0 +1,199 @@
1 +package path
2 +
3 +import (
4 + "strings"
5 +
6 + cid "github.com/ipfs/go-cid"
7 + ipfspath "github.com/ipfs/go-path"
8 +)
9 +
10 +// Path is a generic wrapper for paths used in the API. A path can be resolved
11 +// to a CID using one of Resolve functions in the API.
12 +//
13 +// Paths must be prefixed with a valid prefix:
14 +//
15 +// * /ipfs - Immutable unixfs path (files)
16 +// * /ipld - Immutable ipld path (data)
17 +// * /ipns - Mutable names. Usually resolves to one of the immutable paths
18 +//TODO: /local (MFS)
19 +type Path interface {
20 + // String returns the path as a string.
21 + String() string
22 +
23 + // Namespace returns the first component of the path.
24 + //
25 + // For example path "/ipfs/QmHash", calling Namespace() will return "ipfs"
26 + //
27 + // Calling this method on invalid paths (IsValid() != nil) will result in
28 + // empty string
29 + Namespace() string
30 +
31 + // Mutable returns false if the data pointed to by this path in guaranteed
32 + // to not change.
33 + //
34 + // Note that resolved mutable path can be immutable.
35 + Mutable() bool
36 +
37 + // IsValid checks if this path is a valid ipfs Path, returning nil iff it is
38 + // valid
39 + IsValid() error
40 +}
41 +
42 +// ResolvedPath is a path which was resolved to the last resolvable node.
43 +// ResolvedPaths are guaranteed to return nil from `IsValid`
44 +type ResolvedPath 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 + //
48 + // Examples:
49 + // If you have 3 linked objects: QmRoot -> A -> B:
50 + //
51 + // cidB := {"foo": {"bar": 42 }}
52 + // cidA := {"B": {"/": cidB }}
53 + // cidRoot := {"A": {"/": cidA }}
54 + //
55 + // And resolve paths:
56 + //
57 + // * "/ipfs/${cidRoot}"
58 + // * Calling Cid() will return `cidRoot`
59 + // * Calling Root() will return `cidRoot`
60 + // * Calling Remainder() will return ``
61 + //
62 + // * "/ipfs/${cidRoot}/A"
63 + // * Calling Cid() will return `cidA`
64 + // * Calling Root() will return `cidRoot`
65 + // * Calling Remainder() will return ``
66 + //
67 + // * "/ipfs/${cidRoot}/A/B/foo"
68 + // * Calling Cid() will return `cidB`
69 + // * Calling Root() will return `cidRoot`
70 + // * Calling Remainder() will return `foo`
71 + //
72 + // * "/ipfs/${cidRoot}/A/B/foo/bar"
73 + // * Calling Cid() will return `cidB`
74 + // * Calling Root() will return `cidRoot`
75 + // * Calling Remainder() will return `foo/bar`
76 + Cid() cid.Cid
77 +
78 + // Root returns the CID of the root object of the path
79 + //
80 + // Example:
81 + // If you have 3 linked objects: QmRoot -> A -> B, and resolve path
82 + // "/ipfs/QmRoot/A/B", the Root method will return the CID of object QmRoot
83 + //
84 + // For more examples see the documentation of Cid() method
85 + Root() cid.Cid
86 +
87 + // Remainder returns unresolved part of the path
88 + //
89 + // Example:
90 + // If you have 2 linked objects: QmRoot -> A, where A is a CBOR node
91 + // containing the following data:
92 + //
93 + // {"foo": {"bar": 42 }}
94 + //
95 + // When resolving "/ipld/QmRoot/A/foo/bar", Remainder will return "foo/bar"
96 + //
97 + // For more examples see the documentation of Cid() method
98 + Remainder() string
99 +
100 + Path
101 +}
102 +
103 +// path implements coreiface.Path
104 +type path struct {
105 + path string
106 +}
107 +
108 +// resolvedPath implements coreiface.resolvedPath
109 +type resolvedPath struct {
110 + path
111 + cid cid.Cid
112 + root cid.Cid
113 + remainder string
114 +}
115 +
116 +// Join appends provided segments to the base path
117 +func Join(base Path, a ...string) Path {
118 + s := strings.Join(append([]string{base.String()}, a...), "/")
119 + return &path{path: s}
120 +}
121 +
122 +// IpfsPath creates new /ipfs path from the provided CID
123 +func IpfsPath(c cid.Cid) ResolvedPath {
124 + return &resolvedPath{
125 + path: path{"/ipfs/" + c.String()},
126 + cid: c,
127 + root: c,
128 + remainder: "",
129 + }
130 +}
131 +
132 +// IpldPath creates new /ipld path from the provided CID
133 +func IpldPath(c cid.Cid) ResolvedPath {
134 + return &resolvedPath{
135 + path: path{"/ipld/" + c.String()},
136 + cid: c,
137 + root: c,
138 + remainder: "",
139 + }
140 +}
141 +
142 +// ParsePath parses string path to a Path
143 +func ParsePath(p string) Path {
144 + if pp, err := ipfspath.ParsePath(p); err == nil {
145 + p = pp.String()
146 + }
147 +
148 + return &path{path: p}
149 +}
150 +
151 +// NewResolvedPath creates new ResolvedPath. 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 {
155 + return &resolvedPath{
156 + path: path{ipath.String()},
157 + cid: c,
158 + root: root,
159 + remainder: remainder,
160 + }
161 +}
162 +
163 +func (p *path) String() string {
164 + return p.path
165 +}
166 +
167 +func (p *path) Namespace() string {
168 + ip, err := ipfspath.ParsePath(p.path)
169 + if err != nil {
170 + return ""
171 + }
172 +
173 + if len(ip.Segments()) < 1 {
174 + panic("path without namespace") // this shouldn't happen under any scenario
175 + }
176 + return ip.Segments()[0]
177 +}
178 +
179 +func (p *path) Mutable() bool {
180 + // TODO: MFS: check for /local
181 + return p.Namespace() == "ipns"
182 +}
183 +
184 +func (p *path) IsValid() error {
185 + _, err := ipfspath.ParsePath(p.path)
186 + return err
187 +}
188 +
189 +func (p *resolvedPath) Cid() cid.Cid {
190 + return p.cid
191 +}
192 +
193 +func (p *resolvedPath) Root() cid.Cid {
194 + return p.root
195 +}
196 +
197 +func (p *resolvedPath) Remainder() string {
198 + return p.remainder
199 +}
core/coreiface/pin.go
+7 -6
@@ -2,14 +2,15 @@ package iface
2
3 import (
4 "context"
5 + path "github.com/ipfs/interface-go-ipfs-core/path"
6
6 - options "github.com/ipfs/interface-go-ipfs-core/options"
7 + "github.com/ipfs/interface-go-ipfs-core/options"
8 )
9
10 // Pin holds information about pinned resource
11 type Pin interface {
12 // Path to the pinned object
12 - Path() ResolvedPath
13 + Path() path.ResolvedPath
14
15 // Type of the pin
16 Type() string
@@ -27,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
30 - Path() ResolvedPath
31 + Path() path.ResolvedPath
32
33 // Err is the reason why the node has been marked as bad
34 Err() error
@@ -37,17 +38,17 @@ type BadPinNode interface {
38 type PinAPI interface {
39 // Add creates new pin, be default recursive - pinning the whole referenced
40 // tree
40 - Add(context.Context, Path, ...options.PinAddOption) error
41 + Add(context.Context, path.Path, ...options.PinAddOption) error
42
43 // Ls returns list of pinned objects on this node
44 Ls(context.Context, ...options.PinLsOption) ([]Pin, error)
45
46 // Rm removes pin for object specified by the path
46 - Rm(context.Context, Path, ...options.PinRmOption) error
47 + Rm(context.Context, path.Path, ...options.PinRmOption) error
48
49 // Update changes one pin to another, skipping checks for matching paths in
50 // the old tree
50 - Update(ctx context.Context, from Path, to Path, opts ...options.PinUpdateOption) error
51 + Update(ctx context.Context, from path.Path, to path.Path, opts ...options.PinUpdateOption) error
52
53 // Verify verifies the integrity of pinned objects
54 Verify(context.Context) (<-chan PinStatus, error)
core/coreiface/tests/block.go
+2 -1
@@ -2,6 +2,7 @@ package tests
2
3 import (
4 "context"
5 + "github.com/ipfs/interface-go-ipfs-core/path"
6 "io/ioutil"
7 "strings"
8 "testing"
@@ -110,7 +111,7 @@ func (tp *provider) TestBlockGet(t *testing.T) {
111 t.Error("didn't get correct data back")
112 }
113
113 - p := coreiface.ParsePath("/ipfs/" + res.Path().Cid().String())
114 + p := path.ParsePath("/ipfs/" + res.Path().Cid().String())
115
116 rp, err := api.ResolvePath(ctx, p)
117 if err != nil {
core/coreiface/tests/dag.go
+3 -2
@@ -2,8 +2,9 @@ package tests
2
3 import (
4 "context"
5 + path "github.com/ipfs/interface-go-ipfs-core/path"
6 "math"
6 - "path"
7 + gopath "path"
8 "strings"
9 "testing"
10
@@ -113,7 +114,7 @@ func (tp *provider) TestDagPath(t *testing.T) {
114 t.Fatal(err)
115 }
116
116 - p := coreiface.ParsePath(path.Join(nd.Cid().String(), "lnk"))
117 + p := path.ParsePath(gopath.Join(nd.Cid().String(), "lnk"))
118
119 rp, err := api.ResolvePath(ctx, p)
120 if err != nil {
core/coreiface/tests/name.go
+6 -6
@@ -2,9 +2,10 @@ package tests
2
3 import (
4 "context"
5 + path "github.com/ipfs/interface-go-ipfs-core/path"
6 "io"
7 "math/rand"
7 - "path"
8 + gopath "path"
9 "testing"
10 "time"
11
@@ -30,18 +31,18 @@ func (tp *provider) TestName(t *testing.T) {
31
32 var rnd = rand.New(rand.NewSource(0x62796532303137))
33
33 -func addTestObject(ctx context.Context, api coreiface.CoreAPI) (coreiface.Path, error) {
34 +func addTestObject(ctx context.Context, api coreiface.CoreAPI) (path.Path, error) {
35 return api.Unixfs().Add(ctx, files.NewReaderFile(&io.LimitedReader{R: rnd, N: 4092}))
36 }
37
37 -func appendPath(p coreiface.Path, sub string) coreiface.Path {
38 - return coreiface.ParsePath(path.Join(p.String(), sub))
38 +func appendPath(p path.Path, sub string) path.Path {
39 + return path.ParsePath(gopath.Join(p.String(), sub))
40 }
41
42 func (tp *provider) TestPublishResolve(t *testing.T) {
43 ctx, cancel := context.WithCancel(context.Background())
44 defer cancel()
44 - init := func() (coreiface.CoreAPI, coreiface.Path) {
45 + init := func() (coreiface.CoreAPI, path.Path) {
46 apis, err := tp.MakeAPISwarm(ctx, true, 5)
47 if err != nil {
48 t.Fatal(err)
@@ -56,7 +57,6 @@ func (tp *provider) TestPublishResolve(t *testing.T) {
57 }
58 return api, p
59 }
59 -
60 run := func(t *testing.T, ropts []opt.NameResolveOption) {
61 t.Run("basic", func(t *testing.T) {
62 api, p := init()
core/coreiface/tests/path.go
+7 -7
@@ -2,11 +2,11 @@ package tests
2
3 import (
4 "context"
5 + "github.com/ipfs/interface-go-ipfs-core/path"
6 "math"
7 "strings"
8 "testing"
9
9 - coreiface "github.com/ipfs/interface-go-ipfs-core"
10 "github.com/ipfs/interface-go-ipfs-core/options"
11
12 ipldcbor "github.com/ipfs/go-ipld-cbor"
@@ -75,7 +75,7 @@ func (tp *provider) TestPathRemainder(t *testing.T) {
75 t.Fatal(err)
76 }
77
78 - rp1, err := api.ResolvePath(ctx, coreiface.ParsePath(nd.String()+"/foo/bar"))
78 + rp1, err := api.ResolvePath(ctx, path.ParsePath(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, coreiface.ParsePath(nd.Cid().String()))
109 + rp1, err := api.ResolvePath(ctx, path.ParsePath(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, coreiface.ParsePath("/ipld/"+nd.Cid().String()+"/bar/baz"))
140 + _, err = api.ResolvePath(ctx, path.ParsePath("/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, coreiface.ParsePath("/ipld/"+nd.Cid().String()+"/foo"))
176 + rp, err := api.ResolvePath(ctx, path.ParsePath("/ipld/"+nd.Cid().String()+"/foo"))
177 if err != nil {
178 t.Fatal(err)
179 }
@@ -188,9 +188,9 @@ func (tp *provider) TestPathRoot(t *testing.T) {
188 }
189
190 func (tp *provider) TestPathJoin(t *testing.T) {
191 - p1 := coreiface.ParsePath("/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz")
191 + p1 := path.ParsePath("/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz")
192
193 - if coreiface.Join(p1, "foo").String() != "/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz/foo" {
193 + if path.Join(p1, "foo").String() != "/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz/foo" {
194 t.Error("unexpected path")
195 }
196 }
core/coreiface/tests/pin.go
+7 -6
@@ -2,6 +2,7 @@ package tests
2
3 import (
4 "context"
5 + "github.com/ipfs/interface-go-ipfs-core/path"
6 "math"
7 "strings"
8 "testing"
@@ -127,12 +128,12 @@ func (tp *provider) TestPinRecursive(t *testing.T) {
128 t.Fatal(err)
129 }
130
130 - err = api.Pin().Add(ctx, iface.IpldPath(nd2.Cid()))
131 + err = api.Pin().Add(ctx, path.IpldPath(nd2.Cid()))
132 if err != nil {
133 t.Fatal(err)
134 }
135
135 - err = api.Pin().Add(ctx, iface.IpldPath(nd3.Cid()), opt.Pin.Recursive(false))
136 + err = api.Pin().Add(ctx, path.IpldPath(nd3.Cid()), opt.Pin.Recursive(false))
137 if err != nil {
138 t.Fatal(err)
139 }
@@ -155,8 +156,8 @@ func (tp *provider) TestPinRecursive(t *testing.T) {
156 t.Errorf("unexpected pin list len: %d", len(list))
157 }
158
158 - if list[0].Path().String() != iface.IpldPath(nd3.Cid()).String() {
159 - t.Errorf("unexpected path, %s != %s", list[0].Path().String(), iface.IpfsPath(nd2.Cid()).String())
159 + if list[0].Path().String() != path.IpldPath(nd3.Cid()).String() {
160 + t.Errorf("unexpected path, %s != %s", list[0].Path().String(), path.IpfsPath(nd2.Cid()).String())
161 }
162
163 list, err = api.Pin().Ls(ctx, opt.Pin.Type.Recursive())
@@ -168,8 +169,8 @@ func (tp *provider) TestPinRecursive(t *testing.T) {
169 t.Errorf("unexpected pin list len: %d", len(list))
170 }
171
171 - if list[0].Path().String() != iface.IpldPath(nd2.Cid()).String() {
172 - t.Errorf("unexpected path, %s != %s", list[0].Path().String(), iface.IpldPath(nd3.Cid()).String())
172 + if list[0].Path().String() != path.IpldPath(nd2.Cid()).String() {
173 + t.Errorf("unexpected path, %s != %s", list[0].Path().String(), path.IpldPath(nd3.Cid()).String())
174 }
175
176 list, err = api.Pin().Ls(ctx, opt.Pin.Type.Indirect())
core/coreiface/tests/unixfs.go
+10 -9
@@ -5,6 +5,7 @@ import (
5 "context"
6 "encoding/hex"
7 "fmt"
8 + "github.com/ipfs/interface-go-ipfs-core/path"
9 "io"
10 "io/ioutil"
11 "math"
@@ -101,12 +102,12 @@ func (tp *provider) TestAdd(t *testing.T) {
102 t.Fatal(err)
103 }
104
104 - p := func(h string) coreiface.ResolvedPath {
105 + p := func(h string) path.ResolvedPath {
106 c, err := cid.Parse(h)
107 if err != nil {
108 t.Fatal(err)
109 }
109 - return coreiface.IpfsPath(c)
110 + return path.IpfsPath(c)
111 }
112
113 rf, err := ioutil.TempFile(os.TempDir(), "unixfs-add-real")
@@ -592,7 +593,7 @@ func (tp *provider) TestGetEmptyFile(t *testing.T) {
593 t.Fatal(err)
594 }
595
595 - emptyFilePath := coreiface.ParsePath(emptyFile)
596 + emptyFilePath := path.ParsePath(emptyFile)
597
598 r, err := api.Unixfs().Get(ctx, emptyFilePath)
599 if err != nil {
@@ -621,18 +622,18 @@ func (tp *provider) TestGetDir(t *testing.T) {
622 if err != nil {
623 t.Fatal(err)
624 }
624 - p := coreiface.IpfsPath(edir.Cid())
625 + p := path.IpfsPath(edir.Cid())
626
627 emptyDir, err := api.Object().New(ctx, options.Object.Type("unixfs-dir"))
628 if err != nil {
629 t.Fatal(err)
630 }
631
631 - if p.String() != coreiface.IpfsPath(emptyDir.Cid()).String() {
632 + if p.String() != path.IpfsPath(emptyDir.Cid()).String() {
633 t.Fatalf("expected path %s, got: %s", emptyDir.Cid(), p.String())
634 }
635
635 - r, err := api.Unixfs().Get(ctx, coreiface.IpfsPath(emptyDir.Cid()))
636 + r, err := api.Unixfs().Get(ctx, path.IpfsPath(emptyDir.Cid()))
637 if err != nil {
638 t.Fatal(err)
639 }
@@ -656,7 +657,7 @@ func (tp *provider) TestGetNonUnixfs(t *testing.T) {
657 t.Fatal(err)
658 }
659
659 - _, err = api.Unixfs().Get(ctx, coreiface.IpfsPath(nd.Cid()))
660 + _, err = api.Unixfs().Get(ctx, path.IpfsPath(nd.Cid()))
661 if !strings.Contains(err.Error(), "proto: required field") {
662 t.Fatalf("expected protobuf error, got: %s", err)
663 }
@@ -782,7 +783,7 @@ func (tp *provider) TestLsEmptyDir(t *testing.T) {
783 t.Fatal(err)
784 }
785
785 - links, err := api.Unixfs().Ls(ctx, coreiface.IpfsPath(emptyDir.Cid()))
786 + links, err := api.Unixfs().Ls(ctx, path.IpfsPath(emptyDir.Cid()))
787 if err != nil {
788 t.Fatal(err)
789 }
@@ -811,7 +812,7 @@ func (tp *provider) TestLsNonUnixfs(t *testing.T) {
812 t.Fatal(err)
813 }
814
814 - links, err := api.Unixfs().Ls(ctx, coreiface.IpfsPath(nd.Cid()))
815 + links, err := api.Unixfs().Ls(ctx, path.IpfsPath(nd.Cid()))
816 if err != nil {
817 t.Fatal(err)
818 }
core/coreiface/unixfs.go
+9 -8
@@ -3,16 +3,17 @@ package iface
3 import (
4 "context"
5 "github.com/ipfs/interface-go-ipfs-core/options"
6 + path "github.com/ipfs/interface-go-ipfs-core/path"
7
7 - cid "github.com/ipfs/go-cid"
8 - files "github.com/ipfs/go-ipfs-files"
8 + "github.com/ipfs/go-cid"
9 + "github.com/ipfs/go-ipfs-files"
10 )
11
12 type AddEvent struct {
13 Name string
13 - Path ResolvedPath `json:",omitempty"`
14 - Bytes int64 `json:",omitempty"`
15 - Size string `json:",omitempty"`
14 + Path path.ResolvedPath `json:",omitempty"`
15 + Bytes int64 `json:",omitempty"`
16 + Size string `json:",omitempty"`
17 }
18
19 // FileType is an enum of possible UnixFS file types.
@@ -64,15 +65,15 @@ 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
67 - Add(context.Context, files.Node, ...options.UnixfsAddOption) (ResolvedPath, error)
68 + Add(context.Context, files.Node, ...options.UnixfsAddOption) (path.ResolvedPath, error)
69
70 // Get returns a read-only handle to a file tree referenced by a path
71 //
72 // Note that some implementations of this API may apply the specified context
73 // to operations performed on the returned file
73 - Get(context.Context, Path) (files.Node, error)
74 + Get(context.Context, path.Path) (files.Node, error)
75
76 // Ls returns the list of links in a directory. Links aren't guaranteed to be
77 // returned in order
77 - Ls(context.Context, Path, ...options.UnixfsLsOption) (<-chan DirEntry, error)
78 + Ls(context.Context, path.Path, ...options.UnixfsLsOption) (<-chan DirEntry, error)
79 }