Commit 4597fde8 authored by Łukasz Magiera's avatar Łukasz Magiera

coreapi: implement pin api

License: MIT
Signed-off-by: default avatarŁukasz Magiera <magik6k@gmail.com>
parent b3293937
......@@ -67,6 +67,24 @@ type Pin interface {
Type() string
}
// PinStatus holds information about pin health
type PinStatus interface {
// Ok indicates whether the pin has been verified to be correct
Ok() bool
// BadNodes returns any bad (usually missing) nodes from the pin
BadNodes() []BadPinNode
}
// BadPinNode is a node that has been marked as bad by Pin.Verify
type BadPinNode interface {
// Path is the path of the node
Path() Path
// Err is the reason why the node has been marked as bad
Err() error
}
// CoreAPI defines an unified interface to IPFS for Go programs.
type CoreAPI interface {
// Unixfs returns an implementation of Unixfs API.
......@@ -83,6 +101,7 @@ type CoreAPI interface {
// Key returns an implementation of Key API.
Key() KeyAPI
Pin() PinAPI
// ObjectAPI returns an implementation of Object API
Object() ObjectAPI
......@@ -342,7 +361,7 @@ type PinAPI interface {
WithRecursive(bool) options.PinAddOption
// Ls returns list of pinned objects on this node
Ls(context.Context) ([]Pin, error)
Ls(context.Context, ...options.PinLsOption) ([]Pin, error)
// WithType is an option for Ls which allows to specify which pin types should
// be returned
......@@ -360,10 +379,10 @@ type PinAPI interface {
// Update changes one pin to another, skipping checks for matching paths in
// the old tree
Update(ctx context.Context, from Path, to Path) error
Update(ctx context.Context, from Path, to Path, opts ...options.PinUpdateOption) error
// Verify verifies the integrity of pinned objects
Verify(context.Context) error
Verify(context.Context) (<-chan PinStatus, error)
}
var ErrIsDir = errors.New("object is a directory")
......
......@@ -8,8 +8,13 @@ type PinLsSettings struct {
Type string
}
type PinUpdateSettings struct {
Unpin bool
}
type PinAddOption func(*PinAddSettings) error
type PinLsOption func(settings *PinLsSettings) error
type PinUpdateOption func(*PinUpdateSettings) error
func PinAddOptions(opts ...PinAddOption) (*PinAddSettings, error) {
options := &PinAddSettings{
......@@ -41,6 +46,21 @@ func PinLsOptions(opts ...PinLsOption) (*PinLsSettings, error) {
return options, nil
}
func PinUpdateOptions(opts ...PinUpdateOption) (*PinUpdateSettings, error) {
options := &PinUpdateSettings{
Unpin: true,
}
for _, opt := range opts {
err := opt(options)
if err != nil {
return nil, err
}
}
return options, nil
}
type PinOptions struct{}
func (api *PinOptions) WithRecursive(recucsive bool) PinAddOption {
......@@ -56,3 +76,10 @@ func (api *PinOptions) WithType(t string) PinLsOption {
return nil
}
}
func (api *PinOptions) WithUnpin(unpin bool) PinUpdateOption {
return func(settings *PinUpdateSettings) error {
settings.Unpin = unpin
return nil
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment