Fixed broken invariants at construction.

geesefs-0-30-9
Aaron Jacobs 2015-03-02 14:40:28 +11:00
parent 1b65aaf887
commit c38463a122
2 changed files with 18 additions and 5 deletions

View File

@ -31,5 +31,11 @@ type memDir struct {
//
// TODO(jacobsa): Add good tests exercising concurrent modifications while
// doing readdir, seekdir, etc. calls.
//
// INVIARANT: For each i < len(entries)-1, entries[i].Offset = i+1
entries []fuseutil.Dirent
}
func newDir() *memDir
func (d *memDir) checkInvariants()

View File

@ -47,13 +47,20 @@ type memFS struct {
// Create a file system that stores data and metadata in memory.
func NewMemFS(
clock timeutil.Clock) (fs fuse.FileSystem) {
fs = &memFS{
clock: clock,
clock timeutil.Clock) fuse.FileSystem {
// Set up the basic struct.
fs := &memFS{
clock: clock,
inodes: make([]inode, fuse.RootInodeID+1),
}
fs.(*memFS).mu = syncutil.NewInvariantMutex(fs.(*memFS).checkInvariants)
return
// Set up the root inode.
fs.inodes[fuse.RootInodeID].impl = newDir()
// Set up invariant checking.
fs.mu = syncutil.NewInvariantMutex(fs.checkInvariants)
return fs
}
func (fs *memFS) checkInvariants() {