mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-19 18:05:32 +08:00
core: add context.Context param to core.Resolve()
commands/object: remove objectData() and objectLinks() helpers resolver: added context parameters sharness: $HASH carried the \r from the http protocol with sharness: write curl output to individual files http gw: break PUT handler until PR#1191
This commit is contained in:
@ -91,12 +91,12 @@ output is the raw data of the object.
|
||||
}
|
||||
|
||||
fpath := path.Path(req.Arguments()[0])
|
||||
output, err := objectData(n, fpath)
|
||||
node, err := core.Resolve(req.Context().Context, n, fpath)
|
||||
if err != nil {
|
||||
res.SetError(err, cmds.ErrNormal)
|
||||
return
|
||||
}
|
||||
res.SetOutput(output)
|
||||
res.SetOutput(bytes.NewReader(node.Data))
|
||||
},
|
||||
}
|
||||
|
||||
@ -121,7 +121,12 @@ multihash.
|
||||
}
|
||||
|
||||
fpath := path.Path(req.Arguments()[0])
|
||||
output, err := objectLinks(n, fpath)
|
||||
node, err := core.Resolve(req.Context().Context, n, fpath)
|
||||
if err != nil {
|
||||
res.SetError(err, cmds.ErrNormal)
|
||||
return
|
||||
}
|
||||
output, err := getOutput(node)
|
||||
if err != nil {
|
||||
res.SetError(err, cmds.ErrNormal)
|
||||
return
|
||||
@ -176,7 +181,7 @@ This command outputs data in the following encodings:
|
||||
|
||||
fpath := path.Path(req.Arguments()[0])
|
||||
|
||||
object, err := objectGet(n, fpath)
|
||||
object, err := core.Resolve(req.Context().Context, n, fpath)
|
||||
if err != nil {
|
||||
res.SetError(err, cmds.ErrNormal)
|
||||
return
|
||||
@ -242,7 +247,7 @@ var objectStatCmd = &cmds.Command{
|
||||
|
||||
fpath := path.Path(req.Arguments()[0])
|
||||
|
||||
object, err := objectGet(n, fpath)
|
||||
object, err := core.Resolve(req.Context().Context, n, fpath)
|
||||
if err != nil {
|
||||
res.SetError(err, cmds.ErrNormal)
|
||||
return
|
||||
@ -343,42 +348,6 @@ Data should be in the format specified by the --inputenc flag.
|
||||
Type: Object{},
|
||||
}
|
||||
|
||||
// objectData takes a key string and writes out the raw bytes of that node (if there is one)
|
||||
func objectData(n *core.IpfsNode, fpath path.Path) (io.Reader, error) {
|
||||
dagnode, err := core.Resolve(n, fpath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Debugf("objectData: found dagnode %s (# of bytes: %d - # links: %d)", fpath, len(dagnode.Data), len(dagnode.Links))
|
||||
|
||||
return bytes.NewReader(dagnode.Data), nil
|
||||
}
|
||||
|
||||
// objectLinks takes a key string and lists the links it points to
|
||||
func objectLinks(n *core.IpfsNode, fpath path.Path) (*Object, error) {
|
||||
dagnode, err := core.Resolve(n, fpath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Debugf("objectLinks: found dagnode %s (# of bytes: %d - # links: %d)", fpath, len(dagnode.Data), len(dagnode.Links))
|
||||
|
||||
return getOutput(dagnode)
|
||||
}
|
||||
|
||||
// objectGet takes a key string from args and a format option and serializes the dagnode to that format
|
||||
func objectGet(n *core.IpfsNode, fpath path.Path) (*dag.Node, error) {
|
||||
dagnode, err := core.Resolve(n, fpath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Debugf("objectGet: found dagnode %s (# of bytes: %d - # links: %d)", fpath, len(dagnode.Data), len(dagnode.Links))
|
||||
|
||||
return dagnode, nil
|
||||
}
|
||||
|
||||
// ErrEmptyNode is returned when the input to 'ipfs object put' contains no data
|
||||
var ErrEmptyNode = errors.New("no data or links in this node")
|
||||
|
||||
|
Reference in New Issue
Block a user