@cryptotaxi247 / kubo / commits / dc66b699b

fix writes zeroing files

Jeromy committed Oct 3, 2014 at 21:36 UTC dc66b699b0dfc7dfa5d032bee7d5b681c318221c
2 files changed +12 -5
fuse/ipns/ipns_unix.go
+5 -4
@@ -206,7 +206,6 @@ type Node struct {
206
207 // For writing
208 dataBuf *bytes.Buffer
209 - changed bool
209 }
210
211 func (s *Node) loadData() error {
@@ -302,18 +301,18 @@ func (n *Node) Write(req *fuse.WriteRequest, resp *fuse.WriteResponse, intr fs.I
301 if req.Offset == 0 {
302 n.dataBuf.Reset()
303 n.dataBuf.Write(req.Data)
305 - n.changed = true
304 resp.Size = len(req.Data)
305 } else {
306 log.Error("Unhandled write to offset!")
307 + n.dataBuf = nil
308 }
309 return nil
310 }
311
312 func (n *Node) Flush(req *fuse.FlushRequest, intr fs.Intr) fuse.Error {
314 - log.Debug("Got flush request!")
313 + log.Debug("Got flush request [%s]!", n.name)
314
316 - if n.changed {
315 + if n.dataBuf != nil {
316 //TODO:
317 // This operation holds everything in memory,
318 // 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 {
350 fmt.Println(string(b))
351 //
352
353 + n.dataBuf = nil
354 +
355 n.wasChanged()
356 }
357 return nil
importer/importer_test.go
+7 -1
@@ -43,10 +43,16 @@ func TestSizeBasedSplit(t *testing.T) {
43 testFileConsistency(t, bs, 31*4095)
44 }
45
46 +func dup(b []byte) []byte {
47 + o := make([]byte, len(b))
48 + copy(o, b)
49 + return o
50 +}
51 +
52 func testFileConsistency(t *testing.T, bs BlockSplitter, nbytes int) {
53 buf := new(bytes.Buffer)
54 io.CopyN(buf, rand.Reader, int64(nbytes))
49 - should := buf.Bytes()
55 + should := dup(buf.Bytes())
56 nd, err := NewDagFromReaderWithSplitter(buf, bs)
57 if err != nil {
58 t.Fatal(err)