Commit 4e73fb9a authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

fuse/pathfs: fix LookupKnownChildren I/O errors

There was a thinko in PathFS.Lookup: if GetAttr returns OK, we did not
copy the attribute if there was a known child with that name. This
lead returning status OK, with a zeroed out Attr structure. The 0 mode
would sometimes lead to I/O errors, as files without type are not
allowed.

Fixes #239
parent 66a1eff3
......@@ -545,14 +545,15 @@ func (n *pathInode) Lookup(out *fuse.Attr, name string, context *fuse.Context) (
fullPath := filepath.Join(n.GetPath(), name)
fi, code := n.fs.GetAttr(fullPath, context)
node := n.Inode().GetChild(name)
if node != nil && (!code.Ok() || node.IsDir() != fi.IsDir()) {
n.Inode().RmChild(name)
node = nil
}
if code.Ok() && node == nil {
if code.Ok() {
if node == nil {
node = n.findChild(fi, name, fullPath).Inode()
}
*out = *fi
}
......
......@@ -933,3 +933,26 @@ func TestChgrp(t *testing.T) {
t.Errorf("Chown failed: %v", err)
}
}
func TestLookupKnownChildrenAttrCopied(t *testing.T) {
tc := NewTestCase(t)
defer tc.Cleanup()
if err := ioutil.WriteFile(tc.mountFile, []byte("hello"), 0644); err != nil {
t.Fatalf("WriteFile: %v", err)
}
fi, err := os.Lstat(tc.mountFile)
if err != nil {
t.Fatalf("WriteFile: %v", err)
}
mode := fi.Mode()
time.Sleep(2 * testTtl)
if fi, err = os.Lstat(tc.mountFile); err != nil {
t.Fatalf("Lstat: %v", err)
} else if fi.Mode() != mode {
t.Fatalf("got mode %o, want %o", fi.Mode(), mode)
}
}
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