Check for already existing in memFS.CreateFile.

geesefs-0-30-9
Aaron Jacobs 2015-05-21 13:26:03 +10:00
parent eafe864b8c
commit 4269d7cd47
1 changed files with 8 additions and 0 deletions

View File

@ -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()