Project

General

Profile

Actions

Misc #19691

open

File.realpath on Windows does not return actual case of the file

Added by MSP-Greg (Greg L) 10 months ago. Updated 10 months ago.

Status:
Open
Assignee:
-
[ruby-core:113632]

Description

I don't know what I think of this (expected or bug), but recently in a forum I saw an issue that I don't recall accidentally doing myself. An equivalent example:

ruby -rsingleton -rSingleton -e "puts 'case issue'"

Note the change of casing with Singleton.

On case insensitive file systems, the above will double load the file, which errors.

Obviously, on case sensitive file systems, it errors with cannot load such file -- Singleton

So, options are:

A. No change to current behavior, which I'm fine with.

B. If the OS is case insensitive, don't reload the file, and maybe a warning that Singleton and singleton are equivalent.

Updated by MSP-Greg (Greg L) 10 months ago

Sorry, accidentally used the default 'Tracker type', which is 'Bug'. Meant to post it as 'Misc'

Updated by nobu (Nobuyoshi Nakada) 10 months ago

  • Tracker changed from Bug to Misc
  • Status changed from Open to Feedback
  • Backport deleted (3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN)

I think it has changed since 3.1.

$ ruby3.0 -v -W0 -rsingleton -rSingleton -e 'p $"[-2..-1]'
ruby 3.0.6p216 (2023-03-30 revision 23a532679b) [x86_64-darwin22]
/opt/local/lib/ruby/3.0.0/Singleton.rb:152:in `undef_method': undefined method `extend_object' for class `Singleton' (NameError)
Did you mean?  extended
	from /opt/local/lib/ruby/3.0.0/Singleton.rb:152:in `singleton class'
	from /opt/local/lib/ruby/3.0.0/Singleton.rb:140:in `<module:Singleton>'
	from /opt/local/lib/ruby/3.0.0/Singleton.rb:94:in `<top (required)>'
	from <internal:/opt/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from <internal:/opt/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
bash: exit 1
$ ruby3.1 -v -rsingleton -rSingleton -e 'p $"[-2..-1]'
ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [x86_64-darwin22]
["/opt/local/lib/ruby/3.1.0/did_you_mean.rb", "/opt/local/lib/ruby/3.1.0/singleton.rb"]

Updated by jeremyevans0 (Jeremy Evans) 10 months ago

  • Subject changed from Case insensitive file systems, require filename casing to File.realpath on Windows does not return actual case of the file
  • Status changed from Feedback to Open

Looks like #17885 fixed the issue for case-insensitive Mac OS file systems. However, it is not fixed on Windows because File.realpath on Windows doesn't fix the case:

File.realpath('a')
# => "C:/Users/jeremye/a"
File.realpath('A')
# => "C:/Users/jeremye/A"

Not sure if that is considered a bug in File.realpath, but it would be nice if File.realpath returned the actual case of the file.

Updated by MSP-Greg (Greg L) 10 months ago

@nobu (Nobuyoshi Nakada)

Thanks.

Using the following Windows Rubies, I get different results. All double load and throw NameError:

ruby 3.1.4p223 (2023-03-30 revision 957bb7cb81) [x64-mingw-ucrt]
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x64-mingw-ucrt]
ruby 3.3.0dev (2023-05-24T13:45:34Z master 6d976eb534) [x64-mingw-ucrt]
ruby 3.3.0dev (2023-05-24T13:45:34Z master 6d976eb534) [x64-mswin64_140]

Updated by MSP-Greg (Greg L) 10 months ago

@jeremyevans0 (Jeremy Evans)

Thanks. I hadn't looked yet. JFYI, File.absolute_path does seem to work correctly.

# file name is Greg.txt
puts File.absolute_path 'C:/tmpdir/greg.txt' #=> C:/tmpdir/Greg.txt

# file name is ggreg.txt
puts File.absolute_path 'C:/tmpdir/GGreg.txt' #=> C:/tmpdir/ggreg.txt

Updated by nobu (Nobuyoshi Nakada) 10 months ago

File.absolute_path and File.expand_path normalize a short path to the long path, and the case too (maybe as a side effect).

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0