Bug in Dir.glob in 1.8.6 on Windows?

Hi,

I got a bug report for webgen which appeared when the user change from
ruby 1.8.5 to 1.8.6 using the One-Click-Ruby-Installer. Following is
an extract from an IRB session under Windows with ruby 1.8.6:

irb(main):005:0> Dir[‘src//’]
=> [“src/about.de.page”, “src/about.page”, “src/default.css”, “src/
defau
lt.template”, “src/images”, “src/images/bodybg.gif”, “src/images/
boxbg.g
if”, “src/images/greypx.gif”, “src/images/header.jpg”, “src/images/
inner
bg.gif”, “src/images/leaves.jpg”, “src/images/tabs.gif”, “src/
index.de.p
age”, “src/index.page”, “src/links.de.page”, “src/links.page”]
irb(main):006:0> Dir[‘src///’]
=> [“src/”, “src/about.de.page/”, “src/about.page/”, “src/
default.css/”,
“src/default.template/”, “src/images/”, “src/images/bodybg.gif/”,
“src/
images/boxbg.gif/”, “src/images/greypx.gif/”, “src/images/
header.jpg/”,
“src/images/innerbg.gif/”, “src/images/leaves.jpg/”, “src/images/
tabs.gi
f/”, “src/index.de.page/”, “src/index.page/”, “src/links.de.page/”,
“src
/links.page/”]

Why do all the files get a slash appended and why get files returned
at all? I imagine that the second command should only return
directories… at least this was the behaviour before 1.8.6 - same
session on Windows with Ruby 1.8.5:

irb(main):005:0> Dir[‘src//’]
=> [“src/about.de.page”, “src/about.page”, “src/default.css”, “src/
defau
lt.template”, “src/images”, “src/index.de.page”, “src/index.page”,
“src/
links.de.page”, “src/links.page”, “src/images/bodybg.gif”, “src/images/
b
oxbg.gif”, “src/images/greypx.gif”, “src/images/header.jpg”, “src/
images
/innerbg.gif”, “src/images/leaves.jpg”, “src/images/tabs.gif”]
irb(main):006:0> Dir[‘src///’]
=> [“src/”, “src/images/”, “src/images/”]

As you can see, this outputs the correct result, at least in my
understanding.

Has this behaviour already been seen/has anyone an explanation for
this and does anyone know how to only get directories using Dir.[] in
ruby 1.8.6 under Windows?

Thanks for helping!

Best regards,
Thomas

ps. Also tested this with Ruby 1.8.6 unde Mac OSX and there it works
just fine!

Thomas L. schrieb:

Has this behaviour already been seen/has anyone an explanation for
this and does anyone know how to only get directories using Dir.[] in
ruby 1.8.6 under Windows?

C:\Dokumente und Einstellungen\wolfgang\Desktop>ruby -v
ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]

C:\Dokumente und Einstellungen\wolfgang\Desktop>irb
irb(main):001:0> Dir[‘dirtest//’]
=> [“dirtest/dat1.txt”, “dirtest/dat2.txt”, “dirtest/sub1”,
“dirtest/sub1/sub11”, “dirtest/sub1/sub1/dat1.txt”, “dirtest/sub2”,
“dirtest/sub2/sub21”, “dirtest/sub2/sub2dat1.txt”]
irb(main):002:0> Dir[‘dirtest//’].find_all{|f|File.directory?(f)}
=> [“dirtest/sub1”, “dirtest/sub1/sub11”, “dirtest/sub2”,
“dirtest/sub2/sub21”]

The Problem does not appear using a Ruby 1.9 snapshot under Windows:

C:\Dokumente und Einstellungen\wolfgang\Desktop>ruby19 -v
ruby 1.9.0 (2007-05-15 patchlevel 0) [i386-mingw32]

C:\Dokumente und Einstellungen\wolfgang\Desktop>irb19
irb(main):001:0> Dir[‘dirtest//’]
=> [“dirtest/dat1.txt”, “dirtest/dat2.txt”, “dirtest/sub1”,
“dirtest/sub1/sub11”, “dirtest/sub1/sub1/dat1.txt”, “dirtest/sub2”,
“dirtest/sub2/sub21”, “dirtest/sub2/sub2dat1.txt”]
irb(main):002:0> Dir[‘dirtest///’]
=> [“dirtest/”, “dirtest/sub1/”, “dirtest/sub1/sub11/”, “dirtest/sub2/”,
“dirtest/sub2/sub21/”]

Wolfgang Nádasi-Donner

On May 17, 11:16 pm, Wolfgang Nádasi-Donner [email protected]
wrote:

irb(main):001:0> Dir[‘dirtest//’]
=> [“dirtest/dat1.txt”, “dirtest/dat2.txt”, “dirtest/sub1”,
“dirtest/sub1/sub11”, “dirtest/sub1/sub1/dat1.txt”, “dirtest/sub2”,
“dirtest/sub2/sub21”, “dirtest/sub2/sub2dat1.txt”]
irb(main):002:0> Dir[‘dirtest//’].find_all{|f|File.directory?(f)}
=> [“dirtest/sub1”, “dirtest/sub1/sub11”, “dirtest/sub2”, “dirtest/sub2/sub21”]

Thanks for this suggestions! I know that I can filter afterwards but I
need a version which just uses a glob pattern.

Regards,
Thomas

Hi,

At Fri, 18 May 2007 04:35:04 +0900,
Thomas L. wrote in [ruby-talk:251987]:

I got a bug report for webgen which appeared when the user change from
ruby 1.8.5 to 1.8.6 using the One-Click-Ruby-Installer. Following is
an extract from an IRB session under Windows with ruby 1.8.6:

Thank you for the report, fixed now.

Has this behaviour already been seen/has anyone an explanation for
this and does anyone know how to only get directories using Dir.[] in
ruby 1.8.6 under Windows?

Windows API FindFirstFile/FindNextFile return the file mode
together, and Dir#glob about to utilize it to tell if it is a
directory. The bug is that the info for the first entry,
i.e. “.”, was always used.

On May 18, 10:23 am, Nobuyoshi N. [email protected] wrote:

Has this behaviour already been seen/has anyone an explanation for
this and does anyone know how to only get directories using Dir.[] in
ruby 1.8.6 under Windows?

Windows API FindFirstFile/FindNextFile return the file mode
together, and Dir#glob about to utilize it to tell if it is a
directory. The bug is that the info for the first entry,
i.e. “.”, was always used.

Thanks for the fast reply, the fix and the explanation! I assume that
this fix will be in the next release of the One-Click-Installer for
Windows?!

Thomas

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs