mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-23 19:37:46 +08:00
Merge pull request #4725 from MichaelMure/filesstatlocal
make files stat --with-local return immediately when no data is present
This commit is contained in:
commit
bea666f3cd
@ -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,
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user