Added a test for directories.

geesefs-0-30-9
Aaron Jacobs 2015-03-24 12:02:48 +11:00
parent 38862e8650
commit 096c3fa695
3 changed files with 81 additions and 8 deletions

View File

@ -24,11 +24,14 @@ import (
"golang.org/x/net/context" "golang.org/x/net/context"
) )
// Create a file system containing a single file named "foo". // Create a file system whose sole contents are a file named "foo" and a
// directory named "bar".
// //
// The file may be opened for reading and/or writing. Its initial contents are // The file may be opened for reading and/or writing. Its initial contents are
// empty. Whenever a flush or fsync is received, the supplied function will be // empty. Whenever a flush or fsync is received, the supplied function will be
// called with the current contents of the file and its status returned. // called with the current contents of the file and its status returned.
//
// The directory cannot be modified.
func NewFileSystem( func NewFileSystem(
reportFlush func(string) error, reportFlush func(string) error,
reportFsync func(string) error) (fs fuse.FileSystem, err error) { reportFsync func(string) error) (fs fuse.FileSystem, err error) {
@ -40,7 +43,10 @@ func NewFileSystem(
return return
} }
const fooID = fuse.RootInodeID + 1 const (
fooID = fuse.RootInodeID + 1 + iota
barID
)
type flushFS struct { type flushFS struct {
fuseutil.NotImplementedFileSystem fuseutil.NotImplementedFileSystem
@ -72,6 +78,14 @@ func (fs *flushFS) fooAttributes() fuse.InodeAttributes {
} }
} }
// LOCKS_REQUIRED(fs.mu)
func (fs *flushFS) barAttributes() fuse.InodeAttributes {
return fuse.InodeAttributes{
Nlink: 1,
Mode: 0777 | os.ModeDir,
}
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// File system methods // File system methods
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
@ -94,14 +108,28 @@ func (fs *flushFS) LookUpInode(
defer fs.mu.Unlock() defer fs.mu.Unlock()
// Sanity check. // Sanity check.
if req.Parent != fuse.RootInodeID || req.Name != "foo" { if req.Parent != fuse.RootInodeID {
err = fuse.ENOENT err = fuse.ENOENT
return return
} }
resp.Entry = fuse.ChildInodeEntry{ // Set up the entry.
Child: fooID, switch req.Name {
Attributes: fs.fooAttributes(), case "foo":
resp.Entry = fuse.ChildInodeEntry{
Child: fooID,
Attributes: fs.fooAttributes(),
}
case "bar":
resp.Entry = fuse.ChildInodeEntry{
Child: barID,
Attributes: fs.barAttributes(),
}
default:
err = fuse.ENOENT
return
} }
return return
@ -125,6 +153,10 @@ func (fs *flushFS) GetInodeAttributes(
resp.Attributes = fs.fooAttributes() resp.Attributes = fs.fooAttributes()
return return
case barID:
resp.Attributes = fs.barAttributes()
return
default: default:
err = fuse.ENOENT err = fuse.ENOENT
return return
@ -222,3 +254,21 @@ func (fs *flushFS) FlushFile(
err = fs.reportFlush(string(fs.fooContents)) err = fs.reportFlush(string(fs.fooContents))
return return
} }
func (fs *flushFS) OpenDir(
ctx context.Context,
req *fuse.OpenDirRequest) (
resp *fuse.OpenDirResponse, err error) {
resp = &fuse.OpenDirResponse{}
fs.mu.Lock()
defer fs.mu.Unlock()
// Sanity check.
if req.Inode != barID {
err = fuse.ENOSYS
return
}
return
}

View File

@ -614,7 +614,29 @@ func (t *NoErrorsTest) Mmap_CloseBeforeMunmap() {
} }
func (t *NoErrorsTest) Directory() { func (t *NoErrorsTest) Directory() {
AssertTrue(false, "TODO") var err error
// Open the directory.
t.f1, err = os.Open(path.Join(t.Dir, "bar"))
AssertEq(nil, err)
// Sanity check: stat it.
fi, err := t.f1.Stat()
AssertEq(nil, err)
AssertEq(0777|os.ModeDir, fi.Mode())
// Sync it.
err = t.f1.Sync()
AssertEq(nil, err)
// Close it.
err = t.f1.Close()
t.f1 = nil
AssertEq(nil, err)
// No flushes or fsync requests should have been received.
ExpectThat(t.getFlushes(), ElementsAre())
ExpectThat(t.getFsyncs(), ElementsAre())
} }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

View File

@ -236,6 +236,7 @@ func (t *SubprocessTest) initialize() (err error) {
// Set up basic args for the subprocess. // Set up basic args for the subprocess.
args := []string{ args := []string{
"--fuse.debug",
"--type", "--type",
t.MountType, t.MountType,
"--mount_point", "--mount_point",
@ -270,7 +271,7 @@ func (t *SubprocessTest) initialize() (err error) {
// Set up a command. // Set up a command.
var stderr bytes.Buffer var stderr bytes.Buffer
mountCmd := exec.Command(toolPath, args...) mountCmd := exec.Command(toolPath, args...)
mountCmd.Stderr = &stderr mountCmd.Stderr = os.Stderr
mountCmd.ExtraFiles = extraFiles mountCmd.ExtraFiles = extraFiles
// Start it. // Start it.