Module: QdumpfsFind

Defined in:
lib/qdumpfs/util.rb

Class Method Summary collapse

Class Method Details

.find(logger, *paths) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/qdumpfs/util.rb', line 64

def find(logger, *paths)
  block_given? or return enum_for(__method__, *paths)
  paths.collect!{|d|
    raise Errno::ENOENT unless File.exist?(d);
    d.dup
  }
  while file = paths.shift
    catch(:prune) do
      yield file.dup.taint
      begin
        s = File.lstat(file)
      rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG => e
        logger.print("File.lstat path=#{file} error=#{e.message}")
        next
      end
      if s.directory? then
        begin
          fs = Dir.entries(file, :encoding=>'UTF-8')
        rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG => e
          logger.print("Dir.entries path=#{file} error=#{e.message}")
          next
        end
        fs.sort!
        fs.reverse_each {|f|
          next if f == "." or f == ".."
          f = File.join(file, f)
          paths.unshift f.untaint
        }
      end
    end
  end
end

.pruneObject



97
98
99
# File 'lib/qdumpfs/util.rb', line 97

def prune
  throw :prune
end