Commit fa9a8c95 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Handle .drop_cache in Truncate and GetXAttr too.

Add test.
parent dc255238
......@@ -6,11 +6,11 @@ import (
"github.com/hanwen/go-fuse/fuse"
"log"
"os"
"syscall"
"path"
"path/filepath"
"sync"
"strings"
"sync"
"syscall"
"time"
)
......@@ -320,6 +320,10 @@ func (me *UnionFs) Symlink(pointedTo string, linkName string) (code fuse.Status)
}
func (me *UnionFs) Truncate(path string, offset uint64) (code fuse.Status) {
if path == _DROP_CACHE {
return fuse.OK
}
r := me.getBranch(path)
if r.branch > 0 {
code = me.Promote(path, r)
......@@ -549,6 +553,10 @@ func (me *UnionFs) GetAttr(name string) (a *os.FileInfo, s fuse.Status) {
}
func (me *UnionFs) GetXAttr(name string, attr string) ([]byte, fuse.Status) {
if name == _DROP_CACHE {
return nil, syscall.ENODATA
}
r := me.getBranch(name)
if r.branch >= 0 {
return me.fileSystems[r.branch].GetXAttr(name, attr)
......
......@@ -468,3 +468,44 @@ func TestRemoveAll(t *testing.T) {
}
}
func Readdirnames(dir string) ([]string, os.Error) {
f, err := os.Open(dir)
if err != nil {
return nil, err
}
defer f.Close()
return f.Readdirnames(-1)
}
func TestDropCache(t *testing.T) {
t.Log("TestDropCache")
wd, clean := setupUfs(t)
defer clean()
err := ioutil.WriteFile(wd + "/ro/file", []byte("bla"), 0644)
CheckSuccess(err)
_, err = os.Lstat(wd + "/mount/.drop_cache")
CheckSuccess(err)
names, err := Readdirnames(wd + "/mount")
CheckSuccess(err)
if len(names) != 1 || names[0] != "file" {
t.Fatal("unexpected names", names)
}
err = ioutil.WriteFile(wd + "/ro/file2", []byte("blabla"), 0644)
names2, err := Readdirnames(wd + "/mount")
CheckSuccess(err)
if len(names2) != len(names) {
t.Fatal("mismatch", names2)
}
err = ioutil.WriteFile(wd + "/mount/.drop_cache", []byte("does not matter"), 0644)
CheckSuccess(err)
names2, err = Readdirnames(wd + "/mount")
if len(names2) != 2 {
t.Fatal("mismatch 2", names2)
}
}
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