Skip to content

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

@cespare

Description

@cespare

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions