find-respect-encodings.patch

Kazuki Tsujimoto, 07/19/2013 07:53 PM

Download (1.77 KB)

View differences:

lib/find.rb
37 37
  def find(*paths) # :yield: path
38 38
    block_given? or return enum_for(__method__, *paths)
39 39

  
40
    paths.collect!{|d| raise Errno::ENOENT unless File.exist?(d); d.dup}
41
    while file = paths.shift
42
      catch(:prune) do
43
        yield file.dup.taint
44
        begin
45
          s = File.lstat(file)
46
        rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
47
          next
48
        end
49
        if s.directory? then
40
    fs_encoding = Encoding.find("filesystem")
41

  
42
    paths.collect{|d| raise Errno::ENOENT unless File.exist?(d); d.dup}.each do |path|
43
      enc = path.encoding == Encoding::US_ASCII ? fs_encoding : path.encoding
44
      ps = [path]
45
      while file = ps.shift
46
        catch(:prune) do
47
          yield file.dup.taint
50 48
          begin
51
            fs = Dir.entries(file)
49
            s = File.lstat(file)
52 50
          rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
53 51
            next
54 52
          end
55
          fs.sort!
56
          fs.reverse_each {|f|
57
            next if f == "." or f == ".."
58
            f = File.join(file, f)
59
            paths.unshift f.untaint
60
          }
53
          if s.directory? then
54
            begin
55
              fs = Dir.entries(file, encoding: enc)
56
            rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
57
              next
58
            end
59
            fs.sort!
60
            fs.reverse_each {|f|
61
              next if f == "." or f == ".."
62
              f = File.join(file, f)
63
              ps.unshift f.untaint
64
            }
65
          end
61 66
        end
62 67
      end
63 68
    end
69
    nil
64 70
  end
65 71

  
66 72
  #