add plumbing output + logging
Fixes #157 Found #158
Juan Batiz-Benet committed
Oct 13, 2014 at 02:29 UTC
b204c21d10e7184c2c375b5b07240ed7aa018dbe
2 files changed
+16
-17
core/commands/add.go
+15
-17
@@ -38,14 +38,6 @@ func Add(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Wr
38
return fmt.Errorf("addFile error: %v", err)
39
}
40
41
- // get the key to print it
42
- // k, err := nd.Key()
43
- // if err != nil {
44
- // return fmt.Errorf("addFile error: %v", err)
45
- // }
46
- //
47
- // Commenting out of here, because it's already in addNode below.
48
- // fmt.Fprintf(out, "added %s %s\n", k, path)
41
}
42
return nil
43
}
@@ -89,7 +81,9 @@ func addDir(n *core.IpfsNode, fpath string, depth int, out io.Writer) (*dag.Node
81
}
82
}
83
92
- return tree, addNode(n, tree, fpath)
84
+ log.Info("adding dir: %s", fpath)
85
+
86
+ return tree, addNode(n, tree, fpath, out)
87
}
88
89
func addFile(n *core.IpfsNode, fpath string, depth int, out io.Writer) (*dag.Node, error) {
@@ -98,27 +92,31 @@ func addFile(n *core.IpfsNode, fpath string, depth int, out io.Writer) (*dag.Nod
92
return nil, err
93
}
94
101
- k, err := root.Key()
102
- if err != nil {
103
- return nil, err
104
- }
95
+ log.Info("adding file: %s", fpath)
96
106
- fmt.Fprintf(out, "Adding file: %s = %s\n", fpath, k)
97
for _, l := range root.Links {
108
- fmt.Fprintf(out, "SubBlock: %s\n", l.Hash.B58String())
98
+ log.Info("adding subblock: %s %s", l.Name, l.Hash.B58String())
99
}
100
111
- return root, addNode(n, root, fpath)
101
+ return root, addNode(n, root, fpath, out)
102
}
103
104
// addNode adds the node to the graph + local storage
115
-func addNode(n *core.IpfsNode, nd *dag.Node, fpath string) error {
105
+func addNode(n *core.IpfsNode, nd *dag.Node, fpath string, out io.Writer) error {
106
// add the file to the graph + local storage
107
err := n.DAG.AddRecursive(nd)
108
if err != nil {
109
return err
110
}
111
112
+ k, err := nd.Key()
113
+ if err != nil {
114
+ return err
115
+ }
116
+
117
+ // output that we've added this node
118
+ fmt.Fprintf(out, "added %s %s\n", k, fpath)
119
+
120
// ensure we keep it. atm no-op
121
return n.PinDagNodeRecursively(nd, -1)
122
}
merkledag/merkledag.go
+1
@@ -124,6 +124,7 @@ func (n *Node) Size() (uint64, error) {
124
125
// Multihash hashes the encoded data of this node.
126
func (n *Node) Multihash() (mh.Multihash, error) {
127
+ // Note: Encoded generates the hash and puts it in n.cached.
128
_, err := n.Encoded(false)
129
if err != nil {
130
return nil, err