Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/ruby32/share/ruby
File: find.rb
# frozen_string_literal: true
[0] Fix | Delete
#
[1] Fix | Delete
# find.rb: the Find module for processing all files under a given directory.
[2] Fix | Delete
#
[3] Fix | Delete
[4] Fix | Delete
#
[5] Fix | Delete
# The +Find+ module supports the top-down traversal of a set of file paths.
[6] Fix | Delete
#
[7] Fix | Delete
# For example, to total the size of all files under your home directory,
[8] Fix | Delete
# ignoring anything in a "dot" directory (e.g. $HOME/.ssh):
[9] Fix | Delete
#
[10] Fix | Delete
# require 'find'
[11] Fix | Delete
#
[12] Fix | Delete
# total_size = 0
[13] Fix | Delete
#
[14] Fix | Delete
# Find.find(ENV["HOME"]) do |path|
[15] Fix | Delete
# if FileTest.directory?(path)
[16] Fix | Delete
# if File.basename(path).start_with?('.')
[17] Fix | Delete
# Find.prune # Don't look any further into this directory.
[18] Fix | Delete
# else
[19] Fix | Delete
# next
[20] Fix | Delete
# end
[21] Fix | Delete
# else
[22] Fix | Delete
# total_size += FileTest.size(path)
[23] Fix | Delete
# end
[24] Fix | Delete
# end
[25] Fix | Delete
#
[26] Fix | Delete
module Find
[27] Fix | Delete
[28] Fix | Delete
#
[29] Fix | Delete
# Calls the associated block with the name of every file and directory listed
[30] Fix | Delete
# as arguments, then recursively on their subdirectories, and so on.
[31] Fix | Delete
#
[32] Fix | Delete
# Returns an enumerator if no block is given.
[33] Fix | Delete
#
[34] Fix | Delete
# See the +Find+ module documentation for an example.
[35] Fix | Delete
#
[36] Fix | Delete
def find(*paths, ignore_error: true) # :yield: path
[37] Fix | Delete
block_given? or return enum_for(__method__, *paths, ignore_error: ignore_error)
[38] Fix | Delete
[39] Fix | Delete
fs_encoding = Encoding.find("filesystem")
[40] Fix | Delete
[41] Fix | Delete
paths.collect!{|d| raise Errno::ENOENT, d unless File.exist?(d); d.dup}.each do |path|
[42] Fix | Delete
path = path.to_path if path.respond_to? :to_path
[43] Fix | Delete
enc = path.encoding == Encoding::US_ASCII ? fs_encoding : path.encoding
[44] Fix | Delete
ps = [path]
[45] Fix | Delete
while file = ps.shift
[46] Fix | Delete
catch(:prune) do
[47] Fix | Delete
yield file.dup
[48] Fix | Delete
begin
[49] Fix | Delete
s = File.lstat(file)
[50] Fix | Delete
rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG, Errno::EINVAL
[51] Fix | Delete
raise unless ignore_error
[52] Fix | Delete
next
[53] Fix | Delete
end
[54] Fix | Delete
if s.directory? then
[55] Fix | Delete
begin
[56] Fix | Delete
fs = Dir.children(file, encoding: enc)
[57] Fix | Delete
rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG, Errno::EINVAL
[58] Fix | Delete
raise unless ignore_error
[59] Fix | Delete
next
[60] Fix | Delete
end
[61] Fix | Delete
fs.sort!
[62] Fix | Delete
fs.reverse_each {|f|
[63] Fix | Delete
f = File.join(file, f)
[64] Fix | Delete
ps.unshift f
[65] Fix | Delete
}
[66] Fix | Delete
end
[67] Fix | Delete
end
[68] Fix | Delete
end
[69] Fix | Delete
end
[70] Fix | Delete
nil
[71] Fix | Delete
end
[72] Fix | Delete
[73] Fix | Delete
#
[74] Fix | Delete
# Skips the current file or directory, restarting the loop with the next
[75] Fix | Delete
# entry. If the current file is a directory, that directory will not be
[76] Fix | Delete
# recursively entered. Meaningful only within the block associated with
[77] Fix | Delete
# Find::find.
[78] Fix | Delete
#
[79] Fix | Delete
# See the +Find+ module documentation for an example.
[80] Fix | Delete
#
[81] Fix | Delete
def prune
[82] Fix | Delete
throw :prune
[83] Fix | Delete
end
[84] Fix | Delete
[85] Fix | Delete
module_function :find, :prune
[86] Fix | Delete
end
[87] Fix | Delete
[88] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function