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 {
return n.children != nil
}
// New creates a new inode that will exist within this mount.
func (n *Inode) New(isDir bool, fsi Node) *Inode {
// NewChild adds a new child inode to this inode.
func (n *Inode) NewChild(name string, isDir bool, fsi Node) *Inode {
ch := newInode(isDir, fsi)
ch.mount = n.mount
n.generation = ch.mount.connector.nextGeneration()
n.AddChild(name, ch)
return ch
}
......
......@@ -74,9 +74,9 @@ type memNode struct {
info fuse.Attr
}
func (n *memNode) newNode(isdir bool) *memNode {
func (n *memNode) newNode(name string, isDir bool) *memNode {
newNode := n.fs.newNode()
n.Inode().New(isdir, newNode)
n.Inode().NewChild(name, isDir, newNode)
return newNode
}
......@@ -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) {
ch := n.newNode(true)
ch := n.newNode(name, true)
ch.info.Mode = mode | fuse.S_IFDIR
n.Inode().AddChild(name, ch.Inode())
return ch, fuse.OK
}
......@@ -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) {
ch := n.newNode(false)
ch := n.newNode(name, false)
ch.info.Mode = fuse.S_IFLNK | 0777
ch.link = content
n.Inode().AddChild(name, ch.Inode())
return ch, fuse.OK
}
......@@ -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) {
ch := n.newNode(false)
ch := n.newNode(name, false)
ch.info.Mode = mode | fuse.S_IFREG
f, err := os.Create(ch.filename())
if err != nil {
return nil, nil, fuse.ToStatus(err)
}
n.Inode().AddChild(name, ch.Inode())
return ch.newFile(f), ch, fuse.OK
}
......
......@@ -292,7 +292,6 @@ func (n *pathInode) GetPath() string {
}
func (n *pathInode) addChild(name string, child *pathInode) {
n.Inode().AddChild(name, child.Inode())
child.Parent = n
child.Name = name
......@@ -420,7 +419,7 @@ func (n *pathInode) Mknod(name string, mode uint32, dev uint32, context *fuse.Co
fullPath := filepath.Join(n.GetPath(), name)
code = n.fs.Mknod(fullPath, mode, dev, context)
if code.Ok() {
pNode := n.createChild(false)
pNode := n.createChild(name, false)
newNode = pNode
n.addChild(name, pNode)
}
......@@ -431,7 +430,7 @@ func (n *pathInode) Mkdir(name string, mode uint32, context *fuse.Context) (newN
fullPath := filepath.Join(n.GetPath(), name)
code = n.fs.Mkdir(fullPath, mode, context)
if code.Ok() {
pNode := n.createChild(true)
pNode := n.createChild(name, true)
newNode = pNode
n.addChild(name, pNode)
}
......@@ -458,7 +457,7 @@ func (n *pathInode) Symlink(name string, content string, context *fuse.Context)
fullPath := filepath.Join(n.GetPath(), name)
code = n.fs.Symlink(content, fullPath, context)
if code.Ok() {
pNode := n.createChild(false)
pNode := n.createChild(name, false)
newNode = pNode
n.addChild(name, pNode)
}
......@@ -473,6 +472,7 @@ func (n *pathInode) Rename(oldName string, newParent nodefs.Node, newName string
if code.Ok() {
ch := n.rmChild(oldName)
p.rmChild(newName)
p.Inode().AddChild(newName, ch.Inode())
p.addChild(newName, ch)
}
return code
......@@ -496,9 +496,10 @@ func (n *pathInode) Link(name string, existingFsnode nodefs.Node, context *fuse.
if code.Ok() {
if existing.clientInode != 0 && existing.clientInode == a.Ino {
newNode = existing
n.Inode().AddChild(name, existing.Inode())
n.addChild(name, existing)
} else {
pNode := n.createChild(false)
pNode := n.createChild(name, false)
newNode = pNode
pNode.clientInode = a.Ino
n.addChild(name, pNode)
......@@ -511,19 +512,19 @@ func (n *pathInode) Create(name string, flags uint32, mode uint32, context *fuse
fullPath := filepath.Join(n.GetPath(), name)
file, code = n.fs.Create(fullPath, flags, mode, context)
if code.Ok() {
pNode := n.createChild(false)
pNode := n.createChild(name, false)
newNode = pNode
n.addChild(name, pNode)
}
return
}
func (n *pathInode) createChild(isDir bool) *pathInode {
func (n *pathInode) createChild(name string, isDir bool) *pathInode {
i := new(pathInode)
i.fs = n.fs
i.pathFs = n.pathFs
n.Inode().New(isDir, i)
n.Inode().NewChild(name, isDir, i)
return i
}
......@@ -564,7 +565,7 @@ func (n *pathInode) findChild(fi *fuse.Attr, name string, fullPath string) (out
}
if out == nil {
out = n.createChild(fi.IsDir())
out = n.createChild(name, fi.IsDir())
out.clientInode = fi.Ino
n.addChild(name, out)
} else {
......
......@@ -62,8 +62,7 @@ func TestDeleteNotify(t *testing.T) {
Node: ch.Node(),
ok: make(chan int),
}
newCh := fs.Root().Inode().New(true, &flip)
fs.Root().Inode().AddChild("testdir", newCh)
fs.Root().Inode().NewChild("testdir", true, &flip)
err = ioutil.WriteFile(mnt+"/testdir/testfile", []byte{42}, 0644)
if err != nil {
......
......@@ -119,8 +119,7 @@ func (n *MemTreeFs) addFile(name string, f MemFile) {
fsnode.file = f
}
child = node.New(fsnode.file == nil, fsnode)
node.AddChild(c, child)
child = node.NewChild(c, fsnode.file == nil, fsnode)
}
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