* 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
This commit is contained in:
matz 2003-07-21 15:34:18 +00:00
Родитель 15c3df744f
Коммит 2416271405
6 изменённых файлов: 45 добавлений и 8 удалений

Просмотреть файл

@ -1,3 +1,12 @@
Tue Jul 22 00:19:19 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <matz@ruby-lang.org> Mon Jul 21 01:53:43 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* string.c: use StringValueCStr to retrieve paths to system calls. * string.c: use StringValueCStr to retrieve paths to system calls.

Просмотреть файл

@ -11,6 +11,7 @@ lib/bigdecimal/jacobian.rb
lib/bigdecimal/newton.rb lib/bigdecimal/newton.rb
lib/bigdecimal/ludcmp.rb lib/bigdecimal/ludcmp.rb
lib/bigdecimal/util.rb lib/bigdecimal/util.rb
lib/bigdecimal/nlsolve.rb
sample/linear.rb sample/linear.rb
sample/nlsolve.rb sample/nlsolve.rb
sample/pi.rb sample/pi.rb

Просмотреть файл

@ -3,6 +3,7 @@
# Copyright (C) 2000 Information-technology Promotion Agency, Japan # Copyright (C) 2000 Information-technology Promotion Agency, Japan
require 'cgi' require 'cgi'
require 'tmpdir'
class CGI class CGI
class Session class Session
@ -109,7 +110,7 @@ class CGI
end end
def initialize(session, option={}) def initialize(session, option={})
dir = option['tmpdir'] || ENV['TMP'] || '/tmp' dir = option['tmpdir'] || Dir::TMPDIR
prefix = option['prefix'] || '' prefix = option['prefix'] || ''
id = session.session_id id = session.session_id
unless check_id(id) unless check_id(id)

Просмотреть файл

@ -1,5 +1,6 @@
require 'socket' require 'socket'
require 'drb/drb' require 'drb/drb'
require 'tmpdir'
module DRb module DRb
@ -52,8 +53,7 @@ module DRb
Max_try = 10 Max_try = 10
private private
def self.temp_server def self.temp_server
tmpdir = ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP'] || '/tmp' tmpdir = Dir::TMPDIR
tmpdir = '/tmp' if $SAFE > 0 and tmpdir.tainted?
n = 0 n = 0
while true while true
begin begin

Просмотреть файл

@ -5,6 +5,7 @@
# #
require 'delegate' require 'delegate'
require 'tmpdir'
# A class for managing temporary files. This library is written to be # A class for managing temporary files. This library is written to be
# thread safe. # thread safe.
@ -17,11 +18,10 @@ class Tempfile < SimpleDelegator
# object works just like a File object. # object works just like a File object.
# #
# If tmpdir is omitted, the temporary directory is determined by # If tmpdir is omitted, the temporary directory is determined by
# ENV['TMPDIR'], ENV['TMP'] and and ENV['TEMP'] in the order named. # Dir::TMPDIR provided by 'tmpdir.rb'.
# If none of them is available, or when $SAFE > 0 and the given # When $SAFE > 0 and the given tmpdir is tainted, it uses
# tmpdir is tainted, it uses /tmp. (Note that ENV values are # /tmp. (Note that ENV values are tainted by default)
# tainted by default) def initialize(basename, tmpdir=Dir::TMPDIR)
def initialize(basename, tmpdir=ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp')
if $SAFE > 0 and tmpdir.tainted? if $SAFE > 0 and tmpdir.tainted?
tmpdir = '/tmp' tmpdir = '/tmp'
end end

26
lib/tmpdir.rb Normal file
Просмотреть файл

@ -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