From c3298a7a6bc6cd0bafead60c01169bff17d1d77c Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Mon, 2 Mar 2015 16:12:54 +1100 Subject: [PATCH] Added an inode invariant. --- samples/memfs/inode.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/samples/memfs/inode.go b/samples/memfs/inode.go index 80b3469..b87d6e5 100644 --- a/samples/memfs/inode.go +++ b/samples/memfs/inode.go @@ -50,6 +50,7 @@ type inode struct { // // INVARIANT: If dir is false, this is nil. // INVARIANT: For each i, entries[i].Offset == i+1 + // INVARIANT: Contains no duplicate names. entries []fuseutil.Dirent // GUARDED_BY(mu) // For files, the current contents of the file. @@ -91,10 +92,17 @@ func (inode *inode) checkInvariants() { panic("Non-nil contents in a directory.") } + childNames := make(map[string]struct{}) for i, e := range inode.entries { if e.Offset != fuse.DirOffset(i+1) { panic(fmt.Sprintf("Unexpected offset: %v", e.Offset)) } + + if _, ok := childNames[e.Name]; ok { + panic(fmt.Sprintf("Duplicate name: %s", e.Name)) + } + + childNames[e.Name] = struct{}{} } }