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
This commit is contained in:
parent
cdb57ca7e0
commit
a2f83acc30
@ -272,29 +272,34 @@ func TestRename(t *testing.T, plainDir string) {
|
|||||||
// stat, open, readdir. Returns true if the path exists, false otherwise.
|
// stat, open, readdir. Returns true if the path exists, false otherwise.
|
||||||
// Panics if the result is inconsistent.
|
// Panics if the result is inconsistent.
|
||||||
func VerifyExistence(path string) bool {
|
func VerifyExistence(path string) bool {
|
||||||
// Check that file can be stated
|
// Check if file can be stat()ed
|
||||||
stat := true
|
stat := true
|
||||||
_, err := os.Stat(path)
|
fi, err := os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//t.Log(err)
|
|
||||||
stat = false
|
stat = false
|
||||||
}
|
}
|
||||||
// Check that file can be opened
|
// Check if file can be opened
|
||||||
open := true
|
open := true
|
||||||
fd, err := os.Open(path)
|
fd, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//t.Log(err)
|
|
||||||
open = false
|
open = false
|
||||||
}
|
}
|
||||||
fd.Close()
|
fd.Close()
|
||||||
// Check that file shows up in directory listing
|
// Check if file shows up in directory listing
|
||||||
readdir := false
|
readdir := false
|
||||||
dir := filepath.Dir(path)
|
dir := filepath.Dir(path)
|
||||||
name := filepath.Base(path)
|
name := filepath.Base(path)
|
||||||
fi, err := ioutil.ReadDir(dir)
|
d, err := os.Open(dir)
|
||||||
if err == nil {
|
if err != nil && open == true {
|
||||||
for _, i := range fi {
|
log.Panicf("we can open the file but not the parent dir!? err=%v", err)
|
||||||
if i.Name() == name {
|
} 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
|
readdir = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -303,7 +308,7 @@ func VerifyExistence(path string) bool {
|
|||||||
if stat == open && open == readdir {
|
if stat == open && open == readdir {
|
||||||
return stat
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user