From 4269d7cd470d08ac6937b3335b8b946267d3558d Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Thu, 21 May 2015 13:26:03 +1000 Subject: [PATCH] Check for already existing in memFS.CreateFile. --- samples/memfs/memfs.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/samples/memfs/memfs.go b/samples/memfs/memfs.go index 872b955..1aa4079 100644 --- a/samples/memfs/memfs.go +++ b/samples/memfs/memfs.go @@ -341,6 +341,14 @@ 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 + // duplicate. + _, exists := parent.LookUpChild(op.Name) + if exists { + err = fmt.Errorf("Name %q already exists in parent", op.Name) + 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()