core/commands: Made 'refs' output u.Keys instead of strings
Matt Bell committed
Nov 18, 2014 at 23:20 UTC
db53de806cfbde19e7a8895990f5ebea34e495df
1 file changed
+12
-9
core/commands/refs.go
+12
-9
@@ -2,7 +2,6 @@ package commands
2
3
import (
4
"fmt"
5
- "strings"
5
6
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
7
cmds "github.com/jbenet/go-ipfs/commands"
@@ -13,13 +12,16 @@ import (
12
13
// KeyList is a general type for outputting lists of keys
14
type KeyList struct {
16
- Keys []string
15
+ Keys []u.Key
16
}
17
18
// KeyListTextMarshaler outputs a KeyList as plaintext, one key per line
19
func KeyListTextMarshaler(res cmds.Response) ([]byte, error) {
20
output := res.Output().(*KeyList)
22
- s := strings.Join(output.Keys, "\n")
21
+ s := ""
22
+ for _, key := range output.Keys {
23
+ s += key.B58String() + "\n"
24
+ }
25
return []byte(s), nil
26
}
27
@@ -79,7 +81,7 @@ func getRefs(n *core.IpfsNode, paths []string, unique, recursive bool) (*KeyList
81
refsSeen = make(map[u.Key]bool)
82
}
83
82
- refs := make([]string, 0)
84
+ refs := make([]u.Key, 0)
85
86
for _, path := range paths {
87
object, err := n.Resolver.ResolvePath(path)
@@ -96,7 +98,7 @@ func getRefs(n *core.IpfsNode, paths []string, unique, recursive bool) (*KeyList
98
return &KeyList{refs}, nil
99
}
100
99
-func addRefs(n *core.IpfsNode, object *dag.Node, refs []string, refsSeen map[u.Key]bool, recursive bool) ([]string, error) {
101
+func addRefs(n *core.IpfsNode, object *dag.Node, refs []u.Key, refsSeen map[u.Key]bool, recursive bool) ([]u.Key, error) {
102
for _, link := range object.Links {
103
var found bool
104
found, refs = addRef(link.Hash, refs, refsSeen)
@@ -117,15 +119,16 @@ func addRefs(n *core.IpfsNode, object *dag.Node, refs []string, refsSeen map[u.K
119
return refs, nil
120
}
121
120
-func addRef(h mh.Multihash, refs []string, refsSeen map[u.Key]bool) (bool, []string) {
122
+func addRef(h mh.Multihash, refs []u.Key, refsSeen map[u.Key]bool) (bool, []u.Key) {
123
+ key := u.Key(h)
124
if refsSeen != nil {
122
- _, found := refsSeen[u.Key(h)]
125
+ _, found := refsSeen[key]
126
if found {
127
return true, refs
128
}
126
- refsSeen[u.Key(h)] = true
129
+ refsSeen[key] = true
130
}
131
129
- refs = append(refs, h.B58String())
132
+ refs = append(refs, key)
133
return false, refs
134
}