-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
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 asfs.FS
, use/
-separated paths. -
When the same callback function
fs.WalkDirFunc
is called viafs.WalkDir
(rather thanfilepath.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 bedir\a
rather thandir/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.