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

View File

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