pin.go 1.75 KB
Newer Older
1 2 3 4
package iface

import (
	"context"
Łukasz Magiera's avatar
Łukasz Magiera committed
5
	path "github.com/ipfs/interface-go-ipfs-core/path"
6

Łukasz Magiera's avatar
Łukasz Magiera committed
7
	"github.com/ipfs/interface-go-ipfs-core/options"
8 9 10 11 12
)

// Pin holds information about pinned resource
type Pin interface {
	// Path to the pinned object
13
	Path() path.Resolved
14 15 16

	// Type of the pin
	Type() string
17 18 19

	// if not nil, an error happened. Everything else should be ignored.
	Err() error
20 21 22 23 24 25 26 27 28 29 30 31 32 33
}

// 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
34
	Path() path.Resolved
35 36 37 38 39 40 41 42 43

	// Err is the reason why the node has been marked as bad
	Err() error
}

// PinAPI specifies the interface to pining
type PinAPI interface {
	// Add creates new pin, be default recursive - pinning the whole referenced
	// tree
Łukasz Magiera's avatar
Łukasz Magiera committed
44
	Add(context.Context, path.Path, ...options.PinAddOption) error
45 46

	// Ls returns list of pinned objects on this node
47
	Ls(context.Context, ...options.PinLsOption) (<-chan Pin, error)
48

Michael Muré's avatar
Michael Muré committed
49 50 51 52
	// IsPinned returns whether or not the given cid is pinned
	// and an explanation of why its pinned
	IsPinned(context.Context, path.Path, ...options.PinIsPinnedOption) (string, bool, error)

53
	// Rm removes pin for object specified by the path
Łukasz Magiera's avatar
Łukasz Magiera committed
54
	Rm(context.Context, path.Path, ...options.PinRmOption) error
55 56 57

	// Update changes one pin to another, skipping checks for matching paths in
	// the old tree
Łukasz Magiera's avatar
Łukasz Magiera committed
58
	Update(ctx context.Context, from path.Path, to path.Path, opts ...options.PinUpdateOption) error
59 60 61 62

	// Verify verifies the integrity of pinned objects
	Verify(context.Context) (<-chan PinStatus, error)
}