From 973707a884c3ab778e5de5e8d743870fb03fbf5c Mon Sep 17 00:00:00 2001 From: Jeromy Date: Fri, 19 Feb 2016 18:57:41 -0800 Subject: [PATCH] fix minor mfs truncate bug License: MIT Signed-off-by: Jeromy --- mfs/dir.go | 2 +- test/sharness/t0250-files-api.sh | 19 +++++++++++++++++++ unixfs/mod/dagmodifier.go | 2 +- unixfs/mod/dagmodifier_test.go | 14 ++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/mfs/dir.go b/mfs/dir.go index fc949621ac8..b73d8ad7cc2 100644 --- a/mfs/dir.go +++ b/mfs/dir.go @@ -126,7 +126,7 @@ func (d *Directory) childNode(name string) (FSNode, error) { ndir := NewDirectory(d.ctx, name, nd, d, d.dserv) d.childDirs[name] = ndir return ndir, nil - case ufspb.Data_File: + case ufspb.Data_File, ufspb.Data_Raw: nfi, err := NewFile(name, nd, d, d.dserv) if err != nil { return nil, err diff --git a/test/sharness/t0250-files-api.sh b/test/sharness/t0250-files-api.sh index 4544da473a5..7dd4862bdfb 100755 --- a/test/sharness/t0250-files-api.sh +++ b/test/sharness/t0250-files-api.sh @@ -358,6 +358,25 @@ test_files_api() { verify_dir_contents / ' + # test truncating + test_expect_success "create a new file" ' + echo "some content" | ipfs files write --create /cats + ' + + test_expect_success "truncate and write over that file" ' + echo "fish" | ipfs files write --truncate /cats + ' + + test_expect_success "output looks good" ' + ipfs files read /cats > file_out && + echo "fish" > file_exp && + test_cmp file_out file_exp + ' + + test_expect_success "cleanup" ' + ipfs files rm /cats + ' + # test flush flags test_expect_success "mkdir --flush works" ' ipfs files mkdir --flush --parents /flushed/deep diff --git a/unixfs/mod/dagmodifier.go b/unixfs/mod/dagmodifier.go index ec707259718..33f0824175b 100644 --- a/unixfs/mod/dagmodifier.go +++ b/unixfs/mod/dagmodifier.go @@ -6,8 +6,8 @@ import ( "io" "os" - proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash" + proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" key "github.com/ipfs/go-ipfs/blocks/key" diff --git a/unixfs/mod/dagmodifier_test.go b/unixfs/mod/dagmodifier_test.go index a5ed5dc1b59..fc3810f3f16 100644 --- a/unixfs/mod/dagmodifier_test.go +++ b/unixfs/mod/dagmodifier_test.go @@ -447,6 +447,20 @@ func TestDagTruncate(t *testing.T) { if size != 10 { t.Fatal("size was incorrect!") } + + err = dagmod.Truncate(0) + if err != nil { + t.Fatal(err) + } + + size, err = dagmod.Size() + if err != nil { + t.Fatal(err) + } + + if size != 0 { + t.Fatal("size was incorrect!") + } } func TestSparseWrite(t *testing.T) {