@cryptotaxi247 / kubo / commits / ae6dbb364

coreapi: implement pin api

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

Łukasz Magiera committed Jan 10, 2018 at 18:41 UTC ae6dbb3642d43bb9b1bbb798a564a120965ab21d
2 files changed +49 -3
core/coreiface/interface.go
+22 -3
@@ -67,6 +67,24 @@ type Pin interface {
67 Type() string
68 }
69
70 +// PinStatus holds information about pin health
71 +type PinStatus interface {
72 + // Ok indicates whether the pin has been verified to be correct
73 + Ok() bool
74 +
75 + // BadNodes returns any bad (usually missing) nodes from the pin
76 + BadNodes() []BadPinNode
77 +}
78 +
79 +// BadPinNode is a node that has been marked as bad by Pin.Verify
80 +type BadPinNode interface {
81 + // Path is the path of the node
82 + Path() Path
83 +
84 + // Err is the reason why the node has been marked as bad
85 + Err() error
86 +}
87 +
88 // CoreAPI defines an unified interface to IPFS for Go programs.
89 type CoreAPI interface {
90 // Unixfs returns an implementation of Unixfs API.
@@ -83,6 +101,7 @@ type CoreAPI interface {
101
102 // Key returns an implementation of Key API.
103 Key() KeyAPI
104 + Pin() PinAPI
105
106 // ObjectAPI returns an implementation of Object API
107 Object() ObjectAPI
@@ -342,7 +361,7 @@ type PinAPI interface {
361 WithRecursive(bool) options.PinAddOption
362
363 // Ls returns list of pinned objects on this node
345 - Ls(context.Context) ([]Pin, error)
364 + Ls(context.Context, ...options.PinLsOption) ([]Pin, error)
365
366 // WithType is an option for Ls which allows to specify which pin types should
367 // be returned
@@ -360,10 +379,10 @@ type PinAPI interface {
379
380 // Update changes one pin to another, skipping checks for matching paths in
381 // the old tree
363 - Update(ctx context.Context, from Path, to Path) error
382 + Update(ctx context.Context, from Path, to Path, opts ...options.PinUpdateOption) error
383
384 // Verify verifies the integrity of pinned objects
366 - Verify(context.Context) error
385 + Verify(context.Context) (<-chan PinStatus, error)
386 }
387
388 var ErrIsDir = errors.New("object is a directory")
core/coreiface/options/pin.go
+27
@@ -8,8 +8,13 @@ type PinLsSettings struct {
8 Type string
9 }
10
11 +type PinUpdateSettings struct {
12 + Unpin bool
13 +}
14 +
15 type PinAddOption func(*PinAddSettings) error
16 type PinLsOption func(settings *PinLsSettings) error
17 +type PinUpdateOption func(*PinUpdateSettings) error
18
19 func PinAddOptions(opts ...PinAddOption) (*PinAddSettings, error) {
20 options := &PinAddSettings{
@@ -41,6 +46,21 @@ func PinLsOptions(opts ...PinLsOption) (*PinLsSettings, error) {
46 return options, nil
47 }
48
49 +func PinUpdateOptions(opts ...PinUpdateOption) (*PinUpdateSettings, error) {
50 + options := &PinUpdateSettings{
51 + Unpin: true,
52 + }
53 +
54 + for _, opt := range opts {
55 + err := opt(options)
56 + if err != nil {
57 + return nil, err
58 + }
59 + }
60 +
61 + return options, nil
62 +}
63 +
64 type PinOptions struct{}
65
66 func (api *PinOptions) WithRecursive(recucsive bool) PinAddOption {
@@ -56,3 +76,10 @@ func (api *PinOptions) WithType(t string) PinLsOption {
76 return nil
77 }
78 }
79 +
80 +func (api *PinOptions) WithUnpin(unpin bool) PinUpdateOption {
81 + return func(settings *PinUpdateSettings) error {
82 + settings.Unpin = unpin
83 + return nil
84 + }
85 +}