there are other issues with a recursive walker function, at least on
OSX where the max path length is 1024 bytes but one is able to create
arbitrarily deep directory structures. some tools know how to handle
this (find), others do not (du).
i just pushed an iterative walker that i had done a couple of years
ago for a project. it doesn't use recursion and is capable of finding
even the deepest buried files on OSX.
go get
github.com/mirtchovski/walk (a tester binary is in
github.com/mirtchovski/walk/walk)
here's a comparison between filepath.Walk and the iterative one. each
"A{+}" is the letter A repeated 255 times:
% x=`perl -e "{print 'A'x255;}"`
% mkdir $x && cd $x # repeat several times
...
% filepathwalk /Users/me/AA*
/Users/me/A{+}
/Users/me/A{+}/A{+}
/Users/me/A{+}/A{+}/A{+}
/Users/me/A{+}/A{+}/A{+}/A{+}: lstat /Users/me/A{+}/A{+}/A{+}/A{+}:
file name too long
% walk /Users/me/A{+}*
/Users/me/A{+}
/Users/me/A{+}/A{+}
/Users/me/A{+}/A{+}/A{+}
/Users/me/A{+}/A{+}/A{+}/A{+}
/Users/me/A{+}/A{+}/A{+}/A{+}/A{+}
/Users/me/A{+}/A{+}/A{+}/A{+}/A{+}/main.go
%
I don't think this code is worthy of replacing filepath.Walk (after
all nobody complained about this issue in 4 years!) but it's good to
have it for special cases.