diff --git a/core/commands/refs.go b/core/commands/refs.go index 6aed4524284a12a86e76e57c6a44ab6eba66a868..4390e108c1bef333ca2058eb31c9e2ab97662600 100644 --- a/core/commands/refs.go +++ b/core/commands/refs.go @@ -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 } } }()