Added a test for directories.
parent
38862e8650
commit
096c3fa695
|
@ -24,11 +24,14 @@ import (
|
|||
"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
|
||||
// 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.
|
||||
//
|
||||
// The directory cannot be modified.
|
||||
func NewFileSystem(
|
||||
reportFlush func(string) error,
|
||||
reportFsync func(string) error) (fs fuse.FileSystem, err error) {
|
||||
|
@ -40,7 +43,10 @@ func NewFileSystem(
|
|||
return
|
||||
}
|
||||
|
||||
const fooID = fuse.RootInodeID + 1
|
||||
const (
|
||||
fooID = fuse.RootInodeID + 1 + iota
|
||||
barID
|
||||
)
|
||||
|
||||
type flushFS struct {
|
||||
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
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
@ -94,14 +108,28 @@ func (fs *flushFS) LookUpInode(
|
|||
defer fs.mu.Unlock()
|
||||
|
||||
// Sanity check.
|
||||
if req.Parent != fuse.RootInodeID || req.Name != "foo" {
|
||||
if req.Parent != fuse.RootInodeID {
|
||||
err = fuse.ENOENT
|
||||
return
|
||||
}
|
||||
|
||||
resp.Entry = fuse.ChildInodeEntry{
|
||||
Child: fooID,
|
||||
Attributes: fs.fooAttributes(),
|
||||
// Set up the entry.
|
||||
switch req.Name {
|
||||
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
|
||||
|
@ -125,6 +153,10 @@ func (fs *flushFS) GetInodeAttributes(
|
|||
resp.Attributes = fs.fooAttributes()
|
||||
return
|
||||
|
||||
case barID:
|
||||
resp.Attributes = fs.barAttributes()
|
||||
return
|
||||
|
||||
default:
|
||||
err = fuse.ENOENT
|
||||
return
|
||||
|
@ -222,3 +254,21 @@ func (fs *flushFS) FlushFile(
|
|||
err = fs.reportFlush(string(fs.fooContents))
|
||||
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
|
||||
}
|
||||
|
|
|
@ -614,7 +614,29 @@ func (t *NoErrorsTest) Mmap_CloseBeforeMunmap() {
|
|||
}
|
||||
|
||||
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())
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -236,6 +236,7 @@ func (t *SubprocessTest) initialize() (err error) {
|
|||
|
||||
// Set up basic args for the subprocess.
|
||||
args := []string{
|
||||
"--fuse.debug",
|
||||
"--type",
|
||||
t.MountType,
|
||||
"--mount_point",
|
||||
|
@ -270,7 +271,7 @@ func (t *SubprocessTest) initialize() (err error) {
|
|||
// Set up a command.
|
||||
var stderr bytes.Buffer
|
||||
mountCmd := exec.Command(toolPath, args...)
|
||||
mountCmd.Stderr = &stderr
|
||||
mountCmd.Stderr = os.Stderr
|
||||
mountCmd.ExtraFiles = extraFiles
|
||||
|
||||
// Start it.
|
||||
|
|
Loading…
Reference in New Issue