summaryrefslogtreecommitdiff
path: root/lib/tmpdir.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-29 00:43:12 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-29 00:43:12 +0000
commit285fb001952a688f5213596ded1c244469092353 (patch)
tree26c42559a0f16ea5c79a01a94cdf436f661ff4eb /lib/tmpdir.rb
parente47ebfe5187a19a1d379b97810cd8684de8cc339 (diff)
* lib/tmpdir.rb (@@systmpdir): prior LOCAL_APPDATA if possible, and
should be clean. based on a patch from arton <artonx AT yahoo.co.jp> at [ruby-dev:35269] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/tmpdir.rb')
-rw-r--r--lib/tmpdir.rb19
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb
index 95ef08cfd6..2e82aa528e 100644
--- a/lib/tmpdir.rb
+++ b/lib/tmpdir.rb
@@ -12,16 +12,23 @@ class Dir
begin
require 'Win32API'
+ CSIDL_LOCAL_APPDATA = 0x001c
max_pathlen = 260
windir = ' '*(max_pathlen+1)
begin
- getdir = Win32API.new('kernel32', 'GetSystemWindowsDirectory', 'PL', 'L')
+ getdir = Win32API.new('shell32', 'SHGetFolderPath', 'LLLLP', 'L')
+ raise RuntimeError if getdir.call(0, CSIDL_LOCAL_APPDATA, 0, 0, windir) != 0
+ windir = File.expand_path(windir.rstrip)
rescue RuntimeError
- getdir = Win32API.new('kernel32', 'GetWindowsDirectory', 'PL', 'L')
+ begin
+ getdir = Win32API.new('kernel32', 'GetSystemWindowsDirectory', 'PL', 'L')
+ rescue RuntimeError
+ getdir = Win32API.new('kernel32', 'GetWindowsDirectory', 'PL', 'L')
+ end
+ len = getdir.call(windir, windir.size)
+ windir = File.expand_path(windir[0, len])
end
- len = getdir.call(windir, windir.size)
- windir = File.expand_path(windir[0, len])
- temp = File.join(windir, 'temp')
+ temp = File.join(windir.untaint, 'temp')
@@systmpdir = temp if File.directory?(temp) and File.writable?(temp)
rescue LoadError
end
@@ -41,8 +48,8 @@ class Dir
break
end
end
+ File.expand_path(tmp)
end
- File.expand_path(tmp)
end
# Dir.mktmpdir creates a temporary directory.