mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-19 01:39:35 +08:00
ipfs object put: return error if object is empty (fixes #883)
This commit is contained in:
@ -379,6 +379,9 @@ func objectGet(n *core.IpfsNode, fpath path.Path) (*dag.Node, error) {
|
|||||||
return dagnode, nil
|
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")
|
||||||
|
|
||||||
// objectPut takes a format option, serializes bytes from stdin and updates the dag with that data
|
// objectPut takes a format option, serializes bytes from stdin and updates the dag with that data
|
||||||
func objectPut(n *core.IpfsNode, input io.Reader, encoding string) (*Object, error) {
|
func objectPut(n *core.IpfsNode, input io.Reader, encoding string) (*Object, error) {
|
||||||
var (
|
var (
|
||||||
@ -404,6 +407,12 @@ func objectPut(n *core.IpfsNode, input io.Reader, encoding string) (*Object, err
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check that we have data in the Node to add
|
||||||
|
// otherwise we will add the empty object without raising an error
|
||||||
|
if node.Data == "" && len(node.Links) == 0 {
|
||||||
|
return nil, ErrEmptyNode
|
||||||
|
}
|
||||||
|
|
||||||
dagnode, err = deserializeNode(node)
|
dagnode, err = deserializeNode(node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
5
test/sharness/t0051-object-data/brokenPut.json
Normal file
5
test/sharness/t0051-object-data/brokenPut.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"this": "should",
|
||||||
|
"return": "an",
|
||||||
|
"error":"not valid dag object"
|
||||||
|
}
|
@ -82,5 +82,16 @@ test_expect_success "'ipfs object put' from stdin (pb) output looks good" '
|
|||||||
test_cmp expected_putStdinOut actual_putPbStdinOut
|
test_cmp expected_putStdinOut actual_putPbStdinOut
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success "'ipfs object put broken.json' should fail" '
|
||||||
|
test_expect_code 1 ipfs object put ../t0051-object-data/brokenPut.json 2>actual_putBrokenErr >actual_putBroken
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success "'ipfs object put broken.hjson' output looks good" '
|
||||||
|
touch expected_putBroken &&
|
||||||
|
printf "Error: no data or links in this node\n" > expected_putBrokenErr &&
|
||||||
|
test_cmp expected_putBroken actual_putBroken &&
|
||||||
|
test_cmp expected_putBrokenErr actual_putBrokenErr
|
||||||
|
'
|
||||||
|
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Reference in New Issue
Block a user