mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 03:42:21 +08:00
Replace WithTimeout with WithCancel whenever possible
License: MIT Signed-off-by: rht <rhtbot@gmail.com>
This commit is contained in:
@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
||||
|
||||
@ -81,7 +80,7 @@ it contains, with the following format:
|
||||
Links: make([]LsLink, len(dagnode.Links)),
|
||||
}
|
||||
for j, link := range dagnode.Links {
|
||||
ctx, cancel := context.WithTimeout(req.Context(), time.Minute)
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
link.Node, err = link.GetNode(ctx, node.DAG)
|
||||
if err != nil {
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"io"
|
||||
"sort"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
||||
|
||||
@ -111,7 +110,7 @@ size is the IPFS link size.
|
||||
links := make([]LsLink, len(merkleNode.Links))
|
||||
output.Objects[hash].Links = links
|
||||
for i, link := range merkleNode.Links {
|
||||
getCtx, cancel := context.WithTimeout(ctx, time.Minute)
|
||||
getCtx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
link.Node, err = link.GetNode(getCtx, node.DAG)
|
||||
if err != nil {
|
||||
|
@ -321,8 +321,7 @@ func setupDiscoveryOption(d config.Discovery) DiscoveryOption {
|
||||
func (n *IpfsNode) HandlePeerFound(p peer.PeerInfo) {
|
||||
log.Warning("trying peer info: ", p)
|
||||
ctx, _ := context.WithTimeout(n.Context(), time.Second*10)
|
||||
err := n.PeerHost.Connect(ctx, p)
|
||||
if err != nil {
|
||||
if err := n.PeerHost.Connect(ctx, p); err != nil {
|
||||
log.Warning("Failed to connect to peer found by discovery: ", err)
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ package corerepo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
||||
|
||||
@ -42,7 +41,7 @@ func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Minute)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
err = n.Pinning.Pin(ctx, dagnode, recursive)
|
||||
if err != nil {
|
||||
@ -74,7 +73,7 @@ func Unpin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool
|
||||
for _, dagnode := range dagnodes {
|
||||
k, _ := dagnode.Key()
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Minute)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
err := n.Pinning.Unpin(ctx, k, recursive)
|
||||
if err != nil {
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
gopath "path"
|
||||
"time"
|
||||
|
||||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
||||
|
||||
@ -105,7 +104,7 @@ func addNode(n *core.IpfsNode, node *merkledag.Node) error {
|
||||
if err := n.DAG.AddRecursive(node); err != nil { // add the file to the graph + local storage
|
||||
return err
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(n.Context(), time.Minute)
|
||||
ctx, cancel := context.WithCancel(n.Context())
|
||||
defer cancel()
|
||||
err := n.Pinning.Pin(ctx, node, true) // ensure we keep it
|
||||
return err
|
||||
|
@ -1,8 +1,6 @@
|
||||
package coreunix
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
||||
|
||||
key "github.com/ipfs/go-ipfs/blocks/key"
|
||||
@ -14,7 +12,7 @@ import (
|
||||
func AddMetadataTo(n *core.IpfsNode, skey string, m *ft.Metadata) (string, error) {
|
||||
ukey := key.B58KeyDecode(skey)
|
||||
|
||||
ctx, cancel := context.WithTimeout(n.Context(), time.Minute)
|
||||
ctx, cancel := context.WithCancel(n.Context())
|
||||
defer cancel()
|
||||
nd, err := n.DAG.Get(ctx, ukey)
|
||||
if err != nil {
|
||||
@ -44,7 +42,7 @@ func AddMetadataTo(n *core.IpfsNode, skey string, m *ft.Metadata) (string, error
|
||||
func Metadata(n *core.IpfsNode, skey string) (*ft.Metadata, error) {
|
||||
ukey := key.B58KeyDecode(skey)
|
||||
|
||||
ctx, cancel := context.WithTimeout(n.Context(), time.Minute)
|
||||
ctx, cancel := context.WithCancel(n.Context())
|
||||
defer cancel()
|
||||
nd, err := n.DAG.Get(ctx, ukey)
|
||||
if err != nil {
|
||||
|
@ -1,8 +1,6 @@
|
||||
package ipns
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
||||
|
||||
"github.com/ipfs/go-ipfs/core"
|
||||
@ -22,7 +20,7 @@ func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(n.Context(), time.Minute)
|
||||
ctx, cancel := context.WithCancel(n.Context())
|
||||
defer cancel()
|
||||
|
||||
err = n.Pinning.Pin(ctx, emptyDir, false)
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
||||
|
||||
@ -140,7 +139,7 @@ func (d *Directory) childDir(name string) (*Directory, error) {
|
||||
func (d *Directory) childFromDag(name string) (*dag.Node, error) {
|
||||
for _, lnk := range d.node.Links {
|
||||
if lnk.Name == name {
|
||||
ctx, cancel := context.WithTimeout(d.ctx, time.Minute)
|
||||
ctx, cancel := context.WithCancel(d.ctx)
|
||||
defer cancel()
|
||||
|
||||
return lnk.GetNode(ctx, d.fs.dserv)
|
||||
|
@ -87,7 +87,7 @@ func (s *Resolver) ResolvePathComponents(ctx context.Context, fpath Path) ([]*me
|
||||
}
|
||||
|
||||
log.Debug("Resolve dag get.")
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Minute)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
nd, err := s.DAG.Get(ctx, key.Key(h))
|
||||
if err != nil {
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
|
||||
mh "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
|
||||
@ -460,7 +459,7 @@ func dagTruncate(ctx context.Context, nd *mdag.Node, size uint64, ds mdag.DAGSer
|
||||
var modified *mdag.Node
|
||||
ndata := new(ft.FSNode)
|
||||
for i, lnk := range nd.Links {
|
||||
_ctx, cancel := context.WithTimeout(ctx, time.Minute)
|
||||
_ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
child, err := lnk.GetNode(ctx, ds)
|
||||
|
Reference in New Issue
Block a user