Commit 2b57a876 authored by Jan Mercl's avatar Jan Mercl Committed by Russ Cox

path/filepath: implement documented SkipDir behavior

Currently walk() doesn't check for err == SkipDir when iterating
a directory list, but such promise is made in the docs for WalkFunc.

Fixes #3486.

R=rsc, r
CC=golang-dev
https://golang.org/cl/6257059
parent d87bc2f0
......@@ -320,10 +320,13 @@ func walk(path string, info os.FileInfo, walkFn WalkFunc) error {
}
for _, fileInfo := range list {
if err = walk(Join(path, fileInfo.Name()), fileInfo, walkFn); err != nil {
err = walk(Join(path, fileInfo.Name()), fileInfo, walkFn)
if err != nil {
if !fileInfo.IsDir() || err != SkipDir {
return err
}
}
}
return nil
}
......
......@@ -874,3 +874,26 @@ func TestDriveLetterInEvalSymlinks(t *testing.T) {
t.Errorf("Results of EvalSymlinks do not match: %q and %q", flp, fup)
}
}
func TestBug3486(t *testing.T) { // http://code.google.com/p/go/issues/detail?id=3486
root := os.Getenv("GOROOT")
lib := filepath.Join(root, "lib")
src := filepath.Join(root, "src")
seenSrc := false
filepath.Walk(root, func(pth string, info os.FileInfo, err error) error {
if err != nil {
t.Fatal(err)
}
switch pth {
case lib:
return filepath.SkipDir
case src:
seenSrc = true
}
return nil
})
if !seenSrc {
t.Fatalf("%q not seen", src)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment