Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
b688e72d
Commit
b688e72d
authored
10 years ago
by
Henry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ipfs object put: return error if object is empty (fixes #883)
parent
e0601611
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
0 deletions
+25
-0
core/commands/object.go
core/commands/object.go
+9
-0
test/sharness/t0051-object-data/brokenPut.json
test/sharness/t0051-object-data/brokenPut.json
+5
-0
test/sharness/t0051-object.sh
test/sharness/t0051-object.sh
+11
-0
No files found.
core/commands/object.go
View file @
b688e72d
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
test/sharness/t0051-object-data/brokenPut.json
0 → 100644
View file @
b688e72d
{
"this"
:
"should"
,
"return"
:
"an"
,
"error"
:
"not valid dag object"
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/sharness/t0051-object.sh
View file @
b688e72d
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment