bioffe
bioffe

Reputation: 6393

File.open fails to open relative path if path is bigger than certain size

require 'FileUtils'
path = '../tmp/brpm_storage/FGRKKSSUI/lentkriskeditor/1.2.5/20170705121128/lentkriskeditor-1.2.5-dist/lentkriskeditor-1.2.5/jre/jre1.8.0_131/lib/desktop/icons/HighContrast/48x48/mimetypes/gnome-mime-application-x-java-jnlp-file.png'

FileUtils.mkdir_p(File.dirname(path))

File.open(path, 'wb') {|file|
# File.open(File.expand_path(path), 'wb') {|file|  # Full path always works
    file.write('Hello') 
}

fails

tmp.rb:6:in `initialize': No such file or directory - ../tmp/brpm_storage/FGRKKSSUI/lentkriskeditor/1.2.5/20170705121128/lentkriskeditor-1.2.5-dist/lentkriskeditor-1.2.5/jre/jre1.8.0_131/lib/desktop/icons/HighContrast/48x48/mimetypes/gnome-mime-application-x-java-jnlp-file.png (Errno::ENOENT)
"C:/src3/branches/PSENG-5315/BMC/utils/tmp/brpm_storage/FGRKKSSUI/lentkriskeditor/1.2.5/20170705121128/lentkriskeditor-1.2.5-dist/lentkriskeditor-1.2.5/jre/jre1.8.0_131/lib/desktop/icons/HighContrast/48x48/mimetypes/gnome-mime-application-x-java-jnlp-file.png"
    from C:/src3/branches/PSENG-5315/BMC/utils/yatra_logic/tmp.rb:6:in `open'
    from C:/src3/branches/PSENG-5315/BMC/utils/yatra_logic/tmp.rb:6:in `<top (required)>'
    from -e:1:in `load'
    from -e:1:in `<main>'

I noticed this phenomena in ruby 1.9.3 v551 and 2.0.0. With JRuby everything works as expected. I wonder what is the culprit?

c:\Ruby200\bin\ruby.exe -v
ruby 2.0.0p0 (2013-02-24) [i386-mingw32]

Upvotes: 0

Views: 283

Answers (1)

Jon Wolski
Jon Wolski

Reputation: 2823

See Why does the 260 character path length limit exist in Windows? and https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx

Certain Windows APIs have a file path string-length limit of 260 'characters.' (I assume that refers to a Windows CP-1252 character.)

I suspect that JRuby navigates file paths through the JVM, which works around this limitation. See How does Java circumvent the windows MAX_PATH WinAPI limitation.

Upvotes: 1

Related Questions