Fixed bug with creating new files

This commit is contained in:
Alex Yatskov 2015-06-20 20:50:11 +09:00
parent ec4e931f68
commit ae588545bb
2 changed files with 9 additions and 19 deletions

19
dir.go
View File

@ -86,7 +86,7 @@ func (vd *verDir) createDir(name string) (*verDir, error) {
return dir, nil return dir, nil
} }
func (vd *verDir) createFile(name string, flags fuse.OpenFlags) (*verFile, *verFileHandle, error) { func (vd *verDir) createFile(name string, flags fuse.OpenFlags, mode os.FileMode) (*verFile, *verFileHandle, error) {
if err := vd.version(); err != nil { if err := vd.version(); err != nil {
return nil, nil, err return nil, nil, err
} }
@ -95,7 +95,7 @@ func (vd *verDir) createFile(name string, flags fuse.OpenFlags) (*verFile, *verF
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, true) handle, err := file.open(flags, mode, true)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -130,19 +130,10 @@ func (vd *verDir) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *f
// NodeCreater // NodeCreater
func (vd *verDir) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.CreateResponse) (node fs.Node, handle fs.Handle, err error) { func (vd *verDir) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.CreateResponse) (node fs.Node, handle fs.Handle, err error) {
if req.Mode.IsDir() { if req.Mode.IsDir() {
var dir *verDir node, err = vd.createDir(req.Name)
if dir, err = vd.createDir(req.Name); err == nil { handle = node
node = dir
handle = dir
}
} else if req.Mode.IsRegular() { } else if req.Mode.IsRegular() {
var file *verFile node, handle, err = vd.createFile(req.Name, req.Flags, req.Mode)
var vfh *verFileHandle
if file, vfh, err = vd.createFile(req.Name, req.Flags); err == nil {
node = file
handle = handle
resp.Handle = vfh.id
}
} else { } else {
err = errors.New("unsupported filetype") err = errors.New("unsupported filetype")
} }

View File

@ -62,7 +62,7 @@ func (vf *verFile) version() error {
return nil return nil
} }
func (vf *verFile) open(flags fuse.OpenFlags, create bool) (*verFileHandle, error) { func (vf *verFile) open(flags fuse.OpenFlags, mode os.FileMode, create bool) (*verFileHandle, error) {
if !create && !flags.IsReadOnly() { if !create && !flags.IsReadOnly() {
if err := vf.version(); err != nil { if err := vf.version(); err != nil {
return nil, err return nil, err
@ -71,7 +71,7 @@ func (vf *verFile) open(flags fuse.OpenFlags, create bool) (*verFileHandle, erro
path := vf.node.rebasedPath() path := vf.node.rebasedPath()
handle, err := os.OpenFile(path, int(flags), 0644) handle, err := os.OpenFile(path, int(flags), mode)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -106,12 +106,11 @@ 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, false) handle, err := vf.open(req.Flags, 0644, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp.Handle = handle.id
return handle, nil return handle, nil
} }
@ -178,6 +177,6 @@ func (vfh *verFileHandle) Release(ctx context.Context, req *fuse.ReleaseRequest)
vfh.handle.Close() vfh.handle.Close()
vfh.handle = nil vfh.handle = nil
vfh.node.release(req.Handle) vfh.node.release(vfh.id)
return nil return nil
} }