aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/fuse/fuse_file.go
diff options
context:
space:
mode:
Diffstat (limited to 'swarm/fuse/fuse_file.go')
-rw-r--r--swarm/fuse/fuse_file.go43
1 files changed, 22 insertions, 21 deletions
diff --git a/swarm/fuse/fuse_file.go b/swarm/fuse/fuse_file.go
index c94a0773f..80c26fe05 100644
--- a/swarm/fuse/fuse_file.go
+++ b/swarm/fuse/fuse_file.go
@@ -26,7 +26,7 @@ import (
"bazil.org/fuse"
"bazil.org/fuse/fs"
- "github.com/ethereum/go-ethereum/log"
+ "github.com/ethereum/go-ethereum/swarm/log"
"github.com/ethereum/go-ethereum/swarm/storage"
"golang.org/x/net/context"
)
@@ -50,7 +50,7 @@ type SwarmFile struct {
inode uint64
name string
path string
- key storage.Key
+ addr storage.Address
fileSize int64
reader storage.LazySectionReader
@@ -63,7 +63,7 @@ func NewSwarmFile(path, fname string, minfo *MountInfo) *SwarmFile {
inode: NewInode(),
name: fname,
path: path,
- key: nil,
+ addr: nil,
fileSize: -1, // -1 means , file already exists in swarm and you need to just get the size from swarm
reader: nil,
@@ -73,33 +73,38 @@ func NewSwarmFile(path, fname string, minfo *MountInfo) *SwarmFile {
return newFile
}
-func (file *SwarmFile) Attr(ctx context.Context, a *fuse.Attr) error {
-
- a.Inode = file.inode
+func (sf *SwarmFile) Attr(ctx context.Context, a *fuse.Attr) error {
+ log.Debug("swarmfs Attr", "path", sf.path)
+ sf.lock.Lock()
+ defer sf.lock.Unlock()
+ a.Inode = sf.inode
//TODO: need to get permission as argument
a.Mode = 0700
a.Uid = uint32(os.Getuid())
a.Gid = uint32(os.Getegid())
- if file.fileSize == -1 {
- reader := file.mountInfo.swarmApi.Retrieve(file.key)
+ if sf.fileSize == -1 {
+ reader, _ := sf.mountInfo.swarmApi.Retrieve(sf.addr)
quitC := make(chan bool)
size, err := reader.Size(quitC)
if err != nil {
- log.Warn("Couldnt get size of file %s : %v", file.path, err)
+ log.Error("Couldnt get size of file %s : %v", sf.path, err)
+ return err
}
- file.fileSize = size
+ sf.fileSize = size
+ log.Trace("swarmfs Attr", "size", size)
+ close(quitC)
}
- a.Size = uint64(file.fileSize)
+ a.Size = uint64(sf.fileSize)
return nil
}
func (sf *SwarmFile) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
-
+ log.Debug("swarmfs Read", "path", sf.path, "req.String", req.String())
sf.lock.RLock()
defer sf.lock.RUnlock()
if sf.reader == nil {
- sf.reader = sf.mountInfo.swarmApi.Retrieve(sf.key)
+ sf.reader, _ = sf.mountInfo.swarmApi.Retrieve(sf.addr)
}
buf := make([]byte, req.Size)
n, err := sf.reader.ReadAt(buf, req.Offset)
@@ -108,26 +113,23 @@ func (sf *SwarmFile) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse
}
resp.Data = buf[:n]
sf.reader = nil
- return err
+ return err
}
func (sf *SwarmFile) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error {
-
+ log.Debug("swarmfs Write", "path", sf.path, "req.String", req.String())
if sf.fileSize == 0 && req.Offset == 0 {
-
// A new file is created
err := addFileToSwarm(sf, req.Data, len(req.Data))
if err != nil {
return err
}
resp.Size = len(req.Data)
-
} else if req.Offset <= sf.fileSize {
-
totalSize := sf.fileSize + int64(len(req.Data))
if totalSize > MaxAppendFileSize {
- log.Warn("Append file size reached (%v) : (%v)", sf.fileSize, len(req.Data))
+ log.Warn("swarmfs Append file size reached (%v) : (%v)", sf.fileSize, len(req.Data))
return errFileSizeMaxLimixReached
}
@@ -137,9 +139,8 @@ func (sf *SwarmFile) Write(ctx context.Context, req *fuse.WriteRequest, resp *fu
}
resp.Size = len(req.Data)
} else {
- log.Warn("Invalid write request size(%v) : off(%v)", sf.fileSize, req.Offset)
+ log.Warn("swarmfs Invalid write request size(%v) : off(%v)", sf.fileSize, req.Offset)
return errInvalidOffset
}
-
return nil
}