Commit 5edbae8e authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

fuse/nodefs: don't crash if trying to rename nonexistent entry.

This could happen to unionfs with ClientInodes set, and manipulations
that skipped the backing store.  Added a test.
parent de289915
......@@ -304,6 +304,9 @@ func (c *rawBridge) Rename(input *fuse.RenameIn, oldName string, newName string)
oldParent := c.toInode(input.NodeId)
child := oldParent.GetChild(oldName)
if child == nil {
return fuse.ENOENT
}
if child.mountPoint != nil {
return fuse.EBUSY
}
......
......@@ -567,8 +567,9 @@ func (n *pathInode) findChild(fi *fuse.Attr, name string, fullPath string) (out
out = n.createChild(fi.IsDir())
out.clientInode = fi.Ino
n.addChild(name, out)
} else {
// should add 'out' as a child to n ?
}
return out
}
......
......@@ -88,6 +88,7 @@ func setupUfs(t *testing.T) (workdir string, cleanup func()) {
EntryTimeout: entryTtl / 2,
AttrTimeout: entryTtl / 2,
NegativeTimeout: entryTtl / 2,
PortableInodes: true,
}
pathfs := pathfs.NewPathNodeFs(ufs,
......@@ -1491,3 +1492,30 @@ func TestUnionFsCheckHiddenFiles(t *testing.T) {
t.Fatal("unexpected names", names)
}
}
func TestUnionFSBarf(t *testing.T) {
wd, clean := setupUfs(t)
defer clean()
if err := os.Mkdir(wd+"/mnt/dir", 0755); err != nil {
t.Fatalf("os.Mkdir: %v", err)
}
if err := os.Mkdir(wd+"/mnt/dir2", 0755); err != nil {
t.Fatalf("os.Mkdir: %v", err)
}
if err := ioutil.WriteFile(wd+"/rw/dir/file", []byte("bla"), 0644); err != nil {
t.Fatalf("WriteFile failed: %v", err)
}
if _, err := os.Lstat(wd+"/mnt/dir/file"); err != nil {
t.Fatalf("Lstat: %v", err)
}
if err := os.Rename(wd+"/rw/dir/file", wd+"/rw/file"); err != nil {
t.Fatalf("os.Rename: %v", err)
}
err := os.Rename(wd+"/mnt/file", wd+"/mnt/dir2/file")
if fuse.ToStatus(err) != fuse.ENOENT {
// TODO - this should just succeed?
t.Fatalf("os.Rename: %v", err)
}
}
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