Commit 88feb302 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Fix typo: use links variable for retrieving symlinks.

Add tests.
parent 6281a8be
......@@ -161,7 +161,7 @@ func (me *CachingFileSystem) GetXAttr(name string, attr string) ([]byte, fuse.St
}
func (me *CachingFileSystem) Readlink(name string) (string, fuse.Status) {
r := me.attributes.Get(name).(*linkResponse)
r := me.links.Get(name).(*linkResponse)
return r.linkContent, r.Status
}
......
package unionfs
import (
"os"
"github.com/hanwen/go-fuse/fuse"
"fmt"
"log"
"syscall"
"testing"
)
var _ = fmt.Print
var _ = log.Print
func modeMapEq(m1, m2 map[string]uint32) bool {
if len(m1) != len(m2) {
return false
}
for k, v := range m1 {
val, ok := m2[k]
if !ok || val != v {
return false
}
}
return true
}
func TestCachingFs(t *testing.T) {
wd := fuse.MakeTempDir()
defer os.RemoveAll(wd)
fs := fuse.NewLoopbackFileSystem(wd)
cfs := NewCachingFileSystem(fs, 0)
os.Mkdir(wd+"/orig", 0755)
fi, code := cfs.GetAttr("orig")
if !code.Ok() {
t.Fatal("GetAttr failure", code)
}
if !fi.IsDirectory() {
t.Error("unexpected attr", fi)
}
os.Symlink("orig", wd+"/symlink")
val, code := cfs.Readlink("symlink")
if val != "orig" {
t.Error("unexpected readlink", val)
}
if !code.Ok() {
t.Error("code !ok ", code)
}
stream, code := cfs.OpenDir("")
if !code.Ok() {
t.Fatal("Readdir fail", code)
}
results := make(map[string]uint32)
for v := range stream {
results[v.Name] = v.Mode &^ 07777
}
expected := map[string]uint32{
"symlink": syscall.S_IFLNK,
"orig": fuse.S_IFDIR,
}
if !modeMapEq(results, expected) {
t.Error("Unexpected readdir result", results, expected)
}
}
......@@ -102,7 +102,7 @@ func mapEq(m1, m2 map[string]bool) bool {
}
for k, v := range m1 {
ok, val := m2[k]
val, ok := m2[k]
if !ok || val != v {
return false
}
......
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