2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-01 16:40:50 +00:00
restic/Godeps/_workspace/src/bazil.org/fuse/fs/fstestutil/testfs.go
2015-07-19 23:03:32 +02:00

53 lines
998 B
Go

package fstestutil
import (
"os"
"bazil.org/fuse"
"bazil.org/fuse/fs"
"golang.org/x/net/context"
)
// SimpleFS is a trivial FS that just implements the Root method.
type SimpleFS struct {
Node fs.Node
}
var _ = fs.FS(SimpleFS{})
func (f SimpleFS) Root() (fs.Node, error) {
return f.Node, nil
}
// File can be embedded in a struct to make it look like a file.
type File struct{}
func (f File) Attr(a *fuse.Attr) {
a.Mode = 0666
}
// Dir can be embedded in a struct to make it look like a directory.
type Dir struct{}
func (f Dir) Attr(a *fuse.Attr) {
a.Mode = os.ModeDir | 0777
}
// ChildMap is a directory with child nodes looked up from a map.
type ChildMap map[string]fs.Node
var _ = fs.Node(ChildMap{})
var _ = fs.NodeStringLookuper(ChildMap{})
func (f ChildMap) Attr(a *fuse.Attr) {
a.Mode = os.ModeDir | 0777
}
func (f ChildMap) Lookup(ctx context.Context, name string) (fs.Node, error) {
child, ok := f[name]
if !ok {
return nil, fuse.ENOENT
}
return child, nil
}