func main() { // Scans the arg list and sets up flags debug := flag.Bool("debug", false, "print debugging messages.") flag.Parse() if flag.NArg() < 2 { // TODO - where to get program name? fmt.Println("usage: main MOUNTPOINT BACKING-PREFIX") os.Exit(2) } mountPoint := flag.Arg(0) prefix := flag.Arg(1) fs := nodefs.NewMemNodeFs(prefix) conn := nodefs.NewFileSystemConnector(fs, nil) server, err := fuse.NewServer(conn.RawFS(), mountPoint, nil) if err != nil { fmt.Printf("Mount fail: %v\n", err) os.Exit(1) } server.SetDebug(*debug) fmt.Println("Mounted!") server.Serve() }
func TestDeleteNotify(t *testing.T) { dir, err := ioutil.TempDir("", "go-fuse-delete_test") if err != nil { t.Fatalf("TempDir failed %v", err) } defer os.RemoveAll(dir) fs := nodefs.NewMemNodeFs(dir + "/backing") conn := nodefs.NewFileSystemConnector(fs, &nodefs.Options{PortableInodes: true}) mnt := dir + "/mnt" err = os.Mkdir(mnt, 0755) if err != nil { t.Fatal(err) } state, err := fuse.NewServer(conn.RawFS(), mnt, nil) if err != nil { t.Fatal(err) } state.SetDebug(VerboseTest()) go state.Serve() defer state.Unmount() _, code := fs.Root().Mkdir("testdir", 0755, nil) if !code.Ok() { t.Fatal(code) } ch := fs.Root().Inode().RmChild("testdir") ch.Node().SetInode(nil) flip := flipNode{ Node: ch.Node(), ok: make(chan int), } newCh := fs.Root().Inode().New(true, &flip) fs.Root().Inode().AddChild("testdir", newCh) err = ioutil.WriteFile(mnt+"/testdir/testfile", []byte{42}, 0644) if err != nil { t.Fatal(err) } // Do the test here, so we surely have state.KernelSettings() if state.KernelSettings().Minor < 18 { t.Log("Kernel does not support deletion notify; aborting test.") return } buf := bytes.Buffer{} cmd := exec.Command("/usr/bin/tail", "-f", "testfile") cmd.Dir = mnt + "/testdir" cmd.Stdin = &buf cmd.Stdout = &bytes.Buffer{} cmd.Stderr = os.Stderr err = cmd.Start() if err != nil { t.Fatal(err) } defer func() { cmd.Process.Kill() time.Sleep(100 * time.Millisecond) }() // Wait until tail opened the file. time.Sleep(100 * time.Millisecond) err = os.Remove(mnt + "/testdir/testfile") if err != nil { t.Fatal(err) } // Simulate deletion+mkdir coming from the network close(flip.ok) oldCh := fs.Root().Inode().RmChild("testdir") _, code = fs.Root().Inode().Node().Mkdir("testdir", 0755, nil) if !code.Ok() { t.Fatal("mkdir status", code) } conn.DeleteNotify(fs.Root().Inode(), oldCh, "testdir") _, err = os.Lstat(mnt + "/testdir") if err != nil { t.Fatalf("lstat after del + mkdir failed: %v", err) } }