diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-05-27 07:43:38 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-05-27 07:43:38 +0000 |
commit | 979de48915cd1c0d903eeed0fcec181ab80ef1ae (patch) | |
tree | 5caa2535e7447380b264c1ddedbad23da070ceb2 /lib/pstore.rb | |
parent | 87fb7bb66daa35dcf1750e2f764da0167ac79938 (diff) |
* 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
Diffstat (limited to 'lib/pstore.rb')
-rw-r--r-- | lib/pstore.rb | 18 |
1 files changed, 15 insertions, 3 deletions
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) |