Commit dc66b699 authored by Jeromy's avatar Jeromy

fix writes zeroing files

parent 47275351
......@@ -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
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment