Dir.foreach() mistakenly throws EINVAL in Windows
On Windows 2003 Server (64 bit) I use the attached script to trim files off a disk backup. This code runs fine for days and days but infrequently crashes on the same line of the script: (line 137 - Dir.foreach(copyFullDirName) do | dirEntry |).
The backtrace is:
open': Invalid argument - x:\.\documentforeach'
s and settings\pdculbert\Desktop\Pedram stats\Raw BBS Data by State\FCV30ALL_TES
... 19 levels...
When I check out if the path specified is invalid it in fact exists, its file permissions are correct, etc. The biggest issue (I think) is that the directory contains 121,954 files. Note that the script loops over this directory a number of times successfully before it crashes on one pass some days (or weeks) later.
I've tested that the "x:.\" notation is fine. The directory recursion level is only 8 levels and I don't get a stack too deep error.
Along the "x:.\documents and settings\pdculbert\Desktop\Pedram stats\Raw BBS Data by State\FCV30ALL_TEST\ComDyn" path on the hard drive:
. contains 4 entries
documents and settings contains 17 entries
pdculbert contains 221 entries
Desktop contains 69 entries
Pedram stats contains 16 entries
Raw BBS Data by State contains 82 entries
FCV30ALL_TEST contains 5 entries
ComDyn contains 121,956 entries
Updated by rogerdpack (Roger Pack) almost 10 years ago
do you have a way to recreate this easily?
You might want to try to step through with gdb and see what is going on :)
You might be able to set gdb to break on just the right line.
My guess is that it's a windows OS "resource unavailable" or something that happens every so often when you hit it too hard. Trying with other versions of windows might help.
In the meantime you could add a begin/rescue around it to retry and see if that helps.