t-nissieの日記: 【電脳】Mac OS Xでファイルとディレクトリの拡張属性xattrを再帰的にすべて消す高速なRubyスクリプト 1
Mac OS X の /usr/bin/xattr はPythonスクリプト。起動が遅い。数日前に
書いたようないちいち /usr/bin/xattr を呼び出すようなshスクリプトでは
対象とするファイルが数十あると我慢ならないほど時間がかかる。今回、
Rubyでやることにした。
準備
$ cp /usr/bin/xattr /tmp
$ sudo gem install xattr # xattrを上書きしてしまう
$ cp /tmp/xattr /usr/bin # 上書きされたxattrを元に戻す
delxattr.rb:
#!/usr/bin/env ruby
# delxattr.rb removes all extended attributes (xattr) of all files and directories recursively under the current or given directory.
# Author: t-nissie
# Example1$ delxattr.rb
# Example2$ delxattr.rb ~/foo
# Copying: delxattr.rb is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY. You can copy, modify and
# redistribute delxattr.rb, but only under the conditions described
# in the GNU General Public License (the "GPL"). For more detail,
# see http://www.gnu.org/licenses/gpl.html .
##
require "rubygems"
require "find"
require "xattr"
if ARGV[0]
dir = ARGV[0]
else
dir = "."
end
Find.find(dir){|f|
xattr = Xattr.new(f)
xattr.list.each{|a|
xattr.remove(a)
}
}
最後のeach、そのブロックの中で外でeachで参照しているオブジェクトそのものを変更してるけど、
大丈夫なのか心配。この場合はよいけど、一般的にどうなのか??? 不安なのでわざわざスクリプト
の先頭に「無保証」と書いておいた。ヘタレだ…
そもそも拡張属性なるものをさっぱり理解していない。
こんなにきれいさっぱり消してよいものなのか?
ファイルシステムとかOSによって仕様が異なるのか?
ACLとの関係は?
スクリプト使わせていただきました m(_ _)m (スコア:1)