From: NARUSE Yui Date: 2006-09-07T11:33:43+09:00 Subject: [ruby-dev:29518] PStore bug and verify 成瀬です。 まず、pstore.rb で binary mode へのし忘れがあります。 diff -u -r1.27 pstore.rb --- pstore.rb 5 Feb 2006 05:28:11 -0000 1.27 +++ pstore.rb 7 Sep 2006 02:28:40 -0000 @@ -297,7 +297,14 @@ file = File.open(@filename, File::RDONLY) file.binmode file.flock(File::LOCK_SH) - content = (File.read(new_file) rescue file.read()) + begin + File.open(new_file, "r") {|n| + n.binmode + content = n.read + } + rescue + content = file.read() + end rescue Errno::ENOENT content = "" end 行数が増えてしまって悲しいパッチなのですが、 [ruby-dev:28720] の IO.read の話は進展なしですか? さて、某ちゃんねるで PStore が話題になっていますが、 # f.binmode が効かない? # http://pc8.2ch.net/test/read.cgi/tech/1147935007/81 以前から PStore は信頼性がいまいちという話を継続的に聞きますし、 データが壊れた経験も何度かあります。 そこで、ちゃんと書き込めたか確認するようにしませんか。 今回の件ならば、 diff -u -r1.27 pstore.rb --- pstore.rb 5 Feb 2006 05:28:11 -0000 1.27 +++ pstore.rb 7 Sep 2006 02:22:58 -0000 @@ -330,6 +330,10 @@ t.binmode t.write(content) } + File.open(tmp_file, "r") {|t| + t.binmode + raise unless md5 == Digest::MD5.digest(t.read) + } File.rename(tmp_file, new_file) commit_new(file) end で、新たなデータは失っても、既存のデータは維持できるかなと。 また、何バイトかごとに chksum つけるとか、 何らかのエラー訂正符号をつけられるとだいぶ信頼性が上がると思うのですが。 -- NARUSE, Yui DBDB A476 FDBD 9450 02CD 0EFC BCE3 C388 472E C1EA