Skip to content

Commit 02dc260

Browse files
Merge pull request #4082 from te0d/feat/commands/add-size
ipfs add: added size to response of `ipfs add` command
2 parents 9825e33 + f96f6af commit 02dc260

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

core/coreunix/add.go

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io/ioutil"
88
"os"
99
gopath "path"
10+
"strconv"
1011

1112
bs "github.com/ipfs/go-ipfs/blocks/blockstore"
1213
bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
@@ -46,6 +47,7 @@ type Link struct {
4647
type Object struct {
4748
Hash string
4849
Links []Link
50+
Size string
4951
}
5052

5153
type hiddenFileError struct {
@@ -68,6 +70,7 @@ type AddedObject struct {
6870
Name string
6971
Hash string `json:",omitempty"`
7072
Bytes int64 `json:",omitempty"`
73+
Size string `json:",omitempty"`
7174
}
7275

7376
func NewAdder(ctx context.Context, p pin.Pinner, bs bstore.GCBlockstore, ds dag.DAGService) (*Adder, error) {
@@ -548,6 +551,7 @@ func outputDagnode(out chan interface{}, name string, dn node.Node) error {
548551
out <- &AddedObject{
549552
Hash: o.Hash,
550553
Name: name,
554+
Size: o.Size,
551555
}
552556

553557
return nil
@@ -563,9 +567,14 @@ func NewMemoryDagService() dag.DAGService {
563567
// from core/commands/object.go
564568
func getOutput(dagnode node.Node) (*Object, error) {
565569
c := dagnode.Cid()
570+
s, err := dagnode.Size()
571+
if err != nil {
572+
return nil, err
573+
}
566574

567575
output := &Object{
568576
Hash: c.String(),
577+
Size: strconv.FormatUint(s, 10),
569578
Links: make([]Link, len(dagnode.Links())),
570579
}
571580

test/sharness/t0410-api-add.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2016 Tom O'Donnell
4+
# MIT Licensed; see the LICENSE file in this repository.
5+
#
6+
7+
test_description="Test API add command"
8+
9+
. lib/test-lib.sh
10+
11+
test_init_ipfs
12+
13+
# Verify that that API add command returns size
14+
15+
test_launch_ipfs_daemon
16+
test_expect_success "API Add response includes size field" '
17+
echo "hi" | curl -s -F file=@- "http://localhost:$API_PORT/api/v0/add" | grep "\"Size\": *\"11\""
18+
'
19+
test_kill_ipfs_daemon
20+
21+
test_done

0 commit comments

Comments
 (0)