Open ahoppen opened 1 week ago
@ahoppen the reason that enumeration stops here is because an error has occurred. In particular, the error is:
Error Domain=NSCocoaErrorDomain Code=260 "The file doesn’t exist." on file:///C:/Users/jmschonfeld/Desktop/testDir/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.txt
I suspect some API which we are calling is not handling the long paths well. The documentation states that, for the error handler parameter:
If you specify nil for this parameter, the enumerator object continues to enumerate items as if you had specified a block that returned true.
However it seems like on Windows that behavior is the opposite:
So I agree it seems like there's two problems here:
nil
) error handler is the opposite of what is documented (we should confirm what is documented matches Darwin behavior)For now if you need to work around issue number 1, you can provide a custom error handler which returns true
Oh, great. Thanks for the detailed analysis. We’re not seeing any long path related issues right now because I shortened all paths sufficiently but I’ll use that workaround when we see an issue next time.
The first part of the issue (the default error handler behavior on Windows) will be resolved by https://github.com/swiftlang/swift-corelibs-foundation/pull/5136
Thanks for the fix @jmschonfeld. That was the issue that bogged me more than skipping directories that exceed MAX_PATH
(which is somewhat understandable, I think).
Run the following to create a file at a path that exceeds
MAXPATH
Now run
Notice how it outputs
Directory iteration stops upon reaching the
eeeee…txt
file that exceedsMAX_PATH
anda.txt
is never printed. I would expect directory iteration to eitherbut not to stop iteration upon reaching the first file that exceeds the maximum path length altogether.