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