From fddafc01d667f908359304a60678269c2019790c Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 26 May 2015 12:14:29 +0900 Subject: [PATCH] Misc fixes --- dir.go | 19 ++++++++++--- file.go | 84 ++++++++++++++++++++++++++++++--------------------------- 2 files changed, 61 insertions(+), 42 deletions(-) diff --git a/dir.go b/dir.go index f98b5a4..580fb40 100644 --- a/dir.go +++ b/dir.go @@ -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) diff --git a/file.go b/file.go index ad0724b..af6c964 100644 --- a/file.go +++ b/file.go @@ -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() }