Skip to content

Commit 973707a

Browse files
committedFeb 20, 2016
fix minor mfs truncate bug
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent 8e4cfed commit 973707a

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed
 

‎mfs/dir.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (d *Directory) childNode(name string) (FSNode, error) {
126126
ndir := NewDirectory(d.ctx, name, nd, d, d.dserv)
127127
d.childDirs[name] = ndir
128128
return ndir, nil
129-
case ufspb.Data_File:
129+
case ufspb.Data_File, ufspb.Data_Raw:
130130
nfi, err := NewFile(name, nd, d, d.dserv)
131131
if err != nil {
132132
return nil, err

‎test/sharness/t0250-files-api.sh

+19
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,25 @@ test_files_api() {
358358
verify_dir_contents /
359359
'
360360

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+
361380
# test flush flags
362381
test_expect_success "mkdir --flush works" '
363382
ipfs files mkdir --flush --parents /flushed/deep

‎unixfs/mod/dagmodifier.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"io"
77
"os"
88

9-
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
109
mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash"
10+
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
1111
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
1212

1313
key "github.com/ipfs/go-ipfs/blocks/key"

‎unixfs/mod/dagmodifier_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,20 @@ func TestDagTruncate(t *testing.T) {
447447
if size != 10 {
448448
t.Fatal("size was incorrect!")
449449
}
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+
}
450464
}
451465

452466
func TestSparseWrite(t *testing.T) {

0 commit comments

Comments
 (0)
Please sign in to comment.