Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby18/lib64/ruby/1.8
File: tmpdir.rb
#
[0] Fix | Delete
# tmpdir - retrieve temporary directory path
[1] Fix | Delete
#
[2] Fix | Delete
# $Id: tmpdir.rb 21776 2009-01-26 02:12:10Z shyouhei $
[3] Fix | Delete
#
[4] Fix | Delete
[5] Fix | Delete
require 'fileutils'
[6] Fix | Delete
[7] Fix | Delete
class Dir
[8] Fix | Delete
[9] Fix | Delete
@@systmpdir = '/tmp'
[10] Fix | Delete
[11] Fix | Delete
begin
[12] Fix | Delete
require 'Win32API'
[13] Fix | Delete
CSIDL_LOCAL_APPDATA = 0x001c
[14] Fix | Delete
max_pathlen = 260
[15] Fix | Delete
windir = "\0"*(max_pathlen+1)
[16] Fix | Delete
begin
[17] Fix | Delete
getdir = Win32API.new('shell32', 'SHGetFolderPath', 'LLLLP', 'L')
[18] Fix | Delete
raise RuntimeError if getdir.call(0, CSIDL_LOCAL_APPDATA, 0, 0, windir) != 0
[19] Fix | Delete
windir = File.expand_path(windir.rstrip)
[20] Fix | Delete
rescue RuntimeError
[21] Fix | Delete
begin
[22] Fix | Delete
getdir = Win32API.new('kernel32', 'GetSystemWindowsDirectory', 'PL', 'L')
[23] Fix | Delete
rescue RuntimeError
[24] Fix | Delete
getdir = Win32API.new('kernel32', 'GetWindowsDirectory', 'PL', 'L')
[25] Fix | Delete
end
[26] Fix | Delete
len = getdir.call(windir, windir.size)
[27] Fix | Delete
windir = File.expand_path(windir[0, len])
[28] Fix | Delete
end
[29] Fix | Delete
temp = File.join(windir.untaint, 'temp')
[30] Fix | Delete
@@systmpdir = temp if File.directory?(temp) and File.writable?(temp)
[31] Fix | Delete
rescue LoadError
[32] Fix | Delete
end
[33] Fix | Delete
[34] Fix | Delete
##
[35] Fix | Delete
# Returns the operating system's temporary file path.
[36] Fix | Delete
[37] Fix | Delete
def Dir::tmpdir
[38] Fix | Delete
tmp = '.'
[39] Fix | Delete
if $SAFE > 0
[40] Fix | Delete
tmp = @@systmpdir
[41] Fix | Delete
else
[42] Fix | Delete
for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'],
[43] Fix | Delete
ENV['USERPROFILE'], @@systmpdir, '/tmp']
[44] Fix | Delete
if dir and File.directory?(dir) and File.writable?(dir)
[45] Fix | Delete
tmp = dir
[46] Fix | Delete
break
[47] Fix | Delete
end
[48] Fix | Delete
end
[49] Fix | Delete
File.expand_path(tmp)
[50] Fix | Delete
end
[51] Fix | Delete
end
[52] Fix | Delete
[53] Fix | Delete
# Dir.mktmpdir creates a temporary directory.
[54] Fix | Delete
#
[55] Fix | Delete
# The directory is created with 0700 permission.
[56] Fix | Delete
#
[57] Fix | Delete
# The prefix and suffix of the name of the directory is specified by
[58] Fix | Delete
# the optional first argument, <i>prefix_suffix</i>.
[59] Fix | Delete
# - If it is not specified or nil, "d" is used as the prefix and no suffix is used.
[60] Fix | Delete
# - If it is a string, it is used as the prefix and no suffix is used.
[61] Fix | Delete
# - If it is an array, first element is used as the prefix and second element is used as a suffix.
[62] Fix | Delete
#
[63] Fix | Delete
# Dir.mktmpdir {|dir| dir is ".../d..." }
[64] Fix | Delete
# Dir.mktmpdir("foo") {|dir| dir is ".../foo..." }
[65] Fix | Delete
# Dir.mktmpdir(["foo", "bar"]) {|dir| dir is ".../foo...bar" }
[66] Fix | Delete
#
[67] Fix | Delete
# The directory is created under Dir.tmpdir or
[68] Fix | Delete
# the optional second argument <i>tmpdir</i> if non-nil value is given.
[69] Fix | Delete
#
[70] Fix | Delete
# Dir.mktmpdir {|dir| dir is "#{Dir.tmpdir}/d..." }
[71] Fix | Delete
# Dir.mktmpdir(nil, "/var/tmp") {|dir| dir is "/var/tmp/d..." }
[72] Fix | Delete
#
[73] Fix | Delete
# If a block is given,
[74] Fix | Delete
# it is yielded with the path of the directory.
[75] Fix | Delete
# The directory and its contents are removed
[76] Fix | Delete
# using FileUtils.remove_entry_secure before Dir.mktmpdir returns.
[77] Fix | Delete
# The value of the block is returned.
[78] Fix | Delete
#
[79] Fix | Delete
# Dir.mktmpdir {|dir|
[80] Fix | Delete
# # use the directory...
[81] Fix | Delete
# open("#{dir}/foo", "w") { ... }
[82] Fix | Delete
# }
[83] Fix | Delete
#
[84] Fix | Delete
# If a block is not given,
[85] Fix | Delete
# The path of the directory is returned.
[86] Fix | Delete
# In this case, Dir.mktmpdir doesn't remove the directory.
[87] Fix | Delete
#
[88] Fix | Delete
# dir = Dir.mktmpdir
[89] Fix | Delete
# begin
[90] Fix | Delete
# # use the directory...
[91] Fix | Delete
# open("#{dir}/foo", "w") { ... }
[92] Fix | Delete
# ensure
[93] Fix | Delete
# # remove the directory.
[94] Fix | Delete
# FileUtils.remove_entry_secure dir
[95] Fix | Delete
# end
[96] Fix | Delete
#
[97] Fix | Delete
def Dir.mktmpdir(prefix_suffix=nil, tmpdir=nil)
[98] Fix | Delete
case prefix_suffix
[99] Fix | Delete
when nil
[100] Fix | Delete
prefix = "d"
[101] Fix | Delete
suffix = ""
[102] Fix | Delete
when String
[103] Fix | Delete
prefix = prefix_suffix
[104] Fix | Delete
suffix = ""
[105] Fix | Delete
when Array
[106] Fix | Delete
prefix = prefix_suffix[0]
[107] Fix | Delete
suffix = prefix_suffix[1]
[108] Fix | Delete
else
[109] Fix | Delete
raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
[110] Fix | Delete
end
[111] Fix | Delete
tmpdir ||= Dir.tmpdir
[112] Fix | Delete
t = Time.now.strftime("%Y%m%d")
[113] Fix | Delete
n = nil
[114] Fix | Delete
begin
[115] Fix | Delete
path = "#{tmpdir}/#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
[116] Fix | Delete
path << "-#{n}" if n
[117] Fix | Delete
path << suffix
[118] Fix | Delete
Dir.mkdir(path, 0700)
[119] Fix | Delete
rescue Errno::EEXIST
[120] Fix | Delete
n ||= 0
[121] Fix | Delete
n += 1
[122] Fix | Delete
retry
[123] Fix | Delete
end
[124] Fix | Delete
[125] Fix | Delete
if block_given?
[126] Fix | Delete
begin
[127] Fix | Delete
yield path
[128] Fix | Delete
ensure
[129] Fix | Delete
FileUtils.remove_entry_secure path
[130] Fix | Delete
end
[131] Fix | Delete
else
[132] Fix | Delete
path
[133] Fix | Delete
end
[134] Fix | Delete
end
[135] Fix | Delete
end
[136] Fix | Delete
[137] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function