1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-17 08:33:44 +08:00

ipfs object put: return error if object is empty (fixes #883)

This commit is contained in:
Henry
2015-03-10 22:58:50 +01:00
parent e06016116d
commit b688e72de0
3 changed files with 25 additions and 0 deletions

View File

@ -379,6 +379,9 @@ func objectGet(n *core.IpfsNode, fpath path.Path) (*dag.Node, error) {
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
func objectPut(n *core.IpfsNode, input io.Reader, encoding string) (*Object, error) {
var (
@ -404,6 +407,12 @@ func objectPut(n *core.IpfsNode, input io.Reader, encoding string) (*Object, 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)
if err != nil {
return nil, err

View File

@ -0,0 +1,5 @@
{
"this": "should",
"return": "an",
"error":"not valid dag object"
}

View File

@ -82,5 +82,16 @@ test_expect_success "'ipfs object put' from stdin (pb) output looks good" '
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