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
|
||||
// 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()
|
||||
|
|
|
@ -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 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() {
|
||||
|
|
Loading…
Reference in New Issue