@cryptotaxi247 / kubo / commits / 9e02119ee

coreapi: pin draft

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

Łukasz Magiera committed Jan 9, 2018 at 01:10 UTC 9e02119ee9a6281648fd71aa658a0eaf4a04f341
2 files changed +102
core/coreiface/interface.go
+44
@@ -58,6 +58,15 @@ type BlockStat interface {
58 Path() Path
59 }
60
61 +// Pin holds information about pinned resource
62 +type Pin interface {
63 + // Path to the pinned object
64 + Path() Path
65 +
66 + // Type of the pin
67 + Type() string
68 +}
69 +
70 // CoreAPI defines an unified interface to IPFS for Go programs.
71 type CoreAPI interface {
72 // Unixfs returns an implementation of Unixfs API.
@@ -322,5 +331,40 @@ type ObjectStat struct {
331 CumulativeSize int
332 }
333
334 +// PinAPI specifies the interface to pining
335 +type PinAPI interface {
336 + // Add creates new pin, be default recursive - pinning the whole referenced
337 + // tree
338 + Add(context.Context, Path, ...options.PinAddOption) error
339 +
340 + // WithRecursive is an option for Add which specifies whether to pin an entire
341 + // object tree or just one object. Default: true
342 + WithRecursive(bool) options.PinAddOption
343 +
344 + // Ls returns list of pinned objects on this node
345 + Ls(context.Context) ([]Pin, error)
346 +
347 + // WithType is an option for Ls which allows to specify which pin types should
348 + // be returned
349 + //
350 + // Supported values:
351 + // * "direct" - directly pinned objects
352 + // * "recursive" - roots of recursive pins
353 + // * "indirect" - indirectly pinned objects (referenced by recursively pinned
354 + // objects)
355 + // * "all" - all pinned objects (default)
356 + WithType(string) options.PinLsOption
357 +
358 + // Rm removes pin for object specified by the path
359 + Rm(context.Context, Path) error
360 +
361 + // Update changes one pin to another, skipping checks for matching paths in
362 + // the old tree
363 + Update(ctx context.Context, from Path, to Path) error
364 +
365 + // Verify verifies the integrity of pinned objects
366 + Verify(context.Context) error
367 +}
368 +
369 var ErrIsDir = errors.New("object is a directory")
370 var ErrOffline = errors.New("can't resolve, ipfs node is offline")
core/coreiface/options/pin.go new
+58
@@ -0,0 +1,58 @@
1 +package options
2 +
3 +type PinAddSettings struct {
4 + Recursive bool
5 +}
6 +
7 +type PinLsSettings struct {
8 + Type string
9 +}
10 +
11 +type PinAddOption func(*PinAddSettings) error
12 +type PinLsOption func(settings *PinLsSettings) error
13 +
14 +func PinAddOptions(opts ...PinAddOption) (*PinAddSettings, error) {
15 + options := &PinAddSettings{
16 + Recursive: true,
17 + }
18 +
19 + for _, opt := range opts {
20 + err := opt(options)
21 + if err != nil {
22 + return nil, err
23 + }
24 + }
25 +
26 + return options, nil
27 +}
28 +
29 +func PinLsOptions(opts ...PinLsOption) (*PinLsSettings, error) {
30 + options := &PinLsSettings{
31 + Type: "all",
32 + }
33 +
34 + for _, opt := range opts {
35 + err := opt(options)
36 + if err != nil {
37 + return nil, err
38 + }
39 + }
40 +
41 + return options, nil
42 +}
43 +
44 +type PinOptions struct{}
45 +
46 +func (api *PinOptions) WithRecursive(recucsive bool) PinAddOption {
47 + return func(settings *PinAddSettings) error {
48 + settings.Recursive = recucsive
49 + return nil
50 + }
51 +}
52 +
53 +func (api *PinOptions) WithType(t string) PinLsOption {
54 + return func(settings *PinLsSettings) error {
55 + settings.Type = t
56 + return nil
57 + }
58 +}