Skip to content

Commit

Permalink
fix writes zeroing files
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Oct 3, 2014
1 parent 4727535 commit dc66b69
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 5 additions & 4 deletions fuse/ipns/ipns_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ type Node struct {

// For writing
dataBuf *bytes.Buffer
changed bool
}

func (s *Node) loadData() error {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion importer/importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dc66b69

Please sign in to comment.