core/commands: Added a 'pin ls' command
Matt Bell committed
Nov 18, 2014 at 23:02 UTC
afc7b6f48d7ddfd974b44d53e7bf988565d2c914
1 file changed
+22
core/commands/pin.go
+22
@@ -6,6 +6,7 @@ import (
6
cmds "github.com/jbenet/go-ipfs/commands"
7
"github.com/jbenet/go-ipfs/core"
8
"github.com/jbenet/go-ipfs/merkledag"
9
+ u "github.com/jbenet/go-ipfs/util"
10
)
11
12
var pinCmd = &cmds.Command{
@@ -16,6 +17,7 @@ var pinCmd = &cmds.Command{
17
Subcommands: map[string]*cmds.Command{
18
"add": addPinCmd,
19
"rm": rmPinCmd,
20
+ "ls": listPinCmd,
21
},
22
}
23
@@ -99,6 +101,26 @@ collected if needed.
101
},
102
}
103
104
+var listPinCmd = &cmds.Command{
105
+ Helptext: cmds.HelpText{
106
+ Tagline: "List objects pinned to local storage",
107
+ ShortDescription: `
108
+Returns a list of hashes of objects being pinned. Objects that are indirectly
109
+or recursively pinned are not included in the list.
110
+`,
111
+ },
112
+
113
+ Run: func(req cmds.Request) (interface{}, error) {
114
+ n, err := req.Context().GetNode()
115
+ if err != nil {
116
+ return nil, err
117
+ }
118
+
119
+ return n.Pinning.Set().GetKeys(), nil
120
+ },
121
+ Type: []u.Key{},
122
+}
123
+
124
func pin(n *core.IpfsNode, paths []string, recursive bool) ([]*merkledag.Node, error) {
125
126
dagnodes := make([]*merkledag.Node, 0)