Module: Rex::Find

Defined in:
lib/rex/file.rb

Class Method Summary collapse

Class Method Details

.find(*paths) ⇒ Object

Identical to Find.find from Ruby, but follows symlinks to directories. See blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/68671



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/rex/file.rb', line 123

def self.find(*paths)
  paths.collect!{|d| d.dup}
  while file = paths.shift
    catch(:prune) do
      yield file.dup.taint
      next unless File.exist? file
      begin
        if File.stat(file).directory? then
          d = Dir.open(file)
          begin
            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)
              end
              paths.unshift f.untaint
            end
          ensure
            d.close
          end
        end
      rescue Errno::ENOENT, Errno::EACCES
      end
    end
  end
end

.pruneObject



154
155
156
# File 'lib/rex/file.rb', line 154

def self.prune
  throw :prune
end