Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 0.9.1, JRuby 0.9.2, JRuby 0.9.8, JRuby 0.9.9, JRuby 1.0.0RC1, JRuby 1.0.0RC2
-
Fix Version/s: JRuby 1.1RC3
-
Component/s: None
-
Labels:None
-
Environment:Windows/XP
-
Testcase included:yes
-
Number of attachments :
Description
def test_chdir
wd = Dir.getwd
new_dir = "/"
assert_not_equal(wd, new_dir)
Dir.chdir(new_dir)
wd = Dir.getwd
assert_equal(wd, new_dir) # fails
end
Tom Enebo suggested this is caused by Java File.isAbsolute returning false.
The following is from http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html#isAbsolute()
On UNIX systems, a pathname is absolute if its prefix is "/". On Microsoft Windows systems, a pathname is absolute if its prefix is a drive specifier followed by "
", or if its prefix is "\\\\".
However, in non-Jruby Ruby, "/" works fine as an alias to e.g. C:\
Maybe if isAbsolute returns false, use what getAbsolutePath returns:
require 'java'
include_class('java.io.File')
myfile = JFile.new('/crap.txt')
exists = myfile.exists
is_file = myfile.is_file
is_absolute = myfile.is_absolute
absolute_path = myfile.get_absolute_path
puts "exists=#
"
puts "is_file=#
"
puts "is_absolute=#
"
puts "absolute_path=#
"
-
-
exists=true
is_file=true
is_absolute=false
absolute_path=C:\crap.txt
-
As convenient as it is, I might argue that Ruby is wrong here. Having / map to C: is convenient, but fails to accomodate additional drives. It would also fail mightily on my home desktop, where Windows XP is installed with D: as the root drive.