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