Skip to content

Commit 923797e

Browse files
committed
ipfs add: added size to response of ipfs add command
The `ipfs add` command was modified to include the added node's size as a string. The size is included in the dagnode info sent over the output channel. License: MIT Signed-off-by: Tom O'Donnell [email protected]
1 parent 4c34870 commit 923797e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

core/coreunix/add.go

Lines changed: 9 additions & 0 deletions
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) {
@@ -543,6 +546,7 @@ func outputDagnode(out chan interface{}, name string, dn node.Node) error {
543546
out <- &AddedObject{
544547
Hash: o.Hash,
545548
Name: name,
549+
Size: o.Size,
546550
}
547551

548552
return nil
@@ -558,9 +562,14 @@ func NewMemoryDagService() dag.DAGService {
558562
// from core/commands/object.go
559563
func getOutput(dagnode node.Node) (*Object, error) {
560564
c := dagnode.Cid()
565+
s, err := dagnode.Size()
566+
if err != nil {
567+
return nil, err
568+
}
561569

562570
output := &Object{
563571
Hash: c.String(),
572+
Size: strconv.FormatUint(s, 10),
564573
Links: make([]Link, len(dagnode.Links())),
565574
}
566575

0 commit comments

Comments
 (0)