提交 708e47fc 作者: Juan Batiz-Benet

ipfs blocks local command

ipfs blocks local returns _all_ local refs. For now this is one
long op. future commits will make it async.
上级 da976a5f
......@@ -31,7 +31,7 @@ func KeyListTextMarshaler(res cmds.Response) (io.Reader, error) {
var RefsCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Lists link hashes from an object",
Tagline: "Lists links (references) from an object",
ShortDescription: `
Retrieves the object named by <ipfs-path> and displays the link
hashes it contains, with the following format:
......@@ -41,7 +41,9 @@ hashes it contains, with the following format:
Note: list all refs recursively with -r.
`,
},
Subcommands: map[string]*cmds.Command{
"local": RefsLocalCmd,
},
Arguments: []cmds.Argument{
cmds.StringArg("ipfs-path", true, true, "Path to the object(s) to list refs from"),
},
......@@ -102,6 +104,47 @@ Note: list all refs recursively with -r.
if _, err := rw.WriteRefs(o); err != nil {
log.Error(err)
eptr.SetError(err)
return
}
}
}()
return eptr, nil
},
}
var RefsLocalCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Lists all local references",
ShortDescription: `
Displays the hashes of all local objects.
`,
},
Run: func(req cmds.Request) (interface{}, error) {
n, err := req.Context().GetNode()
if err != nil {
return nil, err
}
// todo: make async
allKeys, err := n.Blockstore.AllKeys(0, 0)
if err != nil {
return nil, err
}
piper, pipew := io.Pipe()
eptr := &ErrPassThroughReader{R: piper}
go func() {
defer pipew.Close()
for _, k := range allKeys {
s := k.Pretty() + "\n"
if _, err := pipew.Write([]byte(s)); err != nil {
log.Error(err)
eptr.SetError(err)
return
}
}
}()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论