Stable find.rb

ディレクトリを再帰的にたどった結果を比較することがあったのですが、
find.rb を使うと、yield ã•ã‚Œã‚‹ãƒ•ã‚¡ã‚¤ãƒ«åã®é †åºãŒ readdir の挙動に依存して
不定なために使えなくて残念な思いをしました。

readdir ãŒè¿”ã™é †ã« yield しなければならないという理由はないと思うので、
ディレクトリ内のファイルを sort してやるというのはどうでしょう?

% svn diff --diff-cmd diff -x ‘-u --ignore-all-space’ lib/find.rb
Index: lib/find.rb

— lib/find.rb (???Ó¥??? 26028)
+++ lib/find.rb (???È¥??Ô¡?)
@@ -46,9 +46,9 @@
end
begin
if s.directory? then

  •  d = Dir.open(file)
    
  •  begin
    
  •    for f in d
    
  •        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
    @@ -58,10 +58,7 @@
    f = File.join(file, f)
    end
    paths.unshift f.untaint
  •    end
    
  •  ensure
    
  •    d.close
    
  •  end
    
  •        }
    
    end
    rescue Errno::ENOENT, Errno::EACCES
    end

e$B$*$O$h$&$4$6$$$^$9!#e(B

In message [email protected]
on Sun, 6 Dec 2009 23:47:35 +0900,
Tanaka A. remove[email protected] wrote:

e$B%G%#%l%/%H%j$r:F5"E*$K$?$I$C$?7k2L$rHf3S$9$k$3$H$,$"$C$?$N$G$9$,!"e(B
find.rb e$B$r;H$&$H!"e(Byield e$B$5$l$k%U%!%$%kL>$N=g=x$,e(B readdir e$B$N5sF0$K0MB8$7$Fe(B
e$BITDj$J$?$a$K;H$($J$/$F;DG0$J;W$$$r$7$^$7$?!#e(B

readdir e$B$,JV$9=g$Ke(B yield e$B$7$J$1$l$P$J$i$J$$$H$$$&M}M3$O$J$$$H;W$&$N$G!"e(B
e$B%G%#%l%/%H%jFb$N%U%!%$%k$re(B sort e$B$7$F$d$k$H$$$&$N$O$I$&$G$7$g$&e(B?
e$B4:$($FM}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Ne(B
    e$BDc2<$,5/$-$=$&!#e(B

find.rb e$B$G$O3F%U%!%$%k$re(B lstat e$B$9$k$N$G!"e(B
e$B=hM};~4V$H$7$F$O$=$A$i$,;YG[E*$K$J$k$N$G$O$J$$$+$H;W$$$^$9!#e(B

e$B$^$?!":#2se(B find.rb e$B$NCf?H$r$_$F5$$,$D$$$?$N$G$9$,e(B
e$B3F%U%!%$%k$re(B stat e$B$7$Fe(B lstat
e$B$9$k$H$$$&%3!<%I$K$J$C$F$$$^$7$?!#e(B
(File.exist? file e$B$H$7$F$+$i!"e(BFile.lstat(file).directory?
e$B$H$7$F$$$?e(B)

e$B$3$l$OL5BL$J$o$1$G$9$,!":#$^$G$KJ86g$r$_$?3P$($,$J$$$3$H$r9M$($k$H!"e(B
find.rb
[email protected]=$r8B3&$^$G5a$a$k$R$H$O$8$D$O$$$J$$$N$G$O$J$$$+$H$$$&5$$,$7$^$9!#e(B

2009e$BG/e(B12e$B7ne(B16e$BF|e(B13:37 Urabe S.
[email protected]:

e$B$=$l$O4QB,HO0O$NLdBj$G$O$J$$$G$7$g$&$+!#e(B
e$B>/$J$/$H$b;d$O$=$l$KITK~$r3P$($Fe([email protected]$C$?$3$H$,$"$j$^$9!#e(B

e$B$O$$!#$o$?$7$,5$$,$D$$$?HO0O$G$O!"$H$$$&$3$H$G$9!#e(B

e$B0U?^$O!"LdBj$K;W$C$??M$OB?$/$J$$$N$G$O$J$$$+$H$$$&$3$H$G$9!#e(B

e$B$8$D$O$$$J$$$N$G$O$J$$$+!"$H$$$&5$$,$7$?$N$O0l?M%5%s%W%k$,8=$l$?$N$Ge(B
e$B$?$7$+$K$$$$$9$.$G!"$^$A$,$$$G$7$?!#e(B

Tanaka A. e$B$5$s$O=q$-$^$7$?e(B:

e$B$3$l$OL5BL$J$o$1$G$9$,!":#$^$G$KJ86g$r$_$?3P$($,$J$$$3$H$r9M$($k$H!"e(B

e$B$=$l$O4QB,HO0O$NLdBj$G$O$J$$$G$7$g$&$+!#e(B
e$B>/$J$/$H$b;d$O$=$l$KITK~$r3P$($Fe([email protected]$C$?$3$H$,$"$j$^$9!#e(B

pdumpfse$B$,%7%9%F%`%3!<%k$NH/9T$7$9$.$GCY$$!#e(B

Alternativee$B$^$G:n$C$?$3$H$,$"$j$^$9!#e(B
http://coderepos.org/share/browser/lang/ruby/misc/shystd/lib/findx.rb