Fixed a bug in newInode.

geesefs-0-30-9
Aaron Jacobs 2015-03-02 16:03:44 +11:00
parent 26ac02968d
commit aebfed4d03
2 changed files with 12 additions and 4 deletions

View File

@ -5,6 +5,7 @@ package memfs
import ( import (
"fmt" "fmt"
"os"
"time" "time"
"github.com/jacobsa/fuse" "github.com/jacobsa/fuse"
@ -57,7 +58,7 @@ func NewMemFS(
} }
// Set up the root inode. // Set up the root inode.
fs.inodes[fuse.RootInodeID] = newInode(true) // dir fs.inodes[fuse.RootInodeID] = newInode(os.ModeDir)
// Set up invariant checking. // Set up invariant checking.
fs.mu = syncutil.NewInvariantMutex(fs.checkInvariants) fs.mu = syncutil.NewInvariantMutex(fs.checkInvariants)

View File

@ -58,9 +58,12 @@ type inode struct {
contents []byte // GUARDED_BY(mu) contents []byte // GUARDED_BY(mu)
} }
func newInode(dir bool) (in *inode) { func newInode(mode os.FileMode) (in *inode) {
in = &inode{ in = &inode{
dir: dir, dir: (mode&os.ModeDir != 0),
attributes: fuse.InodeAttributes{
Mode: mode,
},
} }
in.mu = syncutil.NewInvariantMutex(in.checkInvariants) in.mu = syncutil.NewInvariantMutex(in.checkInvariants)
@ -75,7 +78,11 @@ func (inode *inode) checkInvariants() {
// Check os.ModeDir. // Check os.ModeDir.
if inode.dir != (inode.attributes.Mode&os.ModeDir == os.ModeDir) { if inode.dir != (inode.attributes.Mode&os.ModeDir == os.ModeDir) {
panic(fmt.Sprintf("Unexpected mode: %v", inode.attributes.Mode)) panic(
fmt.Sprintf(
"Unexpected mode: %v, dir: %v",
inode.attributes.Mode,
inode.dir))
} }
// Check directory-specific stuff. // Check directory-specific stuff.