@cryptotaxi247 / kubo / commits / 973707a88

fix minor mfs truncate bug

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Feb 19, 2016 at 18:57 UTC 973707a884c3ab778e5de5e8d743870fb03fbf5c
4 files changed +35 -2
mfs/dir.go
+1 -1
@@ -126,7 +126,7 @@ func (d *Directory) childNode(name string) (FSNode, error) {
126 ndir := NewDirectory(d.ctx, name, nd, d, d.dserv)
127 d.childDirs[name] = ndir
128 return ndir, nil
129 - case ufspb.Data_File:
129 + case ufspb.Data_File, ufspb.Data_Raw:
130 nfi, err := NewFile(name, nd, d, d.dserv)
131 if err != nil {
132 return nil, err
test/sharness/t0250-files-api.sh
+19
@@ -358,6 +358,25 @@ test_files_api() {
358 verify_dir_contents /
359 '
360
361 + # test truncating
362 + test_expect_success "create a new file" '
363 + echo "some content" | ipfs files write --create /cats
364 + '
365 +
366 + test_expect_success "truncate and write over that file" '
367 + echo "fish" | ipfs files write --truncate /cats
368 + '
369 +
370 + test_expect_success "output looks good" '
371 + ipfs files read /cats > file_out &&
372 + echo "fish" > file_exp &&
373 + test_cmp file_out file_exp
374 + '
375 +
376 + test_expect_success "cleanup" '
377 + ipfs files rm /cats
378 + '
379 +
380 # test flush flags
381 test_expect_success "mkdir --flush works" '
382 ipfs files mkdir --flush --parents /flushed/deep
unixfs/mod/dagmodifier.go
+1 -1
@@ -6,8 +6,8 @@ import (
6 "io"
7 "os"
8
9 - proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
9 mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash"
10 + proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
11 context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
12
13 key "github.com/ipfs/go-ipfs/blocks/key"
unixfs/mod/dagmodifier_test.go
+14
@@ -447,6 +447,20 @@ func TestDagTruncate(t *testing.T) {
447 if size != 10 {
448 t.Fatal("size was incorrect!")
449 }
450 +
451 + err = dagmod.Truncate(0)
452 + if err != nil {
453 + t.Fatal(err)
454 + }
455 +
456 + size, err = dagmod.Size()
457 + if err != nil {
458 + t.Fatal(err)
459 + }
460 +
461 + if size != 0 {
462 + t.Fatal("size was incorrect!")
463 + }
464 }
465
466 func TestSparseWrite(t *testing.T) {