* 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
This commit is contained in:
parent
87fb7bb66d
commit
979de48915
@ -73,6 +73,13 @@ Mon May 24 10:46:26 2004 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
|
|||||||
* lib/rdoc/generators/template/html/html.rb: SYSTEM identifiers
|
* lib/rdoc/generators/template/html/html.rb: SYSTEM identifiers
|
||||||
must be absolute URIs
|
must be absolute URIs
|
||||||
|
|
||||||
|
Sun May 23 04:53:50 2004 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
|
||||||
|
|
||||||
|
* lib/pstore.rb (transaction): allow overriding dump and load.
|
||||||
|
[ruby-dev:23567]
|
||||||
|
|
||||||
|
* lib/yaml/store.rb: follow lib/pstore.rb's change.
|
||||||
|
|
||||||
Sat May 22 11:54:10 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sat May 22 11:54:10 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* MANIFEST: add test/openssl/test_x509store.rb.
|
* MANIFEST: add test/openssl/test_x509store.rb.
|
||||||
|
@ -1549,14 +1549,9 @@ class CGI
|
|||||||
body = ""
|
body = ""
|
||||||
end
|
end
|
||||||
if @output_hidden
|
if @output_hidden
|
||||||
hidden = @output_hidden.collect{|k,v|
|
body += @output_hidden.collect{|k,v|
|
||||||
"<INPUT TYPE=HIDDEN NAME=\"#{k}\" VALUE=\"#{v}\">"
|
"<INPUT TYPE=\"HIDDEN\" NAME=\"#{k}\" VALUE=\"#{v}\">"
|
||||||
}.to_s
|
}.to_s
|
||||||
if defined? fieldset
|
|
||||||
body += fieldset{ hidden }
|
|
||||||
else
|
|
||||||
body += hidden
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
super(attributes){body}
|
super(attributes){body}
|
||||||
end
|
end
|
||||||
|
@ -98,7 +98,7 @@ class PStore
|
|||||||
|
|
||||||
content = nil
|
content = nil
|
||||||
file = File.open(@filename, File::RDWR | File::CREAT)
|
file = File.open(@filename, File::RDWR | File::CREAT)
|
||||||
if !read_only
|
unless read_only
|
||||||
file.flock(File::LOCK_EX)
|
file.flock(File::LOCK_EX)
|
||||||
commit_new(file) if FileTest.exist?(new_file)
|
commit_new(file) if FileTest.exist?(new_file)
|
||||||
content = file.read()
|
content = file.read()
|
||||||
@ -112,7 +112,7 @@ class PStore
|
|||||||
end
|
end
|
||||||
|
|
||||||
if content != ""
|
if content != ""
|
||||||
@table = Marshal::load(content)
|
@table = load(content)
|
||||||
if !read_only
|
if !read_only
|
||||||
size = content.size
|
size = content.size
|
||||||
md5 = Digest::MD5.digest(content)
|
md5 = Digest::MD5.digest(content)
|
||||||
@ -132,7 +132,7 @@ class PStore
|
|||||||
ensure
|
ensure
|
||||||
if !read_only and !@abort
|
if !read_only and !@abort
|
||||||
tmp_file = @filename + ".tmp"
|
tmp_file = @filename + ".tmp"
|
||||||
content = Marshal::dump(@table)
|
content = dump(@table)
|
||||||
if !md5 || size != content.size || md5 != Digest::MD5.digest(content)
|
if !md5 || size != content.size || md5 != Digest::MD5.digest(content)
|
||||||
File.open(tmp_file, "w") {|t|
|
File.open(tmp_file, "w") {|t|
|
||||||
t.write(content)
|
t.write(content)
|
||||||
@ -151,6 +151,18 @@ class PStore
|
|||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dump(table)
|
||||||
|
Marshal::dump(table)
|
||||||
|
end
|
||||||
|
|
||||||
|
def load(content)
|
||||||
|
Marshal::load(content)
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_file(file)
|
||||||
|
Marshal::load(file)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def commit_new(f)
|
def commit_new(f)
|
||||||
f.truncate(0)
|
f.truncate(0)
|
||||||
|
@ -189,12 +189,15 @@ class ConditionVariable
|
|||||||
# Releases the lock held in +mutex+ and waits; reacquires the lock on wakeup.
|
# Releases the lock held in +mutex+ and waits; reacquires the lock on wakeup.
|
||||||
#
|
#
|
||||||
def wait(mutex)
|
def wait(mutex)
|
||||||
|
begin
|
||||||
mutex.exclusive_unlock do
|
mutex.exclusive_unlock do
|
||||||
@waiters.push(Thread.current)
|
@waiters.push(Thread.current)
|
||||||
Thread.stop
|
Thread.stop
|
||||||
end
|
end
|
||||||
|
ensure
|
||||||
mutex.lock
|
mutex.lock
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Wakes up the first thread in line waiting for this lock.
|
# Wakes up the first thread in line waiting for this lock.
|
||||||
|
@ -3,14 +3,8 @@
|
|||||||
#
|
#
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
require 'pstore'
|
require 'pstore'
|
||||||
require 'fileutils'
|
|
||||||
|
|
||||||
module YAML
|
class YAML::Store < PStore
|
||||||
|
|
||||||
class Store < PStore
|
|
||||||
#
|
|
||||||
# Constructor
|
|
||||||
#
|
|
||||||
def initialize( *o )
|
def initialize( *o )
|
||||||
@opt = YAML::DEFAULTS.dup
|
@opt = YAML::DEFAULTS.dup
|
||||||
if String === o.first
|
if String === o.first
|
||||||
@ -21,56 +15,15 @@ module YAML
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
def dump(table)
|
||||||
# Override Pstore#transaction
|
@table.to_yaml(@opt)
|
||||||
#
|
|
||||||
def transaction
|
|
||||||
raise YAML::Error, "nested transaction" if @transaction
|
|
||||||
raise YAML::Error, "no filename for transaction" unless @filename
|
|
||||||
begin
|
|
||||||
@transaction = true
|
|
||||||
value = nil
|
|
||||||
backup = @filename+"~"
|
|
||||||
if File::exist?(@filename)
|
|
||||||
file = File::open(@filename, "rb+")
|
|
||||||
orig = true
|
|
||||||
else
|
|
||||||
@table = {}
|
|
||||||
file = File::open(@filename, "wb+")
|
|
||||||
file.write( @table.to_yaml( @opt ) )
|
|
||||||
end
|
|
||||||
file.flock(File::LOCK_EX)
|
|
||||||
if orig
|
|
||||||
FileUtils::copy @filename, backup
|
|
||||||
@table = YAML::load( file )
|
|
||||||
end
|
|
||||||
begin
|
|
||||||
catch(:pstore_abort_transaction) do
|
|
||||||
value = yield(self)
|
|
||||||
end
|
|
||||||
rescue Exception
|
|
||||||
@abort = true
|
|
||||||
raise
|
|
||||||
ensure
|
|
||||||
unless @abort
|
|
||||||
begin
|
|
||||||
file.rewind
|
|
||||||
file.write( @table.to_yaml( @opt ) )
|
|
||||||
file.truncate(file.pos)
|
|
||||||
rescue
|
|
||||||
File::rename backup, @filename if File::exist?(backup)
|
|
||||||
raise
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@abort = false
|
|
||||||
end
|
|
||||||
ensure
|
|
||||||
@table = nil
|
|
||||||
@transaction = false
|
|
||||||
file.close if file
|
|
||||||
end
|
|
||||||
value
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def load(content)
|
||||||
|
YAML::load(content)
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_file(file)
|
||||||
|
YAML::load(file)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user