diff options
Diffstat (limited to 'lib/find.rb')
-rw-r--r-- | lib/find.rb | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/lib/find.rb b/lib/find.rb index e79756a918..80bb5d6f59 100644 --- a/lib/find.rb +++ b/lib/find.rb @@ -10,27 +10,30 @@ module Find def find(*path) while file = path.shift - catch(:prune) { + catch(:prune) do yield file - if File.lstat(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) + begin + if File.lstat(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 + path.unshift f end - path.unshift f + ensure + d.close end - ensure - d.close end + rescue Errno::ENOENT end - } + end end end |