Skip to content

Commit

Permalink
add plumbing output + logging
Browse files Browse the repository at this point in the history
Fixes #157
Found #158
  • Loading branch information
jbenet committed Oct 13, 2014
1 parent cb15a43 commit b204c21
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
32 changes: 15 additions & 17 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ func Add(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Wr
return fmt.Errorf("addFile error: %v", err)
}

// get the key to print it
// k, err := nd.Key()
// if err != nil {
// return fmt.Errorf("addFile error: %v", err)
// }
//
// Commenting out of here, because it's already in addNode below.
// fmt.Fprintf(out, "added %s %s\n", k, path)
}
return nil
}
Expand Down Expand Up @@ -89,7 +81,9 @@ func addDir(n *core.IpfsNode, fpath string, depth int, out io.Writer) (*dag.Node
}
}

return tree, addNode(n, tree, fpath)
log.Info("adding dir: %s", fpath)

return tree, addNode(n, tree, fpath, out)
}

func addFile(n *core.IpfsNode, fpath string, depth int, out io.Writer) (*dag.Node, error) {
Expand All @@ -98,27 +92,31 @@ func addFile(n *core.IpfsNode, fpath string, depth int, out io.Writer) (*dag.Nod
return nil, err
}

k, err := root.Key()
if err != nil {
return nil, err
}
log.Info("adding file: %s", fpath)

fmt.Fprintf(out, "Adding file: %s = %s\n", fpath, k)
for _, l := range root.Links {
fmt.Fprintf(out, "SubBlock: %s\n", l.Hash.B58String())
log.Info("adding subblock: %s %s", l.Name, l.Hash.B58String())
}

return root, addNode(n, root, fpath)
return root, addNode(n, root, fpath, out)
}

// addNode adds the node to the graph + local storage
func addNode(n *core.IpfsNode, nd *dag.Node, fpath string) error {
func addNode(n *core.IpfsNode, nd *dag.Node, fpath string, out io.Writer) error {
// add the file to the graph + local storage
err := n.DAG.AddRecursive(nd)
if err != nil {
return err
}

k, err := nd.Key()
if err != nil {
return err
}

// output that we've added this node
fmt.Fprintf(out, "added %s %s\n", k, fpath)

// ensure we keep it. atm no-op
return n.PinDagNodeRecursively(nd, -1)
}
1 change: 1 addition & 0 deletions merkledag/merkledag.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (n *Node) Size() (uint64, error) {

// Multihash hashes the encoded data of this node.
func (n *Node) Multihash() (mh.Multihash, error) {
// Note: Encoded generates the hash and puts it in n.cached.
_, err := n.Encoded(false)
if err != nil {
return nil, err
Expand Down

0 comments on commit b204c21

Please sign in to comment.