return old find until fixed
-# frozen_string_literal: false
#
# find.rb: the Find module for processing all files under a given directory.
#
@@ -31,46 +30,39 @@ module Find
# Calls the associated block with the name of every file and directory listed
# as arguments, then recursively on their subdirectories, and so on.
#
- # Returns an enumerator if no block is given.
- #
# See the +Find+ module documentation for an example.
#
- def find(*paths, ignore_error: true) # :yield: path
- block_given? or return enum_for(__method__, *paths, ignore_error: ignore_error)
-
- fs_encoding = Encoding.find("filesystem")
+ def find(*paths) # :yield: path
+ block_given? or return enum_for(__method__, *paths)
- paths.collect!{|d| raise Errno::ENOENT unless File.exist?(d); d.dup}.each do |path|
- path = path.to_path if path.respond_to? :to_path
- enc = path.encoding == Encoding::US_ASCII ? fs_encoding : path.encoding
- ps = [path]
- while file = ps.shift
+ paths.collect!{|d| raise Errno::ENOENT unless File.exist?(d); d.dup}
+ while file = paths.shift
catch(:prune) do
yield file.dup.taint
+ next unless File.exist? file
begin
- s = File.lstat(file)
- rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
- raise unless ignore_error
- next
- end
- if s.directory? then
+ if File.lstat(file).directory? then
+ d = Dir.open(file)
begin
- fs = Dir.entries(file, encoding: enc)
- rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
- raise unless ignore_error
- next
- end
- fs.sort!
- fs.reverse_each {|f|
+ for f in d
next if f == "." or f == ".."
+ if File::ALT_SEPARATOR and file =~ /^(?:[\/\\]|[A-Za-z]:[\/\\]?)$/ then
+ f = file + f
+ elsif file == "/" then
+ f = "/" + f
+ else
f = File.join(file, f)
- ps.unshift f.untaint
- }
end
+ paths.unshift f.untaint
+ end
+ ensure
+ d.close
+ end
+ end
+ rescue Errno::ENOENT, Errno::EACCES
end
end
end
- nil
end
#
