diff --git a/afero_test.go b/afero_test.go index 827c05c..58c6602 100644 --- a/afero_test.go +++ b/afero_test.go @@ -32,7 +32,7 @@ var ( Fss = []Fs{&MemMapFs{}, &OsFs{}} ) -var testRegistry map[Fs][]string = make(map[Fs][]string) +var testRegistry = make(map[Fs][]string) func testDir(fs Fs) string { name, err := TempDir(fs, "", "afero") diff --git a/path.go b/path.go index faf5129..13d4c1d 100644 --- a/path.go +++ b/path.go @@ -59,8 +59,8 @@ func walk(fs Fs, path string, info os.FileInfo, walkFn filepath.WalkFunc) error } for _, name := range names { - if name == path { - // skip current directory to avoid infinite recursion + if name == "" { + // skip empty names to avoid infinite recursion continue } filename := filepath.Join(path, name) diff --git a/path_test.go b/path_test.go index 104a6bc..874b448 100644 --- a/path_test.go +++ b/path_test.go @@ -67,3 +67,27 @@ func TestWalk(t *testing.T) { t.Fail() } } + +func TestWalkRemoveRoot(t *testing.T) { + defer removeAllTestFiles(t) + fs := Fss[0] + rootPath := "." + + err := fs.RemoveAll(rootPath) + if err != nil { + t.Error(err) + } + + testRegistry[fs] = append(testRegistry[fs], rootPath) + setupTestFiles(t, fs, rootPath) + + walkFn := func(path string, info os.FileInfo, err error) error { + fmt.Println(path, info.Name(), info.IsDir(), info.Size(), err) + return err + } + + err = Walk(fs, rootPath, walkFn) + if err != nil { + t.Error(err) + } +}