Misc fixes

This commit is contained in:
Alex Yatskov 2015-05-26 12:14:29 +09:00
parent 5e10b3d8c1
commit fddafc01d6
2 changed files with 61 additions and 42 deletions

19
dir.go
View File

@ -26,7 +26,6 @@ import (
"bazil.org/fuse"
"bazil.org/fuse/fs"
"golang.org/x/net/context"
"log"
"os"
"path"
)
@ -82,8 +81,6 @@ func (this *versionedDir) createFile(name string, flags int) (*versionedFile, er
file := newVersionedFile(node, this)
file.handle = handle
log.Printf("createFile: %s => %v", childPath, file.node.info.Size())
this.files[name] = file
return file, nil
}
@ -93,6 +90,22 @@ func (this *versionedDir) Attr(attr *fuse.Attr) {
attr.Inode = this.inode
}
func (this *versionedDir) Getattr(ctx context.Context, req *fuse.GetattrRequest, resp *fuse.GetattrResponse) error {
info, err := os.Stat(this.node.rebasedPath())
if err != nil {
return err
}
this.node.info = info
this.Attr(&resp.Attr)
return nil
}
func (this *versionedDir) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error {
this.Attr(&resp.Attr)
return nil
}
func (this *versionedDir) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.CreateResponse) (fs.Node, fs.Handle, error) {
if req.Mode.IsDir() {
dir, err := this.createDir(req.Name)

84
file.go
View File

@ -27,7 +27,6 @@ import (
"bazil.org/fuse/fs"
"errors"
"golang.org/x/net/context"
"log"
"os"
)
@ -64,9 +63,51 @@ func (this *versionedFile) Attr(attr *fuse.Attr) {
attr.Inode = this.inode
}
func (this *versionedFile) Getattr(ctx context.Context, req *fuse.GetattrRequest, resp *fuse.GetattrResponse) error {
info, err := os.Stat(this.node.rebasedPath())
if err != nil {
return err
}
this.node.info = info
this.Attr(&resp.Attr)
return nil
}
func (this *versionedFile) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error {
this.Attr(&resp.Attr)
return nil
}
func (this *versionedFile) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
if this.handle == nil {
return errors.New("attempted to read from unopened file")
}
resp.Data = make([]byte, req.Size)
if _, err := this.handle.ReadAt(resp.Data, req.Offset); err != nil {
return err
}
return nil
}
func (this *versionedFile) ReadAll(ctx context.Context) ([]byte, error) {
if this.handle == nil {
return nil, errors.New("attempted to read from unopened file")
}
data := make([]byte, this.node.info.Size())
if _, err := this.handle.Read(data); err != nil {
return nil, err
}
return data, nil
}
func (this *versionedFile) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error {
if this.handle == nil {
return errors.New("attempted to write unopened file")
return errors.New("attempted to write to unopened file")
}
size, err := this.handle.WriteAt(req.Data, req.Offset)
@ -78,19 +119,6 @@ func (this *versionedFile) Write(ctx context.Context, req *fuse.WriteRequest, re
return nil
}
func (this *versionedFile) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error {
info, err := os.Stat(this.node.rebasedPath())
if err != nil {
return err
}
log.Printf("Setattr: %s => %v", this.node.path, req)
this.node.info = info
this.Attr(&resp.Attr)
return nil
}
func (this *versionedFile) Release(ctx context.Context, req *fuse.ReleaseRequest) error {
if this.handle == nil {
return errors.New("attempted to release unopened file")
@ -102,31 +130,9 @@ func (this *versionedFile) Release(ctx context.Context, req *fuse.ReleaseRequest
}
func (this *versionedFile) Fsync(ctx context.Context, req *fuse.FsyncRequest) error {
return nil
}
func (this *versionedFile) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
if this.handle == nil {
return errors.New("attempted to read unopened file")
return errors.New("attempted to sync unopened file")
}
resp.Data = make([]byte, req.Size)
if _, err := this.handle.ReadAt(resp.Data, req.Offset); err != nil {
return err
}
return nil
}
func (this *versionedFile) ReadAll(ctx context.Context) ([]byte, error) {
if this.handle == nil {
return nil, errors.New("attempted to read unopened file")
}
data := make([]byte, this.node.info.Size())
if _, err := this.handle.Read(data); err != nil {
return nil, err
}
return data, nil
return this.handle.Sync()
}