From 148d9879d56126d00a87d2b5336f55a9d2e6fe3e Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 16 May 2015 20:33:35 +0900 Subject: [PATCH] Better debugging messages --- dir.go | 11 ++++++++--- file.go | 5 +++++ fs/vfs_0/root/test_file | 1 + fs/vfs_2/root/test_file | 1 + node.go | 9 ++++++++- vfs.go | 6 +++--- 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/dir.go b/dir.go index 5259f79..99f6eaf 100644 --- a/dir.go +++ b/dir.go @@ -26,6 +26,7 @@ import ( "bazil.org/fuse" "bazil.org/fuse/fs" "golang.org/x/net/context" + "log" ) type versionedDir struct { @@ -44,27 +45,31 @@ func newVersionedDir(node *versionedNode, inode uint64) *versionedDir { } func (this versionedDir) Attr(attr *fuse.Attr) { + log.Printf("versionedDir::Attr: %s", this.node) + attr.Mode = this.node.info.Mode() attr.Inode = this.inode } func (this versionedDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) { - var entries []fuse.Dirent + log.Printf("versionedDir::ReadDirAll: %s", this.node) + var entries []fuse.Dirent for name, dir := range this.dirs { entry := fuse.Dirent{Inode: dir.inode, Name: name, Type: fuse.DT_File} entries = append(entries, entry) } - for name, file := range this.files { entry := fuse.Dirent{Inode: file.inode, Name: name, Type: fuse.DT_Dir} entries = append(entries, entry) } - return nil, nil + return entries, nil } func (this versionedDir) Lookup(ctx context.Context, name string) (fs.Node, error) { + log.Printf("versionedDir::Lookup: %s", this.node) + if dir, ok := this.dirs[name]; ok { return dir, nil } diff --git a/file.go b/file.go index 2d55671..e19a44d 100644 --- a/file.go +++ b/file.go @@ -26,6 +26,7 @@ import ( "bazil.org/fuse" "golang.org/x/net/context" "io/ioutil" + "log" ) type versionedFile struct { @@ -38,12 +39,16 @@ func newVersionedFile(node *versionedNode, inode uint64) *versionedFile { } func (this versionedFile) Attr(attr *fuse.Attr) { + log.Printf("versionedFile::Attr: %s", this.node) + attr.Mode = this.node.info.Mode() attr.Inode = this.inode attr.Size = uint64(this.node.info.Size()) } func (this versionedFile) ReadAll(ctx context.Context) ([]byte, error) { + log.Printf("versionedFile::ReadAll: %s", this.node) + bytes, err := ioutil.ReadFile(this.node.rebasedPath()) if err != nil { return nil, err diff --git a/fs/vfs_0/root/test_file b/fs/vfs_0/root/test_file index e69de29..802992c 100644 --- a/fs/vfs_0/root/test_file +++ b/fs/vfs_0/root/test_file @@ -0,0 +1 @@ +Hello world diff --git a/fs/vfs_2/root/test_file b/fs/vfs_2/root/test_file index e69de29..584c647 100644 --- a/fs/vfs_2/root/test_file +++ b/fs/vfs_2/root/test_file @@ -0,0 +1 @@ +Blahblahblah diff --git a/node.go b/node.go index 80f5ac9..b015217 100644 --- a/node.go +++ b/node.go @@ -22,7 +22,10 @@ package main -import "os" +import ( + "fmt" + "os" +) type versionedNode struct { path string @@ -35,3 +38,7 @@ type versionedNodeMap map[string]*versionedNode func (this *versionedNode) rebasedPath() string { return this.ver.rebasePath(this.path) } + +func (this *versionedNode) String() string { + return fmt.Sprintf("%s (%s)", this.path, this.rebasedPath()) +} diff --git a/vfs.go b/vfs.go index b05e4ea..35eb6d2 100644 --- a/vfs.go +++ b/vfs.go @@ -36,10 +36,10 @@ func main() { c, err := fuse.Mount( "mp", - fuse.FSName("helloworld"), - fuse.Subtype("hellofs"), + fuse.FSName("vfs"), + fuse.Subtype("vfs"), fuse.LocalVolume(), - fuse.VolumeName("Hello world!"), + fuse.VolumeName("vfs"), ) if err != nil { log.Fatal(err)