tests: smarter error handling in ResetTmpDir

Look at the error code from os.Remove and decide about the
right thing to do.

Gets rid of spurious fusermount error messages.
This commit is contained in:
Jakob Unterwurzacher 2016-09-25 14:57:04 +02:00
parent 7bbf6ad6ea
commit f8da264222
1 changed files with 11 additions and 3 deletions

View File

@ -54,10 +54,18 @@ func ResetTmpDir(plaintextNames bool) {
d := filepath.Join(TmpDir, e.Name())
err = os.Remove(d)
if err != nil {
if testing.Verbose() {
fmt.Printf("%v, trying umount\n", d, err)
pe := err.(*os.PathError)
if pe.Err == syscall.EBUSY {
if testing.Verbose() {
fmt.Printf("Remove failed: %v. Maybe still mounted?\n", pe)
}
err = UnmountErr(d)
if err != nil {
panic(err)
}
} else if pe.Err != syscall.ENOTEMPTY {
panic("Unhandled error: " + pe.Err.Error())
}
UnmountErr(d)
err = os.RemoveAll(d)
if err != nil {
panic(err)