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