From f8da264222f7348c6b9e6dd9d372200f850d2878 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 25 Sep 2016 14:57:04 +0200 Subject: [PATCH] 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. --- tests/test_helpers/helpers.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go index 7e1f4e8..5c71d30 100644 --- a/tests/test_helpers/helpers.go +++ b/tests/test_helpers/helpers.go @@ -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)