@cryptotaxi247 / kubo / commits / 6e6badf10

add -w: fix to work correctly with dirs.

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>

Juan Batiz-Benet committed Jul 29, 2015 at 01:39 UTC 6e6badf105d446f03afe6fab4bc7bba64ef9c520
2 files changed +27 -25
core/commands/add.go
+5 -15
@@ -10,7 +10,6 @@ import (
10 cmds "github.com/ipfs/go-ipfs/commands"
11 files "github.com/ipfs/go-ipfs/commands/files"
12 core "github.com/ipfs/go-ipfs/core"
13 - coreunix "github.com/ipfs/go-ipfs/core/coreunix"
13 importer "github.com/ipfs/go-ipfs/importer"
14 "github.com/ipfs/go-ipfs/importer/chunk"
15 dag "github.com/ipfs/go-ipfs/merkledag"
@@ -128,10 +127,14 @@ remains to be implemented.
127 node: n,
128 out: outChan,
129 progress: progress,
131 - wrap: wrap,
130 hidden: hidden,
131 trickle: trickle,
132 }
133 +
134 + if wrap {
135 + file = files.NewSliceFile("", []files.File{file})
136 + }
137 +
138 rootnd, err := addParams.addFile(file)
139 if err != nil {
140 res.SetError(err, cmds.ErrNormal)
@@ -247,7 +250,6 @@ type adder struct {
250 node *core.IpfsNode
251 out chan interface{}
252 progress bool
250 - wrap bool
253 hidden bool
254 trickle bool
255 }
@@ -299,18 +301,6 @@ func (params *adder) addFile(file files.File) (*dag.Node, error) {
301 reader = &progressReader{file: file, out: params.out}
302 }
303
302 - if params.wrap {
303 - p, dagnode, err := coreunix.AddWrapped(params.node, reader, path.Base(file.FileName()))
304 - if err != nil {
305 - return nil, err
306 - }
307 - params.out <- &AddedObject{
308 - Hash: p,
309 - Name: file.FileName(),
310 - }
311 - return dagnode, nil
312 - }
313 -
304 dagnode, err := add(params.node, reader, params.trickle)
305 if err != nil {
306 return nil, err
test/sharness/t0040-add-and-cat.sh
+22 -10
@@ -212,6 +212,28 @@ test_expect_success "'ipfs cat' output looks good" '
212 test_cmp mountdir/bigfile actual
213 '
214
215 +test_expect_success "ipfs add -w succeeds" '
216 + ipfs add -w mountdir/hello.txt >actual
217 +'
218 +
219 +test_expect_success "ipfs add -w output looks good" '
220 + HASH_W1="QmVr26fY1tKyspEJBniVhqxQeEjhF78XerGiqWAwraVLQH" &&
221 + HASH_W2="QmVJfrqd4ogGZME6LWkkikAGddYgh9dBs2U14DHZZUBk7W" &&
222 + echo "added $HASH_W1 mountdir/hello.txt" >expected &&
223 + echo "added $HASH_W2 " >>expected &&
224 + test_cmp expected actual
225 +'
226 +
227 +test_expect_success "ipfs add -w succeeds (dir)" '
228 + ipfs add -r -w mountdir | tail -n1 >actual
229 +'
230 +
231 +test_expect_success "ipfs add -w output looks good (dir)" '
232 + HASH_W="Qmc341yGztU1o8n3c1u5xTYF3uE3zPPP2NYemG9MKz775V" &&
233 + echo "added $HASH_W " >expected &&
234 + test_cmp expected actual
235 +'
236 +
237 test_expect_success FUSE "cat ipfs/bigfile succeeds" '
238 cat "ipfs/$HASH" >actual
239 '
@@ -262,16 +284,6 @@ test_expect_success FUSE,EXPENSIVE "cat ipfs/bigfile looks good" '
284 test_cmp sha1_expected sha1_actual
285 '
286
265 -test_expect_success "ipfs add -w succeeds" '
266 - ipfs add -w mountdir/hello.txt >actual
267 -'
268 -
269 -test_expect_success "ipfs add -w output looks good" '
270 - HASH="QmVJfrqd4ogGZME6LWkkikAGddYgh9dBs2U14DHZZUBk7W" &&
271 - echo "added $HASH/hello.txt mountdir/hello.txt" >expected &&
272 - test_cmp expected actual
273 -'
274 -
287 test_kill_ipfs_daemon
288
289 test_done