Commit 728f17d3 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

cmd/ipfs/pin.go now uses MakeCommand

+ added recursive pinning func
parent 26a481a9
package main package main
import ( import (
"os"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag" "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander" "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
"github.com/jbenet/go-ipfs/core/commands" "github.com/jbenet/go-ipfs/core/commands"
"github.com/jbenet/go-ipfs/daemon"
u "github.com/jbenet/go-ipfs/util"
) )
var cmdIpfsPin = &commander.Command{ var cmdIpfsPin = &commander.Command{
...@@ -22,28 +18,8 @@ var cmdIpfsPin = &commander.Command{ ...@@ -22,28 +18,8 @@ var cmdIpfsPin = &commander.Command{
Flag: *flag.NewFlagSet("ipfs-pin", flag.ExitOnError), Flag: *flag.NewFlagSet("ipfs-pin", flag.ExitOnError),
} }
func pinCmd(c *commander.Command, inp []string) error { func init() {
if len(inp) < 1 { cmdIpfsPin.Flag.Bool("r", false, "pin objects recursively")
u.POut(c.Long)
return nil
}
cmd := daemon.NewCommand()
cmd.Command = "pin"
cmd.Args = inp
err := daemon.SendCommand(cmd, "localhost:12345")
if err != nil {
conf, err := getConfigDir(c.Parent)
if err != nil {
return err
}
n, err := localNode(conf, false)
if err != nil {
return err
}
return commands.Pin(n, cmd.Args, cmd.Opts, os.Stdout)
}
return nil
} }
var pinCmd = MakeCommand("pin", []string{"r"}, commands.Pin)
...@@ -133,5 +133,5 @@ func addNode(n *core.IpfsNode, nd *dag.Node, fpath string) error { ...@@ -133,5 +133,5 @@ func addNode(n *core.IpfsNode, nd *dag.Node, fpath string) error {
u.POut("added %s %s\n", k.Pretty(), fpath) u.POut("added %s %s\n", k.Pretty(), fpath)
// ensure we keep it. atm no-op // ensure we keep it. atm no-op
return n.PinDagNode(nd) return n.PinDagNodeRecursively(nd, -1)
} }
...@@ -8,13 +8,20 @@ import ( ...@@ -8,13 +8,20 @@ import (
) )
func Pin(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error { func Pin(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
// if recursive, set flag
depth := 1
if r, ok := opts["r"].(bool); r && ok {
depth = -1
}
for _, fn := range args { for _, fn := range args {
dagnode, err := n.Resolver.ResolvePath(fn) dagnode, err := n.Resolver.ResolvePath(fn)
if err != nil { if err != nil {
return fmt.Errorf("pin error: %v", err) return fmt.Errorf("pin error: %v", err)
} }
err = n.PinDagNode(dagnode) err = n.PinDagNodeRecursively(dagnode, depth)
if err != nil { if err != nil {
return fmt.Errorf("pin: %v", err) return fmt.Errorf("pin: %v", err)
} }
......
...@@ -240,8 +240,13 @@ func initConnections(ctx context.Context, cfg *config.Config, pstore peer.Peerst ...@@ -240,8 +240,13 @@ func initConnections(ctx context.Context, cfg *config.Config, pstore peer.Peerst
} }
} }
// PinDagNode ensures a given node is stored persistently locally. // PinDagNode ensures a given node is stored persistently locally
func (n *IpfsNode) PinDagNode(nd *merkledag.Node) error { func (n *IpfsNode) PinDagNode(nd *merkledag.Node) error {
u.DOut("Pinning node. Currently No-Op\n") return n.PinDagNodeRecursively(nd, 1)
}
// PinDagNodeRecursively ensures a given node is stored persistently locally
func (n *IpfsNode) PinDagNodeRecursively(nd *merkledag.Node, depth int) error {
u.DOut("Pinning node recursively. Currently No-Op\n")
return nil 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