Created
February 18, 2012 12:45
-
-
Save shirosaki/1859130 to your computer and use it in GitHub Desktop.
Long name conversion on webrick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/webrick/httpservlet/filehandler.rb b/lib/webrick/httpservlet/filehandler.rb | |
index 8736f57..e03db0f 100644 | |
--- a/lib/webrick/httpservlet/filehandler.rb | |
+++ b/lib/webrick/httpservlet/filehandler.rb | |
@@ -327,12 +327,26 @@ module WEBrick | |
end | |
end | |
+ if /mswin|mingw/ =~ RUBY_PLATFORM | |
+ require 'Win32API' | |
+ | |
+ GetLongPathName = Win32API.new(*%w"kernel32 GetLongPathName SSI I") | |
+ | |
+ def long_path_name(name) | |
+ if (len = GetLongPathName.call(name, nil, 0)).nonzero? | |
+ buf = "\0" * len | |
+ buf[0...GetLongPathName.call(name, buf, buf.size)] | |
+ end | |
+ end | |
+ end | |
+ | |
def shift_path_info(req, res, path_info, base=nil) | |
tmp = path_info.shift | |
base = base || tmp | |
req.path_info = path_info.join | |
req.script_name << base | |
res.filename = File.expand_path(res.filename + base) | |
+ res.filename = long_path_name(res.filename) if /mswin|mingw/ =~ RUBY_PLATFORM | |
check_filename(req, res, File.basename(res.filename)) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment