From 979de48915cd1c0d903eeed0fcec181ab80ef1ae Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 27 May 2004 07:43:38 +0000 Subject: * lib/pstore.rb (transaction): allow overriding dump and load. [ruby-dev:23567] * lib/yaml/store.rb: follow lib/pstore.rb's change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/pstore.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'lib/pstore.rb') diff --git a/lib/pstore.rb b/lib/pstore.rb index d6f5872fe9..25294fe009 100644 --- a/lib/pstore.rb +++ b/lib/pstore.rb @@ -98,7 +98,7 @@ class PStore content = nil file = File.open(@filename, File::RDWR | File::CREAT) - if !read_only + unless read_only file.flock(File::LOCK_EX) commit_new(file) if FileTest.exist?(new_file) content = file.read() @@ -112,7 +112,7 @@ class PStore end if content != "" - @table = Marshal::load(content) + @table = load(content) if !read_only size = content.size md5 = Digest::MD5.digest(content) @@ -132,7 +132,7 @@ class PStore ensure if !read_only and !@abort tmp_file = @filename + ".tmp" - content = Marshal::dump(@table) + content = dump(@table) if !md5 || size != content.size || md5 != Digest::MD5.digest(content) File.open(tmp_file, "w") {|t| t.write(content) @@ -151,6 +151,18 @@ class PStore value end + def dump(table) + Marshal::dump(table) + end + + def load(content) + Marshal::load(content) + end + + def load_file(file) + Marshal::load(file) + end + private def commit_new(f) f.truncate(0) -- cgit v1.2.3