Skip to content

Commit

Permalink
add -w: fix to work correctly with dirs.
Browse files Browse the repository at this point in the history
this commit changes the behavior of ipfs add -w:

- it makes it able to work with ipfs add -r <dir>
- instead of hacking around the add, we simply just add a wrapper
  directory around the whole result of the add. this means that
  ipfs add -w calls will output _two_ lines, but this is actually
  more correct than outputting one line, as two objects were added.
  this _may_ break scripts out there which expect the output to
  look a certain way. we should consider whether the old output is
  more _useful_ (even if less in-line with the model.)

License: MIT
Signed-off-by: Juan Batiz-Benet <juan@benet.ai>
  • Loading branch information
jbenet committed Jul 29, 2015
1 parent 578fd02 commit a8dae30
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
20 changes: 5 additions & 15 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
cmds "github.com/ipfs/go-ipfs/commands"
files "github.com/ipfs/go-ipfs/commands/files"
core "github.com/ipfs/go-ipfs/core"
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
importer "github.com/ipfs/go-ipfs/importer"
"github.com/ipfs/go-ipfs/importer/chunk"
dag "github.com/ipfs/go-ipfs/merkledag"
Expand Down Expand Up @@ -128,10 +127,14 @@ remains to be implemented.
node: n,
out: outChan,
progress: progress,
wrap: wrap,
hidden: hidden,
trickle: trickle,
}

if wrap {
file = files.NewSliceFile("", []files.File{file})
}

rootnd, err := addParams.addFile(file)
if err != nil {
res.SetError(err, cmds.ErrNormal)
Expand Down Expand Up @@ -247,7 +250,6 @@ type adder struct {
node *core.IpfsNode
out chan interface{}
progress bool
wrap bool
hidden bool
trickle bool
}
Expand Down Expand Up @@ -299,18 +301,6 @@ func (params *adder) addFile(file files.File) (*dag.Node, error) {
reader = &progressReader{file: file, out: params.out}
}

if params.wrap {
p, dagnode, err := coreunix.AddWrapped(params.node, reader, path.Base(file.FileName()))
if err != nil {
return nil, err
}
params.out <- &AddedObject{
Hash: p,
Name: file.FileName(),
}
return dagnode, nil
}

dagnode, err := add(params.node, reader, params.trickle)
if err != nil {
return nil, err
Expand Down
16 changes: 14 additions & 2 deletions test/sharness/t0040-add-and-cat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,20 @@ test_expect_success "ipfs add -w succeeds" '
'

test_expect_success "ipfs add -w output looks good" '
HASH="QmVJfrqd4ogGZME6LWkkikAGddYgh9dBs2U14DHZZUBk7W" &&
echo "added $HASH/hello.txt mountdir/hello.txt" >expected &&
HASH1="QmVr26fY1tKyspEJBniVhqxQeEjhF78XerGiqWAwraVLQH" &&
HASH2="QmVJfrqd4ogGZME6LWkkikAGddYgh9dBs2U14DHZZUBk7W" &&
echo "added $HASH1 mountdir/hello.txt" >expected &&
echo "added $HASH2 " >>expected &&
test_cmp expected actual
'

test_expect_success "ipfs add -w succeeds (dir)" '
ipfs add -r -w mountdir | tail -n1 >actual
'

test_expect_success "ipfs add -w output looks good (dir)" '
HASH="Qmc341yGztU1o8n3c1u5xTYF3uE3zPPP2NYemG9MKz775V" &&
echo "added $HASH " >expected &&
test_cmp expected actual
'

Expand Down

0 comments on commit a8dae30

Please sign in to comment.