@cryptotaxi247 / kubo / commits / 161503c26

coreapi: separate path into two types

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@79875b01300b77c8437ec0ca1b22d497edb79cd9 This commit was moved from ipfs/boxo@5a61226d830993d09c7d76d970b1c5a9de94f834

Łukasz Magiera committed Feb 8, 2018 at 17:39 UTC 161503c26f9fdc99045fc10d731bb8036769e390
8 files changed +28 -53
core/coreiface/block.go
+2 -2
@@ -13,13 +13,13 @@ type BlockStat interface {
13 Size() int
14
15 // Path returns path to the block
16 - Path() Path
16 + Path() ResolvedPath
17 }
18
19 // BlockAPI specifies the interface to the block layer
20 type BlockAPI interface {
21 // Put imports raw block data, hashing it using specified settings.
22 - Put(context.Context, io.Reader, ...options.BlockPutOption) (Path, error)
22 + Put(context.Context, io.Reader, ...options.BlockPutOption) (ResolvedPath, error)
23
24 // Get attempts to resolve the path and return a reader for data in the block
25 Get(context.Context, Path) (io.Reader, error)
core/coreiface/coreapi.go
+4 -10
@@ -5,10 +5,8 @@ package iface
5 import (
6 "context"
7
8 - options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
9 -
10 - cid "gx/ipfs/QmapdYm1b22Frv3k17fqrBYTFRxwiaVJkB299Mfn33edeB/go-cid"
8 ipld "gx/ipfs/QmZtNq8dArGfnpCZfx2pUNY7UcjGhVp5qqwQ4hH6mpTMRQ/go-ipld-format"
9 + cid "gx/ipfs/QmapdYm1b22Frv3k17fqrBYTFRxwiaVJkB299Mfn33edeB/go-cid"
10 )
11
12 // CoreAPI defines an unified interface to IPFS for Go programs
@@ -35,19 +33,15 @@ type CoreAPI interface {
33 Object() ObjectAPI
34
35 // ResolvePath resolves the path using Unixfs resolver
38 - ResolvePath(context.Context, Path) (Path, error)
36 + ResolvePath(context.Context, Path) (ResolvedPath, error)
37
38 // ResolveNode resolves the path (if not resolved already) using Unixfs
39 // resolver, gets and returns the resolved Node
40 ResolveNode(context.Context, Path) (ipld.Node, error)
41
42 // ParsePath parses string path to a Path
45 - ParsePath(context.Context, string, ...options.ParsePathOption) (Path, error)
46 -
47 - // WithResolve is an option for ParsePath which when set to true tells
48 - // ParsePath to also resolve the path
49 - WithResolve(bool) options.ParsePathOption
43 + ParsePath(context.Context, string) (Path, error)
44
45 // ParseCid creates new path from the provided CID
52 - ParseCid(*cid.Cid) Path
46 + ParseCid(*cid.Cid) ResolvedPath
47 }
core/coreiface/dag.go
+1 -1
@@ -14,7 +14,7 @@ type DagAPI interface {
14 // Put inserts data using specified format and input encoding.
15 // Unless used with WithCodec or WithHash, the defaults "dag-cbor" and
16 // "sha256" are used.
17 - Put(ctx context.Context, src io.Reader, opts ...options.DagPutOption) (Path, error)
17 + Put(ctx context.Context, src io.Reader, opts ...options.DagPutOption) (ResolvedPath, error)
18
19 // Get attempts to resolve and get the node specified by the path
20 Get(ctx context.Context, path Path) (ipld.Node, error)
core/coreiface/object.go
+5 -5
@@ -38,7 +38,7 @@ type ObjectAPI interface {
38 New(context.Context, ...options.ObjectNewOption) (ipld.Node, error)
39
40 // Put imports the data into merkledag
41 - Put(context.Context, io.Reader, ...options.ObjectPutOption) (Path, error)
41 + Put(context.Context, io.Reader, ...options.ObjectPutOption) (ResolvedPath, error)
42
43 // Get returns the node for the path
44 Get(context.Context, Path) (ipld.Node, error)
@@ -55,14 +55,14 @@ type ObjectAPI interface {
55 // AddLink adds a link under the specified path. child path can point to a
56 // subdirectory within the patent which must be present (can be overridden
57 // with WithCreate option).
58 - AddLink(ctx context.Context, base Path, name string, child Path, opts ...options.ObjectAddLinkOption) (Path, error)
58 + AddLink(ctx context.Context, base Path, name string, child Path, opts ...options.ObjectAddLinkOption) (ResolvedPath, error)
59
60 // RmLink removes a link from the node
61 - RmLink(ctx context.Context, base Path, link string) (Path, error)
61 + RmLink(ctx context.Context, base Path, link string) (ResolvedPath, error)
62
63 // AppendData appends data to the node
64 - AppendData(context.Context, Path, io.Reader) (Path, error)
64 + AppendData(context.Context, Path, io.Reader) (ResolvedPath, error)
65
66 // SetData sets the data contained in the node
67 - SetData(context.Context, Path, io.Reader) (Path, error)
67 + SetData(context.Context, Path, io.Reader) (ResolvedPath, error)
68 }
core/coreiface/options/path.go deleted
-30
@@ -1,30 +0,0 @@
1 -package options
2 -
3 -type ParsePathSettings struct {
4 - Resolve bool
5 -}
6 -
7 -type ParsePathOption func(*ParsePathSettings) error
8 -
9 -func ParsePathOptions(opts ...ParsePathOption) (*ParsePathSettings, error) {
10 - options := &ParsePathSettings{
11 - Resolve: false,
12 - }
13 -
14 - for _, opt := range opts {
15 - err := opt(options)
16 - if err != nil {
17 - return nil, err
18 - }
19 - }
20 - return options, nil
21 -}
22 -
23 -type ApiOptions struct{}
24 -
25 -func (api *ApiOptions) WithResolve(r bool) ParsePathOption {
26 - return func(settings *ParsePathSettings) error {
27 - settings.Resolve = r
28 - return nil
29 - }
30 -}
core/coreiface/path.go
+13 -2
@@ -6,13 +6,24 @@ import (
6
7 // Path is a generic wrapper for paths used in the API. A path can be resolved
8 // to a CID using one of Resolve functions in the API.
9 +// TODO: figure out/explain namespaces
10 type Path interface {
11 // String returns the path as a string.
12 String() string
13 +
14 + // Namespace returns the first component of the path
15 + Namespace() string
16 +}
17 +
18 +// ResolvedPath is a resolved Path
19 +type ResolvedPath interface {
20 // Cid returns cid referred to by path
21 Cid() *cid.Cid
22 +
23 // Root returns cid of root path
24 Root() *cid.Cid
16 - // Resolved returns whether path has been fully resolved
17 - Resolved() bool
25 +
26 + //TODO: Path remainder
27 +
28 + Path
29 }
core/coreiface/pin.go
+2 -2
@@ -9,7 +9,7 @@ import (
9 // Pin holds information about pinned resource
10 type Pin interface {
11 // Path to the pinned object
12 - Path() Path
12 + Path() ResolvedPath
13
14 // Type of the pin
15 Type() string
@@ -27,7 +27,7 @@ type PinStatus interface {
27 // BadPinNode is a node that has been marked as bad by Pin.Verify
28 type BadPinNode interface {
29 // Path is the path of the node
30 - Path() Path
30 + Path() ResolvedPath
31
32 // Err is the reason why the node has been marked as bad
33 Err() error
core/coreiface/unixfs.go
+1 -1
@@ -10,7 +10,7 @@ import (
10 // UnixfsAPI is the basic interface to immutable files in IPFS
11 type UnixfsAPI interface {
12 // Add imports the data from the reader into merkledag file
13 - Add(context.Context, io.Reader) (Path, error)
13 + Add(context.Context, io.Reader) (ResolvedPath, error)
14
15 // Cat returns a reader for the file
16 Cat(context.Context, Path) (Reader, error)