BUG: CGI.Session on Windows

If a newbie tries to get CGI Sessions working, he will run in the
following bug. No code example that i have seen so far starts with supplying
the temporary diectory as an option.

s = CGI::Session.new(cgi,{“tmpdir” => “z:/temp/”, “session_path” => “/”})

And if a user does not do this it will result in an error because the
default in “session.rb:105” is

“dir = option[‘tmpdir’] || ENV[‘TMP’] || ‘/tmp’”

‘/tmp’ is not valid under windows and normally (standart
configuration) CGI’s don’t get the environment variables from the
system. So could we change this into

"dir = option[‘tmpdir’] || ENV[‘TMP’] || Dir::temp_directory

and add a “temp_directory” method to the Dir class that returns '/tmp’
or on windows the value of the “GetTempPath” function.

I would highly recommand this change. It makes the newbies life much
easier.

BTW is there any public bug tracking system where i can add such
requests.

Hi,

···

In message “BUG: CGI.Session on Windows” on 03/07/20, Lothar Scholz mailinglists@scriptolutions.com writes:

‘/tmp’ is not valid under windows and normally (standart
configuration) CGI’s don’t get the environment variables from the
system. So could we change this into

"dir = option[‘tmpdir’] || ENV[‘TMP’] || Dir::temp_directory

and add a “temp_directory” method to the Dir class that returns ‘/tmp’
or on windows the value of the “GetTempPath” function.

I would highly recommand this change. It makes the newbies life much
easier.

Interesting idea. We have same problem for tempfile library. Maybe
it can be defined by Ruby library. I think GetTempPath can be
accessed via Win32API, right?

						matz.

require “Win32API”
MAX_PATH = 260

def temp_path
t_path = ’ '*(MAX_PATH+1)
t_path[0, Win32API.new(‘kernel32’, ‘GetTempPath’, ‘LP’, ‘L’).call(t_path.size, t_path)]
end

puts temp_path

→ C:\TEMP\

Remarks (from Win32 help)

The GetTempPath function gets the temporary file path as follows:

1. The path specified by the TMP environment variable.

2. The path specified by the TEMP environment variable, if TMP is not defined.

3. The current directory, if both TMP and TEMP are not defined.

daz

···

In message “BUG: CGI.Session on Windows” > on 03/07/20, Lothar Scholz mailinglists@scriptolutions.com writes:

‘/tmp’ is not valid under windows and normally (standart
configuration) CGI’s don’t get the environment variables from the
system. So could we change this into

"dir = option[‘tmpdir’] || ENV[‘TMP’] || Dir::temp_directory

and add a “temp_directory” method to the Dir class that returns ‘/tmp’
or on windows the value of the “GetTempPath” function.

I would highly recommand this change. It makes the newbies life much
easier.

Interesting idea. We have same problem for tempfile library. Maybe
it can be defined by Ruby library. I think GetTempPath can be
accessed via Win32API, right?

matz.

Hi,

···

In message “Re: BUG: CGI.Session on Windows” on 03/07/21, “daz” dooby@d10.karoo.co.uk writes:

require “Win32API”
MAX_PATH = 260

def temp_path
t_path = ’ '*(MAX_PATH+1)
t_path[0, Win32API.new(‘kernel32’, ‘GetTempPath’, ‘LP’, ‘L’).call(t_path.size, t_path)]
end

puts temp_path

→ C:\TEMP\

Thank you for the code. It will help me a lot.

						matz.