@cryptotaxi247 / kubo / commits / 1c53ef3f9

coreapi: make the interfaces path centric

The new coreiface.Path maps a path to the cid.Cid resulting from a full path resolution. The path is internally represented as a go-ipfs/path.Path, but that doesn't matter to the outside. Apart from the path-to-CID mapping, it also aims to hold all resolved segment CIDs of the path. Right now it only exposes Root(), and only for flat paths a la /ipfs/Qmfoo. In other cases, the root is nil. In the future, resolution will internally use go-ipfs/path.Resolver.ResolvePathComponents and thus always return the proper resolved segments, via Root(), or a future Segments() func. - Add coreiface.Path with Cid() and Root(). - Add CoreAPI.ResolvePath() for getting a coreiface.Path. - All functions now expect and return coreiface.Path. - Add ParsePath() and ParseCid() for constructing a coreiface.Path. - Add coreiface.Node and Link which are simply go-ipld-node.Node and Link. - Add CoreAPI.ResolveNode() for getting a Node from a Path. License: MIT Signed-off-by: Lars Gierth <larsg@systemli.org> This commit was moved from ipfs/interface-go-ipfs-core@66af039105d5e4ebc82a178143d8643ad3fed91d This commit was moved from ipfs/boxo@61e07c830c0222fbd796118e7784e24ecf1c7e24

Lars Gierth committed Mar 17, 2017 at 03:47 UTC 1c53ef3f984b664538ada9d9adf27cdc4ea3c2b6
1 file changed +15 -4
core/coreiface/interface.go
+15 -4
@@ -9,6 +9,16 @@ import (
9 ipld "gx/ipfs/QmYDscK7dmdo2GZ9aumS8s5auUUAH5mR1jvj5pYhWusfK7/go-ipld-node"
10 )
11
12 +type Path interface {
13 + String() string
14 + Cid() *cid.Cid
15 + Root() *cid.Cid
16 + Resolved() bool
17 +}
18 +
19 +// TODO: should we really copy these?
20 +// if we didn't, godoc would generate nice links straight to go-ipld-node
21 +type Node ipld.Node
22 type Link ipld.Link
23
24 type Reader interface {
@@ -18,12 +28,14 @@ type Reader interface {
28
29 type CoreAPI interface {
30 Unixfs() UnixfsAPI
31 + ResolvePath(context.Context, Path) (Path, error)
32 + ResolveNode(context.Context, Path) (Node, error)
33 }
34
35 type UnixfsAPI interface {
24 - Add(context.Context, io.Reader) (*cid.Cid, error)
25 - Cat(context.Context, string) (Reader, error)
26 - Ls(context.Context, string) ([]*Link, error)
36 + Add(context.Context, io.Reader) (Path, error)
37 + Cat(context.Context, Path) (Reader, error)
38 + Ls(context.Context, Path) ([]*Link, error)
39 }
40
41 // type ObjectAPI interface {
@@ -49,5 +61,4 @@ type UnixfsAPI interface {
61 // }
62
63 var ErrIsDir = errors.New("object is a directory")
52 -var ErrIsNonDag = errors.New("not a merkledag object")
64 var ErrOffline = errors.New("can't resolve, ipfs node is offline")