func TestDefaultNodeMount(t *testing.T) { dir, err := ioutil.TempDir("", "go-fuse") if err != nil { t.Fatalf("TempDir: %v", err) } defer os.RemoveAll(dir) root := nodefs.NewDefaultNode() s, conn, err := nodefs.MountRoot(dir, root, nil) if err != nil { t.Fatalf("MountRoot: %v", err) } go s.Serve() defer s.Unmount() if err := conn.Mount(root.Inode(), "sub", nodefs.NewDefaultNode(), nil); !err.Ok() { t.Fatalf("Mount: %v", err) } if entries, err := ioutil.ReadDir(dir); err != nil { t.Fatalf("ReadDir: %v", err) } else if len(entries) != 1 { t.Fatalf("got %d entries", len(entries)) } else if entries[0].Name() != "sub" { t.Fatalf("got %q, want %q", entries[0].Name(), "sub") } }
func TestMountOnExisting(t *testing.T) { ts := NewTestCase(t) defer ts.Cleanup() err := os.Mkdir(ts.mnt+"/mnt", 0777) if err != nil { t.Fatalf("Mkdir failed: %v", err) } nfs := nodefs.NewDefaultNode() code := ts.connector.Mount(ts.rootNode(), "mnt", nfs, nil) if code != fuse.EBUSY { t.Fatal("expect EBUSY:", code) } err = os.Remove(ts.mnt + "/mnt") if err != nil { t.Fatalf("Remove failed: %v", err) } code = ts.connector.Mount(ts.rootNode(), "mnt", nfs, nil) if !code.Ok() { t.Fatal("expect OK:", code) } code = ts.pathFs.Unmount("mnt") if !code.Ok() { t.Errorf("Unmount failed: %v", code) } }
func NewMemTreeFs(files map[string]MemFile) *MemTreeFs { fs := &MemTreeFs{ root: &memNode{Node: nodefs.NewDefaultNode()}, files: files, } fs.root.fs = fs return fs }
func (n *MemTreeFs) addFile(name string, f MemFile) { comps := strings.Split(name, "/") node := n.root.Inode() for i, c := range comps { child := node.GetChild(c) if child == nil { fsnode := &memNode{ Node: nodefs.NewDefaultNode(), fs: n, } if i == len(comps)-1 { fsnode.file = f } child = node.NewChild(c, fsnode.file == nil, fsnode) } node = child } }