Fixed broken invariants at construction.
parent
1b65aaf887
commit
c38463a122
|
@ -31,5 +31,11 @@ type memDir struct {
|
||||||
//
|
//
|
||||||
// TODO(jacobsa): Add good tests exercising concurrent modifications while
|
// TODO(jacobsa): Add good tests exercising concurrent modifications while
|
||||||
// doing readdir, seekdir, etc. calls.
|
// doing readdir, seekdir, etc. calls.
|
||||||
|
//
|
||||||
|
// INVIARANT: For each i < len(entries)-1, entries[i].Offset = i+1
|
||||||
entries []fuseutil.Dirent
|
entries []fuseutil.Dirent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newDir() *memDir
|
||||||
|
|
||||||
|
func (d *memDir) checkInvariants()
|
||||||
|
|
|
@ -47,13 +47,20 @@ type memFS struct {
|
||||||
|
|
||||||
// Create a file system that stores data and metadata in memory.
|
// Create a file system that stores data and metadata in memory.
|
||||||
func NewMemFS(
|
func NewMemFS(
|
||||||
clock timeutil.Clock) (fs fuse.FileSystem) {
|
clock timeutil.Clock) fuse.FileSystem {
|
||||||
fs = &memFS{
|
// Set up the basic struct.
|
||||||
clock: clock,
|
fs := &memFS{
|
||||||
|
clock: clock,
|
||||||
|
inodes: make([]inode, fuse.RootInodeID+1),
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.(*memFS).mu = syncutil.NewInvariantMutex(fs.(*memFS).checkInvariants)
|
// Set up the root inode.
|
||||||
return
|
fs.inodes[fuse.RootInodeID].impl = newDir()
|
||||||
|
|
||||||
|
// Set up invariant checking.
|
||||||
|
fs.mu = syncutil.NewInvariantMutex(fs.checkInvariants)
|
||||||
|
|
||||||
|
return fs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *memFS) checkInvariants() {
|
func (fs *memFS) checkInvariants() {
|
||||||
|
|
Loading…
Reference in New Issue