From a2f83acc303e7ba382c6cbd0e8d218832166fc4d Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Fri, 4 Jan 2019 17:32:27 +0100 Subject: tests: fix VerifyExistence() helper, it missed unstat()able files VerifyExistence missed unstat()able files in the directory listing because ioutil.ReadDir() filtered them out. https://github.com/rfjakob/gocryptfs/issues/285 --- tests/test_helpers/helpers.go | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go index 90eebdf..e735cf4 100644 --- a/tests/test_helpers/helpers.go +++ b/tests/test_helpers/helpers.go @@ -272,29 +272,34 @@ func TestRename(t *testing.T, plainDir string) { // stat, open, readdir. Returns true if the path exists, false otherwise. // Panics if the result is inconsistent. func VerifyExistence(path string) bool { - // Check that file can be stated + // Check if file can be stat()ed stat := true - _, err := os.Stat(path) + fi, err := os.Stat(path) if err != nil { - //t.Log(err) stat = false } - // Check that file can be opened + // Check if file can be opened open := true fd, err := os.Open(path) if err != nil { - //t.Log(err) open = false } fd.Close() - // Check that file shows up in directory listing + // Check if file shows up in directory listing readdir := false dir := filepath.Dir(path) name := filepath.Base(path) - fi, err := ioutil.ReadDir(dir) - if err == nil { - for _, i := range fi { - if i.Name() == name { + d, err := os.Open(dir) + if err != nil && open == true { + log.Panicf("we can open the file but not the parent dir!? err=%v", err) + } else if err == nil { + defer d.Close() + listing, err := d.Readdirnames(0) + if stat && fi.IsDir() && err != nil { + log.Panicf("It's a directory, but readdirnames failed: %v", err) + } + for _, entry := range listing { + if entry == name { readdir = true } } @@ -303,7 +308,7 @@ func VerifyExistence(path string) bool { if stat == open && open == readdir { return stat } - log.Panicf("inconsistent result: stat=%v open=%v readdir=%v", stat, open, readdir) + log.Panicf("inconsistent result on %q: stat=%v open=%v readdir=%v, path=%q", name, stat, open, readdir, path) return false } -- cgit v1.2.3