From 9d4fcebedf1042df2ab24a68a9e207efe0173450 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Mon, 2 Mar 2015 14:22:59 +1100 Subject: [PATCH] Implemented memFS.OpenDir. --- samples/memfs/fs.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/samples/memfs/fs.go b/samples/memfs/fs.go index 04ebc6e..ecb01c1 100644 --- a/samples/memfs/fs.go +++ b/samples/memfs/fs.go @@ -4,6 +4,8 @@ package memfs import ( + "fmt" + "github.com/jacobsa/fuse" "github.com/jacobsa/fuse/fuseutil" "github.com/jacobsa/gcloud/syncutil" @@ -64,3 +66,25 @@ func (fs *memFS) Init( resp = &fuse.InitResponse{} return } + +func (fs *memFS) OpenDir( + ctx context.Context, + req *fuse.OpenDirRequest) (resp *fuse.OpenDirResponse, err error) { + fs.mu.RLock() + defer fs.mu.RUnlock() + + // We don't mutate spontaneosuly, so if the VFS layer has asked for an + // inode that doesn't exist, something screwed up earlier (a lookup, a + // cache invalidation, etc.). + if req.Inode >= fuse.InodeID(len(fs.inodes)) { + panic(fmt.Sprintf("Inode out of range: %v vs. %v", req.Inode, len(fs.inodes))) + } + + var inode *inode = &fs.inodes[req.Inode] + if inode.impl == nil { + panic(fmt.Sprintf("Dead inode requested: %v", req.Inode)) + } + + // All is good. + return +}