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

Add GetXAttr() to CachingFileSystem.

parent 45317e97
......@@ -4,15 +4,23 @@ import (
"fmt"
"github.com/hanwen/go-fuse/fuse"
"os"
"strings"
)
var _ = fmt.Println
const _XATTRSEP = "@XATTR@"
type attrResponse struct {
*os.FileInfo
fuse.Status
}
type xattrResponse struct {
data []byte
fuse.Status
}
type dirResponse struct {
entries []fuse.DirEntry
fuse.Status
......@@ -30,6 +38,7 @@ type CachingFileSystem struct {
attributes *TimedCache
dirs *TimedCache
links *TimedCache
xattr *TimedCache
}
func readDir(fs fuse.FileSystem, name string) *dirResponse {
......@@ -53,7 +62,16 @@ func readDir(fs fuse.FileSystem, name string) *dirResponse {
func getAttr(fs fuse.FileSystem, name string) *attrResponse {
a, code := fs.GetAttr(name)
return &attrResponse{
FileInfo: a,
FileInfo: a,
Status: code,
}
}
func getXAttr(fs fuse.FileSystem, nameAttr string) *xattrResponse {
ns := strings.Split(nameAttr, _XATTRSEP, 2)
a, code := fs.GetXAttr(ns[0], ns[1])
return &xattrResponse{
data: a,
Status: code,
}
}
......@@ -72,6 +90,9 @@ func NewCachingFileSystem(fs fuse.FileSystem, ttlNs int64) *CachingFileSystem {
c.attributes = NewTimedCache(func(n string) interface{} { return getAttr(fs, n) }, ttlNs)
c.dirs = NewTimedCache(func(n string) interface{} { return readDir(fs, n) }, ttlNs)
c.links = NewTimedCache(func(n string) interface{} { return readLink(fs, n) }, ttlNs)
c.xattr = NewTimedCache(func(n string) interface{} {
return getXAttr(fs, n)
},ttlNs)
return c
}
......@@ -80,6 +101,12 @@ func (me *CachingFileSystem) GetAttr(name string) (*os.FileInfo, fuse.Status) {
return r.FileInfo, r.Status
}
func (me *CachingFileSystem) GetXAttr(name string, attr string) ([]byte, fuse.Status) {
key := name + _XATTRSEP + attr
r := me.xattr.Get(key).(*xattrResponse)
return r.data, r.Status
}
func (me *CachingFileSystem) Readlink(name string) (string, fuse.Status) {
r := me.attributes.Get(name).(*linkResponse)
return r.linkContent, r.Status
......
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