diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | lib/find.rb | 29 |
2 files changed, 17 insertions, 16 deletions
@@ -1,3 +1,7 @@ +Sun Dec 13 23:48:25 2009 Tanaka Akira <akr@fsij.org> + + * lib/find.rb (Find.find): sort directory entries. [ruby-dev:39847] + Sun Dec 13 20:55:30 2009 Tanaka Akira <akr@fsij.org> * test/ruby/envutil.rb (invoke_ruby): call to_str for stdin_data to diff --git a/lib/find.rb b/lib/find.rb index f9bc754152..12e2a5a938 100644 --- a/lib/find.rb +++ b/lib/find.rb @@ -46,22 +46,19 @@ module Find end begin if s.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 + fs = Dir.entries(file) + fs.sort! + fs.reverse_each {|f| + 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 rescue Errno::ENOENT, Errno::EACCES end |