summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/fusefrontend/file.go10
-rw-r--r--internal/fusefrontend/fs.go22
2 files changed, 19 insertions, 13 deletions
diff --git a/internal/fusefrontend/file.go b/internal/fusefrontend/file.go
index ce806b6..33afcb9 100644
--- a/internal/fusefrontend/file.go
+++ b/internal/fusefrontend/file.go
@@ -41,9 +41,13 @@ type file struct {
header *contentenc.FileHeader
}
-func NewFile(fd *os.File, writeOnly bool, contentEnc *contentenc.ContentEnc) nodefs.File {
+func NewFile(fd *os.File, writeOnly bool, contentEnc *contentenc.ContentEnc) (nodefs.File, fuse.Status) {
var st syscall.Stat_t
- syscall.Fstat(int(fd.Fd()), &st)
+ err := syscall.Fstat(int(fd.Fd()), &st)
+ if err != nil {
+ toggledlog.Warn.Printf("NewFile: Fstat on fd %d failed: %v\n", fd.Fd(), err)
+ return nil, fuse.ToStatus(err)
+ }
wlock.register(st.Ino)
return &file{
@@ -51,7 +55,7 @@ func NewFile(fd *os.File, writeOnly bool, contentEnc *contentenc.ContentEnc) nod
writeOnly: writeOnly,
contentEnc: contentEnc,
ino: st.Ino,
- }
+ }, fuse.OK
}
// intFd - return the backing file descriptor as an integer. Used for debug
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) {