Merge pull request #4725 from MichaelMure/filesstatlocal

make files stat --with-local return immediately when no data is present
This commit is contained in:
Whyrusleeping 2018-03-05 09:39:34 -08:00 committed by GitHub
commit bea666f3cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -125,7 +125,20 @@ var filesStatCmd = &cmds.Command{
return
}
nd, err := getNodeFromPath(req.Context, node, path)
withLocal, _ := req.Options["with-local"].(bool)
var dagserv ipld.DAGService
if withLocal {
// an offline DAGService will not fetch from the network
dagserv = dag.NewDAGService(bservice.New(
node.Blockstore,
offline.Exchange(node.Blockstore),
))
} else {
dagserv = node.DAG
}
nd, err := getNodeFromPath(req.Context, node, dagserv, path)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
@ -137,18 +150,11 @@ var filesStatCmd = &cmds.Command{
return
}
withLocal, _ := req.Options["with-local"].(bool)
if !withLocal {
res.Emit(o)
return
}
// an offline DAGService will not fetch from the network
dagserv := dag.NewDAGService(bservice.New(
node.Blockstore,
offline.Exchange(node.Blockstore),
))
local, sizeLocal, err := walkBlock(req.Context, dagserv, nd)
o.WithLocality = true
@ -321,7 +327,7 @@ var filesCpCmd = &oldcmds.Command{
dst += gopath.Base(src)
}
nd, err := getNodeFromPath(req.Context(), node, src)
nd, err := getNodeFromPath(req.Context(), node, node.DAG, src)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
@ -345,7 +351,7 @@ var filesCpCmd = &oldcmds.Command{
},
}
func getNodeFromPath(ctx context.Context, node *core.IpfsNode, p string) (ipld.Node, error) {
func getNodeFromPath(ctx context.Context, node *core.IpfsNode, dagservice ipld.DAGService, p string) (ipld.Node, error) {
switch {
case strings.HasPrefix(p, "/ipfs/"):
np, err := path.ParsePath(p)
@ -354,7 +360,7 @@ func getNodeFromPath(ctx context.Context, node *core.IpfsNode, p string) (ipld.N
}
resolver := &resolver.Resolver{
DAG: node.DAG,
DAG: dagservice,
ResolveOnce: uio.ResolveUnixfsOnce,
}