提交 973707a8 作者: Jeromy

fix minor mfs truncate bug

License: MIT
Signed-off-by: 's avatarJeromy <jeromyj@gmail.com>
上级 8e4cfed0
...@@ -126,7 +126,7 @@ func (d *Directory) childNode(name string) (FSNode, error) { ...@@ -126,7 +126,7 @@ func (d *Directory) childNode(name string) (FSNode, error) {
ndir := NewDirectory(d.ctx, name, nd, d, d.dserv) ndir := NewDirectory(d.ctx, name, nd, d, d.dserv)
d.childDirs[name] = ndir d.childDirs[name] = ndir
return ndir, nil return ndir, nil
case ufspb.Data_File: case ufspb.Data_File, ufspb.Data_Raw:
nfi, err := NewFile(name, nd, d, d.dserv) nfi, err := NewFile(name, nd, d, d.dserv)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -358,6 +358,25 @@ test_files_api() { ...@@ -358,6 +358,25 @@ test_files_api() {
verify_dir_contents / 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 flush flags
test_expect_success "mkdir --flush works" ' test_expect_success "mkdir --flush works" '
ipfs files mkdir --flush --parents /flushed/deep ipfs files mkdir --flush --parents /flushed/deep
......
...@@ -6,8 +6,8 @@ import ( ...@@ -6,8 +6,8 @@ import (
"io" "io"
"os" "os"
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash" mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash"
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
key "github.com/ipfs/go-ipfs/blocks/key" key "github.com/ipfs/go-ipfs/blocks/key"
......
...@@ -447,6 +447,20 @@ func TestDagTruncate(t *testing.T) { ...@@ -447,6 +447,20 @@ func TestDagTruncate(t *testing.T) {
if size != 10 { if size != 10 {
t.Fatal("size was incorrect!") 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) { func TestSparseWrite(t *testing.T) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论