Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipfs add: added size to response of ipfs add command #4082

Merged
merged 2 commits into from
Jul 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions core/coreunix/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"os"
gopath "path"
"strconv"

bs "github.com/ipfs/go-ipfs/blocks/blockstore"
bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
Expand Down Expand Up @@ -46,6 +47,7 @@ type Link struct {
type Object struct {
Hash string
Links []Link
Size string
}

type hiddenFileError struct {
Expand All @@ -68,6 +70,7 @@ type AddedObject struct {
Name string
Hash string `json:",omitempty"`
Bytes int64 `json:",omitempty"`
Size string `json:",omitempty"`
}

func NewAdder(ctx context.Context, p pin.Pinner, bs bstore.GCBlockstore, ds dag.DAGService) (*Adder, error) {
Expand Down Expand Up @@ -543,6 +546,7 @@ func outputDagnode(out chan interface{}, name string, dn node.Node) error {
out <- &AddedObject{
Hash: o.Hash,
Name: name,
Size: o.Size,
}

return nil
Expand All @@ -558,9 +562,14 @@ func NewMemoryDagService() dag.DAGService {
// from core/commands/object.go
func getOutput(dagnode node.Node) (*Object, error) {
c := dagnode.Cid()
s, err := dagnode.Size()
if err != nil {
return nil, err
}

output := &Object{
Hash: c.String(),
Size: strconv.FormatUint(s, 10),
Links: make([]Link, len(dagnode.Links())),
}

Expand Down
21 changes: 21 additions & 0 deletions test/sharness/t0410-api-add.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
#
# Copyright (c) 2016 Tom O'Donnell
# MIT Licensed; see the LICENSE file in this repository.
#

test_description="Test API add command"

. lib/test-lib.sh

test_init_ipfs

# Verify that that API add command returns size

test_launch_ipfs_daemon
test_expect_success "API Add response includes size field" '
echo "hi" | curl -s -F file=@- "http://localhost:$API_PORT/api/v0/add" | grep "\"Size\": *\"11\""
'
test_kill_ipfs_daemon

test_done