diff options
author | Jakob Unterwurzacher | 2016-05-29 22:41:46 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2016-05-29 22:43:48 +0200 |
commit | fd53dfd2ad88d9d277e5ab93fba1b81a5f2255d4 (patch) | |
tree | 488d411a2dde99390a2500cd505c87617e01335f /internal/fusefrontend/fs.go | |
parent | 77813bdc13118fd08bbff7a68c9d5268080a2a15 (diff) |
fusefronted: check Fstat return value on file create
The Fstat call should never fail, but still, if it does return an error
it should be handled properly.
Diffstat (limited to 'internal/fusefrontend/fs.go')
-rw-r--r-- | internal/fusefrontend/fs.go | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/internal/fusefrontend/fs.go b/internal/fusefrontend/fs.go index b7528a1..1ef88b7 100644 --- a/internal/fusefrontend/fs.go +++ b/internal/fusefrontend/fs.go @@ -100,7 +100,7 @@ func (fs *FS) Open(path string, flags uint32, context *fuse.Context) (fuseFile n return nil, fuse.ToStatus(err) } - return NewFile(f, writeOnly, fs.contentEnc), fuse.OK + return NewFile(f, writeOnly, fs.contentEnc) } func (fs *FS) Create(path string, flags uint32, mode uint32, context *fuse.Context) (fuseFile nodefs.File, code fuse.Status) { @@ -113,8 +113,10 @@ func (fs *FS) Create(path string, flags uint32, mode uint32, context *fuse.Conte return nil, fuse.ToStatus(err) } - // Handle long file name + var fd *os.File cName := filepath.Base(cPath) + + // Handle long file name if nametransform.IsLongContent(cName) { var dirfd *os.File dirfd, err = os.Open(filepath.Dir(cPath)) @@ -136,16 +138,16 @@ func (fs *FS) Create(path string, flags uint32, mode uint32, context *fuse.Conte nametransform.DeleteLongName(dirfd, cName) return nil, fuse.ToStatus(err) } - fd := os.NewFile(uintptr(fdRaw), cName) - - return NewFile(fd, writeOnly, fs.contentEnc), fuse.OK + fd = os.NewFile(uintptr(fdRaw), cName) + } else { + // Normal (short) file name + fd, err = os.OpenFile(cPath, iflags|os.O_CREATE, os.FileMode(mode)) + if err != nil { + return nil, fuse.ToStatus(err) + } } - fd, err := os.OpenFile(cPath, iflags|os.O_CREATE, os.FileMode(mode)) - if err != nil { - return nil, fuse.ToStatus(err) - } - return NewFile(fd, writeOnly, fs.contentEnc), fuse.OK + return NewFile(fd, writeOnly, fs.contentEnc) } func (fs *FS) Chmod(path string, mode uint32, context *fuse.Context) (code fuse.Status) { |