summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreban <eban@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-23 16:37:35 +0000
committereban <eban@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-23 16:37:35 +0000
commit02f036ddbcb3409092e397b2df247bd9447e8b3f (patch)
treecc4e482833c937fb79e2ec09690f04ed2992fe7a
parent231247c010acba191b78ed2d1310c935e63ad919 (diff)
* lib/tmpdir.rb (tmpdir): new method. remove TMPDIR.
use GetSystemWindowsDirectory(GetSystemDirectory), not GetTempPath. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4129 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--lib/cgi/session.rb2
-rw-r--r--lib/drb/unix.rb2
-rw-r--r--lib/tempfile.rb4
-rw-r--r--lib/tmpdir.rb38
5 files changed, 36 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 51ae2ecbb7..199e5aa636 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Jul 24 01:32:04 2003 WATANABE Hirofumi <eban@ruby-lang.org>
+
+ * lib/tmpdir.rb (tmpdir): new method. remove TMPDIR.
+ use GetSystemWindowsDirectory(GetSystemDirectory), not GetTempPath.
+
Thu Jul 24 01:08:43 2003 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl: imported.
diff --git a/lib/cgi/session.rb b/lib/cgi/session.rb
index ae4fb19449..0ce82b3920 100644
--- a/lib/cgi/session.rb
+++ b/lib/cgi/session.rb
@@ -110,7 +110,7 @@ class CGI
end
def initialize(session, option={})
- dir = option['tmpdir'] || Dir::TMPDIR
+ 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 6c6b703c03..eef4902cef 100644
--- a/lib/drb/unix.rb
+++ b/lib/drb/unix.rb
@@ -53,7 +53,7 @@ module DRb
Max_try = 10
private
def self.temp_server
- tmpdir = Dir::TMPDIR
+ tmpdir = Dir::tmpdir
n = 0
while true
begin
diff --git a/lib/tempfile.rb b/lib/tempfile.rb
index baaac8fc88..f5dc801b21 100644
--- a/lib/tempfile.rb
+++ b/lib/tempfile.rb
@@ -18,10 +18,10 @@ class Tempfile < SimpleDelegator
# object works just like a File object.
#
# If tmpdir is omitted, the temporary directory is determined by
- # Dir::TMPDIR provided by 'tmpdir.rb'.
+ # 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)
+ 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
index 6fde398ed4..eaec830b08 100644
--- a/lib/tmpdir.rb
+++ b/lib/tmpdir.rb
@@ -5,22 +5,38 @@
#
class Dir
+
+ @@systmpdir = '/tmp'
+
begin
- require "Win32API"
+ require 'Win32API'
max_pathlen = 260
- t_path = ' '*(max_pathlen+1)
- t_path = t_path[0, Win32API.new('kernel32', 'GetTempPath', 'LP', 'L').call(t_path.size, t_path)]
- t_path.untaint
- TMPDIR = File.expand_path(t_path)
+ windir = ' '*(max_pathlen+1)
+ begin
+ getdir = Win32API.new('kernel32', 'GetSystemWindowsDirectory', 'PL', 'L')
+ rescue RuntimeError
+ getdir = Win32API.new('kernel32', 'GetSystemDirectory', 'PL', 'L')
+ end
+ getdir.call(windir, windir.size)
+ windir = File.expand_path(windir.rstrip.untaint)
+ temp = File.join(windir, 'temp')
+ @@systmpdir = temp if File.directory?(temp) and File.writable?(temp)
rescue LoadError
+ end
+
+ def Dir::tmpdir
+ tmp = '.'
if $SAFE > 0
- TMPDIR = '/tmp'
+ tmp = @@systmpdir
else
- TMPDIR = File.expand_path(ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp')
+ for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'],
+ ENV['USERPROFILE'], @@systmpdir, '/tmp']
+ if dir and File.directory?(dir) and File.writable?(dir)
+ tmp = dir
+ break
+ end
+ end
end
+ File.expand_path(tmp)
end
end
-
-if __FILE__ == $0
- puts Dir::TMPDIR
-end