def transaction(read_only = false, &block)
value = nil
raise PStore::Error, "nested transaction" if @transaction
@lock.synchronize do
@rdonly = read_only
@transaction = true
@abort = false
file = open_and_lock_file(@filename, read_only)
if file
begin
@table, checksum, original_data_size = load_data(file, read_only)
catch(:pstore_abort_transaction) do
value = yield(self)
end
if !@abort && !read_only
save_data(checksum, original_data_size, file)
end
ensure
file.close if !file.closed?
end
else
@table = {}
catch(:pstore_abort_transaction) do
value = yield(self)
end
end
end
ensure
@transaction = false
value
end