Navigation Menu

Skip to content
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

path/filepath: document that WalkDir calls fs.WalkDirFunc with platform-specific paths #52812

Closed
cespare opened this issue May 10, 2022 · 1 comment
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@cespare
Copy link
Contributor

cespare commented May 10, 2022

The function filepath.WalkDir uses the callback fs.WalkDirFunc.

Within path/filepath, paths generally use the slash separator of the host platform, so the root parameter to filepath.WalkDir is clearly a platform-specific path.

However, it wasn't obvious to me upon reading the documentation whether the path passed to the WalkDirFunc was a platform-specific path or used / as the path separator. In fact, all the paths use the platform separator, but I had to read the code to be sure. Here are some reasons I thought the WalkDirFunc path might be /-separated:

  • Other types/functions inside io/fs, such as fs.FS, use /-separated paths.

  • When the same callback function fs.WalkDirFunc is called via fs.WalkDir (rather than filepath.WalkDir) it sees /-separated paths.

  • The fs.WalkDirFunc documentation mentions /-separated paths:

        The path argument contains the argument to WalkDir as a prefix. That is, if
        WalkDir is called with root argument "dir" and finds a file named "a" in
        that directory, the walk function will be called with argument "dir/a".
    

    (I believe that on Windows, if this is coming from filepath.WalkDir, then it would be dir\a rather than dir/a.)

I think the documentation of filepath.WalkDir and/or fs.WalkDirFunc could be clearer on this point.

/cc @rsc who wrote most of this stuff as part of io/fs for Go 1.16.

@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 10, 2022
@gopherbot
Copy link

Change https://go.dev/cl/405615 mentions this issue: path/filepath: document that WalkDir uses OS paths

@seankhliao seankhliao added this to the Go1.20 milestone Aug 20, 2022
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Sep 14, 2022
@golang golang locked and limited conversation to collaborators Sep 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants