This commit is contained in:
Alex Yatskov 2015-06-20 22:21:02 +09:00
parent ae588545bb
commit 60d28df429
3 changed files with 11 additions and 13 deletions

2
dir.go
View File

@ -95,7 +95,7 @@ func (vd *verDir) createFile(name string, flags fuse.OpenFlags, mode os.FileMode
node := newVerNode(childPath, vd.node.ver, nil, NodeFlagVer) node := newVerNode(childPath, vd.node.ver, nil, NodeFlagVer)
file := newVerFile(node, vd) file := newVerFile(node, vd)
handle, err := file.open(flags, mode, true) handle, err := file.open(flags, mode)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }

16
file.go
View File

@ -38,11 +38,11 @@ type verFile struct {
node *verNode node *verNode
inode uint64 inode uint64
parent *verDir parent *verDir
handles map[fuse.HandleID]*verFileHandle handles map[uint64]*verFileHandle
} }
func newVerFile(node *verNode, parent *verDir) *verFile { func newVerFile(node *verNode, parent *verDir) *verFile {
return &verFile{node, allocInode(), parent, make(map[fuse.HandleID]*verFileHandle)} return &verFile{node, allocInode(), parent, make(map[uint64]*verFileHandle)}
} }
func (vf *verFile) version() error { func (vf *verFile) version() error {
@ -62,8 +62,8 @@ func (vf *verFile) version() error {
return nil return nil
} }
func (vf *verFile) open(flags fuse.OpenFlags, mode os.FileMode, create bool) (*verFileHandle, error) { func (vf *verFile) open(flags fuse.OpenFlags, mode os.FileMode) (*verFileHandle, error) {
if !create && !flags.IsReadOnly() { if !flags.IsReadOnly() {
if err := vf.version(); err != nil { if err := vf.version(); err != nil {
return nil, err return nil, err
} }
@ -76,14 +76,14 @@ func (vf *verFile) open(flags fuse.OpenFlags, mode os.FileMode, create bool) (*v
return nil, err return nil, err
} }
id := fuse.HandleID(allocHandleId()) id := allocHandleId()
verHandle := &verFileHandle{vf, path, handle, id} verHandle := &verFileHandle{vf, path, handle, id}
vf.handles[id] = verHandle vf.handles[id] = verHandle
return verHandle, nil return verHandle, nil
} }
func (vf *verFile) release(handle fuse.HandleID) { func (vf *verFile) release(handle uint64) {
delete(vf.handles, handle) delete(vf.handles, handle)
} }
@ -106,7 +106,7 @@ func (vf *verFile) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *
// NodeOpener // NodeOpener
func (vf *verFile) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error) { func (vf *verFile) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error) {
handle, err := vf.open(req.Flags, 0644, false) handle, err := vf.open(req.Flags, 0644)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -133,7 +133,7 @@ type verFileHandle struct {
node *verFile node *verFile
path string path string
handle *os.File handle *os.File
id fuse.HandleID id uint64
} }
// HandleReader // HandleReader

View File

@ -32,8 +32,6 @@ import (
"strconv" "strconv"
"sync/atomic" "sync/atomic"
"time" "time"
"bazil.org/fuse"
) )
var inodeCnt, handleCnt uint64 var inodeCnt, handleCnt uint64
@ -42,8 +40,8 @@ func allocInode() uint64 {
return atomic.AddUint64(&inodeCnt, 1) return atomic.AddUint64(&inodeCnt, 1)
} }
func allocHandleId() fuse.HandleID { func allocHandleId() uint64 {
return fuse.HandleID(atomic.AddUint64(&handleCnt, 1)) return atomic.AddUint64(&handleCnt, 1)
} }
func copyFile(src, dst string) (int64, error) { func copyFile(src, dst string) (int64, error) {