mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-28 17:03:58 +08:00
fix writes zeroing files
This commit is contained in:
@ -206,7 +206,6 @@ type Node struct {
|
|||||||
|
|
||||||
// For writing
|
// For writing
|
||||||
dataBuf *bytes.Buffer
|
dataBuf *bytes.Buffer
|
||||||
changed bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Node) loadData() error {
|
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 {
|
if req.Offset == 0 {
|
||||||
n.dataBuf.Reset()
|
n.dataBuf.Reset()
|
||||||
n.dataBuf.Write(req.Data)
|
n.dataBuf.Write(req.Data)
|
||||||
n.changed = true
|
|
||||||
resp.Size = len(req.Data)
|
resp.Size = len(req.Data)
|
||||||
} else {
|
} else {
|
||||||
log.Error("Unhandled write to offset!")
|
log.Error("Unhandled write to offset!")
|
||||||
|
n.dataBuf = nil
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) Flush(req *fuse.FlushRequest, intr fs.Intr) fuse.Error {
|
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:
|
//TODO:
|
||||||
// This operation holds everything in memory,
|
// This operation holds everything in memory,
|
||||||
// should be changed to stream the block creation/storage
|
// 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))
|
fmt.Println(string(b))
|
||||||
//
|
//
|
||||||
|
|
||||||
|
n.dataBuf = nil
|
||||||
|
|
||||||
n.wasChanged()
|
n.wasChanged()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -43,10 +43,16 @@ func TestSizeBasedSplit(t *testing.T) {
|
|||||||
testFileConsistency(t, bs, 31*4095)
|
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) {
|
func testFileConsistency(t *testing.T, bs BlockSplitter, nbytes int) {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
io.CopyN(buf, rand.Reader, int64(nbytes))
|
io.CopyN(buf, rand.Reader, int64(nbytes))
|
||||||
should := buf.Bytes()
|
should := dup(buf.Bytes())
|
||||||
nd, err := NewDagFromReaderWithSplitter(buf, bs)
|
nd, err := NewDagFromReaderWithSplitter(buf, bs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
Reference in New Issue
Block a user