ipfs blocks local command

ipfs blocks local returns _all_ local refs. For now this is one
long op. future commits will make it async.
This commit is contained in:
Juan Batiz-Benet 2015-01-09 23:27:50 -08:00
parent da976a5f21
commit 708e47fcbc

View File

@ -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
}
}
}()