Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
e7aa1166
Commit
e7aa1166
authored
10 years ago
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add writerAt for fuse writes
parent
dc66b699
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
18 deletions
+51
-18
fuse/ipns/ipns_unix.go
fuse/ipns/ipns_unix.go
+22
-18
fuse/ipns/writerat.go
fuse/ipns/writerat.go
+29
-0
No files found.
fuse/ipns/ipns_unix.go
View file @
e7aa1166
package ipns
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
"bytes"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/bazil.org/fuse"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
...
...
@@ -205,7 +204,7 @@ type Node struct {
cached *mdag.PBData
// For writing
dataBuf *bytes.Buffer
writerBuf WriteAtBuf
}
func (s *Node) loadData() error {
...
...
@@ -290,21 +289,25 @@ func (s *Node) ReadAll(intr fs.Intr) ([]byte, fuse.Error) {
}
// this is a terrible function... 'ReadAll'?
// what if i have a 6TB file? GG RAM.
return ioutil.ReadAll(r)
b, err := ioutil.ReadAll(r)
if err != nil {
log.Error("[%s] Readall error: %s", s.name, err)
return nil, err
}
if len(b) > 4 {
log.Debug("ReadAll trailing bytes: %v", b[len(b)-4:])
}
return b, nil
}
func (n *Node) Write(req *fuse.WriteRequest, resp *fuse.WriteResponse, intr fs.Intr) fuse.Error {
log.Debug("ipns: Node Write [%s]: flags = %s, offset = %d, size = %d", n.name, req.Flags.String(), req.Offset, len(req.Data))
if n.
data
Buf == nil {
n.
data
Buf =
n
ew
(bytes.Buffer
)
if n.
writer
Buf == nil {
n.
writer
Buf =
N
ew
WriterAtFromBytes(nil
)
}
if req.Offset == 0 {
n.dataBuf.Reset()
n.dataBuf.Write(req.Data)
resp.Size = len(req.Data)
} else {
log.Error("Unhandled write to offset!")
n.dataBuf = nil
_, err := n.writerBuf.WriteAt(req.Data, req.Offset)
if err != nil {
return err
}
return nil
}
...
...
@@ -312,7 +315,7 @@ func (n *Node) Write(req *fuse.WriteRequest, resp *fuse.WriteResponse, intr fs.I
func (n *Node) Flush(req *fuse.FlushRequest, intr fs.Intr) fuse.Error {
log.Debug("Got flush request [%s]!", n.name)
if n.
data
Buf != nil {
if n.
writer
Buf != nil {
//TODO:
// This operation holds everything in memory,
// should be changed to stream the block creation/storage
...
...
@@ -321,9 +324,10 @@ func (n *Node) Flush(req *fuse.FlushRequest, intr fs.Intr) fuse.Error {
//NOTE:
// This should only occur on a file object, if this were to be a
// folder, bad things would happen.
newNode, err := imp.NewDagFromReader(n.dataBuf)
buf := bytes.NewReader(n.writerBuf.Bytes())
newNode, err := imp.NewDagFromReader(buf)
if err != nil {
log.Critical("error creating dag from
data
Buf: %s", err)
log.Critical("error creating dag from
writer
Buf: %s", err)
return fuse.ENODATA
}
if n.parent != nil {
...
...
@@ -350,7 +354,7 @@ func (n *Node) Flush(req *fuse.FlushRequest, intr fs.Intr) fuse.Error {
fmt.Println(string(b))
//
n.
data
Buf = nil
n.
writer
Buf = nil
n.wasChanged()
}
...
...
@@ -382,7 +386,7 @@ func (n *Node) republishRoot() error {
return err
}
n.
data
Buf = nil
n.
writer
Buf = nil
ndkey, err := root.Nd.Key()
if err != nil {
...
...
This diff is collapsed.
Click to expand it.
fuse/ipns/writerat.go
0 → 100644
View file @
e7aa1166
package
ipns
import
"io"
type
WriteAtBuf
interface
{
io
.
WriterAt
Bytes
()
[]
byte
}
type
writerAt
struct
{
buf
[]
byte
}
func
NewWriterAtFromBytes
(
b
[]
byte
)
WriteAtBuf
{
return
&
writerAt
{
b
}
}
// TODO: make this better in the future, this is just a quick hack for now
func
(
wa
*
writerAt
)
WriteAt
(
p
[]
byte
,
off
int64
)
(
int
,
error
)
{
if
off
+
int64
(
len
(
p
))
>
int64
(
len
(
wa
.
buf
))
{
wa
.
buf
=
append
(
wa
.
buf
,
make
([]
byte
,
(
int
(
off
)
+
len
(
p
))
-
len
(
wa
.
buf
))
...
)
}
copy
(
wa
.
buf
[
off
:
],
p
)
return
len
(
p
),
nil
}
func
(
wa
*
writerAt
)
Bytes
()
[]
byte
{
return
wa
.
buf
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment