Commit 45317e97 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Cleanup temp directories after use.

parent 3b479a8f
......@@ -131,6 +131,7 @@ func TestFSetAttr(t *testing.T) {
state.Mount(dir)
state.Debug = true
defer state.Unmount()
defer os.RemoveAll(dir)
go state.Loop(false)
......
......@@ -40,6 +40,10 @@ func (me *MountState) KernelSettings() InitIn {
return me.kernelSettings
}
func (me *MountState) MountPoint() string {
return me.mountPoint
}
// Mount filesystem on mountPoint.
func (me *MountState) Mount(mountPoint string) os.Error {
file, mp, err := mount(mountPoint)
......
......@@ -14,6 +14,7 @@ func TestPathDebug(t *testing.T) {
connector := NewFileSystemConnector(debugFs, nil)
mountPoint := MakeTempDir()
defer os.RemoveAll(mountPoint)
state := NewMountState(connector)
state.Mount(mountPoint)
......
......@@ -95,6 +95,7 @@ func TestXAttrRead(t *testing.T) {
connector := NewFileSystemConnector(xfs, nil)
mountPoint := MakeTempDir()
defer os.RemoveAll(mountPoint)
state := NewMountState(connector)
state.Mount(mountPoint)
......
......@@ -30,7 +30,7 @@ func WriteFile(name string, contents string) {
CheckSuccess(err)
}
func setup(t *testing.T) (workdir string, state *fuse.MountState) {
func setup(t *testing.T) (workdir string, cleanup func()) {
wd := fuse.MakeTempDir()
err := os.Mkdir(wd+"/mount", 0700)
fuse.CheckSuccess(err)
......@@ -45,18 +45,21 @@ func setup(t *testing.T) (workdir string, state *fuse.MountState) {
fs := NewAutoUnionFs(wd+"/store", testAOpts)
connector := fuse.NewFileSystemConnector(fs, &testAOpts.MountOptions)
state = fuse.NewMountState(connector)
state := fuse.NewMountState(connector)
state.Mount(wd + "/mount")
state.Debug = true
go state.Loop(false)
return wd, state
return wd, func() {
state.Unmount()
os.RemoveAll(wd)
}
}
func TestAutoFsSymlink(t *testing.T) {
wd, state := setup(t)
defer state.Unmount()
wd, clean := setup(t)
defer clean()
err := os.Mkdir(wd+"/store/foo", 0755)
CheckSuccess(err)
os.Symlink(wd+"/ro", wd+"/store/foo/READONLY")
......@@ -88,8 +91,8 @@ func TestAutoFsSymlink(t *testing.T) {
}
func TestCreationChecks(t *testing.T) {
wd, state := setup(t)
defer state.Unmount()
wd, clean := setup(t)
defer clean()
err := os.Mkdir(wd+"/store/foo", 0755)
CheckSuccess(err)
......
......@@ -26,7 +26,7 @@ var testOpts = UnionFsOptions{
BranchCacheTTLSecs: entryTtl,
}
func setupUfs(t *testing.T) (workdir string, state *fuse.MountState) {
func setupUfs(t *testing.T) (workdir string, cleanup func()) {
wd := fuse.MakeTempDir()
err := os.Mkdir(wd+"/mount", 0700)
fuse.CheckSuccess(err)
......@@ -49,12 +49,15 @@ func setupUfs(t *testing.T) (workdir string, state *fuse.MountState) {
}
connector := fuse.NewFileSystemConnector(ufs, opts)
state = fuse.NewMountState(connector)
state := fuse.NewMountState(connector)
state.Mount(wd + "/mount")
state.Debug = true
go state.Loop(false)
return wd, state
return wd, func() {
state.Unmount()
os.RemoveAll(wd)
}
}
func writeToFile(path string, contents string) {
......@@ -118,8 +121,8 @@ func remove(path string) {
}
func TestSymlink(t *testing.T) {
wd, state := setupUfs(t)
defer state.Unmount()
wd, clean := setupUfs(t)
defer clean()
err := os.Symlink("/foobar", wd+"/mount/link")
CheckSuccess(err)
......@@ -133,8 +136,8 @@ func TestSymlink(t *testing.T) {
}
func TestChtimes(t *testing.T) {
wd, state := setupUfs(t)
defer state.Unmount()
wd, clean := setupUfs(t)
defer clean()
writeToFile(wd+"/ro/file", "a")
err := os.Chtimes(wd + "/ro/file", 42e9, 43e9)
......@@ -150,8 +153,8 @@ func TestChtimes(t *testing.T) {
}
func TestChmod(t *testing.T) {
wd, state := setupUfs(t)
defer state.Unmount()
wd, clean := setupUfs(t)
defer clean()
ro_fn := wd + "/ro/file"
m_fn := wd + "/mount/file"
......@@ -177,8 +180,8 @@ func TestChmod(t *testing.T) {
}
func TestBasic(t *testing.T) {
wd, state := setupUfs(t)
defer state.Unmount()
wd, clean := setupUfs(t)
defer clean()
writeToFile(wd+"/rw/rw", "a")
writeToFile(wd+"/ro/ro1", "a")
......@@ -240,8 +243,8 @@ func TestBasic(t *testing.T) {
}
func TestPromote(t *testing.T) {
wd, state := setupUfs(t)
defer state.Unmount()
wd, clean := setupUfs(t)
defer clean()
err := os.Mkdir(wd+"/ro/subdir", 0755)
CheckSuccess(err)
......@@ -250,8 +253,8 @@ func TestPromote(t *testing.T) {
}
func TestCreate(t *testing.T) {
wd, state := setupUfs(t)
defer state.Unmount()
wd, clean := setupUfs(t)
defer clean()
err := os.MkdirAll(wd+"/ro/subdir/sub2", 0755)
CheckSuccess(err)
......@@ -261,8 +264,8 @@ func TestCreate(t *testing.T) {
}
func TestOpenUndeletes(t *testing.T) {
wd, state := setupUfs(t)
defer state.Unmount()
wd, clean := setupUfs(t)
defer clean()
writeToFile(wd+"/ro/file", "X")
err := os.Remove(wd + "/mount/file")
......@@ -273,8 +276,8 @@ func TestOpenUndeletes(t *testing.T) {
}
func TestMkdir(t *testing.T) {
wd, state := setupUfs(t)
defer state.Unmount()
wd, clean := setupUfs(t)
defer clean()
dirname := wd + "/mount/subdir"
err := os.Mkdir(dirname, 0755)
......@@ -285,8 +288,8 @@ func TestMkdir(t *testing.T) {
}
func TestMkdirPromote(t *testing.T) {
wd, state := setupUfs(t)
defer state.Unmount()
wd, clean := setupUfs(t)
defer clean()
dirname := wd + "/ro/subdir/subdir2"
err := os.MkdirAll(dirname, 0755)
......@@ -320,7 +323,7 @@ func TestRename(t *testing.T) {
for i, c := range configs {
t.Log("Config", i, c)
wd, state := setupUfs(t)
wd, clean := setupUfs(t)
if c.f1_ro {
writeToFile(wd+"/ro/file1", "c1")
}
......@@ -354,14 +357,14 @@ func TestRename(t *testing.T) {
_, err = os.Lstat(wd + "/mount/file1")
CheckSuccess(err)
state.Unmount()
clean()
}
}
func TestWritableDir(t *testing.T) {
t.Log("TestWritableDir")
wd, state := setupUfs(t)
defer state.Unmount()
wd, clean := setupUfs(t)
defer clean()
dirname := wd + "/ro/subdir"
err := os.Mkdir(dirname, 0555)
......@@ -376,8 +379,8 @@ func TestWritableDir(t *testing.T) {
func TestTruncate(t *testing.T) {
t.Log("TestTruncate")
wd, state := setupUfs(t)
defer state.Unmount()
wd, clean := setupUfs(t)
defer clean()
writeToFile(wd+"/ro/file", "hello")
os.Truncate(wd+"/mount/file", 2)
......@@ -393,8 +396,8 @@ func TestTruncate(t *testing.T) {
func TestCopyChmod(t *testing.T) {
t.Log("TestCopyChmod")
wd, state := setupUfs(t)
defer state.Unmount()
wd, clean := setupUfs(t)
defer clean()
contents := "hello"
fn := wd + "/mount/y"
......@@ -426,8 +429,8 @@ func abs(dt int64) int64 {
func TestTruncateTimestamp(t *testing.T) {
t.Log("TestTruncateTimestamp")
wd, state := setupUfs(t)
defer state.Unmount()
wd, clean := setupUfs(t)
defer clean()
contents := "hello"
fn := wd + "/mount/y"
......
......@@ -24,9 +24,11 @@ func TestMultiZipFs(t *testing.T) {
fs := NewMultiZipFs()
state := fuse.NewMountState(fs.Connector)
mountPoint := fuse.MakeTempDir()
defer os.RemoveAll(mountPoint)
state.Debug = true
err = state.Mount(mountPoint)
defer state.Unmount()
CheckSuccess(err)
go state.Loop(true)
......@@ -97,6 +99,4 @@ func TestMultiZipFs(t *testing.T) {
if err == nil {
t.Error("stat should fail after unmount.", fi)
}
state.Unmount()
}
......@@ -16,10 +16,12 @@ func TestZipFs(t *testing.T) {
connector := fuse.NewFileSystemConnector(zfs, nil)
mountPoint := fuse.MakeTempDir()
defer os.RemoveAll(mountPoint)
state := fuse.NewMountState(connector)
state.Mount(mountPoint)
defer state.Unmount()
go state.Loop(false)
d, err := os.Open(mountPoint)
......@@ -57,6 +59,4 @@ func TestZipFs(t *testing.T) {
t.Error("content fail", b[:n])
}
f.Close()
state.Unmount()
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment