Add "--raw-leaves" option to "ipfs files"
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
Kevin Atkinson committed
Aug 8, 2017 at 14:33 UTC
a3bd2c23b3b84aaf3090457021f04efeed3cca70
3 files changed
+213
-189
core/commands/files/files.go
+3
@@ -43,6 +43,7 @@ operations.
43
},
44
Options: []cmds.Option{
45
cmds.BoolOption("f", "flush", "Flush target and ancestors after write.").Default(true),
46
+ cmds.BoolOption("raw-leaves", "Use raw blocks for newly created leaf nodes. (experimental)"),
47
},
48
Subcommands: map[string]*cmds.Command{
49
"read": FilesReadCmd,
@@ -598,6 +599,7 @@ stat' on the file or any of its ancestors.
599
create, _, _ := req.Option("create").Bool()
600
trunc, _, _ := req.Option("truncate").Bool()
601
flush, _, _ := req.Option("flush").Bool()
602
+ rawLeaves, _, _ := req.Option("raw-leaves").Bool()
603
604
nd, err := req.InvocContext().GetNode()
605
if err != nil {
@@ -620,6 +622,7 @@ stat' on the file or any of its ancestors.
622
res.SetError(err, cmds.ErrNormal)
623
return
624
}
625
+ fi.RawLeaves = rawLeaves
626
627
wfd, err := fi.Open(mfs.OpenWriteOnly, flush)
628
if err != nil {
mfs/file.go
+3
@@ -23,6 +23,8 @@ type File struct {
23
dserv dag.DAGService
24
node node.Node
25
nodelk sync.Mutex
26
+
27
+ RawLeaves bool
28
}
29
30
// NewFile returns a NewFile object with the given parameters
@@ -79,6 +81,7 @@ func (fi *File) Open(flags int, sync bool) (FileDescriptor, error) {
81
if err != nil {
82
return nil, err
83
}
84
+ dmod.RawLeaves = fi.RawLeaves
85
86
return &fileDescriptor{
87
inode: fi,
test/sharness/t0250-files-api.sh
+207
-189
@@ -89,114 +89,116 @@ test_sharding() {
89
}
90
91
test_files_api() {
92
- ROOT_HASH=$1
92
+ local EXTRA ARGS
93
+ EXTRA=$1
94
+ ARGS=$2
95
94
- test_expect_success "can mkdir in root" '
95
- ipfs files mkdir /cats
96
+ test_expect_success "can mkdir in root $EXTRA" '
97
+ ipfs files $ARGS mkdir /cats
98
'
99
98
- test_expect_success "'files ls' lists root by default" '
99
- ipfs files ls >actual &&
100
+ test_expect_success "'files ls' lists root by default $EXTRA" '
101
+ ipfs files $ARGS ls >actual &&
102
echo "cats" >expected &&
103
test_cmp expected actual
104
'
105
104
- test_expect_success "directory was created" '
106
+ test_expect_success "directory was created $EXTRA" '
107
verify_path_exists /cats
108
'
109
108
- test_expect_success "directory is empty" '
110
+ test_expect_success "directory is empty $EXTRA" '
111
verify_dir_contents /cats
112
'
113
# we do verification of stat formatting now as we depend on it
114
113
- test_expect_success "stat works" '
114
- ipfs files stat / >stat
115
+ test_expect_success "stat works $EXTRA" '
116
+ ipfs files $ARGS stat / >stat
117
'
118
117
- test_expect_success "hash is first line of stat" '
119
+ test_expect_success "hash is first line of stat $EXTRA" '
120
ipfs ls $(head -1 stat) | grep "cats"
121
'
122
121
- test_expect_success "stat --hash gives only hash" '
122
- ipfs files stat --hash / >actual &&
123
+ test_expect_success "stat --hash gives only hash $EXTRA" '
124
+ ipfs files $ARGS stat --hash / >actual &&
125
head -n1 stat >expected &&
126
test_cmp expected actual
127
'
128
127
- test_expect_success "stat with multiple format options should fail" '
128
- test_must_fail ipfs files stat --hash --size /
129
+ test_expect_success "stat with multiple format options should fail $EXTRA" '
130
+ test_must_fail ipfs files $ARGS stat --hash --size /
131
'
132
131
- test_expect_success "compare hash option with format" '
132
- ipfs files stat --hash / >expected &&
133
- ipfs files stat --format='"'"'<hash>'"'"' / >actual &&
133
+ test_expect_success "compare hash option with format $EXTRA" '
134
+ ipfs files $ARGS stat --hash / >expected &&
135
+ ipfs files $ARGS stat --format='"'"'<hash>'"'"' / >actual &&
136
test_cmp expected actual
137
'
136
- test_expect_success "compare size option with format" '
137
- ipfs files stat --size / >expected &&
138
- ipfs files stat --format='"'"'<cumulsize>'"'"' / >actual &&
138
+ test_expect_success "compare size option with format $EXTRA" '
139
+ ipfs files $ARGS stat --size / >expected &&
140
+ ipfs files $ARGS stat --format='"'"'<cumulsize>'"'"' / >actual &&
141
test_cmp expected actual
142
'
143
142
- test_expect_success "check root hash" '
143
- ipfs files stat --hash / > roothash
144
+ test_expect_success "check root hash $EXTRA" '
145
+ ipfs files $ARGS stat --hash / > roothash
146
'
147
146
- test_expect_success "cannot mkdir /" '
147
- test_expect_code 1 ipfs files mkdir /
148
+ test_expect_success "cannot mkdir / $EXTRA" '
149
+ test_expect_code 1 ipfs files $ARGS mkdir /
150
'
151
150
- test_expect_success "check root hash was not changed" '
151
- ipfs files stat --hash / > roothashafter &&
152
+ test_expect_success "check root hash was not changed $EXTRA" '
153
+ ipfs files $ARGS stat --hash / > roothashafter &&
154
test_cmp roothash roothashafter
155
'
156
155
- test_expect_success "can put files into directory" '
156
- ipfs files cp /ipfs/$FILE1 /cats/file1
157
+ test_expect_success "can put files into directory $EXTRA" '
158
+ ipfs files $ARGS cp /ipfs/$FILE1 /cats/file1
159
'
160
159
- test_expect_success "file shows up in directory" '
161
+ test_expect_success "file shows up in directory $EXTRA" '
162
verify_dir_contents /cats file1
163
'
164
163
- test_expect_success "file has correct hash and size in directory" '
165
+ test_expect_success "file has correct hash and size in directory $EXTRA" '
166
echo "file1 $FILE1 4" > ls_l_expected &&
165
- ipfs files ls -l /cats > ls_l_actual &&
167
+ ipfs files $ARGS ls -l /cats > ls_l_actual &&
168
test_cmp ls_l_expected ls_l_actual
169
'
170
169
- test_expect_success "can read file" '
170
- ipfs files read /cats/file1 > file1out
171
+ test_expect_success "can read file $EXTRA" '
172
+ ipfs files $ARGS read /cats/file1 > file1out
173
'
174
173
- test_expect_success "output looks good" '
175
+ test_expect_success "output looks good $EXTRA" '
176
echo foo > expected &&
177
test_cmp expected file1out
178
'
179
178
- test_expect_success "can put another file into root" '
179
- ipfs files cp /ipfs/$FILE2 /file2
180
+ test_expect_success "can put another file into root $EXTRA" '
181
+ ipfs files $ARGS cp /ipfs/$FILE2 /file2
182
'
183
182
- test_expect_success "file shows up in root" '
184
+ test_expect_success "file shows up in root $EXTRA" '
185
verify_dir_contents / file2 cats
186
'
187
186
- test_expect_success "can read file" '
187
- ipfs files read /file2 > file2out
188
+ test_expect_success "can read file $EXTRA" '
189
+ ipfs files $ARGS read /file2 > file2out
190
'
191
190
- test_expect_success "output looks good" '
192
+ test_expect_success "output looks good $EXTRA" '
193
echo bar > expected &&
194
test_cmp expected file2out
195
'
196
195
- test_expect_success "can make deep directory" '
196
- ipfs files mkdir -p /cats/this/is/a/dir
197
+ test_expect_success "can make deep directory $EXTRA" '
198
+ ipfs files $ARGS mkdir -p /cats/this/is/a/dir
199
'
200
199
- test_expect_success "directory was created correctly" '
201
+ test_expect_success "directory was created correctly $EXTRA" '
202
verify_path_exists /cats/this/is/a/dir &&
203
verify_dir_contents /cats this file1 &&
204
verify_dir_contents /cats/this is &&
@@ -205,362 +207,378 @@ test_files_api() {
207
verify_dir_contents /cats/this/is/a/dir
208
'
209
208
- test_expect_success "can copy file into new dir" '
209
- ipfs files cp /ipfs/$FILE3 /cats/this/is/a/dir/file3
210
+ test_expect_success "can copy file into new dir $EXTRA" '
211
+ ipfs files $ARGS cp /ipfs/$FILE3 /cats/this/is/a/dir/file3
212
'
213
212
- test_expect_success "can read file" '
213
- ipfs files read /cats/this/is/a/dir/file3 > output
214
+ test_expect_success "can read file $EXTRA" '
215
+ ipfs files $ARGS read /cats/this/is/a/dir/file3 > output
216
'
217
216
- test_expect_success "output looks good" '
218
+ test_expect_success "output looks good $EXTRA" '
219
echo baz > expected &&
220
test_cmp expected output
221
'
222
221
- test_expect_success "file shows up in dir" '
223
+ test_expect_success "file shows up in dir $EXTRA" '
224
verify_dir_contents /cats/this/is/a/dir file3
225
'
226
225
- test_expect_success "can remove file" '
226
- ipfs files rm /cats/this/is/a/dir/file3
227
+ test_expect_success "can remove file $EXTRA" '
228
+ ipfs files $ARGS rm /cats/this/is/a/dir/file3
229
'
230
229
- test_expect_success "file no longer appears" '
231
+ test_expect_success "file no longer appears $EXTRA" '
232
verify_dir_contents /cats/this/is/a/dir
233
'
234
233
- test_expect_success "can remove dir" '
234
- ipfs files rm -r /cats/this/is/a/dir
235
+ test_expect_success "can remove dir $EXTRA" '
236
+ ipfs files $ARGS rm -r /cats/this/is/a/dir
237
'
238
237
- test_expect_success "dir no longer appears" '
239
+ test_expect_success "dir no longer appears $EXTRA" '
240
verify_dir_contents /cats/this/is/a
241
'
242
241
- test_expect_success "can remove file from root" '
242
- ipfs files rm /file2
243
+ test_expect_success "can remove file from root $EXTRA" '
244
+ ipfs files $ARGS rm /file2
245
'
246
245
- test_expect_success "file no longer appears" '
247
+ test_expect_success "file no longer appears $EXTRA" '
248
verify_dir_contents / cats
249
'
250
249
- test_expect_success "check root hash" '
250
- ipfs files stat --hash / > roothash
251
+ test_expect_success "check root hash $EXTRA" '
252
+ ipfs files $ARGS stat --hash / > roothash
253
'
254
253
- test_expect_success "cannot remove root" '
254
- test_expect_code 1 ipfs files rm -r /
255
+ test_expect_success "cannot remove root $EXTRA" '
256
+ test_expect_code 1 ipfs files $ARGS rm -r /
257
'
258
257
- test_expect_success "check root hash was not changed" '
258
- ipfs files stat --hash / > roothashafter &&
259
+ test_expect_success "check root hash was not changed $EXTRA" '
260
+ ipfs files $ARGS stat --hash / > roothashafter &&
261
test_cmp roothash roothashafter
262
'
263
264
# test read options
265
264
- test_expect_success "read from offset works" '
265
- ipfs files read -o 1 /cats/file1 > output
266
+ test_expect_success "read from offset works $EXTRA" '
267
+ ipfs files $ARGS read -o 1 /cats/file1 > output
268
'
269
268
- test_expect_success "output looks good" '
270
+ test_expect_success "output looks good $EXTRA" '
271
echo oo > expected &&
272
test_cmp expected output
273
'
274
273
- test_expect_success "read with size works" '
274
- ipfs files read -n 2 /cats/file1 > output
275
+ test_expect_success "read with size works $EXTRA" '
276
+ ipfs files $ARGS read -n 2 /cats/file1 > output
277
'
278
277
- test_expect_success "output looks good" '
279
+ test_expect_success "output looks good $EXTRA" '
280
printf fo > expected &&
281
test_cmp expected output
282
'
283
282
- test_expect_success "cannot read from negative offset" '
283
- test_expect_code 1 ipfs files read --offset -3 /cats/file1
284
+ test_expect_success "cannot read from negative offset $EXTRA" '
285
+ test_expect_code 1 ipfs files $ARGS read --offset -3 /cats/file1
286
'
287
286
- test_expect_success "read from offset 0 works" '
287
- ipfs files read --offset 0 /cats/file1 > output
288
+ test_expect_success "read from offset 0 works $EXTRA" '
289
+ ipfs files $ARGS read --offset 0 /cats/file1 > output
290
'
291
290
- test_expect_success "output looks good" '
292
+ test_expect_success "output looks good $EXTRA" '
293
echo foo > expected &&
294
test_cmp expected output
295
'
296
295
- test_expect_success "read last byte works" '
296
- ipfs files read --offset 2 /cats/file1 > output
297
+ test_expect_success "read last byte works $EXTRA" '
298
+ ipfs files $ARGS read --offset 2 /cats/file1 > output
299
'
300
299
- test_expect_success "output looks good" '
301
+ test_expect_success "output looks good $EXTRA" '
302
echo o > expected &&
303
test_cmp expected output
304
'
305
304
- test_expect_success "offset past end of file fails" '
305
- test_expect_code 1 ipfs files read --offset 5 /cats/file1
306
+ test_expect_success "offset past end of file fails $EXTRA" '
307
+ test_expect_code 1 ipfs files $ARGS read --offset 5 /cats/file1
308
'
309
308
- test_expect_success "cannot read negative count bytes" '
310
+ test_expect_success "cannot read negative count bytes $EXTRA" '
311
test_expect_code 1 ipfs read --count -1 /cats/file1
312
'
313
312
- test_expect_success "reading zero bytes prints nothing" '
313
- ipfs files read --count 0 /cats/file1 > output
314
+ test_expect_success "reading zero bytes prints nothing $EXTRA" '
315
+ ipfs files $ARGS read --count 0 /cats/file1 > output
316
'
317
316
- test_expect_success "output looks good" '
318
+ test_expect_success "output looks good $EXTRA" '
319
printf "" > expected &&
320
test_cmp expected output
321
'
322
321
- test_expect_success "count > len(file) prints entire file" '
322
- ipfs files read --count 200 /cats/file1 > output
323
+ test_expect_success "count > len(file) prints entire file $EXTRA" '
324
+ ipfs files $ARGS read --count 200 /cats/file1 > output
325
'
326
325
- test_expect_success "output looks good" '
327
+ test_expect_success "output looks good $EXTRA" '
328
echo foo > expected &&
329
test_cmp expected output
330
'
331
332
# test write
333
332
- test_expect_success "can write file" '
334
+ test_expect_success "can write file $EXTRA" '
335
echo "ipfs rocks" > tmpfile &&
334
- cat tmpfile | ipfs files write --create /cats/ipfs
336
+ cat tmpfile | ipfs files $ARGS write --create /cats/ipfs
337
'
338
337
- test_expect_success "file was created" '
339
+ test_expect_success "file was created $EXTRA" '
340
verify_dir_contents /cats ipfs file1 this
341
'
342
341
- test_expect_success "can read file we just wrote" '
342
- ipfs files read /cats/ipfs > output
343
+ test_expect_success "can read file we just wrote $EXTRA" '
344
+ ipfs files $ARGS read /cats/ipfs > output
345
'
346
345
- test_expect_success "can write to offset" '
346
- echo "is super cool" | ipfs files write -o 5 /cats/ipfs
347
+ test_expect_success "can write to offset $EXTRA" '
348
+ echo "is super cool" | ipfs files $ARGS write -o 5 /cats/ipfs
349
'
350
349
- test_expect_success "file looks correct" '
351
+ test_expect_success "file looks correct $EXTRA" '
352
echo "ipfs is super cool" > expected &&
351
- ipfs files read /cats/ipfs > output &&
353
+ ipfs files $ARGS read /cats/ipfs > output &&
354
test_cmp expected output
355
'
356
355
- test_expect_success "cant write to negative offset" '
356
- ipfs files stat --hash /cats/ipfs > filehash &&
357
- test_expect_code 1 ipfs files write --offset -1 /cats/ipfs < output
357
+ test_expect_success "file hash correct $EXTRA" '
358
+ echo $FILE_HASH > filehash_expected &&
359
+ ipfs files $ARGS stat --hash /cats/ipfs > filehash &&
360
+ test_cmp filehash_expected filehash
361
'
362
360
- test_expect_success "verify file was not changed" '
361
- ipfs files stat --hash /cats/ipfs > afterhash &&
363
+ test_expect_success "cant write to negative offset $EXTRA" '
364
+ test_expect_code 1 ipfs files $ARGS write --offset -1 /cats/ipfs < output
365
+ '
366
+
367
+ test_expect_success "verify file was not changed $EXTRA" '
368
+ ipfs files $ARGS stat --hash /cats/ipfs > afterhash &&
369
test_cmp filehash afterhash
370
'
371
365
- test_expect_success "write new file for testing" '
366
- echo foobar | ipfs files write --create /fun
372
+ test_expect_success "write new file for testing $EXTRA" '
373
+ echo foobar | ipfs files $ARGS write --create /fun
374
'
375
369
- test_expect_success "write to offset past end works" '
370
- echo blah | ipfs files write --offset 50 /fun
376
+ test_expect_success "write to offset past end works $EXTRA" '
377
+ echo blah | ipfs files $ARGS write --offset 50 /fun
378
'
379
373
- test_expect_success "can read file" '
374
- ipfs files read /fun > sparse_output
380
+ test_expect_success "can read file $EXTRA" '
381
+ ipfs files $ARGS read /fun > sparse_output
382
'
383
377
- test_expect_success "output looks good" '
384
+ test_expect_success "output looks good $EXTRA" '
385
echo foobar > sparse_expected &&
386
echo blah | dd of=sparse_expected bs=50 seek=1 &&
387
test_cmp sparse_expected sparse_output
388
'
389
383
- test_expect_success "cleanup" '
384
- ipfs files rm /fun
390
+ test_expect_success "cleanup $EXTRA" '
391
+ ipfs files $ARGS rm /fun
392
'
393
387
- test_expect_success "cannot write to directory" '
388
- ipfs files stat --hash /cats > dirhash &&
389
- test_expect_code 1 ipfs files write /cats < output
394
+ test_expect_success "cannot write to directory $EXTRA" '
395
+ ipfs files $ARGS stat --hash /cats > dirhash &&
396
+ test_expect_code 1 ipfs files $ARGS write /cats < output
397
'
398
392
- test_expect_success "verify dir was not changed" '
393
- ipfs files stat --hash /cats > afterdirhash &&
399
+ test_expect_success "verify dir was not changed $EXTRA" '
400
+ ipfs files $ARGS stat --hash /cats > afterdirhash &&
401
test_cmp dirhash afterdirhash
402
'
403
397
- test_expect_success "cannot write to nonexistant path" '
398
- test_expect_code 1 ipfs files write /cats/bar/ < output
404
+ test_expect_success "cannot write to nonexistant path $EXTRA" '
405
+ test_expect_code 1 ipfs files $ARGS write /cats/bar/ < output
406
'
407
401
- test_expect_success "no new paths were created" '
408
+ test_expect_success "no new paths were created $EXTRA" '
409
verify_dir_contents /cats file1 ipfs this
410
'
411
405
- test_expect_success "write 'no-flush' succeeds" '
406
- echo "testing" | ipfs files write -f=false -e /cats/walrus
412
+ test_expect_success "write 'no-flush' succeeds $EXTRA" '
413
+ echo "testing" | ipfs files $ARGS write -f=false -e /cats/walrus
414
'
415
409
- test_expect_success "root hash not bubbled up yet" '
416
+ test_expect_success "root hash not bubbled up yet $EXTRA" '
417
test -z "$ONLINE" ||
418
(ipfs refs local > refsout &&
419
test_expect_code 1 grep $ROOT_HASH refsout)
420
'
421
415
- test_expect_success "changes bubbled up to root on inspection" '
416
- ipfs files stat --hash / > root_hash
422
+ test_expect_success "changes bubbled up to root on inspection $EXTRA" '
423
+ ipfs files $ARGS stat --hash / > root_hash
424
'
425
419
- test_expect_success "root hash looks good" '
426
+ test_expect_success "root hash looks good $EXTRA" '
427
export EXP_ROOT_HASH="$ROOT_HASH" &&
428
echo $EXP_ROOT_HASH > root_hash_exp &&
429
test_cmp root_hash_exp root_hash
430
'
431
425
- test_expect_success "flush root succeeds" '
426
- ipfs files flush /
432
+ test_expect_success "flush root succeeds $EXTRA" '
433
+ ipfs files $ARGS flush /
434
'
435
436
# test mv
430
- test_expect_success "can mv dir" '
431
- ipfs files mv /cats/this/is /cats/
437
+ test_expect_success "can mv dir $EXTRA" '
438
+ ipfs files $ARGS mv /cats/this/is /cats/
439
'
440
434
- test_expect_success "mv worked" '
441
+ test_expect_success "mv worked $EXTRA" '
442
verify_dir_contents /cats file1 ipfs this is walrus &&
443
verify_dir_contents /cats/this
444
'
445
439
- test_expect_success "cleanup, remove 'cats'" '
440
- ipfs files rm -r /cats
446
+ test_expect_success "cleanup, remove 'cats' $EXTRA" '
447
+ ipfs files $ARGS rm -r /cats
448
'
449
443
- test_expect_success "cleanup looks good" '
450
+ test_expect_success "cleanup looks good $EXTRA" '
451
verify_dir_contents /
452
'
453
454
# test truncating
448
- test_expect_success "create a new file" '
449
- echo "some content" | ipfs files write --create /cats
455
+ test_expect_success "create a new file $EXTRA" '
456
+ echo "some content" | ipfs files $ARGS write --create /cats
457
'
458
452
- test_expect_success "truncate and write over that file" '
453
- echo "fish" | ipfs files write --truncate /cats
459
+ test_expect_success "truncate and write over that file $EXTRA" '
460
+ echo "fish" | ipfs files $ARGS write --truncate /cats
461
'
462
456
- test_expect_success "output looks good" '
457
- ipfs files read /cats > file_out &&
463
+ test_expect_success "output looks good $EXTRA" '
464
+ ipfs files $ARGS read /cats > file_out &&
465
echo "fish" > file_exp &&
466
test_cmp file_out file_exp
467
'
468
462
- test_expect_success "cleanup" '
463
- ipfs files rm /cats
469
+ test_expect_success "cleanup $EXTRA" '
470
+ ipfs files $ARGS rm /cats
471
'
472
473
# test flush flags
467
- test_expect_success "mkdir --flush works" '
468
- ipfs files mkdir --flush --parents /flushed/deep
474
+ test_expect_success "mkdir --flush works $EXTRA" '
475
+ ipfs files $ARGS mkdir --flush --parents /flushed/deep
476
'
477
471
- test_expect_success "mkdir --flush works a second time" '
472
- ipfs files mkdir --flush --parents /flushed/deep
478
+ test_expect_success "mkdir --flush works a second time $EXTRA" '
479
+ ipfs files $ARGS mkdir --flush --parents /flushed/deep
480
'
481
475
- test_expect_success "dir looks right" '
482
+ test_expect_success "dir looks right $EXTRA" '
483
verify_dir_contents / flushed
484
'
485
479
- test_expect_success "child dir looks right" '
486
+ test_expect_success "child dir looks right $EXTRA" '
487
verify_dir_contents /flushed deep
488
'
489
483
- test_expect_success "cleanup" '
484
- ipfs files rm -r /flushed
490
+ test_expect_success "cleanup $EXTRA" '
491
+ ipfs files $ARGS rm -r /flushed
492
'
493
487
- test_expect_success "child dir looks right" '
494
+ test_expect_success "child dir looks right $EXTRA" '
495
verify_dir_contents /
496
'
497
498
# test for https://github.com/ipfs/go-ipfs/issues/2654
492
- test_expect_success "create and remove dir" '
493
- ipfs files mkdir /test_dir &&
494
- ipfs files rm -r "/test_dir"
499
+ test_expect_success "create and remove dir $EXTRA" '
500
+ ipfs files $ARGS mkdir /test_dir &&
501
+ ipfs files $ARGS rm -r "/test_dir"
502
'
503
497
- test_expect_success "create test file" '
498
- echo "content" | ipfs files write -e "/test_file"
504
+ test_expect_success "create test file $EXTRA" '
505
+ echo "content" | ipfs files $ARGS write -e "/test_file"
506
'
507
501
- test_expect_success "copy test file onto test dir" '
502
- ipfs files cp "/test_file" "/test_dir"
508
+ test_expect_success "copy test file onto test dir $EXTRA" '
509
+ ipfs files $ARGS cp "/test_file" "/test_dir"
510
'
511
505
- test_expect_success "test /test_dir" '
506
- ipfs files stat "/test_dir" | grep -q "^Type: file"
512
+ test_expect_success "test /test_dir $EXTRA" '
513
+ ipfs files $ARGS stat "/test_dir" | grep -q "^Type: file"
514
'
515
509
- test_expect_success "clean up /test_dir and /test_file" '
510
- ipfs files rm -r /test_dir &&
511
- ipfs files rm -r /test_file
516
+ test_expect_success "clean up /test_dir and /test_file $EXTRA" '
517
+ ipfs files $ARGS rm -r /test_dir &&
518
+ ipfs files $ARGS rm -r /test_file
519
'
520
514
- test_expect_success "make a directory and a file" '
515
- ipfs files mkdir /adir &&
516
- echo "blah" | ipfs files write --create /foobar
521
+ test_expect_success "make a directory and a file $EXTRA" '
522
+ ipfs files $ARGS mkdir /adir &&
523
+ echo "blah" | ipfs files $ARGS write --create /foobar
524
'
525
519
- test_expect_success "copy a file into a directory" '
520
- ipfs files cp /foobar /adir/
526
+ test_expect_success "copy a file into a directory $EXTRA" '
527
+ ipfs files $ARGS cp /foobar /adir/
528
'
529
523
- test_expect_success "file made it into directory" '
524
- ipfs files ls /adir | grep foobar
530
+ test_expect_success "file made it into directory $EXTRA" '
531
+ ipfs files $ARGS ls /adir | grep foobar
532
'
533
527
- test_expect_success "clean up" '
528
- ipfs files rm -r /foobar &&
529
- ipfs files rm -r /adir
534
+ test_expect_success "clean up $EXTRA" '
535
+ ipfs files $ARGS rm -r /foobar &&
536
+ ipfs files $ARGS rm -r /adir
537
'
538
532
- test_expect_success "root mfs entry is empty" '
539
+ test_expect_success "root mfs entry is empty $EXTRA" '
540
verify_dir_contents /
541
'
542
536
- test_expect_success "repo gc" '
543
+ test_expect_success "repo gc $EXTRA" '
544
ipfs repo gc
545
'
546
}
547
548
# test offline and online
542
-test_expect_success "can create some files for testing" '
543
- create_files
544
-'
545
-test_files_api QmcwKfTMCT7AaeiD92hWjnZn9b6eh9NxnhfSzN5x2vnDpt
549
547
-test_expect_success "can create some files for testing with raw-leaves" '
548
- create_files --raw-leaves
549
-'
550
-test_files_api QmTpKiKcAj4sbeesN6vrs5w3QeVmd4QmGpxRL81hHut4dZ
550
+tests_for_files_api() {
551
+ local EXTRA
552
+ EXTRA=$1
553
+
554
+ test_expect_success "can create some files for testing ($extra)" '
555
+ create_files
556
+ '
557
+ ROOT_HASH=QmcwKfTMCT7AaeiD92hWjnZn9b6eh9NxnhfSzN5x2vnDpt
558
+ FILE_HASH=QmQdQt9qooenjeaNhiKHF3hBvmNteB4MQBtgu3jxgf9c7i
559
+ test_files_api "($EXTRA)"
560
+
561
+ test_expect_success "can create some files for testing with raw-leaves ($extra)" '
562
+ create_files --raw-leaves
563
+ '
564
+ ROOT_HASH=QmTpKiKcAj4sbeesN6vrs5w3QeVmd4QmGpxRL81hHut4dZ
565
+ test_files_api "($EXTRA, partial raw-leaves)"
566
+
567
+ test_expect_success "can create some files for testing with raw-leaves ($extra)" '
568
+ create_files --raw-leaves
569
+ '
570
+ ROOT_HASH=QmW3dMSU6VNd1mEdpk9S3ZYRuR1YwwoXjGaZhkyK6ru9YU
571
+ FILE_HASH=QmRCgHeoKxCqK2Es6M6nPUDVWz19yNQPnsXGsXeuTkSKpN
572
+ test_files_api "($EXTRA, raw-leaves)" --raw-leaves
573
+}
574
+
575
+tests_for_files_api "online"
576
577
test_launch_ipfs_daemon --offline
578
579
ONLINE=1 # set online flag so tests can easily tell
555
-test_expect_success "can create some files for testing" '
556
- create_files
557
-'
558
-test_files_api QmcwKfTMCT7AaeiD92hWjnZn9b6eh9NxnhfSzN5x2vnDpt
580
560
-test_expect_success "can create some files for testing with raw-leaves" '
561
- create_files --raw-leaves
562
-'
563
-test_files_api QmTpKiKcAj4sbeesN6vrs5w3QeVmd4QmGpxRL81hHut4dZ
581
+tests_for_files_api "offline"
582
583
test_kill_ipfs_daemon --offline
584