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

Add GetXAttr() to CachingFileSystem.

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