Skip to content

Commit 86fcc67

Browse files
committed
Add a test to validate the proposed fix
1 parent c689108 commit 86fcc67

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

afero_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var (
3232
Fss = []Fs{&MemMapFs{}, &OsFs{}}
3333
)
3434

35-
var testRegistry map[Fs][]string = make(map[Fs][]string)
35+
var testRegistry = make(map[Fs][]string)
3636

3737
func testDir(fs Fs) string {
3838
name, err := TempDir(fs, "", "afero")

path.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ func walk(fs Fs, path string, info os.FileInfo, walkFn filepath.WalkFunc) error
5959
}
6060

6161
for _, name := range names {
62-
if name == path {
63-
// skip current directory to avoid infinite recursion
62+
if name == "" {
63+
// skip empty names to avoid infinite recursion
6464
continue
6565
}
6666
filename := filepath.Join(path, name)

path_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,27 @@ func TestWalk(t *testing.T) {
6767
t.Fail()
6868
}
6969
}
70+
71+
func TestWalkRemoveRoot(t *testing.T) {
72+
defer removeAllTestFiles(t)
73+
fs := Fss[0]
74+
rootPath := "."
75+
76+
err := fs.RemoveAll(rootPath)
77+
if err != nil {
78+
t.Error(err)
79+
}
80+
81+
testRegistry[fs] = append(testRegistry[fs], rootPath)
82+
setupTestFiles(t, fs, rootPath)
83+
84+
walkFn := func(path string, info os.FileInfo, err error) error {
85+
fmt.Println(path, info.Name(), info.IsDir(), info.Size(), err)
86+
return err
87+
}
88+
89+
err = Walk(fs, rootPath, walkFn)
90+
if err != nil {
91+
t.Error(err)
92+
}
93+
}

0 commit comments

Comments
 (0)