-
Notifications
You must be signed in to change notification settings - Fork 514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the infinite recursion with afero.Walk #409
base: master
Are you sure you want to change the base?
Conversation
@spf13 Please, who can review this PR ? |
@erstam this needs a simple test (that does infinite recursion without this patch). |
…irectory names listing
@bep I worked more on this issue and noticed something interesting. In my code where I use afero, I am removing the root folder of the fs instance and this causes the infinite recursion when using the Walk method. Should removing the root be forbidden on all Fs types ? I see in MemMapFs there is a Btw, using Windows here, if ever it matters. The below test function will reproduce the issue. 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)
}
} Seeing this case implies my proposed fix is just a workaround. The real fix would be to better protect the root path from deletion. |
Will we see this merged at some point ? |
This PR fixes #185
Fix the infinite recursion by skipping the current directory in the directory names listing