Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix nil fileEntry #537

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion fs/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,9 @@ func (b *rawBridge) Create(cancel <-chan struct{}, input *fuse.CreateIn, name st
}

child, fe := b.addNewChild(parent, name, child, f, input.Flags|syscall.O_CREAT|syscall.O_EXCL, &out.EntryOut)
out.Fh = uint64(fe.fh)
if fe != nil {
out.Fh = uint64(fe.fh)
}
out.OpenFlags = flags

b.addBackingID(child, f, &out.OpenOut)
Expand Down
57 changes: 57 additions & 0 deletions fs/rawbridge_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package fs

import (
"context"
"os"
"syscall"
"testing"
"time"

"github.com/hanwen/go-fuse/v2/fuse"
)

// CustomFS is our file system structure.
type CustomFS struct {
Inode
}

// Implement Create method for CustomFS
func (f *CustomFS) Create(ctx context.Context, name string, flags uint32, mode uint32, out *fuse.EntryOut) (inode *Inode, fh FileHandle, fuseFlags uint32, errno syscall.Errno) {
child := f.NewPersistentInode(ctx, &Inode{}, StableAttr{Mode: fuse.S_IFREG})
return child, nil, 0, syscall.F_OK
}

func TestFileSystem(t *testing.T) {
// Create a temporary directory for mounting
mountDir, err := os.MkdirTemp("", "go-fuse-test")
if err != nil {
t.Fatalf("failed to create temp directory: %v", err)
}
defer os.RemoveAll(mountDir)

// Create a file system instance
root := &CustomFS{}
opts := &Options{}
opts.MountOptions.Options = append(opts.MountOptions.Options, "rw")
server, err := Mount(mountDir, root, &Options{})
if err != nil {
t.Fatalf("failed to mount filesystem: %v", err)
}
defer server.Unmount()

// Waiting for the file system to mount
time.Sleep(100 * time.Millisecond)

// Checking file creation
filePath := mountDir + "/test.file"
file, err := os.Create(filePath)
if err != nil {
t.Fatalf("failed to create file in mounted filesystem: %v", err)
}
file.Close()

// Check that the file was created
if _, err := os.Stat(filePath); os.IsNotExist(err) {
t.Fatalf("file not created in mounted filesystem")
}
}