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