Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../opt/alt/ruby31/share/ruby
File: pstore.rb
# frozen_string_literal: true
[0] Fix | Delete
# = PStore -- Transactional File Storage for Ruby Objects
[1] Fix | Delete
#
[2] Fix | Delete
# pstore.rb -
[3] Fix | Delete
# originally by matz
[4] Fix | Delete
# documentation by Kev Jackson and James Edward Gray II
[5] Fix | Delete
# improved by Hongli Lai
[6] Fix | Delete
#
[7] Fix | Delete
# See PStore for documentation.
[8] Fix | Delete
[9] Fix | Delete
require "digest"
[10] Fix | Delete
[11] Fix | Delete
#
[12] Fix | Delete
# PStore implements a file based persistence mechanism based on a Hash. User
[13] Fix | Delete
# code can store hierarchies of Ruby objects (values) into the data store file
[14] Fix | Delete
# by name (keys). An object hierarchy may be just a single object. User code
[15] Fix | Delete
# may later read values back from the data store or even update data, as needed.
[16] Fix | Delete
#
[17] Fix | Delete
# The transactional behavior ensures that any changes succeed or fail together.
[18] Fix | Delete
# This can be used to ensure that the data store is not left in a transitory
[19] Fix | Delete
# state, where some values were updated but others were not.
[20] Fix | Delete
#
[21] Fix | Delete
# Behind the scenes, Ruby objects are stored to the data store file with
[22] Fix | Delete
# Marshal. That carries the usual limitations. Proc objects cannot be
[23] Fix | Delete
# marshalled, for example.
[24] Fix | Delete
#
[25] Fix | Delete
# == Usage example:
[26] Fix | Delete
#
[27] Fix | Delete
# require "pstore"
[28] Fix | Delete
#
[29] Fix | Delete
# # a mock wiki object...
[30] Fix | Delete
# class WikiPage
[31] Fix | Delete
# def initialize( page_name, author, contents )
[32] Fix | Delete
# @page_name = page_name
[33] Fix | Delete
# @revisions = Array.new
[34] Fix | Delete
#
[35] Fix | Delete
# add_revision(author, contents)
[36] Fix | Delete
# end
[37] Fix | Delete
#
[38] Fix | Delete
# attr_reader :page_name
[39] Fix | Delete
#
[40] Fix | Delete
# def add_revision( author, contents )
[41] Fix | Delete
# @revisions << { :created => Time.now,
[42] Fix | Delete
# :author => author,
[43] Fix | Delete
# :contents => contents }
[44] Fix | Delete
# end
[45] Fix | Delete
#
[46] Fix | Delete
# def wiki_page_references
[47] Fix | Delete
# [@page_name] + @revisions.last[:contents].scan(/\b(?:[A-Z]+[a-z]+){2,}/)
[48] Fix | Delete
# end
[49] Fix | Delete
#
[50] Fix | Delete
# # ...
[51] Fix | Delete
# end
[52] Fix | Delete
#
[53] Fix | Delete
# # create a new page...
[54] Fix | Delete
# home_page = WikiPage.new( "HomePage", "James Edward Gray II",
[55] Fix | Delete
# "A page about the JoysOfDocumentation..." )
[56] Fix | Delete
#
[57] Fix | Delete
# # then we want to update page data and the index together, or not at all...
[58] Fix | Delete
# wiki = PStore.new("wiki_pages.pstore")
[59] Fix | Delete
# wiki.transaction do # begin transaction; do all of this or none of it
[60] Fix | Delete
# # store page...
[61] Fix | Delete
# wiki[home_page.page_name] = home_page
[62] Fix | Delete
# # ensure that an index has been created...
[63] Fix | Delete
# wiki[:wiki_index] ||= Array.new
[64] Fix | Delete
# # update wiki index...
[65] Fix | Delete
# wiki[:wiki_index].push(*home_page.wiki_page_references)
[66] Fix | Delete
# end # commit changes to wiki data store file
[67] Fix | Delete
#
[68] Fix | Delete
# ### Some time later... ###
[69] Fix | Delete
#
[70] Fix | Delete
# # read wiki data...
[71] Fix | Delete
# wiki.transaction(true) do # begin read-only transaction, no changes allowed
[72] Fix | Delete
# wiki.roots.each do |data_root_name|
[73] Fix | Delete
# p data_root_name
[74] Fix | Delete
# p wiki[data_root_name]
[75] Fix | Delete
# end
[76] Fix | Delete
# end
[77] Fix | Delete
#
[78] Fix | Delete
# == Transaction modes
[79] Fix | Delete
#
[80] Fix | Delete
# By default, file integrity is only ensured as long as the operating system
[81] Fix | Delete
# (and the underlying hardware) doesn't raise any unexpected I/O errors. If an
[82] Fix | Delete
# I/O error occurs while PStore is writing to its file, then the file will
[83] Fix | Delete
# become corrupted.
[84] Fix | Delete
#
[85] Fix | Delete
# You can prevent this by setting <em>pstore.ultra_safe = true</em>.
[86] Fix | Delete
# However, this results in a minor performance loss, and only works on platforms
[87] Fix | Delete
# that support atomic file renames. Please consult the documentation for
[88] Fix | Delete
# +ultra_safe+ for details.
[89] Fix | Delete
#
[90] Fix | Delete
# Needless to say, if you're storing valuable data with PStore, then you should
[91] Fix | Delete
# backup the PStore files from time to time.
[92] Fix | Delete
class PStore
[93] Fix | Delete
VERSION = "0.1.1"
[94] Fix | Delete
[95] Fix | Delete
RDWR_ACCESS = {mode: IO::RDWR | IO::CREAT | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze
[96] Fix | Delete
RD_ACCESS = {mode: IO::RDONLY | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze
[97] Fix | Delete
WR_ACCESS = {mode: IO::WRONLY | IO::CREAT | IO::TRUNC | IO::BINARY, encoding: Encoding::ASCII_8BIT}.freeze
[98] Fix | Delete
[99] Fix | Delete
# The error type thrown by all PStore methods.
[100] Fix | Delete
class Error < StandardError
[101] Fix | Delete
end
[102] Fix | Delete
[103] Fix | Delete
# Whether PStore should do its best to prevent file corruptions, even when under
[104] Fix | Delete
# unlikely-to-occur error conditions such as out-of-space conditions and other
[105] Fix | Delete
# unusual OS filesystem errors. Setting this flag comes at the price in the form
[106] Fix | Delete
# of a performance loss.
[107] Fix | Delete
#
[108] Fix | Delete
# This flag only has effect on platforms on which file renames are atomic (e.g.
[109] Fix | Delete
# all POSIX platforms: Linux, MacOS X, FreeBSD, etc). The default value is false.
[110] Fix | Delete
attr_accessor :ultra_safe
[111] Fix | Delete
[112] Fix | Delete
#
[113] Fix | Delete
# To construct a PStore object, pass in the _file_ path where you would like
[114] Fix | Delete
# the data to be stored.
[115] Fix | Delete
#
[116] Fix | Delete
# PStore objects are always reentrant. But if _thread_safe_ is set to true,
[117] Fix | Delete
# then it will become thread-safe at the cost of a minor performance hit.
[118] Fix | Delete
#
[119] Fix | Delete
def initialize(file, thread_safe = false)
[120] Fix | Delete
dir = File::dirname(file)
[121] Fix | Delete
unless File::directory? dir
[122] Fix | Delete
raise PStore::Error, format("directory %s does not exist", dir)
[123] Fix | Delete
end
[124] Fix | Delete
if File::exist? file and not File::readable? file
[125] Fix | Delete
raise PStore::Error, format("file %s not readable", file)
[126] Fix | Delete
end
[127] Fix | Delete
@filename = file
[128] Fix | Delete
@abort = false
[129] Fix | Delete
@ultra_safe = false
[130] Fix | Delete
@thread_safe = thread_safe
[131] Fix | Delete
@lock = Thread::Mutex.new
[132] Fix | Delete
end
[133] Fix | Delete
[134] Fix | Delete
# Raises PStore::Error if the calling code is not in a PStore#transaction.
[135] Fix | Delete
def in_transaction
[136] Fix | Delete
raise PStore::Error, "not in transaction" unless @lock.locked?
[137] Fix | Delete
end
[138] Fix | Delete
#
[139] Fix | Delete
# Raises PStore::Error if the calling code is not in a PStore#transaction or
[140] Fix | Delete
# if the code is in a read-only PStore#transaction.
[141] Fix | Delete
#
[142] Fix | Delete
def in_transaction_wr
[143] Fix | Delete
in_transaction
[144] Fix | Delete
raise PStore::Error, "in read-only transaction" if @rdonly
[145] Fix | Delete
end
[146] Fix | Delete
private :in_transaction, :in_transaction_wr
[147] Fix | Delete
[148] Fix | Delete
#
[149] Fix | Delete
# Retrieves a value from the PStore file data, by _name_. The hierarchy of
[150] Fix | Delete
# Ruby objects stored under that root _name_ will be returned.
[151] Fix | Delete
#
[152] Fix | Delete
# *WARNING*: This method is only valid in a PStore#transaction. It will
[153] Fix | Delete
# raise PStore::Error if called at any other time.
[154] Fix | Delete
#
[155] Fix | Delete
def [](name)
[156] Fix | Delete
in_transaction
[157] Fix | Delete
@table[name]
[158] Fix | Delete
end
[159] Fix | Delete
#
[160] Fix | Delete
# This method is just like PStore#[], save that you may also provide a
[161] Fix | Delete
# _default_ value for the object. In the event the specified _name_ is not
[162] Fix | Delete
# found in the data store, your _default_ will be returned instead. If you do
[163] Fix | Delete
# not specify a default, PStore::Error will be raised if the object is not
[164] Fix | Delete
# found.
[165] Fix | Delete
#
[166] Fix | Delete
# *WARNING*: This method is only valid in a PStore#transaction. It will
[167] Fix | Delete
# raise PStore::Error if called at any other time.
[168] Fix | Delete
#
[169] Fix | Delete
def fetch(name, default=PStore::Error)
[170] Fix | Delete
in_transaction
[171] Fix | Delete
unless @table.key? name
[172] Fix | Delete
if default == PStore::Error
[173] Fix | Delete
raise PStore::Error, format("undefined root name `%s'", name)
[174] Fix | Delete
else
[175] Fix | Delete
return default
[176] Fix | Delete
end
[177] Fix | Delete
end
[178] Fix | Delete
@table[name]
[179] Fix | Delete
end
[180] Fix | Delete
#
[181] Fix | Delete
# Stores an individual Ruby object or a hierarchy of Ruby objects in the data
[182] Fix | Delete
# store file under the root _name_. Assigning to a _name_ already in the data
[183] Fix | Delete
# store clobbers the old data.
[184] Fix | Delete
#
[185] Fix | Delete
# == Example:
[186] Fix | Delete
#
[187] Fix | Delete
# require "pstore"
[188] Fix | Delete
#
[189] Fix | Delete
# store = PStore.new("data_file.pstore")
[190] Fix | Delete
# store.transaction do # begin transaction
[191] Fix | Delete
# # load some data into the store...
[192] Fix | Delete
# store[:single_object] = "My data..."
[193] Fix | Delete
# store[:obj_hierarchy] = { "Kev Jackson" => ["rational.rb", "pstore.rb"],
[194] Fix | Delete
# "James Gray" => ["erb.rb", "pstore.rb"] }
[195] Fix | Delete
# end # commit changes to data store file
[196] Fix | Delete
#
[197] Fix | Delete
# *WARNING*: This method is only valid in a PStore#transaction and it cannot
[198] Fix | Delete
# be read-only. It will raise PStore::Error if called at any other time.
[199] Fix | Delete
#
[200] Fix | Delete
def []=(name, value)
[201] Fix | Delete
in_transaction_wr
[202] Fix | Delete
@table[name] = value
[203] Fix | Delete
end
[204] Fix | Delete
#
[205] Fix | Delete
# Removes an object hierarchy from the data store, by _name_.
[206] Fix | Delete
#
[207] Fix | Delete
# *WARNING*: This method is only valid in a PStore#transaction and it cannot
[208] Fix | Delete
# be read-only. It will raise PStore::Error if called at any other time.
[209] Fix | Delete
#
[210] Fix | Delete
def delete(name)
[211] Fix | Delete
in_transaction_wr
[212] Fix | Delete
@table.delete name
[213] Fix | Delete
end
[214] Fix | Delete
[215] Fix | Delete
#
[216] Fix | Delete
# Returns the names of all object hierarchies currently in the store.
[217] Fix | Delete
#
[218] Fix | Delete
# *WARNING*: This method is only valid in a PStore#transaction. It will
[219] Fix | Delete
# raise PStore::Error if called at any other time.
[220] Fix | Delete
#
[221] Fix | Delete
def roots
[222] Fix | Delete
in_transaction
[223] Fix | Delete
@table.keys
[224] Fix | Delete
end
[225] Fix | Delete
#
[226] Fix | Delete
# Returns true if the supplied _name_ is currently in the data store.
[227] Fix | Delete
#
[228] Fix | Delete
# *WARNING*: This method is only valid in a PStore#transaction. It will
[229] Fix | Delete
# raise PStore::Error if called at any other time.
[230] Fix | Delete
#
[231] Fix | Delete
def root?(name)
[232] Fix | Delete
in_transaction
[233] Fix | Delete
@table.key? name
[234] Fix | Delete
end
[235] Fix | Delete
# Returns the path to the data store file.
[236] Fix | Delete
def path
[237] Fix | Delete
@filename
[238] Fix | Delete
end
[239] Fix | Delete
[240] Fix | Delete
#
[241] Fix | Delete
# Ends the current PStore#transaction, committing any changes to the data
[242] Fix | Delete
# store immediately.
[243] Fix | Delete
#
[244] Fix | Delete
# == Example:
[245] Fix | Delete
#
[246] Fix | Delete
# require "pstore"
[247] Fix | Delete
#
[248] Fix | Delete
# store = PStore.new("data_file.pstore")
[249] Fix | Delete
# store.transaction do # begin transaction
[250] Fix | Delete
# # load some data into the store...
[251] Fix | Delete
# store[:one] = 1
[252] Fix | Delete
# store[:two] = 2
[253] Fix | Delete
#
[254] Fix | Delete
# store.commit # end transaction here, committing changes
[255] Fix | Delete
#
[256] Fix | Delete
# store[:three] = 3 # this change is never reached
[257] Fix | Delete
# end
[258] Fix | Delete
#
[259] Fix | Delete
# *WARNING*: This method is only valid in a PStore#transaction. It will
[260] Fix | Delete
# raise PStore::Error if called at any other time.
[261] Fix | Delete
#
[262] Fix | Delete
def commit
[263] Fix | Delete
in_transaction
[264] Fix | Delete
@abort = false
[265] Fix | Delete
throw :pstore_abort_transaction
[266] Fix | Delete
end
[267] Fix | Delete
#
[268] Fix | Delete
# Ends the current PStore#transaction, discarding any changes to the data
[269] Fix | Delete
# store.
[270] Fix | Delete
#
[271] Fix | Delete
# == Example:
[272] Fix | Delete
#
[273] Fix | Delete
# require "pstore"
[274] Fix | Delete
#
[275] Fix | Delete
# store = PStore.new("data_file.pstore")
[276] Fix | Delete
# store.transaction do # begin transaction
[277] Fix | Delete
# store[:one] = 1 # this change is not applied, see below...
[278] Fix | Delete
# store[:two] = 2 # this change is not applied, see below...
[279] Fix | Delete
#
[280] Fix | Delete
# store.abort # end transaction here, discard all changes
[281] Fix | Delete
#
[282] Fix | Delete
# store[:three] = 3 # this change is never reached
[283] Fix | Delete
# end
[284] Fix | Delete
#
[285] Fix | Delete
# *WARNING*: This method is only valid in a PStore#transaction. It will
[286] Fix | Delete
# raise PStore::Error if called at any other time.
[287] Fix | Delete
#
[288] Fix | Delete
def abort
[289] Fix | Delete
in_transaction
[290] Fix | Delete
@abort = true
[291] Fix | Delete
throw :pstore_abort_transaction
[292] Fix | Delete
end
[293] Fix | Delete
[294] Fix | Delete
#
[295] Fix | Delete
# Opens a new transaction for the data store. Code executed inside a block
[296] Fix | Delete
# passed to this method may read and write data to and from the data store
[297] Fix | Delete
# file.
[298] Fix | Delete
#
[299] Fix | Delete
# At the end of the block, changes are committed to the data store
[300] Fix | Delete
# automatically. You may exit the transaction early with a call to either
[301] Fix | Delete
# PStore#commit or PStore#abort. See those methods for details about how
[302] Fix | Delete
# changes are handled. Raising an uncaught Exception in the block is
[303] Fix | Delete
# equivalent to calling PStore#abort.
[304] Fix | Delete
#
[305] Fix | Delete
# If _read_only_ is set to +true+, you will only be allowed to read from the
[306] Fix | Delete
# data store during the transaction and any attempts to change the data will
[307] Fix | Delete
# raise a PStore::Error.
[308] Fix | Delete
#
[309] Fix | Delete
# Note that PStore does not support nested transactions.
[310] Fix | Delete
#
[311] Fix | Delete
def transaction(read_only = false) # :yields: pstore
[312] Fix | Delete
value = nil
[313] Fix | Delete
if !@thread_safe
[314] Fix | Delete
raise PStore::Error, "nested transaction" unless @lock.try_lock
[315] Fix | Delete
else
[316] Fix | Delete
begin
[317] Fix | Delete
@lock.lock
[318] Fix | Delete
rescue ThreadError
[319] Fix | Delete
raise PStore::Error, "nested transaction"
[320] Fix | Delete
end
[321] Fix | Delete
end
[322] Fix | Delete
begin
[323] Fix | Delete
@rdonly = read_only
[324] Fix | Delete
@abort = false
[325] Fix | Delete
file = open_and_lock_file(@filename, read_only)
[326] Fix | Delete
if file
[327] Fix | Delete
begin
[328] Fix | Delete
@table, checksum, original_data_size = load_data(file, read_only)
[329] Fix | Delete
[330] Fix | Delete
catch(:pstore_abort_transaction) do
[331] Fix | Delete
value = yield(self)
[332] Fix | Delete
end
[333] Fix | Delete
[334] Fix | Delete
if !@abort && !read_only
[335] Fix | Delete
save_data(checksum, original_data_size, file)
[336] Fix | Delete
end
[337] Fix | Delete
ensure
[338] Fix | Delete
file.close
[339] Fix | Delete
end
[340] Fix | Delete
else
[341] Fix | Delete
# This can only occur if read_only == true.
[342] Fix | Delete
@table = {}
[343] Fix | Delete
catch(:pstore_abort_transaction) do
[344] Fix | Delete
value = yield(self)
[345] Fix | Delete
end
[346] Fix | Delete
end
[347] Fix | Delete
ensure
[348] Fix | Delete
@lock.unlock
[349] Fix | Delete
end
[350] Fix | Delete
value
[351] Fix | Delete
end
[352] Fix | Delete
[353] Fix | Delete
private
[354] Fix | Delete
# Constant for relieving Ruby's garbage collector.
[355] Fix | Delete
CHECKSUM_ALGO = %w[SHA512 SHA384 SHA256 SHA1 RMD160 MD5].each do |algo|
[356] Fix | Delete
begin
[357] Fix | Delete
break Digest(algo)
[358] Fix | Delete
rescue LoadError
[359] Fix | Delete
end
[360] Fix | Delete
end
[361] Fix | Delete
EMPTY_STRING = ""
[362] Fix | Delete
EMPTY_MARSHAL_DATA = Marshal.dump({})
[363] Fix | Delete
EMPTY_MARSHAL_CHECKSUM = CHECKSUM_ALGO.digest(EMPTY_MARSHAL_DATA)
[364] Fix | Delete
[365] Fix | Delete
#
[366] Fix | Delete
# Open the specified filename (either in read-only mode or in
[367] Fix | Delete
# read-write mode) and lock it for reading or writing.
[368] Fix | Delete
#
[369] Fix | Delete
# The opened File object will be returned. If _read_only_ is true,
[370] Fix | Delete
# and the file does not exist, then nil will be returned.
[371] Fix | Delete
#
[372] Fix | Delete
# All exceptions are propagated.
[373] Fix | Delete
#
[374] Fix | Delete
def open_and_lock_file(filename, read_only)
[375] Fix | Delete
if read_only
[376] Fix | Delete
begin
[377] Fix | Delete
file = File.new(filename, **RD_ACCESS)
[378] Fix | Delete
begin
[379] Fix | Delete
file.flock(File::LOCK_SH)
[380] Fix | Delete
return file
[381] Fix | Delete
rescue
[382] Fix | Delete
file.close
[383] Fix | Delete
raise
[384] Fix | Delete
end
[385] Fix | Delete
rescue Errno::ENOENT
[386] Fix | Delete
return nil
[387] Fix | Delete
end
[388] Fix | Delete
else
[389] Fix | Delete
file = File.new(filename, **RDWR_ACCESS)
[390] Fix | Delete
file.flock(File::LOCK_EX)
[391] Fix | Delete
return file
[392] Fix | Delete
end
[393] Fix | Delete
end
[394] Fix | Delete
[395] Fix | Delete
# Load the given PStore file.
[396] Fix | Delete
# If +read_only+ is true, the unmarshalled Hash will be returned.
[397] Fix | Delete
# If +read_only+ is false, a 3-tuple will be returned: the unmarshalled
[398] Fix | Delete
# Hash, a checksum of the data, and the size of the data.
[399] Fix | Delete
def load_data(file, read_only)
[400] Fix | Delete
if read_only
[401] Fix | Delete
begin
[402] Fix | Delete
table = load(file)
[403] Fix | Delete
raise Error, "PStore file seems to be corrupted." unless table.is_a?(Hash)
[404] Fix | Delete
rescue EOFError
[405] Fix | Delete
# This seems to be a newly-created file.
[406] Fix | Delete
table = {}
[407] Fix | Delete
end
[408] Fix | Delete
table
[409] Fix | Delete
else
[410] Fix | Delete
data = file.read
[411] Fix | Delete
if data.empty?
[412] Fix | Delete
# This seems to be a newly-created file.
[413] Fix | Delete
table = {}
[414] Fix | Delete
checksum = empty_marshal_checksum
[415] Fix | Delete
size = empty_marshal_data.bytesize
[416] Fix | Delete
else
[417] Fix | Delete
table = load(data)
[418] Fix | Delete
checksum = CHECKSUM_ALGO.digest(data)
[419] Fix | Delete
size = data.bytesize
[420] Fix | Delete
raise Error, "PStore file seems to be corrupted." unless table.is_a?(Hash)
[421] Fix | Delete
end
[422] Fix | Delete
data.replace(EMPTY_STRING)
[423] Fix | Delete
[table, checksum, size]
[424] Fix | Delete
end
[425] Fix | Delete
end
[426] Fix | Delete
[427] Fix | Delete
def on_windows?
[428] Fix | Delete
is_windows = RUBY_PLATFORM =~ /mswin|mingw|bccwin|wince/
[429] Fix | Delete
self.class.__send__(:define_method, :on_windows?) do
[430] Fix | Delete
is_windows
[431] Fix | Delete
end
[432] Fix | Delete
is_windows
[433] Fix | Delete
end
[434] Fix | Delete
[435] Fix | Delete
def save_data(original_checksum, original_file_size, file)
[436] Fix | Delete
new_data = dump(@table)
[437] Fix | Delete
[438] Fix | Delete
if new_data.bytesize != original_file_size || CHECKSUM_ALGO.digest(new_data) != original_checksum
[439] Fix | Delete
if @ultra_safe && !on_windows?
[440] Fix | Delete
# Windows doesn't support atomic file renames.
[441] Fix | Delete
save_data_with_atomic_file_rename_strategy(new_data, file)
[442] Fix | Delete
else
[443] Fix | Delete
save_data_with_fast_strategy(new_data, file)
[444] Fix | Delete
end
[445] Fix | Delete
end
[446] Fix | Delete
[447] Fix | Delete
new_data.replace(EMPTY_STRING)
[448] Fix | Delete
end
[449] Fix | Delete
[450] Fix | Delete
def save_data_with_atomic_file_rename_strategy(data, file)
[451] Fix | Delete
temp_filename = "#{@filename}.tmp.#{Process.pid}.#{rand 1000000}"
[452] Fix | Delete
temp_file = File.new(temp_filename, **WR_ACCESS)
[453] Fix | Delete
begin
[454] Fix | Delete
temp_file.flock(File::LOCK_EX)
[455] Fix | Delete
temp_file.write(data)
[456] Fix | Delete
temp_file.flush
[457] Fix | Delete
File.rename(temp_filename, @filename)
[458] Fix | Delete
rescue
[459] Fix | Delete
File.unlink(temp_file) rescue nil
[460] Fix | Delete
raise
[461] Fix | Delete
ensure
[462] Fix | Delete
temp_file.close
[463] Fix | Delete
end
[464] Fix | Delete
end
[465] Fix | Delete
[466] Fix | Delete
def save_data_with_fast_strategy(data, file)
[467] Fix | Delete
file.rewind
[468] Fix | Delete
file.write(data)
[469] Fix | Delete
file.truncate(data.bytesize)
[470] Fix | Delete
end
[471] Fix | Delete
[472] Fix | Delete
[473] Fix | Delete
# This method is just a wrapped around Marshal.dump
[474] Fix | Delete
# to allow subclass overriding used in YAML::Store.
[475] Fix | Delete
def dump(table) # :nodoc:
[476] Fix | Delete
Marshal::dump(table)
[477] Fix | Delete
end
[478] Fix | Delete
[479] Fix | Delete
# This method is just a wrapped around Marshal.load.
[480] Fix | Delete
# to allow subclass overriding used in YAML::Store.
[481] Fix | Delete
def load(content) # :nodoc:
[482] Fix | Delete
Marshal::load(content)
[483] Fix | Delete
end
[484] Fix | Delete
[485] Fix | Delete
def empty_marshal_data
[486] Fix | Delete
EMPTY_MARSHAL_DATA
[487] Fix | Delete
end
[488] Fix | Delete
def empty_marshal_checksum
[489] Fix | Delete
EMPTY_MARSHAL_CHECKSUM
[490] Fix | Delete
end
[491] Fix | Delete
end
[492] Fix | Delete
[493] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function