From bc969387cae8918cb8d84ef95e059cfcbc19f474 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Thu, 21 May 2015 15:22:26 +1000 Subject: [PATCH] Fixed memfs bugs. --- samples/memfs/memfs.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/samples/memfs/memfs.go b/samples/memfs/memfs.go index beacc4c..588ec7d 100644 --- a/samples/memfs/memfs.go +++ b/samples/memfs/memfs.go @@ -301,6 +301,14 @@ func (fs *memFS) MkDir( parent := fs.getInodeForModifyingOrDie(op.Parent) defer parent.mu.Unlock() + // Ensure that the name doesn't already exist, so we don't wind up with a + // duplicate. + _, exists := parent.LookUpChild(op.Name) + if exists { + err = fuse.EEXIST + return + } + // Set up attributes from the child, using the credentials of the calling // process as owner (matching inode_init_owner, cf. http://goo.gl/5qavg8). childAttrs := fuseops.InodeAttributes{ @@ -341,7 +349,7 @@ func (fs *memFS) CreateFile( parent := fs.getInodeForModifyingOrDie(op.Parent) defer parent.mu.Unlock() - // Ensure that the name doesn't alread exist, so we don't wind up with a + // Ensure that the name doesn't already exist, so we don't wind up with a // duplicate. _, exists := parent.LookUpChild(op.Name) if exists { @@ -396,6 +404,14 @@ func (fs *memFS) CreateSymlink( parent := fs.getInodeForModifyingOrDie(op.Parent) defer parent.mu.Unlock() + // Ensure that the name doesn't already exist, so we don't wind up with a + // duplicate. + _, exists := parent.LookUpChild(op.Name) + if exists { + err = fuse.EEXIST + return + } + // Set up attributes from the child, using the credentials of the calling // process as owner (matching inode_init_owner, cf. http://goo.gl/5qavg8). now := fs.clock.Now()