Commit 0285ae75 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

fuse/nodefs: change Inode.New to Inode.NewChild.

NewChild also adds inode as a child.

Code that did:

  ch := n.Inode().New(isDir, fsNode)
  n.Inode().AddChild(name, ch)

should be changed to look like

  ch := n.Inode().NewChild(name, isDir, fsNode)
parent e8c92b25
...@@ -111,11 +111,12 @@ func (n *Inode) IsDir() bool { ...@@ -111,11 +111,12 @@ func (n *Inode) IsDir() bool {
return n.children != nil return n.children != nil
} }
// New creates a new inode that will exist within this mount. // NewChild adds a new child inode to this inode.
func (n *Inode) New(isDir bool, fsi Node) *Inode { func (n *Inode) NewChild(name string, isDir bool, fsi Node) *Inode {
ch := newInode(isDir, fsi) ch := newInode(isDir, fsi)
ch.mount = n.mount ch.mount = n.mount
n.generation = ch.mount.connector.nextGeneration() n.generation = ch.mount.connector.nextGeneration()
n.AddChild(name, ch)
return ch return ch
} }
......
...@@ -74,9 +74,9 @@ type memNode struct { ...@@ -74,9 +74,9 @@ type memNode struct {
info fuse.Attr info fuse.Attr
} }
func (n *memNode) newNode(isdir bool) *memNode { func (n *memNode) newNode(name string, isDir bool) *memNode {
newNode := n.fs.newNode() newNode := n.fs.newNode()
n.Inode().New(isdir, newNode) n.Inode().NewChild(name, isDir, newNode)
return newNode return newNode
} }
...@@ -97,9 +97,8 @@ func (n *memNode) StatFs() *fuse.StatfsOut { ...@@ -97,9 +97,8 @@ func (n *memNode) StatFs() *fuse.StatfsOut {
} }
func (n *memNode) Mkdir(name string, mode uint32, context *fuse.Context) (newNode Node, code fuse.Status) { func (n *memNode) Mkdir(name string, mode uint32, context *fuse.Context) (newNode Node, code fuse.Status) {
ch := n.newNode(true) ch := n.newNode(name, true)
ch.info.Mode = mode | fuse.S_IFDIR ch.info.Mode = mode | fuse.S_IFDIR
n.Inode().AddChild(name, ch.Inode())
return ch, fuse.OK return ch, fuse.OK
} }
...@@ -116,10 +115,9 @@ func (n *memNode) Rmdir(name string, context *fuse.Context) (code fuse.Status) { ...@@ -116,10 +115,9 @@ func (n *memNode) Rmdir(name string, context *fuse.Context) (code fuse.Status) {
} }
func (n *memNode) Symlink(name string, content string, context *fuse.Context) (newNode Node, code fuse.Status) { func (n *memNode) Symlink(name string, content string, context *fuse.Context) (newNode Node, code fuse.Status) {
ch := n.newNode(false) ch := n.newNode(name, false)
ch.info.Mode = fuse.S_IFLNK | 0777 ch.info.Mode = fuse.S_IFLNK | 0777
ch.link = content ch.link = content
n.Inode().AddChild(name, ch.Inode())
return ch, fuse.OK return ch, fuse.OK
} }
...@@ -137,14 +135,13 @@ func (n *memNode) Link(name string, existing Node, context *fuse.Context) (newNo ...@@ -137,14 +135,13 @@ func (n *memNode) Link(name string, existing Node, context *fuse.Context) (newNo
} }
func (n *memNode) Create(name string, flags uint32, mode uint32, context *fuse.Context) (file File, newNode Node, code fuse.Status) { func (n *memNode) Create(name string, flags uint32, mode uint32, context *fuse.Context) (file File, newNode Node, code fuse.Status) {
ch := n.newNode(false) ch := n.newNode(name, false)
ch.info.Mode = mode | fuse.S_IFREG ch.info.Mode = mode | fuse.S_IFREG
f, err := os.Create(ch.filename()) f, err := os.Create(ch.filename())
if err != nil { if err != nil {
return nil, nil, fuse.ToStatus(err) return nil, nil, fuse.ToStatus(err)
} }
n.Inode().AddChild(name, ch.Inode())
return ch.newFile(f), ch, fuse.OK return ch.newFile(f), ch, fuse.OK
} }
......
...@@ -292,7 +292,6 @@ func (n *pathInode) GetPath() string { ...@@ -292,7 +292,6 @@ func (n *pathInode) GetPath() string {
} }
func (n *pathInode) addChild(name string, child *pathInode) { func (n *pathInode) addChild(name string, child *pathInode) {
n.Inode().AddChild(name, child.Inode())
child.Parent = n child.Parent = n
child.Name = name child.Name = name
...@@ -420,7 +419,7 @@ func (n *pathInode) Mknod(name string, mode uint32, dev uint32, context *fuse.Co ...@@ -420,7 +419,7 @@ func (n *pathInode) Mknod(name string, mode uint32, dev uint32, context *fuse.Co
fullPath := filepath.Join(n.GetPath(), name) fullPath := filepath.Join(n.GetPath(), name)
code = n.fs.Mknod(fullPath, mode, dev, context) code = n.fs.Mknod(fullPath, mode, dev, context)
if code.Ok() { if code.Ok() {
pNode := n.createChild(false) pNode := n.createChild(name, false)
newNode = pNode newNode = pNode
n.addChild(name, pNode) n.addChild(name, pNode)
} }
...@@ -431,7 +430,7 @@ func (n *pathInode) Mkdir(name string, mode uint32, context *fuse.Context) (newN ...@@ -431,7 +430,7 @@ func (n *pathInode) Mkdir(name string, mode uint32, context *fuse.Context) (newN
fullPath := filepath.Join(n.GetPath(), name) fullPath := filepath.Join(n.GetPath(), name)
code = n.fs.Mkdir(fullPath, mode, context) code = n.fs.Mkdir(fullPath, mode, context)
if code.Ok() { if code.Ok() {
pNode := n.createChild(true) pNode := n.createChild(name, true)
newNode = pNode newNode = pNode
n.addChild(name, pNode) n.addChild(name, pNode)
} }
...@@ -458,7 +457,7 @@ func (n *pathInode) Symlink(name string, content string, context *fuse.Context) ...@@ -458,7 +457,7 @@ func (n *pathInode) Symlink(name string, content string, context *fuse.Context)
fullPath := filepath.Join(n.GetPath(), name) fullPath := filepath.Join(n.GetPath(), name)
code = n.fs.Symlink(content, fullPath, context) code = n.fs.Symlink(content, fullPath, context)
if code.Ok() { if code.Ok() {
pNode := n.createChild(false) pNode := n.createChild(name, false)
newNode = pNode newNode = pNode
n.addChild(name, pNode) n.addChild(name, pNode)
} }
...@@ -473,6 +472,7 @@ func (n *pathInode) Rename(oldName string, newParent nodefs.Node, newName string ...@@ -473,6 +472,7 @@ func (n *pathInode) Rename(oldName string, newParent nodefs.Node, newName string
if code.Ok() { if code.Ok() {
ch := n.rmChild(oldName) ch := n.rmChild(oldName)
p.rmChild(newName) p.rmChild(newName)
p.Inode().AddChild(newName, ch.Inode())
p.addChild(newName, ch) p.addChild(newName, ch)
} }
return code return code
...@@ -496,9 +496,10 @@ func (n *pathInode) Link(name string, existingFsnode nodefs.Node, context *fuse. ...@@ -496,9 +496,10 @@ func (n *pathInode) Link(name string, existingFsnode nodefs.Node, context *fuse.
if code.Ok() { if code.Ok() {
if existing.clientInode != 0 && existing.clientInode == a.Ino { if existing.clientInode != 0 && existing.clientInode == a.Ino {
newNode = existing newNode = existing
n.Inode().AddChild(name, existing.Inode())
n.addChild(name, existing) n.addChild(name, existing)
} else { } else {
pNode := n.createChild(false) pNode := n.createChild(name, false)
newNode = pNode newNode = pNode
pNode.clientInode = a.Ino pNode.clientInode = a.Ino
n.addChild(name, pNode) n.addChild(name, pNode)
...@@ -511,19 +512,19 @@ func (n *pathInode) Create(name string, flags uint32, mode uint32, context *fuse ...@@ -511,19 +512,19 @@ func (n *pathInode) Create(name string, flags uint32, mode uint32, context *fuse
fullPath := filepath.Join(n.GetPath(), name) fullPath := filepath.Join(n.GetPath(), name)
file, code = n.fs.Create(fullPath, flags, mode, context) file, code = n.fs.Create(fullPath, flags, mode, context)
if code.Ok() { if code.Ok() {
pNode := n.createChild(false) pNode := n.createChild(name, false)
newNode = pNode newNode = pNode
n.addChild(name, pNode) n.addChild(name, pNode)
} }
return return
} }
func (n *pathInode) createChild(isDir bool) *pathInode { func (n *pathInode) createChild(name string, isDir bool) *pathInode {
i := new(pathInode) i := new(pathInode)
i.fs = n.fs i.fs = n.fs
i.pathFs = n.pathFs i.pathFs = n.pathFs
n.Inode().New(isDir, i) n.Inode().NewChild(name, isDir, i)
return i return i
} }
...@@ -564,7 +565,7 @@ func (n *pathInode) findChild(fi *fuse.Attr, name string, fullPath string) (out ...@@ -564,7 +565,7 @@ func (n *pathInode) findChild(fi *fuse.Attr, name string, fullPath string) (out
} }
if out == nil { if out == nil {
out = n.createChild(fi.IsDir()) out = n.createChild(name, fi.IsDir())
out.clientInode = fi.Ino out.clientInode = fi.Ino
n.addChild(name, out) n.addChild(name, out)
} else { } else {
......
...@@ -62,8 +62,7 @@ func TestDeleteNotify(t *testing.T) { ...@@ -62,8 +62,7 @@ func TestDeleteNotify(t *testing.T) {
Node: ch.Node(), Node: ch.Node(),
ok: make(chan int), ok: make(chan int),
} }
newCh := fs.Root().Inode().New(true, &flip) fs.Root().Inode().NewChild("testdir", true, &flip)
fs.Root().Inode().AddChild("testdir", newCh)
err = ioutil.WriteFile(mnt+"/testdir/testfile", []byte{42}, 0644) err = ioutil.WriteFile(mnt+"/testdir/testfile", []byte{42}, 0644)
if err != nil { if err != nil {
......
...@@ -119,8 +119,7 @@ func (n *MemTreeFs) addFile(name string, f MemFile) { ...@@ -119,8 +119,7 @@ func (n *MemTreeFs) addFile(name string, f MemFile) {
fsnode.file = f fsnode.file = f
} }
child = node.New(fsnode.file == nil, fsnode) child = node.NewChild(c, fsnode.file == nil, fsnode)
node.AddChild(c, child)
} }
node = child node = child
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment