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

Add a Name function to the FileSystem.

parent 5f46e065
......@@ -16,6 +16,9 @@ import (
// Include DefaultFileSystem to provide a default null implementation of
// required methods.
type FileSystem interface {
// Used for pretty printing.
Name() string
// Attributes
GetAttr(name string) (*os.FileInfo, Status)
......
......@@ -276,3 +276,7 @@ func (me *DefaultFileSystem) Create(name string, flags uint32, mode uint32) (fil
func (me *DefaultFileSystem) Utimens(name string, AtimeNs uint64, CtimeNs uint64) (code Status) {
return ENOSYS
}
func (me *DefaultFileSystem) Name() string {
return "DefaultFileSystem"
}
......@@ -158,3 +158,8 @@ func (me *LoopbackFileSystem) ListXAttr(name string) ([]string, Status) {
func (me *LoopbackFileSystem) RemoveXAttr(name string, attr string) Status {
return Status(Removexattr(me.GetPath(name), attr))
}
func (me *LoopbackFileSystem) Name() string {
return fmt.Sprintf("LoopbackFileSystem(%s)", me.Root)
}
package unionfs
import (
"fmt"
"github.com/hanwen/go-fuse/fuse"
"log"
"os"
......@@ -59,6 +60,10 @@ func NewAutoUnionFs(directory string, options AutoUnionFsOptions) *AutoUnionFs {
return a
}
func (me *AutoUnionFs) Name() string {
return fmt.Sprintf("AutoUnionFs(%s)", me.root)
}
func (me *AutoUnionFs) Mount(connector *fuse.FileSystemConnector) {
me.connector = connector
if me.options.UpdateOnMount {
......@@ -356,3 +361,4 @@ func (me *AutoUnionFs) OpenDir(name string) (stream chan fuse.DirEntry, status f
close(stream)
return stream, status
}
......@@ -139,6 +139,10 @@ func (me *CachingFileSystem) OpenDir(name string) (stream chan fuse.DirEntry, st
return nil, r.Status
}
func (me *CachingFileSystem) Name() string {
return fmt.Sprintf("CachingFileSystem(%s)", me.FileSystem.Name())
}
func (me *CachingFileSystem) Open(name string, flags uint32) (f fuse.File, status fuse.Status) {
if flags&fuse.O_ANYWRITE != 0 && name == _DROP_CACHE {
me.DropCache()
......
package unionfs
import (
"fmt"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/zipfs"
"os"
......@@ -32,6 +31,5 @@ func NewUnionFsFromRoots(roots []string, opts *UnionFsOptions, roCaching bool) (
fses = append(fses, fs)
}
identifier := fmt.Sprintf("%v", roots)
return NewUnionFs(identifier, fses, *opts), nil
return NewUnionFs(fses, *opts), nil
}
......@@ -60,8 +60,6 @@ func filePathHash(path string) string {
type UnionFs struct {
fuse.DefaultFileSystem
name string
// The same, but as interfaces.
fileSystems []fuse.FileSystem
......@@ -84,9 +82,8 @@ const (
_DROP_CACHE = ".drop_cache"
)
func NewUnionFs(name string, fileSystems []fuse.FileSystem, options UnionFsOptions) *UnionFs {
func NewUnionFs(fileSystems []fuse.FileSystem, options UnionFsOptions) *UnionFs {
g := new(UnionFs)
g.name = name
g.options = &options
g.fileSystems = fileSystems
......@@ -745,7 +742,7 @@ func (me *UnionFs) DropSubFsCaches() {
func (me *UnionFs) Open(name string, flags uint32) (fuseFile fuse.File, status fuse.Status) {
if name == _DROP_CACHE {
if flags&fuse.O_ANYWRITE != 0 {
log.Println("Forced cache drop on", me.name)
log.Println("Forced cache drop on", me.Name())
me.DropBranchCache()
me.DropDeletionCache()
me.DropSubFsCaches()
......@@ -778,5 +775,9 @@ func (me *UnionFs) Flush(name string) fuse.Status {
}
func (me *UnionFs) Name() string {
return me.name
names := []string{}
for _, fs := range me.fileSystems {
names = append(names, fs.Name())
}
return fmt.Sprintf("%v", names)
}
......@@ -42,7 +42,7 @@ func setupUfs(t *testing.T) (workdir string, cleanup func()) {
fses = append(fses, fuse.NewLoopbackFileSystem(wd+"/rw"))
fses = append(fses,
NewCachingFileSystem(fuse.NewLoopbackFileSystem(wd+"/ro"), 0))
ufs := NewUnionFs("testFs", fses, testOpts)
ufs := NewUnionFs(fses, testOpts)
// We configure timeouts are smaller, so we can check for
// UnionFs's cache consistency.
......@@ -630,7 +630,7 @@ func TestDisappearing(t *testing.T) {
var fses []fuse.FileSystem
fses = append(fses, wrFs)
fses = append(fses, fuse.NewLoopbackFileSystem(wd+"/ro"))
ufs := NewUnionFs("testFs", fses, testOpts)
ufs := NewUnionFs(fses, testOpts)
opts := &fuse.FileSystemOptions{
EntryTimeout: entryTtl,
......
......@@ -89,6 +89,10 @@ func NewMemTreeFileSystem(t *MemTree) *MemTreeFileSystem {
const mem_DIRMODE uint32 = fuse.S_IFDIR | 0500
const mem_FILEMODE uint32 = fuse.S_IFREG | 0400
func (me *MemTreeFileSystem) Name() string {
return "MemTreeFileSystem"
}
func (me *MemTreeFileSystem) GetAttr(name string) (*os.FileInfo, fuse.Status) {
dir, file := me.tree.Lookup(name)
if dir == nil {
......
......@@ -46,6 +46,10 @@ func NewMultiZipFs() *MultiZipFs {
return m
}
func (me *MultiZipFs) Name() string {
return "MultiZipFs"
}
func (me *MultiZipFs) Mount(connector *fuse.FileSystemConnector) {
me.Connector = connector
}
......
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