tests: clean up leftover mounts in resetTmpDir

Failure in the example filesystems tests can leave them mounted.
This commit is contained in:
Jakob Unterwurzacher 2016-04-10 19:43:37 +02:00
parent db72fcea41
commit bd1f17ca9f
1 changed files with 12 additions and 3 deletions

View File

@ -23,10 +23,17 @@ const gocryptfsBinary = "../gocryptfs"
// resetTmpDir - delete old tmp dir, create new one, write gocryptfs.diriv
func resetTmpDir(plaintextNames bool) {
fu := exec.Command("fusermount", "-z", "-u", defaultPlainDir)
fu.Run()
err := os.RemoveAll(tmpDir)
// Try to unmount everything
entries, err := ioutil.ReadDir(tmpDir)
if err == nil {
for _, e := range entries {
fu := exec.Command("fusermount", "-z", "-u", filepath.Join(tmpDir, e.Name()))
fu.Run()
}
}
err = os.RemoveAll(tmpDir)
if err != nil {
fmt.Println("resetTmpDir: RemoveAll:" + err.Error())
os.Exit(1)
@ -162,6 +169,8 @@ func testMkdirRmdir(t *testing.T, plainDir string) {
}
err = syscall.Rmdir(dir)
if err != nil {
// Make sure the directory can cleaned up by the next test run
os.Chmod(dir, 0700)
t.Fatal(err)
}
}