Implemented memFS.Unlink.

geesefs-0-30-9
Aaron Jacobs 2015-03-06 23:29:47 -06:00
parent 731de36a27
commit 07bef0b128
1 changed files with 32 additions and 0 deletions

View File

@ -417,6 +417,38 @@ func (fs *memFS) RmDir(
return
}
func (fs *memFS) Unlink(
ctx context.Context,
req *fuse.UnlinkRequest) (resp *fuse.UnlinkResponse, err error) {
resp = &fuse.UnlinkResponse{}
fs.mu.Lock()
defer fs.mu.Unlock()
// Grab the parent, which we will update shortly.
parent := fs.getInodeForModifyingOrDie(req.Parent)
defer parent.mu.Unlock()
// Find the child within the parent.
childID, ok := parent.LookUpChild(req.Name)
if !ok {
err = fuse.ENOENT
return
}
// Grab the child.
child := fs.getInodeForModifyingOrDie(childID)
defer child.mu.Unlock()
// Remove the entry within the parent.
parent.RemoveChild(req.Name)
// Mark the child as unlinked.
child.linkCount--
return
}
func (fs *memFS) OpenDir(
ctx context.Context,
req *fuse.OpenDirRequest) (resp *fuse.OpenDirResponse, err error) {