Commit cd2ac441 authored by rht's avatar rht

Make sure ctx in commands are derived from req.Context

License: MIT
Signed-off-by: default avatarrht <rhtbot@gmail.com>
parent c3db1bde
package io
import (
"time"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
key "github.com/ipfs/go-ipfs/blocks/key"
......@@ -29,22 +27,13 @@ func NewDirectory(dserv mdag.DAGService) *directoryBuilder {
}
// AddChild adds a (name, key)-pair to the root node.
func (d *directoryBuilder) AddChild(name string, k key.Key) error {
// TODO(cryptix): consolidate context managment
ctx, cancel := context.WithTimeout(context.TODO(), time.Minute)
defer cancel()
func (d *directoryBuilder) AddChild(ctx context.Context, name string, k key.Key) error {
cnode, err := d.dserv.Get(ctx, k)
if err != nil {
return err
}
err = d.dirnode.AddNodeLinkClean(name, cnode)
if err != nil {
return err
}
return nil
return d.dirnode.AddNodeLinkClean(name, cnode)
}
// GetNode returns the root of this directoryBuilder
......
......@@ -428,7 +428,7 @@ func (dm *DagModifier) Truncate(size int64) error {
return dm.expandSparse(int64(size) - realSize)
}
nnode, err := dagTruncate(dm.curNode, uint64(size), dm.dagserv)
nnode, err := dagTruncate(dm.ctx, dm.curNode, uint64(size), dm.dagserv)
if err != nil {
return err
}
......@@ -443,7 +443,7 @@ func (dm *DagModifier) Truncate(size int64) error {
}
// dagTruncate truncates the given node to 'size' and returns the modified Node
func dagTruncate(nd *mdag.Node, size uint64, ds mdag.DAGService) (*mdag.Node, error) {
func dagTruncate(ctx context.Context, nd *mdag.Node, size uint64, ds mdag.DAGService) (*mdag.Node, error) {
if len(nd.Links) == 0 {
// TODO: this can likely be done without marshaling and remarshaling
pbn, err := ft.FromBytes(nd.Data)
......@@ -460,7 +460,7 @@ func dagTruncate(nd *mdag.Node, size uint64, ds mdag.DAGService) (*mdag.Node, er
var modified *mdag.Node
ndata := new(ft.FSNode)
for i, lnk := range nd.Links {
ctx, cancel := context.WithTimeout(context.TODO(), time.Minute)
_ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()
child, err := lnk.GetNode(ctx, ds)
......@@ -475,7 +475,7 @@ func dagTruncate(nd *mdag.Node, size uint64, ds mdag.DAGService) (*mdag.Node, er
// found the child we want to cut
if size < cur+childsize {
nchild, err := dagTruncate(child, size-cur, ds)
nchild, err := dagTruncate(_ctx, child, size-cur, ds)
if err != nil {
return nil, err
}
......
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