pin.go 532 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10
package commands

import (
	"fmt"
	"io"

	"github.com/jbenet/go-ipfs/core"
)

func Pin(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
11 12 13 14 15 16 17

	// if recursive, set flag
	depth := 1
	if r, ok := opts["r"].(bool); r && ok {
		depth = -1
	}

18 19 20 21 22 23
	for _, fn := range args {
		dagnode, err := n.Resolver.ResolvePath(fn)
		if err != nil {
			return fmt.Errorf("pin error: %v", err)
		}

24
		err = n.PinDagNodeRecursively(dagnode, depth)
25 26 27 28 29 30
		if err != nil {
			return fmt.Errorf("pin: %v", err)
		}
	}
	return nil
}