Skip to content

path/filepath: SkipDir does not work as expected for non-directory files #16280

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

Closed
FugiTech opened this issue Jul 6, 2016 · 3 comments
Closed
Milestone

Comments

@FugiTech
Copy link

FugiTech commented Jul 6, 2016

  1. What version of Go are you using (go version)?
    go version go1.6.1 darwin/amd64
  2. What operating system and processor architecture are you using (go env)?
    GOARCH="amd64"
    GOOS="darwin"
  3. What did you do?
    Returned filepath.SkipDir in a filepath.WalkFunc when the file was not a directory.
  4. What did you expect to see?
    filepath.Walk would return nil
  5. What did you see instead?
    filepath.Walk returned filepath.SkipDir

I don't know whether this is an issue with the documentation or implementation, but the behavior seems to contradict the documentation for filepath.WalkFunc.

If an error is returned, processing stops. The sole exception is when the function returns the special value SkipDir. If the function returns SkipDir when invoked on a directory, Walk skips the directory's contents entirely. If the function returns SkipDir when invoked on a non-directory file, Walk skips the remaining files in the containing directory.

@ianlancetaylor ianlancetaylor changed the title filepath.SkipDir does not work as expected for non-directory files path/filepath: SkipDir does not work as expected for non-directory files Jul 6, 2016
@ianlancetaylor
Copy link
Member

Can you provide a test case? I'm not seeing the problem.

@ianlancetaylor ianlancetaylor added this to the Go1.8 milestone Jul 6, 2016
@FugiTech
Copy link
Author

FugiTech commented Jul 6, 2016

I've created a test case at https://play.golang.org/p/fGh07NE1g3

I would expect the output to be

2009/11/10 23:00:00 /tmp
2009/11/10 23:00:00 /tmp/first054003078
2009/11/10 23:00:00 /tmp/second116774189
2009/11/10 23:00:00 Worked as expected!

but instead it is

2009/11/10 23:00:00 /tmp
2009/11/10 23:00:00 /tmp/first054003078
2009/11/10 23:00:00 /tmp/second116774189
2009/11/10 23:00:00 skip this directory

@ianlancetaylor
Copy link
Member

Thanks for the example.

I think the bug is a failure to handle SkipDir in the top-level directory.

@golang golang locked and limited conversation to collaborators Aug 25, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants