diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-07-21 15:34:18 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-07-21 15:34:18 +0000 |
commit | 24162714051692617fe25fda7e88c58e25013c97 (patch) | |
tree | 619799712c383752f7cd302906684a9c0856203e /lib | |
parent | 15c3df744f228f3d967ca624533d17f491555e93 (diff) | |
download | ruby-24162714051692617fe25fda7e88c58e25013c97.tar.gz |
* lib/tmpdir.rb: new library to get temporary directory path,
using GetTempPath on Win32 environment.
* lib/tempfile.rb: now uses tmpdir.rb.
* lib/cgi/session.rb, ib/drb/unix.rb: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4109 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cgi/session.rb | 3 | ||||
-rw-r--r-- | lib/drb/unix.rb | 4 | ||||
-rw-r--r-- | lib/tempfile.rb | 10 | ||||
-rw-r--r-- | lib/tmpdir.rb | 26 |
4 files changed, 35 insertions, 8 deletions
diff --git a/lib/cgi/session.rb b/lib/cgi/session.rb index 9306508239..ae4fb19449 100644 --- a/lib/cgi/session.rb +++ b/lib/cgi/session.rb @@ -3,6 +3,7 @@ # Copyright (C) 2000 Information-technology Promotion Agency, Japan require 'cgi' +require 'tmpdir' class CGI class Session @@ -109,7 +110,7 @@ class CGI end def initialize(session, option={}) - dir = option['tmpdir'] || ENV['TMP'] || '/tmp' + dir = option['tmpdir'] || Dir::TMPDIR prefix = option['prefix'] || '' id = session.session_id unless check_id(id) diff --git a/lib/drb/unix.rb b/lib/drb/unix.rb index f9a2f75acd..6c6b703c03 100644 --- a/lib/drb/unix.rb +++ b/lib/drb/unix.rb @@ -1,5 +1,6 @@ require 'socket' require 'drb/drb' +require 'tmpdir' module DRb @@ -52,8 +53,7 @@ module DRb Max_try = 10 private def self.temp_server - tmpdir = ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP'] || '/tmp' - tmpdir = '/tmp' if $SAFE > 0 and tmpdir.tainted? + tmpdir = Dir::TMPDIR n = 0 while true begin diff --git a/lib/tempfile.rb b/lib/tempfile.rb index b122795294..baaac8fc88 100644 --- a/lib/tempfile.rb +++ b/lib/tempfile.rb @@ -5,6 +5,7 @@ # require 'delegate' +require 'tmpdir' # A class for managing temporary files. This library is written to be # thread safe. @@ -17,11 +18,10 @@ class Tempfile < SimpleDelegator # object works just like a File object. # # If tmpdir is omitted, the temporary directory is determined by - # ENV['TMPDIR'], ENV['TMP'] and and ENV['TEMP'] in the order named. - # If none of them is available, or when $SAFE > 0 and the given - # tmpdir is tainted, it uses /tmp. (Note that ENV values are - # tainted by default) - def initialize(basename, tmpdir=ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp') + # Dir::TMPDIR provided by 'tmpdir.rb'. + # When $SAFE > 0 and the given tmpdir is tainted, it uses + # /tmp. (Note that ENV values are tainted by default) + def initialize(basename, tmpdir=Dir::TMPDIR) if $SAFE > 0 and tmpdir.tainted? tmpdir = '/tmp' end diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb new file mode 100644 index 0000000000..5e8dd6bf35 --- /dev/null +++ b/lib/tmpdir.rb @@ -0,0 +1,26 @@ +# +# tmpdir - retrieve temporary directory path +# +# $Id$ +# + +class Dir + begin + require "Win32API" + max_pathlen = 260 + t_path = ' '*(max_pathlen+1) + t_path[0, Win32API.new('kernel32', 'GetTempPath', 'LP', 'L').call(t_path.size, t_path)] + t_path.untaint + TMPDIR = t_path + rescue LoadError + if $SAFE > 0 + TMPDIR = '/tmp' + else + TMPDIR = ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp' + end + end +end + +if __FILE__ == $0 + puts Dir::TMPDIR +end |