Bug #4474 » patch.diff
| pstore.rb | ||
|---|---|---|
|
if File::exist? file and not File::readable? file
|
||
|
raise PStore::Error, format("file %s not readable", file)
|
||
|
end
|
||
|
@transaction = false
|
||
|
@filename = file
|
||
|
@abort = false
|
||
|
@ultra_safe = false
|
||
|
@thread_safe = thread_safe
|
||
|
if @thread_safe
|
||
|
@lock = Mutex.new
|
||
|
else
|
||
|
@lock = DummyMutex.new
|
||
|
end
|
||
|
@lock = Mutex.new
|
||
|
end
|
||
|
# Raises PStore::Error if the calling code is not in a PStore#transaction.
|
||
|
def in_transaction
|
||
|
raise PStore::Error, "not in transaction" unless @transaction
|
||
|
raise PStore::Error, "not in transaction" unless @lock.locked?
|
||
|
end
|
||
|
#
|
||
|
# Raises PStore::Error if the calling code is not in a PStore#transaction or
|
||
| ... | ... | |
|
#
|
||
|
def transaction(read_only = false, &block) # :yields: pstore
|
||
|
value = nil
|
||
|
raise PStore::Error, "nested transaction" if @transaction
|
||
|
raise PStore::Error, "nested transaction" if !@thread_safe && @lock.locked?
|
||
|
@lock.synchronize do
|
||
|
@rdonly = read_only
|
||
|
@transaction = true
|
||
|
@abort = false
|
||
|
file = open_and_lock_file(@filename, read_only)
|
||
|
if file
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
value
|
||
|
ensure
|
||
|
@transaction = false
|
||
|
end
|
||
|
private
|
||
| ... | ... | |
|
EMPTY_MARSHAL_DATA = Marshal.dump({})
|
||
|
EMPTY_MARSHAL_CHECKSUM = Digest::MD5.digest(EMPTY_MARSHAL_DATA)
|
||
|
class DummyMutex
|
||
|
def synchronize
|
||
|
yield
|
||
|
end
|
||
|
end
|
||
|
#
|
||
|
# Open the specified filename (either in read-only mode or in
|
||
|
# read-write mode) and lock it for reading or writing.
|
||