From 24162714051692617fe25fda7e88c58e25013c97 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 21 Jul 2003 15:34:18 +0000 Subject: [PATCH] * 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 --- ChangeLog | 9 +++++++++ ext/bigdecimal/MANIFEST | 1 + lib/cgi/session.rb | 3 ++- lib/drb/unix.rb | 4 ++-- lib/tempfile.rb | 10 +++++----- lib/tmpdir.rb | 26 ++++++++++++++++++++++++++ 6 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 lib/tmpdir.rb diff --git a/ChangeLog b/ChangeLog index 41514edaf2..4003a6ad4b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Tue Jul 22 00:19:19 2003 Yukihiro Matsumoto + + * 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. + Mon Jul 21 01:53:43 2003 Yukihiro Matsumoto * string.c: use StringValueCStr to retrieve paths to system calls. diff --git a/ext/bigdecimal/MANIFEST b/ext/bigdecimal/MANIFEST index 8e9415eeea..88fc3c2efb 100644 --- a/ext/bigdecimal/MANIFEST +++ b/ext/bigdecimal/MANIFEST @@ -11,6 +11,7 @@ lib/bigdecimal/jacobian.rb lib/bigdecimal/newton.rb lib/bigdecimal/ludcmp.rb lib/bigdecimal/util.rb +lib/bigdecimal/nlsolve.rb sample/linear.rb sample/nlsolve.rb sample/pi.rb 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