From 57cb4ccda3997583e2e24733c360f4edbf5f0e0e Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Tue, 3 Mar 2015 11:28:41 +1100 Subject: [PATCH] Outlined memFS.RmDir. --- samples/memfs/fs.go | 23 +++++++++++++++++++++++ samples/memfs/inode.go | 7 +++++++ 2 files changed, 30 insertions(+) diff --git a/samples/memfs/fs.go b/samples/memfs/fs.go index 27906ac..6e8b216 100644 --- a/samples/memfs/fs.go +++ b/samples/memfs/fs.go @@ -294,6 +294,29 @@ func (fs *memFS) MkDir( return } +func (fs *memFS) RmDir( + ctx context.Context, + req *fuse.RmDirRequest) (resp *fuse.RmDirResponse, err error) { + resp = &fuse.RmDirResponse{} + + fs.mu.Lock() + defer fs.mu.Unlock() + + // Grab the parent, which we will update shortly. + parent := fs.getInodeForModifyingOrDie(req.Parent) + defer parent.mu.Unlock() + + // TODO(jacobsa): Check for empty. (Make sure we have a failing test first.) + + // Remove the entry within the parent. + parent.RemoveChild(req.Name) + + // TODO(jacobsa): Remove the child when it's forgotten. (Can we get a failing + // test by looking at inode ID allocation?) + + return +} + func (fs *memFS) OpenDir( ctx context.Context, req *fuse.OpenDirRequest) (resp *fuse.OpenDirResponse, err error) { diff --git a/samples/memfs/inode.go b/samples/memfs/inode.go index f17306e..af641ea 100644 --- a/samples/memfs/inode.go +++ b/samples/memfs/inode.go @@ -158,6 +158,13 @@ func (inode *inode) AddChild( inode.entries = append(inode.entries, e) } +// Remove an entry for a child. +// +// REQUIRES: inode.dir +// REQUIRES: An entry for the given name exists. +// EXCLUSIVE_LOCKS_REQUIRED(inode.mu) +func (inode *inode) RemoveChild(name string) + // Serve a ReadDir request. // // REQUIRED: inode.dir