From: "Shirai,Kaoru" Date: 2003-02-10T15:22:40+09:00 Subject: [ruby-list:37081] setup.rb: Patch to ignore CVS,*~,... This is a multi-part message in MIME format. --Multipart_Mon__10_Feb_2003_15:22:16_+0900_08281008 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit  白井です。   [ruby-list:30270] setup.rb のスレッドでも議論されていた、 install.rb/setup.rb で .bak .org .rej CVS/ RCS/ といったゴミを弾けないか という問題についてです。   tarball で配布する際はあらかじめ削除するという手があるのですが、 CVS ディレクトリを含むソースツリー上で開発している時にも install.rb/setup.rb を使いたい場面があります。やはりゴミはインストールの対象から除いてくれた 方がありがたいと思います。  というわけで、 setup-3.1.2 に対するパッチを書きました。これにより、 RCS CVS *~ *.bak *.BAK core *.core #* .#* *.orig *.rej *.old といったファイルがインストールの対象から除かれます。  ところで、 src/*.rb から install.rb/setup.rb を作る方法が見付からなか ったのですが、どうすれば良いのでしょうか? とりあえず、 for type in setup install; do cat src/in.$type.rb \ | ruby -ne 'if ($_ =~ %r"setup/(\w+)") then system("cat", "src/#{$1}.rb") else print($_) end' \ > $type.rb done という風に生成しています。 -- shirai@korinkan.co.jp Shirai,Kaoru Korinkan Ltd. --Multipart_Mon__10_Feb_2003_15:22:16_+0900_08281008 Content-Type: text/plain; name="cvsignore.diff" Content-Disposition: attachment; filename="cvsignore.diff" Content-Transfer-Encoding: 7bit diff -x CVS -x tmp -x *~ -Nru setup-3.1.2.orig/src/fileop.rb setup-3.1.2/src/fileop.rb --- setup-3.1.2.orig/src/fileop.rb Tue May 7 13:52:44 2002 +++ setup-3.1.2/src/fileop.rb Mon Feb 10 14:52:29 2003 @@ -1,3 +1,31 @@ +module CvsIgnore + PATTERNS = %w( RCS CVS *~ *.bak *.BAK core *.core #* .#* *.orig *.rej *.old ) + + class << self + def match?(fpath) + matched = false + filename = File.basename(fpath) + CvsIgnore::PATTERNS.each do |pattern| + matched = glob_match(pattern, filename) + break if matched + end + matched + end + + def glob_match(pat, str) + case pat[0] + when nil + not str[0] + when ?* + glob_match(pat[1..-1], str) || str[0] && glob_match(pat, str[1..-1]) + when ?? + str[0] && glob_match(pat[1..-1], str[1..-1]) + else + pat[0] == str[0] && glob_match(pat[1..-1], str[1..-1]) + end + end + end +end module FileOperations @@ -102,13 +130,20 @@ def all_files( dname ) Dir.open( dname ) {|d| - return d.find_all {|n| File.file? "#{dname}/#{n}" } + return d.find_all {|n| + path = "#{dname}/#{n}" + File.file?(path) && !(CvsIgnore.match?(path)) + } } end def all_dirs( dname ) Dir.open( dname ) {|d| - return d.find_all {|n| dir? "#{dname}/#{n}" } - %w(. ..) + dirs = d.find_all {|n| + path = "#{dname}/#{n}" + dir?(path) && !(CvsIgnore.match?(path)) + } + return (dirs - %w(. ..)) } end --Multipart_Mon__10_Feb_2003_15:22:16_+0900_08281008--