Ruby & Windows and Dir() EINVAL bug?

B

bdezonia

Hello,

I am using Ruby 1.8.6-26 on Windows. I have this little test script:

******************************************************************************************
system("dir x:\\.\\Radeloff\\Projects\\DATA\\NLCD_2001\\landcover\
\nlcd_fg11")

serverDirName = "x:/./Radeloff/Projects/DATA_NLCD_2001/landcover/
nlcd_fg11"

Dir.new(serverDirName).each do | dirEntry |
if inHere.nil?
print "Found the directory #{serverDirName} just fine!\n"
inHere = true
end
end
******************************************************************************************

The first line succeeds. The Dir.new() line bombs out with
Errno::EINVAL.Note that the Dir.new() code was taken out of a working
script that works for millions of files and directories except this
one. The funky "x:/./..." stuff works all the time. I have looked at
file permissions on the directory in question and it matches other
directories in the same place that work fine.

Can anyone tell me what could be wrong here? Could this be a Ruby bug?
 
D

Daniel Berger

Hello,

I am using Ruby 1.8.6-26 on Windows. I have this little test script:

*************************************************************************= **=AD***************
system("dir x:\\.\\Radeloff\\Projects\\DATA\\NLCD_2001\\landcover\
\nlcd_fg11")

serverDirName =3D "x:/./Radeloff/Projects/DATA_NLCD_2001/landcover/
nlcd_fg11"

Dir.new(serverDirName).each do | dirEntry |
=A0 if inHere.nil?
=A0 =A0 print "Found the directory #{serverDirName} just fine!\n"
=A0 =A0 inHere =3D true
=A0 end
end
*************************************************************************= **=AD***************

The first line succeeds. The Dir.new() line bombs out with
Errno::EINVAL.Note that the Dir.new() code was taken out of a working
script that works for millions of files and directories except this
one. The funky "x:/./..." stuff works all the time. I have looked at
file permissions on the directory in question and it matches other
directories in the same place that work fine.

Can anyone tell me what could be wrong here? Could this be a Ruby bug?

It's not being caused by the '.'. I just tried it:

irb(main):002:0> Dir.new("C:/staging").each{ |f| p f }
"."
".."
"ptools-1.1.6"
"windows-pr-0.9.8"
"windows-pr-0.9.8.zip"
=3D> #<Dir:0x2e37ea0>
irb(main):003:0> Dir.new("C:/./staging").each{ |f| p f }
"."
".."
"ptools-1.1.6"
"windows-pr-0.9.8"
"windows-pr-0.9.8.zip"
=3D> #<Dir:0x2e32874>

BTW, you can shortcut Dir.new(dir).each with Dir.foreach(dir),
although I don't think it will solve your problem.

Regards,

Dan
 
G

Greg Halsey

system("dir x:\\.\\Radeloff\\Projects\\DATA\\NLCD_2001\\landcover\
\nlcd_fg11")

serverDirName = "x:/./Radeloff/Projects/DATA_NLCD_2001/landcover/
nlcd_fg11"

was the error a typo? should it have been:

serverDirName = "x:/./Radeloff/Projects/DATA/NLCD_2001/landcover/
nlcd_fg11"
 
B

bdezonia

was the error a typo? should it have been:

 serverDirName = "x:/./Radeloff/Projects/DATA/NLCD_2001/landcover/
 nlcd_fg11"

Arg. Yes and no. My test program did have a typo. Once fixed the test
program works.

Unfortunately the actual script it was taken from is typoless and I'm
still at a loss for why it crashes. I'm not specifying this directory.
Its being built from the Dir above it. I have so many files that it
takes days to get to this directory before the crash. Thus I'm having
trouble debugging it. (I also don't think this is the only directory
it crashes on like this but I haven't tracked it carefully to know)

The only thing I forgot to mention is that this is running on Server
2003 64-bit.
 
D

Daniel Berger

Arg. Yes and no. My test program did have a typo. Once fixed the test
program works.

Unfortunately the actual script it was taken from is typoless and I'm
still at a loss for why it crashes. I'm not specifying this directory.
Its being built from the Dir above it. I have so many files that it
takes days to get to this directory before the crash. Thus I'm having
trouble debugging it. (I also don't think this is the only directory
it crashes on like this but I haven't tracked it carefully to know)

The only thing I forgot to mention is that this is running on Server
2003 64-bit.

Try wrapping the offending code in a begin/rescue and see if you can
glean anything from the backtrace.

begin
your_code
rescue Errno::EINVAL => err
log(file)
log(err.backtrace.join("\n")
raise
end

Regards,

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top