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 6e6badf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 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
32 changes: 22 additions & 10 deletions test/sharness/t0040-add-and-cat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,28 @@ test_expect_success "'ipfs cat' output looks good" '
test_cmp mountdir/bigfile actual
'

test_expect_success "ipfs add -w succeeds" '
ipfs add -w mountdir/hello.txt >actual
'

test_expect_success "ipfs add -w output looks good" '
HASH_W1="QmVr26fY1tKyspEJBniVhqxQeEjhF78XerGiqWAwraVLQH" &&
HASH_W2="QmVJfrqd4ogGZME6LWkkikAGddYgh9dBs2U14DHZZUBk7W" &&
echo "added $HASH_W1 mountdir/hello.txt" >expected &&
echo "added $HASH_W2 " >>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_W="Qmc341yGztU1o8n3c1u5xTYF3uE3zPPP2NYemG9MKz775V" &&
echo "added $HASH_W " >expected &&
test_cmp expected actual
'

test_expect_success FUSE "cat ipfs/bigfile succeeds" '
cat "ipfs/$HASH" >actual
'
Expand Down Expand Up @@ -262,16 +284,6 @@ test_expect_success FUSE,EXPENSIVE "cat ipfs/bigfile looks good" '
test_cmp sha1_expected sha1_actual
'

test_expect_success "ipfs add -w succeeds" '
ipfs add -w mountdir/hello.txt >actual
'

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

test_kill_ipfs_daemon

test_done

0 comments on commit 6e6badf

Please sign in to comment.