Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/ruby22/lib64/ruby/2.2.0
File: tmpdir.rb
#
[0] Fix | Delete
# tmpdir - retrieve temporary directory path
[1] Fix | Delete
#
[2] Fix | Delete
# $Id: tmpdir.rb 63017 2018-03-28 14:34:14Z usa $
[3] Fix | Delete
#
[4] Fix | Delete
[5] Fix | Delete
require 'fileutils'
[6] Fix | Delete
begin
[7] Fix | Delete
require 'etc.so'
[8] Fix | Delete
rescue LoadError # rescue LoadError for miniruby
[9] Fix | Delete
end
[10] Fix | Delete
[11] Fix | Delete
class Dir
[12] Fix | Delete
[13] Fix | Delete
@@systmpdir ||= defined?(Etc.systmpdir) ? Etc.systmpdir : '/tmp'
[14] Fix | Delete
[15] Fix | Delete
##
[16] Fix | Delete
# Returns the operating system's temporary file path.
[17] Fix | Delete
[18] Fix | Delete
def self.tmpdir
[19] Fix | Delete
if $SAFE > 0
[20] Fix | Delete
@@systmpdir
[21] Fix | Delete
else
[22] Fix | Delete
tmp = nil
[23] Fix | Delete
[ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp', '.'].each do |dir|
[24] Fix | Delete
next if !dir
[25] Fix | Delete
dir = File.expand_path(dir)
[26] Fix | Delete
if stat = File.stat(dir) and stat.directory? and stat.writable? and
[27] Fix | Delete
(!stat.world_writable? or stat.sticky?)
[28] Fix | Delete
tmp = dir
[29] Fix | Delete
break
[30] Fix | Delete
end rescue nil
[31] Fix | Delete
end
[32] Fix | Delete
raise ArgumentError, "could not find a temporary directory" unless tmp
[33] Fix | Delete
tmp
[34] Fix | Delete
end
[35] Fix | Delete
end
[36] Fix | Delete
[37] Fix | Delete
# Dir.mktmpdir creates a temporary directory.
[38] Fix | Delete
#
[39] Fix | Delete
# The directory is created with 0700 permission.
[40] Fix | Delete
# Application should not change the permission to make the temporary directory accessible from other users.
[41] Fix | Delete
#
[42] Fix | Delete
# The prefix and suffix of the name of the directory is specified by
[43] Fix | Delete
# the optional first argument, <i>prefix_suffix</i>.
[44] Fix | Delete
# - If it is not specified or nil, "d" is used as the prefix and no suffix is used.
[45] Fix | Delete
# - If it is a string, it is used as the prefix and no suffix is used.
[46] Fix | Delete
# - If it is an array, first element is used as the prefix and second element is used as a suffix.
[47] Fix | Delete
#
[48] Fix | Delete
# Dir.mktmpdir {|dir| dir is ".../d..." }
[49] Fix | Delete
# Dir.mktmpdir("foo") {|dir| dir is ".../foo..." }
[50] Fix | Delete
# Dir.mktmpdir(["foo", "bar"]) {|dir| dir is ".../foo...bar" }
[51] Fix | Delete
#
[52] Fix | Delete
# The directory is created under Dir.tmpdir or
[53] Fix | Delete
# the optional second argument <i>tmpdir</i> if non-nil value is given.
[54] Fix | Delete
#
[55] Fix | Delete
# Dir.mktmpdir {|dir| dir is "#{Dir.tmpdir}/d..." }
[56] Fix | Delete
# Dir.mktmpdir(nil, "/var/tmp") {|dir| dir is "/var/tmp/d..." }
[57] Fix | Delete
#
[58] Fix | Delete
# If a block is given,
[59] Fix | Delete
# it is yielded with the path of the directory.
[60] Fix | Delete
# The directory and its contents are removed
[61] Fix | Delete
# using FileUtils.remove_entry before Dir.mktmpdir returns.
[62] Fix | Delete
# The value of the block is returned.
[63] Fix | Delete
#
[64] Fix | Delete
# Dir.mktmpdir {|dir|
[65] Fix | Delete
# # use the directory...
[66] Fix | Delete
# open("#{dir}/foo", "w") { ... }
[67] Fix | Delete
# }
[68] Fix | Delete
#
[69] Fix | Delete
# If a block is not given,
[70] Fix | Delete
# The path of the directory is returned.
[71] Fix | Delete
# In this case, Dir.mktmpdir doesn't remove the directory.
[72] Fix | Delete
#
[73] Fix | Delete
# dir = Dir.mktmpdir
[74] Fix | Delete
# begin
[75] Fix | Delete
# # use the directory...
[76] Fix | Delete
# open("#{dir}/foo", "w") { ... }
[77] Fix | Delete
# ensure
[78] Fix | Delete
# # remove the directory.
[79] Fix | Delete
# FileUtils.remove_entry dir
[80] Fix | Delete
# end
[81] Fix | Delete
#
[82] Fix | Delete
def Dir.mktmpdir(prefix_suffix=nil, *rest)
[83] Fix | Delete
path = Tmpname.create(prefix_suffix || "d", *rest) {|n| mkdir(n, 0700)}
[84] Fix | Delete
if block_given?
[85] Fix | Delete
begin
[86] Fix | Delete
yield path
[87] Fix | Delete
ensure
[88] Fix | Delete
stat = File.stat(File.dirname(path))
[89] Fix | Delete
if stat.world_writable? and !stat.sticky?
[90] Fix | Delete
raise ArgumentError, "parent directory is world writable but not sticky"
[91] Fix | Delete
end
[92] Fix | Delete
FileUtils.remove_entry path
[93] Fix | Delete
end
[94] Fix | Delete
else
[95] Fix | Delete
path
[96] Fix | Delete
end
[97] Fix | Delete
end
[98] Fix | Delete
[99] Fix | Delete
module Tmpname # :nodoc:
[100] Fix | Delete
module_function
[101] Fix | Delete
[102] Fix | Delete
def tmpdir
[103] Fix | Delete
Dir.tmpdir
[104] Fix | Delete
end
[105] Fix | Delete
[106] Fix | Delete
def make_tmpname((prefix, suffix), n)
[107] Fix | Delete
prefix = (String.try_convert(prefix) or
[108] Fix | Delete
raise ArgumentError, "unexpected prefix: #{prefix.inspect}")
[109] Fix | Delete
prefix = prefix.delete("#{File::SEPARATOR}#{File::ALT_SEPARATOR}")
[110] Fix | Delete
suffix &&= (String.try_convert(suffix) or
[111] Fix | Delete
raise ArgumentError, "unexpected suffix: #{suffix.inspect}")
[112] Fix | Delete
suffix &&= suffix.delete("#{File::SEPARATOR}#{File::ALT_SEPARATOR}")
[113] Fix | Delete
t = Time.now.strftime("%Y%m%d")
[114] Fix | Delete
path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
[115] Fix | Delete
path << "-#{n}" if n
[116] Fix | Delete
path << suffix if suffix
[117] Fix | Delete
path
[118] Fix | Delete
end
[119] Fix | Delete
[120] Fix | Delete
def create(basename, tmpdir=nil, max_try: nil, **opts)
[121] Fix | Delete
if $SAFE > 0 and tmpdir.tainted?
[122] Fix | Delete
tmpdir = '/tmp'
[123] Fix | Delete
else
[124] Fix | Delete
tmpdir ||= tmpdir()
[125] Fix | Delete
end
[126] Fix | Delete
n = nil
[127] Fix | Delete
begin
[128] Fix | Delete
path = File.join(tmpdir, make_tmpname(basename, n))
[129] Fix | Delete
yield(path, n, opts)
[130] Fix | Delete
rescue Errno::EEXIST
[131] Fix | Delete
n ||= 0
[132] Fix | Delete
n += 1
[133] Fix | Delete
retry if !max_try or n < max_try
[134] Fix | Delete
raise "cannot generate temporary name using `#{basename}' under `#{tmpdir}'"
[135] Fix | Delete
end
[136] Fix | Delete
path
[137] Fix | Delete
end
[138] Fix | Delete
end
[139] Fix | Delete
end
[140] Fix | Delete
[141] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function