Commit 3d9d5c3f authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Hide pathfs.DefaultFileSystem to reduce API clutter.

parent f2ebdfe7
......@@ -11,8 +11,8 @@ import (
// Typically, each call happens in its own goroutine, so take care to
// make the file system thread-safe.
//
// Include DefaultFileSystem to provide a default null implementation of
// required methods.
// NewDefaultFileSystem provides a null implementation of required
// methods.
type FileSystem interface {
// Used for pretty printing.
String() string
......
......@@ -6,106 +6,110 @@ import (
"github.com/hanwen/go-fuse/fuse"
)
var _ = FileSystem((*DefaultFileSystem)(nil))
// NewDefaultFileSystem creates a filesystem that responds ENOSYS for
// all methods
func NewDefaultFileSystem() FileSystem {
return (*defaultFileSystem)(nil)
}
// DefaultFileSystem implements a FileSystem that returns ENOSYS for every operation.
type DefaultFileSystem struct{}
// defaultFileSystem implements a FileSystem that returns ENOSYS for every operation.
type defaultFileSystem struct{}
// DefaultFileSystem
func (fs *DefaultFileSystem) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.Status) {
// defaultFileSystem
func (fs *defaultFileSystem) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse.Status) {
return nil, fuse.ENOSYS
}
func (fs *DefaultFileSystem) GetXAttr(name string, attr string, context *fuse.Context) ([]byte, fuse.Status) {
func (fs *defaultFileSystem) GetXAttr(name string, attr string, context *fuse.Context) ([]byte, fuse.Status) {
return nil, fuse.ENOSYS
}
func (fs *DefaultFileSystem) SetXAttr(name string, attr string, data []byte, flags int, context *fuse.Context) fuse.Status {
func (fs *defaultFileSystem) SetXAttr(name string, attr string, data []byte, flags int, context *fuse.Context) fuse.Status {
return fuse.ENOSYS
}
func (fs *DefaultFileSystem) ListXAttr(name string, context *fuse.Context) ([]string, fuse.Status) {
func (fs *defaultFileSystem) ListXAttr(name string, context *fuse.Context) ([]string, fuse.Status) {
return nil, fuse.ENOSYS
}
func (fs *DefaultFileSystem) RemoveXAttr(name string, attr string, context *fuse.Context) fuse.Status {
func (fs *defaultFileSystem) RemoveXAttr(name string, attr string, context *fuse.Context) fuse.Status {
return fuse.ENOSYS
}
func (fs *DefaultFileSystem) Readlink(name string, context *fuse.Context) (string, fuse.Status) {
func (fs *defaultFileSystem) Readlink(name string, context *fuse.Context) (string, fuse.Status) {
return "", fuse.ENOSYS
}
func (fs *DefaultFileSystem) Mknod(name string, mode uint32, dev uint32, context *fuse.Context) fuse.Status {
func (fs *defaultFileSystem) Mknod(name string, mode uint32, dev uint32, context *fuse.Context) fuse.Status {
return fuse.ENOSYS
}
func (fs *DefaultFileSystem) Mkdir(name string, mode uint32, context *fuse.Context) fuse.Status {
func (fs *defaultFileSystem) Mkdir(name string, mode uint32, context *fuse.Context) fuse.Status {
return fuse.ENOSYS
}
func (fs *DefaultFileSystem) Unlink(name string, context *fuse.Context) (code fuse.Status) {
func (fs *defaultFileSystem) Unlink(name string, context *fuse.Context) (code fuse.Status) {
return fuse.ENOSYS
}
func (fs *DefaultFileSystem) Rmdir(name string, context *fuse.Context) (code fuse.Status) {
func (fs *defaultFileSystem) Rmdir(name string, context *fuse.Context) (code fuse.Status) {
return fuse.ENOSYS
}
func (fs *DefaultFileSystem) Symlink(value string, linkName string, context *fuse.Context) (code fuse.Status) {
func (fs *defaultFileSystem) Symlink(value string, linkName string, context *fuse.Context) (code fuse.Status) {
return fuse.ENOSYS
}
func (fs *DefaultFileSystem) Rename(oldName string, newName string, context *fuse.Context) (code fuse.Status) {
func (fs *defaultFileSystem) Rename(oldName string, newName string, context *fuse.Context) (code fuse.Status) {
return fuse.ENOSYS
}
func (fs *DefaultFileSystem) Link(oldName string, newName string, context *fuse.Context) (code fuse.Status) {
func (fs *defaultFileSystem) Link(oldName string, newName string, context *fuse.Context) (code fuse.Status) {
return fuse.ENOSYS
}
func (fs *DefaultFileSystem) Chmod(name string, mode uint32, context *fuse.Context) (code fuse.Status) {
func (fs *defaultFileSystem) Chmod(name string, mode uint32, context *fuse.Context) (code fuse.Status) {
return fuse.ENOSYS
}
func (fs *DefaultFileSystem) Chown(name string, uid uint32, gid uint32, context *fuse.Context) (code fuse.Status) {
func (fs *defaultFileSystem) Chown(name string, uid uint32, gid uint32, context *fuse.Context) (code fuse.Status) {
return fuse.ENOSYS
}
func (fs *DefaultFileSystem) Truncate(name string, offset uint64, context *fuse.Context) (code fuse.Status) {
func (fs *defaultFileSystem) Truncate(name string, offset uint64, context *fuse.Context) (code fuse.Status) {
return fuse.ENOSYS
}
func (fs *DefaultFileSystem) Open(name string, flags uint32, context *fuse.Context) (file fuse.File, code fuse.Status) {
func (fs *defaultFileSystem) Open(name string, flags uint32, context *fuse.Context) (file fuse.File, code fuse.Status) {
return nil, fuse.ENOSYS
}
func (fs *DefaultFileSystem) OpenDir(name string, context *fuse.Context) (stream []fuse.DirEntry, status fuse.Status) {
func (fs *defaultFileSystem) OpenDir(name string, context *fuse.Context) (stream []fuse.DirEntry, status fuse.Status) {
return nil, fuse.ENOSYS
}
func (fs *DefaultFileSystem) OnMount(nodeFs *PathNodeFs) {
func (fs *defaultFileSystem) OnMount(nodeFs *PathNodeFs) {
}
func (fs *DefaultFileSystem) OnUnmount() {
func (fs *defaultFileSystem) OnUnmount() {
}
func (fs *DefaultFileSystem) Access(name string, mode uint32, context *fuse.Context) (code fuse.Status) {
func (fs *defaultFileSystem) Access(name string, mode uint32, context *fuse.Context) (code fuse.Status) {
return fuse.ENOSYS
}
func (fs *DefaultFileSystem) Create(name string, flags uint32, mode uint32, context *fuse.Context) (file fuse.File, code fuse.Status) {
func (fs *defaultFileSystem) Create(name string, flags uint32, mode uint32, context *fuse.Context) (file fuse.File, code fuse.Status) {
return nil, fuse.ENOSYS
}
func (fs *DefaultFileSystem) Utimens(name string, Atime *time.Time, Mtime *time.Time, context *fuse.Context) (code fuse.Status) {
func (fs *defaultFileSystem) Utimens(name string, Atime *time.Time, Mtime *time.Time, context *fuse.Context) (code fuse.Status) {
return fuse.ENOSYS
}
func (fs *DefaultFileSystem) String() string {
return "DefaultFileSystem"
func (fs *defaultFileSystem) String() string {
return "defaultFileSystem"
}
func (fs *DefaultFileSystem) StatFs(name string) *fuse.StatfsOut {
func (fs *defaultFileSystem) StatFs(name string) *fuse.StatfsOut {
return nil
}
......@@ -17,15 +17,18 @@ var _ = log.Println
type loopbackFileSystem struct {
Root string
DefaultFileSystem
FileSystem
}
// A FUSE filesystem that shunts all request to an underlying file
// system. Its main purpose is to provide test coverage without
// having to build a synthetic filesystem.
func NewLoopbackFileSystem(root string) (out *loopbackFileSystem) {
out = new(loopbackFileSystem)
out.Root = root
out = &loopbackFileSystem{
FileSystem: NewDefaultFileSystem(),
Root: root,
}
return out
}
......
......@@ -10,7 +10,7 @@ import (
)
type ownerFs struct {
DefaultFileSystem
FileSystem
}
const _RANDOM_OWNER = 31415265
......@@ -32,7 +32,7 @@ func (fs *ownerFs) GetAttr(name string, context *fuse.Context) (*fuse.Attr, fuse
func setupOwnerTest(t *testing.T, opts *fuse.FileSystemOptions) (workdir string, cleanup func()) {
wd, err := ioutil.TempDir("", "go-fuse-owner_test")
fs := &ownerFs{}
fs := &ownerFs{NewDefaultFileSystem()}
nfs := NewPathNodeFs(fs, nil)
state, _, err := fuse.MountNodeFileSystem(wd, nfs, opts)
if err != nil {
......
......@@ -97,7 +97,7 @@ func (fs *PathNodeFs) OnUnmount() {
func (fs *PathNodeFs) String() string {
name := fs.fs.String()
if name == "DefaultFileSystem" {
if name == "defaultFileSystem" {
name = fmt.Sprintf("%T", fs.fs)
name = strings.TrimLeft(name, "*")
}
......
......@@ -24,13 +24,16 @@ type XAttrTestFs struct {
filename string
attrs map[string][]byte
DefaultFileSystem
FileSystem
}
func NewXAttrFs(nm string, m map[string][]byte) *XAttrTestFs {
x := new(XAttrTestFs)
x.filename = nm
x.attrs = make(map[string][]byte, len(m))
x := &XAttrTestFs{
filename: nm,
attrs: make(map[string][]byte, len(m)),
FileSystem: NewDefaultFileSystem(),
}
for k, v := range m {
x.attrs[k] = v
}
......
......@@ -109,7 +109,7 @@ func TestCacheFs(t *testing.T) {
}
type nonseekFs struct {
pathfs.DefaultFileSystem
pathfs.FileSystem
Length int
}
......@@ -134,7 +134,7 @@ func (fs *nonseekFs) Open(name string, flags uint32, context *fuse.Context) (fus
}
func TestNonseekable(t *testing.T) {
fs := &nonseekFs{}
fs := &nonseekFs{FileSystem: pathfs.NewDefaultFileSystem()}
fs.Length = 200 * 1024
dir, err := ioutil.TempDir("", "go-fuse-cache_test")
......
......@@ -2,7 +2,6 @@ package test
import (
"io/ioutil"
"log"
"os"
"testing"
......@@ -10,10 +9,9 @@ import (
"github.com/hanwen/go-fuse/fuse/pathfs"
)
var _ = log.Println
type DefaultReadFS struct {
pathfs.DefaultFileSystem
pathfs.FileSystem
size uint64
exist bool
}
......@@ -33,7 +31,10 @@ func (fs *DefaultReadFS) Open(name string, f uint32, context *fuse.Context) (fus
}
func defaultReadTest(t *testing.T) (root string, cleanup func()) {
fs := &DefaultReadFS{}
fs := &DefaultReadFS{
FileSystem: pathfs.NewDefaultFileSystem(),
}
var err error
dir, err := ioutil.TempDir("", "go-fuse")
if err != nil {
......
......@@ -90,7 +90,7 @@ func (f *MutableDataFile) Chmod(perms uint32) fuse.Status {
// This FS only supports a single r/w file called "/file".
type FSetAttrFs struct {
pathfs.DefaultFileSystem
pathfs.FileSystem
file *MutableDataFile
}
......@@ -162,7 +162,9 @@ func setupFAttrTest(t *testing.T, fs pathfs.FileSystem) (dir string, clean func(
}
func TestDataReadLarge(t *testing.T) {
fs := &FSetAttrFs{}
fs := &FSetAttrFs{
FileSystem: pathfs.NewDefaultFileSystem(),
}
dir, clean, _ := setupFAttrTest(t, fs)
defer clean()
......@@ -181,7 +183,9 @@ func TestDataReadLarge(t *testing.T) {
}
func TestFSetAttr(t *testing.T) {
fs := &FSetAttrFs{}
fs := &FSetAttrFs{
FileSystem: pathfs.NewDefaultFileSystem(),
}
dir, clean, sync := setupFAttrTest(t, fs)
defer clean()
......
......@@ -14,7 +14,7 @@ import (
var _ = log.Println
type NotifyFs struct {
pathfs.DefaultFileSystem
pathfs.FileSystem
size uint64
exist bool
}
......@@ -46,7 +46,7 @@ type NotifyTest struct {
func NewNotifyTest(t *testing.T) *NotifyTest {
me := &NotifyTest{}
me.fs = &NotifyFs{}
me.fs = &NotifyFs{FileSystem: pathfs.NewDefaultFileSystem()}
var err error
me.dir, err = ioutil.TempDir("", "go-fuse-notify_test")
if err != nil {
......
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