1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-27 07:57:30 +08:00

fix writes zeroing files

This commit is contained in:
Jeromy
2014-10-03 21:36:29 +00:00
parent 4727535160
commit dc66b699b0
2 changed files with 12 additions and 5 deletions

View File

@ -206,7 +206,6 @@ type Node struct {
// For writing
dataBuf *bytes.Buffer
changed bool
}
func (s *Node) loadData() error {
@ -302,18 +301,18 @@ func (n *Node) Write(req *fuse.WriteRequest, resp *fuse.WriteResponse, intr fs.I
if req.Offset == 0 {
n.dataBuf.Reset()
n.dataBuf.Write(req.Data)
n.changed = true
resp.Size = len(req.Data)
} else {
log.Error("Unhandled write to offset!")
n.dataBuf = nil
}
return nil
}
func (n *Node) Flush(req *fuse.FlushRequest, intr fs.Intr) fuse.Error {
log.Debug("Got flush request!")
log.Debug("Got flush request [%s]!", n.name)
if n.changed {
if n.dataBuf != nil {
//TODO:
// This operation holds everything in memory,
// should be changed to stream the block creation/storage
@ -351,6 +350,8 @@ func (n *Node) Flush(req *fuse.FlushRequest, intr fs.Intr) fuse.Error {
fmt.Println(string(b))
//
n.dataBuf = nil
n.wasChanged()
}
return nil

View File

@ -43,10 +43,16 @@ func TestSizeBasedSplit(t *testing.T) {
testFileConsistency(t, bs, 31*4095)
}
func dup(b []byte) []byte {
o := make([]byte, len(b))
copy(o, b)
return o
}
func testFileConsistency(t *testing.T, bs BlockSplitter, nbytes int) {
buf := new(bytes.Buffer)
io.CopyN(buf, rand.Reader, int64(nbytes))
should := buf.Bytes()
should := dup(buf.Bytes())
nd, err := NewDagFromReaderWithSplitter(buf, bs)
if err != nil {
t.Fatal(err)